Is an else statement in robot framework? - selenium

I am running the following keyword in the robot framework:
Welcome Page Should Be Open
Run Keyword If '${BROWSER}' == 'IE' Location Should Be ${LOGIN URL IE}
Run Keyword If '${BROWSER}' != 'IE' Location Should Be ${LOGIN URL}
Wait Until Page Contains Accounts 5s
Page Should Contain Accounts
Instead of having 2 Run Keyword If statements I was wondering if robot has a else statement that could be used or and OR statement that could be used?
Cheers

Starting with version 2.7.4 of robot framework you can use ELSE when calling Run keyword if.
From the documentation:
Starting from Robot version 2.7.4, this keyword supports also optional
ELSE and ELSE IF branches. Both of these are defined in *args and must
use exactly format ELSE or ELSE IF, respectively. ELSE branches must
contain first the name of the keyword to execute and then its possible
arguments. ELSE IF branches must first contain a condition, like the
first argument to this keyword, and then the keyword to execute and
its possible arguments. It is possible to have ELSE branch after ELSE
IF and to have multiple ELSE IF branches.
For example (for clarity I'm using the pipe separated format and continuation features):
| | Run Keyword If | '${BROWSER}' == 'IE'
| | ... | Location should be | ${LOGIN URL IE}
| | ... | ELSE
| | ... | Location should be | ${LOGIN_URL}

Related

Selenium IDE Chrome - Regex

I am trying to get Selenium IDE to check some text and make sure it is Numbers Only, I have created the below (using Google) and it seems to fail each time.
Error :
assertText on css=tbody > tr:nth-child(1) > td:nth-child(1) with value regexpi:^[0-9]+$ Failed:
09:44:54
Actual value "10640355" did not match "regexpi:^[0-9]+$"
enter image description here
Can anyone tell me what I need to change, or have a step by step guide on how to add this check properly
https://www.selenium.dev/selenium-ide/docs/en/api/commands#assert-text
Regex is not supported for assert text:
https://github.com/SeleniumHQ/selenium-ide/issues/141 for details.
Workaround:
screenshot
code:
store text | css=tbody > tr:nth-child(1) > td:nth-child(1) | actualText
execute script | return RegExp('^[0-9]+$','g').test(${actualText}) | isNumber
assert | isNumber | true

Chrome Selenium IDE 3.4.5 extension "execute script" command not storing as variable

I am trying to create a random number generator:
Command | Tgt | Val |
store | tom | tester
store | dominic | envr
execute script | Math.floor(Math.random()*11111); | number
type | id=XXX | ${tester}.${dominic}.${number}
Expected result:
tom.dominic.0 <-- random number
Instead I get this:
tom.dominic.${number}
I looked thru all the resources and it seems the recent selenium update/version has changed the approach and I cannot find a solution.
I realize this question is 2 years old, but it's a fairly common one, so I'll answer it and see if there are other answers that address it.
If you want to assign the result of a script run by the "execute script" in Selenium IDE to a Selenium variable, you have to return the value from JavaScript. So instead of
execute script | Math.floor(Math.random()*11111); | number
you need
execute script | return Math.floor(Math.random()*11111); | number
Also, in your final assignment that puts the 3 pieces together, you needed ${envr} instead of ${dominic}.

How can I compare two stored texts in Selenium IDE?

How can I compare two stored texts and if they are equal to echo some result?
You can use the verifyEval command to compare two variables:
store | text | i
store | different text | j
verifyEval | storedVars['i']==storedVars['j'] | true
Running this script as written will cause the test to fail with [error] Actual value 'false' did not match 'true'. Change j to text, and it will complete without error.
Note that this can also be used to verify that two strings are not equal, by changing true to false in the verifyEval command.
As of 3.17 IDE for Chrome:
Command Target Value
assert variableX ${variableY}
IMPORANT: the target does NOT need ${}...or you'll get a null

Selenium IDE - verify content of Cookie

Does anyone know how I would go about verifying that a cookie value contains a text substring in Selenium IDE?
e.g. if I had a cookie called 'MyCookie' which had as its contents 'This is my value', and I wanted to assert that the cookie contained the substring 'value', is this possible using the IDE?
Update
Solution is as follows
storeCookieByName | MyCookie | variable1
storeEval | storedVars['variable1'].indexOf('value') > 0 ? true: false|result;
verifyExpression | $(result) | true
In selenium ide storeCookieByName(name, variableName) function return the value of cookies, in this function you provide only cookies name in target column and write any variable in value column
Command | Target | value
storeCookieByName | mf_user | test
echo | ${test}
name - the name of the cookie.
storeCookieByName function Returns: the value of the cookie
In the IDE use the storeCookieByName function providing the cookie name and the variable name you want the value to store the cookie into.

Selenium IDE regex gives error "Threw an exception: missing ) after argument list"

In my test case I am trying to capture the dynamic state id from the url of current web page.
My Selenium IDE code is:
storeLocation | myLocation
echo | ${myLocation}
myLocation returns https://stage.abcx.com/ui/States/ManageTitle.ddx? action=view&stateid=76702
storeEval | re=/^sid/;re.exec(${myLocation}) | new
echo | ${new}
The error I keep getting is
[error] Threw an exception: missing ) after argument list
I have searched the net to find what's wrong with my code but could not figure out the issue.
Am new to Selenium and regex would appreciate any help.
Thanks!
You can try to replace
storeEval | re=/^sid/;re.exec(${myLocation}) | new
with:
storeEval | /\\d*$/.exec(storedVars['myLocation']) | new
new will contain all last digits from myLocation. Some info about the difference between ${x} and storedVars['x'] can be found here.