How to check if an condition is true in protractor? - if-statement

I want to show message based on the following condition. But it's not working. Can anyone help me in this regard.
if(errorMsg.isDisplayed()==='false'){
console.log('valid');
}else{
console.log('invalid');
};

You do not need to check that the errorMsg.isDisplayed method is false. You can simply do
if(errorMsg.isDisplayed()){
console.log('valid');
}else{
console.log('invalid');
};
This is provided that the isDisplayed() method works for the element that you have in question.

I found the solution. Here is the code:
errorMsg.isPresent().then(function(result) {
if (result) {
console.log('Invalid');
} else {
console.log('Valid');
}
});

Related

How can I get a simple bixby Action to work with refresh?

I have this action it its model file HandlQuestionTimeOut.model.bxb :
action (HandleQuestionTimeOut)
{
type(Calculation)
description (Handles Question Time Out.)
collect
{
input (message)
{
type (core.Text)
min (Required) max (One)
}
}
output (core.Text)
}
This in HandleQuestionTimeOut.js
var console = require("console");
module.exports.function = function handleQuestionTimeOut (message)
{
console.log("handleQuestionTimeOut -> message: " + message);
return message;
}
This in the quiz.endpoints.bxb inside the endpoints bracket:
action-endpoint (HandleQuestionTimeOut)
{
accepted-inputs (message)
local-endpoint (HandleQuestionTimeOut.js)
}
I am trying to call that action with refresh like this:
input-view
{
match: Answer(this)
{
to-input: UpdateQuiz(action)
}
refresh
{
if(true)
{
spec
{
delay-seconds (3)
with-request
{
intent
{
goal {HandleQuestionTimeOut}
value: core.Text(Timeout)
}
}
}
}
}
// code continues...
Can you please tell what am I doing wrong? I don't get that HandleQuestionTimeOut log in the console.
Can you clarify you questions?
Though I noticed something, based on my personal opinion:
1) correct module.exports.function -> module.export.function
2) In the refresh section I think you need to specify condition for 'true' or is it there for debugging purpose?
I've just verified that this issue is fixed in 20B SDK release.
Please refer the release notes for details about other changes.

Pocketsphinx returns empty string for hypothesis

I'm using pocketshpinx for speech recognition in a custom C++ application. I noticed that sometimes the hypothesis string returned by the ps_get_hyp() method is an empty string.
Question: Is this an expected behaviour? If so, is there a way to tell pocketsphinx to not give the empty string as a hypothesis?
Following is a snippet of the relevant portion of my code:
do { ReadAudioBuffer(); } while (!in_speech);
while (in_speech) { ReadAudioBuffer(); }
ps_end_utt(ps);
hyp = ps_get_hyp(ps, NULL);
The ReadAudioBuffer() method:
void SpeechRecognizer::ReadAudioBuffer()
{
if ((k = ad_read(ad, adbuf, 2048)) < 0)
{
UE_LOG(LogTemp, Warning, TEXT("Failed to read audio\n"));
return;
}
ps_process_raw(ps, adbuf, k, FALSE, FALSE);
in_speech = ps_get_in_speech(ps);
FPlatformProcess::Sleep(0.005);
}
Question: Is this an expected behaviour?
There is nothing wrong with it
If so, is there a way to tell pocketsphinx to not give the empty string as a hypothesis?
If you said nothing what should be returned then?
FPlatformProcess::Sleep(0.005);
Sleep is not really needed here

How to check whether given email address is invalid in action script 3?

