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.
Related
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
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}.
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}
3 security questions appearing on the screen like in random order like 1,3,2 or 2.1 and then 3:
Pets name? 2. City you were born? 3. School you attend?
Lets say that answer is a last word of each question. How to code it in Selenium ide. I guess to use GoToif, GotoLabel and StoreEval? Also, the answer should be stripped to one last word without space and "?"
You can store text or value in Selenium IDE.
The Command : storeText | storeValue (or storeAttribute if you want to stora an attribute of the element)
The Target must be a css or an xpath expression which can localize the appropriate element
The Value is the name of the new local variable in your Selenium IDE script
After using store command you can use your new variable like this: ${yourNewVariable}
For example:
storeAttribute xpath=//div[#id='name-day']#name nameday
echo ${nameday}
You can use while loop and goto function in selenium ide with this addon : https://addons.mozilla.org/en-us/firefox/addon/flow-control/
Some commands:
gotoif
while
gotolabel
Example:
store 1 answers
while storedVars.answers <= 3
echo ${answers}
...
store javascript{storedVars.answers++;}
endWhile
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