Conditional state is not proper

Hi folks,

my test execution in a conditional statement (if) jumps into the block, even the given element is not visible. That shall not be the case…
The test is a login process with a for loop and should look like this (simplified):
For Loop (row <= TestData, row++) {
Enter E-Mail & Password → click “Login”
If "element is present “Login successful” {than proceed into the block where you click “my Account” and BREAK}
}

If the elemt is not present, the for loop starts again. But what happens is, that the system always says, the “Login successful” is present, even it is not.

My code segment:

for (def rowNum = 1; rowNum <= findTestData(‘Nutzer_und_Passwort’).getRowNumbers(); rowNum++) {
WebUI.clearText(findTestObject(‘Inputfields/input_Login_E-Mail’), FailureHandling.STOP_ON_FAILURE)

WebUI.clearText(findTestObject('Inputfields/input_Login_Passwort'), FailureHandling.STOP_ON_FAILURE)

WebUI.sendKeys(findTestObject('Inputfields/input_Login_E-Mail'), findTestData('Nutzer_und_Passwort').getValue(1, rowNum))

WebUI.sendKeys(findTestObject('Inputfields/input_Login_Passwort'), findTestData('Nutzer_und_Passwort').getValue(2, rowNum))

WebUI.click(findTestObject('Buttons/btn_Modal_Login'))

//Thread.sleep(700)
**if (WebUI.waitForElementNotVisible(findTestObject('Messages/div_Login_erfolgreich'), 1) == true)** {
    WebUI.waitForElementClickable(findTestObject('Buttons/btn_Startseite_Mein-Konto'), 6)

    WebUI.click(findTestObject('Buttons/btn_Mein-Konto_toggle'))

    WebUI.click(findTestObject('Buttons/btn_Startseite_Mein-Konto'), FailureHandling.STOP_ON_FAILURE)

    break
}

}

The Object’s property by attribute says:

//div[@id = ‘loginmessage’ and @class = ‘alert alert-success’ and (contains(text(), ‘Login erfolgreich. Bitte warten Sie…’) or contains(., ‘Login erfolgreich. Bitte warten Sie…’))]

Am i did something wrong or is that a bug? The test was working just fine but i haven’t executed it for a while (like ~1 to 1,5 months). I searched the HTML Code for the element and it is definetly not present. Please help.

Thanks in advance and kind regards,

M. Dietrich

Edit: When i rerun the rest from the beginning of the for loop, the test case will finish with a successful login…

you have multiple selectors enabled, uncheck the others and try again.

Just a note that an element MAY be present but not visible. There is a difference. You are correctly checking if the element is visible.

Another note is that your code in picture has WebUI.waitForElementVisible but your code that has been copied into forum has WebUI.waitForElementNotVisible.

Another note, you probably should not compare in the if statement against the WebUI.waitForElementVisible. I say this only because of the timing aspect–you may need to wait longer than you think. Instead compare against WebUI.verifyElementVisible. And you do not need to actually do the compare but only:

WebUI.waitForElementVisible(TO, 10)
if (WebUI.verifyElementVisible(TO)) {
“your steps here”
}

Both WebUI.waitForElementVisible and WebUI.verifyElementVisible return boolean values so use the return value of true to move into your if condition.

Will give it a try and come back here :+1:

Edit: I tried it only with the text and the test again states that the element is visible - even it is NOT visible… :thinking: Thanks for the idea.

Thanks for the reply. I tried multiple variants in order to make it work so that’s the reason why there are differences in the code and screenshot. I also tried to verify if the element is visible before the loop statement, but that’s not the case (see screenshot - the outcommented line).

I also must note that the element is NOT present and also NOT visible in the DOM when i manually search for it.
As you can see the return statement is true (boolean) and only when true is returned the test should jump into the if condition. But that’s not the case.
As i mentioned above: After the testcase stops due to a failure and i manually continue from the FOR loop it works just fine. So i think this is a bug, but i’m not sure about that. :thinking:

The login changes with each testrun, so the test must try each of the four combinations.
Here is a screenshot of the rerun after it fails. I just started at the point 26 (the FOR loop)

I think will be better to make the final decision by grabbing the text of the element (and locate it by id or other fail proof selector), not by simply checking if the element is there or not. looks like in both cases (success of failure) is same element but only the text is changing.
I think I faced such similar situation before, the element was generated by a JS … so in the DOM all the time were present both text’s, but only one was visible at a time.

Nope. The class is changing from alert.alert-danger to alert.alert-success. I already checked that. The text is also not present in the DOM until you successfully passed the login process.

Here is the code segment of the jquery.min.js

if(data.reload)
                    {
                        errorMessage.toggleClass("alert-danger");
                        errorMessage.toggleClass("alert-success");

And here is the element caught via breakpoints step-by-step:

The support didn’t react since 14 days now. I hope anyone of you can help. Any suggestions?

Hi @dietrich

Things are a bit confusing, so I am not entirely sure, but let me summarize. According to my understanding, you’re trying to verify the case where log-in fails which triggers the appearance of an element. To test this, you’re trying to verify if that element is visible in order to do subsequent actions. The problem is verifying element’s visibility seems to always pass even if the element is not visible.

Have you tried to eliminate the most obvious answer, which is the locator is selecting multiple elements ? What happens if you only use the class selector (i.e .alert-danger) for that element (please make sure that .alert-danger returns only one element in the Chrome Dev Tool.

Also, try to turn off Self-Healing (if you’re using KSE) to see how it goes. A possibility is that Self-Healing was triggered on waitForElementVisible which attempts fo find a working locator.

Hi @ThanhTo,

thank you for the reply. The WebUI.waitForElementVisible was working until the last one or two patches. If you can provide me with the info how to deactivate the self-healing feature via code line(s) it would be great since i really like the feature for the other elements/test cases.

The class .alert-danger returns all error messages possible on this page, so selecting it by the class or a combination of class & for example id wouldn’t be an unique identifier. The class .alert-success returns only the text

Login erfolgreich. Bitte warten Sie…

and turns the red background to a green background via CSS. So getting the color would also be a workaround, i guess. But the point is that there is a bug which needs to be identified and fixed. I also want to mention that the for loop will pass when i continue the test from the moment where the for loop begins.

@dietrich

Please click on Self-Healing icon on the toolbar, go to settings and add waitForElementVisible under the list of keywords to be excluded.

Regarding this, it is not clear to me that it is a bug. We have to be sure that with the same HTML structure, the same test script, the same execution condition, the recent version of Katalon exhibits this behavior while the earlier versions did not.

1 Like

@ThanhTo just ran it with KSE 7.5.5 and it was absolutely fine. I update to the most recent version which is 7.7.2 and i got the error again. So yeah. It is very likely a bug that needs to be adressed and fixed.
Excluding from self-healing was not successful.

As you can see: The first attempt to login successfully fails since the password is wrong. The “Login erfolgreich…” didn’t appear and the FOR loop continues from the beginng (clearing the textfield and enter the next email/password combination). Than it successfully detects the Element and continues with the testcase.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.