I need to check whether given email address is invalid in action script. Following is the code/regex i came up with.
private function isEmailInvalid(email:String):Boolean
{
var pattern:RegExp = /(\w|[_.\-])+#((\w|-)+\.)+\w{2,4}+/;
var result:Object = pattern.exec(email);
if(result == null) {
return true;
}
return false;
}
But it seems like above code do not cover all the test cases in the following link:
http://blogs.msdn.com/b/testing123/archive/2009/02/05/email-address-test-cases.aspx
Does anyone have better way of doing this?
Folowing are the tested valid emails i used (above function should return "false" for these):
firstname.lastname#domain.com
firstname+lastname#domain.com
email#domain.co.jp
Folowing are the invalid ones (so function should return "true" for these):
email#domain#domain.com
.email#domain.com
email..email#domain.com
plainaddress, email#domain..com
Remove the + at the last and you must need to put anchors.
^(\w|[_.\-])+#((\w|-)+\.)+\w{2,4}$
Simplified one,
^[\w_.-]+#([\w-]+\.)+\w{2,4}$
DEMO
Try this RegExp :
RegExp = /\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*/;

Groovy/Grails: Declaring a JsonBuilder inside a loop without overwriting previously generated jsons

Hello I am trying to create a list of json objects in groovy
List relClinicStatementList = []
for (BloodTestRow row in BTList){
def jsonListBuilder = new groovy.json.JsonBuilder()
def internalJson = jsonListBuilder{
'targetRelationshipToSource' {
'code' 'part-of'
'codeSystem' 'MG'
}
'observationResult'{
'observationFocus'{
'code' "${row.exam}"
'codeSystem' 'mobiguide'
'displayName' "${row.exam}"
}
'observationValue' {
'physicalQuantity' {
'value' "${row.value}"
'unit' "${row.unit}"
}
}
}
}
println jsonListBuilder.toPrettyString()
relClinicStatementList.add(internalJson)
}
And the toPrettyString() method correctly shows the json structure I want.
However if at the end of the loop I try to print all of the items I have in the list like this:
for (JsonBuilder entry in relClinicStatementList){
println entry.toPrettyString()
}
I get all the elements inside my relClinicalStatement list to be equal to the latest I created... I felt like declaring a new JsonBuilder at each loop would prevent this behaviour... am I missing something? I must admit I come from Java and have the feeling that using groovy classes here makes this behave a little differently from what I expect.
How do I solve this issue?
Thanks in advance
I can't reproduce the behaviour you are seeing, but I think the problem is that I don't believe internalJson is what you think it is (it's a list of 2 closures).
If you change your code to:
List relClinicStatementList = btList.collect { row ->
new groovy.json.JsonBuilder( {
targetRelationshipToSource {
code 'part-of'
codeSystem 'MG'
}
observationResult {
observationFocus {
code "$row.exam"
codeSystem 'mobiguide'
displayName "$row.exam"
}
observationValue {
physicalQuantity {
value "$row.value"
unit "$row.unit"
}
}
}
} )
}
relClinicStatementList.each { entry ->
println entry.toPrettyString()
}
Does it work as you'd expect?

How to wait for a promise to be fulfilled before continuing

How can I wait until a Promise is resolved before executing the next line of code?
e.g.
var option = null;
if(mustHaveOption){
option = store.find("option", 1).then(function(option){ return option })
}
//wait until promise is resolved before returning this value
return option;
rallrall provided the correct answer in his comment: you can't
The solution for me was to redesign my code to return promises and then the receiving function must evaluate the result something along the lines of:
function a(){
var option = null;
return mustHaveOption ? store.find("option", 1) : false;
}
}
function b(){
res = a();
if (!res){
res.then(function(option){
// see option here
});
}
}
Another key solution for me was to use a hash of promises. One creates an array of all the promises that must be resolve before executing the next code:
Em.RSVP.Promise.all(arrayOfPromises).then(function(results){
//code that must be executed only after all of the promises in arrayOfPromises is resolved
});
It tooks me a while to wrap my head around this async way of programming - but once I did things work quite nicely.
With ES6, you can now use the async/await syntax. It makes the code much more readable:
async getSomeOption() {
var option = null;
if (mustHaveOption) {
option = await store.find("option", 1)
}
}
return option;
PS: this code could be simplified, but I'd rather keep it close from the example given above.
You can start to show a loading gif, then you can subscribe to the didLoad event for the record, inside which you can continue your actual processing..
record = App.User.find(1);
//show gif..
record.on("didLoad", function() {
console.log("ren loaded!");
});
//end gif; continue processing..