Hi All,
I’m trying to implement a code where during a test case,
IF an Element A appears then stop/fail the test case, if not continue with the test case.
i’m using below code. however, it doens’t seem to work.
${textPresence} Wait Until Page Contains Element ‘id’
Run Keyword If ‘${textPresence}’ == ‘True’ Wait Until Page Contains ‘text’ timeout=2700s
Any help is appreciated.
Thanks in advance.
Hi Vinay,
Many libraries have some form of a should not
keyword (e.g. Element Should Not Be Visible from SeleniumLibrary)
If the library you’re using doesn’t have that then you can use the BuiltIn Run Keyword And Expect Error to inverse the logic of any keyword you have.
Hope that helps,
Dave.
Hey Dave,
Thanks for the reply.
I’m using selenium library and have those keywords.
However, in my case the process loads from 1% to 100%. It always doesn’t complete 100 %. sometimes it fails at 4% or 8% and an error is displayed. so I need the test case to fail if an error is displayed within a certain time frame. If not, then conutinue with the test case until it reaches 100%.
to give you clear picture. without the error element i’m using i had below code which work fine as long as the page loads up to 100%
Wait Until Page Contains 100% timeout=3000s
but i want to add a code before this which checks if an error is displayed on the page, then fail/stop the test case.
Hi Vinay,
Then use Run Keyword And Expect Error
as I mentioned like this:
first you need the locator for the error message, replace ${ErrorMessage}
in my example with the real locator
Run Keyword And Expect Error Wait Until Page Contains ${ErrorMessage} timeout=1500s
Wait Until Page Contains 100% timeout=3000s
-
If the error message shows on the screen within the timeout the first Wait Until Page Contains
will pass, but as we expect it to fail Run Keyword And Expect Error
will then fail and the test will stop
-
If the error message doesn’t show on the screen within the timeout the first Wait Until Page Contains
will fail, but as we expected it to fail Run Keyword And Expect Error
will then pass and continue to the second Wait Until Page Contains
Dave.
Hey Dave,
I tried to implement the first code ‘run keyword and expect error’. however, when i do that it’s not allowing me to add ‘wait until page contains’ as you mentioned above.
instead it is asking for below.
Hi Vinay,
Yeah I missed that, just use a *
to match any error
Run Keyword And Expect Error * Wait Until Page Contains ${ErrorMessage} timeout=1500s
Wait Until Page Contains 100% timeout=3000s
Unless you want to restrict it to a specific error.
Dave.
1 Like