Variable Not Being Set

I have the following code:

String mytestvalue = 'N'
// check if it logged us in
if(WebUI.verifyTextPresent("Hello,", false,FailureHandling.CONTINUE_ON_FAILURE)){
mytestvalue = 'Y' //this never sets the value
}
mytestvalue = 'Y' //this sets the value

Even if the “if” statement resolves to true and the code sets mytestvalue = ‘Y’, it still isn’t getting set to ‘Y’.

However, on the following line where I set it (just for testing) it seems to set it fine.

Any ideas?

Are you sure that the case goes inside the if condition?

most probably the verifyTextPressent is never resolved to true, and that’s why the value settings it’s happening outside the block, unconditionally.

try to replace the condition with something like ‘if true { myValue = ‘Y’}’ and you will notice is working.

also you can put something like

println(WebUI.verifyTextPresent( blah blah))

before the if to check what is actually hapening

I think the root cause is the usage of a keyword as a condition for if.

got the feeling that is not returning a boolean, but an object, since the verification keyword is an assert, not just a condition.

you have to find a different way to use it in the if block, something like:

if (elementInPage.hasText(‘blah blah’)) {}

I will dig a bit later for a solution, not at the right PC right now

my bad, looks like indeed, the keyword is returning a boolean.
I made the following quick experiment:

WebUI.openBrowser('www.google.ro')
println(WebUI.verifyTextPresent('memento', false))
if (WebUI.verifyTextPresent('memento', false,FailureHandling.CONTINUE_ON_FAILURE)) {
println("I am inside if")
}
println("now i am outside if")

working as expected.

the problem may be just a typo, you are missing a space after ‘if’ (and after the condition too)

Ibus said:

my bad, looks like indeed, the keyword is returning a boolean.
I made the following quick experiment:

WebUI.openBrowser('www.google.ro')

println(WebUI.verifyTextPresent(‘memento’, false))
if (WebUI.verifyTextPresent(‘memento’, false,FailureHandling.CONTINUE_ON_FAILURE)) {
println(“I am inside if”)
}
println(“now i am outside if”)


working as expected.

the problem may be just a typo, you are missing a space after 'if' (and after the condition too)

  

Ok thanks. I will try this.