assertText a message that has line break in Selenium IDE - selenium

I am new in Selenium IDE and need to assertText a value that has line break. Example:
Actual Message to assertText:
Hello
World
store | Hello <br/> World | txtValue
assertText | id=label | ${txtValue}
Please help.

Pass your id=label into a variable, remove the line breaks, then run an assertion against the variable.
Store expected text:
store | Hello World | txtValue
Store page text:
storeText | xpath=(//*[#id=label]) | labelValue
Remove line breaks from page text:
echo | javascript{storedVars.labelValue = storedVars.labelValue.replace(/(\r\n|\n|\r)/gm,"")} |
Assert your expected text = your page text:
assertExpression | javascript{storedVars.txtValue==storedVars.labelValue} | true

Following pattern matching worked for me on Selenium IDE 2.5.0
regexp:Hello\s+World

Related

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}.

Running RobotFramework Tests on Sauce Labs - error with timing out

I have existing selenium tests written in Robot IDE Framework that I'm trying to run in Sauce Labs.
I'm using the sample test from this tutorial to see if I can get at least one test running. http://datakurre.pandala.org/2014/03/cross-browser-selenium-testing-with.html
The test passes locally, and passes all the tests on Sauce Labs, but then times out and gives and error, "Test did not see a new command for 90 seconds. Timing out.
error" because it's not disconnecting Remote Web Driver.
I've tried all of these, together and separately at the end of the "Close test browser" function:
Close all browsers
Process close
Stop selenium server
I've also tried adding ((RemoteWebDriver) getCurrentWebDriver()).quit() in one of the python functions that runs during the closing process. I'm new to Selenium and Robot Framework, so I'm not sure how to grab the Remote Web Driver.
Here is the code, in case that helps:
*** Settings ***
Test Setup Open test browser
Test Teardown Close test browser
Resource ../../Keywords/super.txt
Library Selenium2Library
Library ../../Library/SauceLabs.py
*** Variables ***
${LOGIN_FAIL_MSG} Incorrect username or password.
${COMMAND_EXECUTOR} http://username:key#ondemand.saucelabs.com:80/wd/hub
${REMOTE_URL} http://username:key#ondemand.saucelabs.com:80/wd/hub
${DESIRED_CAPABILITIES} username:name,access-key:key,name:Testing RobotFramework,platform:Windows 8.1,version:26,browserName:CHROME,javascriptEnabled:True
*** Test Cases ***
Incorrect username or password
[Tags] Login
Go to https://saucelabs.com/login
Page should contain element id=username
Page should contain element id=password
Input text id=username anonymous
Input text id=password secret
Click button id=submit
Page should contain ${LOGIN_FAIL_MSG}
[Teardown]
*** Keywords ***
Open test browser
Open browser http://www.google.com ${BROWSER} \ remote_url=${REMOTE_URL} desired_capabilities=${DESIRED_CAPABILITIES}
Close test browser
Run keyword if '${REMOTE_URL}' != '' Report Sauce status ${SUITE_NAME} | ${TEST_NAME} ${TEST_STATUS} ${TEST_TAGS} ${REMOTE_URL}
Close all browsers
Process close
Stop selenium server
You shouldn't need to do anything special to close down the connection. My guess is, there's something in your test that is preventing the browser from being closed. My recommendation is to start with a simpler example, and start from the command line. Get that working, and then work your way up to being able to run something more complex from within RIDE.
Here is a working example where I removed all of the extra stuff in the test. I am able to run this both from the command line and via RIDE on Windows. You'll have to add in your own key, however:
*** Settings ***
| Library | Selenium2Library
*** Variables ***
| #{_tmp}
| ... | name:Testing RobotFramework Selenium2Library,
| ... | browserName:internet explorer,
| ... | platform:Windows 8,
| ... | version:10
| ${CAPABILITIES} | ${EMPTY.join(${_tmp})}
| ${KEY} | <put your username:key here>
| ${REMOTE_URL} | http://${KEY}#ondemand.saucelabs.com:80/wd/hub
| ${URL} | https://saucelabs.com/login
| ${LOGIN_FAIL_MSG} | Incorrect username or password.
*** Test cases ***
| Example of connecting to saucelabs via robot
| | [Setup]
| | ... | Open Browser
| | ... | ${URL}
| | ... | remote_url=${REMOTE_URL}
| | ... | desired_capabilities=${CAPABILITIES}
| |
| | Page should contain element | id=username
| | Page should contain element | id=password
| |
| | Input text | id=username | anonymous
| | Input text | id=password | secret
| | Click button | id=submit
| |
| | Page should contain | ${LOGIN_FAIL_MSG}
| |
| | [Teardown] | Close all browsers

"-" character is converted to ? in console for gherkin language used in cucumber feature file

I am using cucumber feature file to execute or write my test cases. Issue is that I am using data table as :
| abc | 1234567890 |
| defg | New Activation – Monthly (Credit in store) |
Now issue is this that console is throwing an error that :
Cannot locate element with text: New Activation ? Monthly (Credit in store).
I am not able to understand why ? is being displayed instead of "–" .

How to verify that my link title attribute has specified value?

I have a link somewhere on my page, let say like this
my link label
How to verify, that my link title attribute has 'my title message' value?
Assertattribute command use to verify it, please check this code.
assertattribute | title = my title message#href | http://example.com
assertattribute | link=my link label#href | http://example.com
From Selenium IDE use this:
command | target | value
-------------------------------------------------------------
assertAttribute | link=my link label#title | my title message
try like this.
command: verifyTitle
target: my title message
this command will compare the actual page title with the text given in the command target if both is same no error will show other wise error will display
Thank You...

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.