I use Selenium IDE to test some webpage content.
My problem is: I have a test case with several 'clickAndWait' instructions on different links. Some links are missing on the webpage. My test case stops at the first missing link. I need my test case to be executed entirely even if a link is missing.
Example:
open | myurl.com |
clickAndWait | mainLink |
clickAndWait | minorLink1 |
verifyTextPresent | text1 |
clickAndWait | mainLink |
clickAndWait | minorLink2 |
verifyTextPresent | text2 |
clickAndWait | mainLink |
clickAndWait | minorLink3 |
verifyTextPresent | text3 |
The problem is, if minorLink1 does not exist, the whole test case is stopped, but I need minorLink2 and minorLink3 to be tested.
Does anyone can help me?
Thanks by advance,
Thomas.
Within the IDE you will not be able to run this as one test if you want it to continue, as the IDE simply follows the instruction order and has to stop when an instruction breaks. You could separate these into separate tests within the IDE, or you could move the operation to one of the supported environments like Java or C#, where you could write logic to avoid a full stop.
You could use loops which I have found to be very effective with ever changing lists where data can start on page one but end up on any page.
Or you could use gotoif command which would look something like this:
<tr>
<td>storeElementPresent</td>
<td>${category_header_obj}</td>
<td>present</td>
</tr>
<tr>
<td>gotoIf</td>
<td>storedVars['present']==false</td>
<td>exit</td>
</tr>
<tr>
<td>verifyText</td>
<td>${category_header_obj}</td>
<td>Categories</td>
</tr>
<tr>
<td>Label</td>
<td></td>
<td>exit</td>
</tr>
Related
I had written a Selenium command via IDE by implementing gotoIf
when the statement is true it jumps to the label but while the statement if false it is not going to the desired label
I have attached the command and log as well
You just need to make sure the code you want to execute if "home" is found is inside your gotoIf statement. It should look like below
gotoIf | ${test}==true | A
click | css=a.aits-log-out
label | A
Remove label | B as your gotoIf statement isn't looking for that label because you haven't defined it.
Code to copy paste if you want that as well
<tr>
<td>gotoIf</td>
<td>${test} == true</td>
<td>A</td>
</tr>
<tr>
<td>click</td>
<td>css=a.aits-log-out</td>
<td></td>
</tr>
<tr>
<td>label</td>
<td>A</td>
<td></td>
</tr>
I´m testing web page and i need to assert code fragment in javascript code, such as
<script type="text/javascript" src="//img.xxxx.com/u/14/p42449.js"></script>
<script type="text/javascript">
window.ptag_params = {
zone: "homepage",
customerId: "Your customer ID",
siteType: "Site Type",
};
</script>
I´ve tried use
<tr>
<td>verifyHtmlSource</td>
<td>*42449*</td>
<td></td>
</tr>
but I don´t see any response, in log only
[info] Executing: |verifyHtmlSource | *42449* | |
What am i doing wrong???
The selenium command you've used there isn't really the best for what you're trying to do. All that will do is check that somewhere within the entire html of the page, the number 42449 appears, doesn't guarantee it will find it in the script fragment you want to see it in. in regards to the logs, you won't see any more output than you have in the log with a verify command because it will just pass or fail depending on if it finds that number.
If you need to confirm this element exists and would like to see some output containing it in the logs your best bet would be a combination of verifyelement and storelement Example below
Script
<tr>
<td>verifyAttribute</td>
<td>css=script#src</td>
<td>*42449.js</td>
</tr>
<tr>
<td>storeAttribute</td>
<td>css=script#src</td>
<td>source</td>
</tr>
<tr>
<td>echo</td>
<td>${source}</td>
<td></td>
</tr>
Log Output
[info] Playing test case Untitled
[info] Executing: |verifyAttribute | css=script#src | *42449.js |
[info] Executing: |storeAttribute | css=script#src | source |
[info] Executing: |echo | ${source} | |
[info] echo: //img.xxxx.com/u/14/p42449.js
[info] Test case passed
The only thing you'd need to be careful with is if you have multiple script tags on your page, you'd just need to amend the locator with an nth value if it's the second or third script etc.
Finally, i´ve used
<tr>
<td>storeHtmlSource</td>
<td>buscaPixelesVen</td>
<td></td>
</tr>
<tr>
<td>verifyEval</td>
<td>javascript{storedVars['buscaPixelesVen'].indexOf("42449",0)>0}</td>
<td>true</td>
</tr>
and it works. Maybe is not the best solution, but is enough.
Thanks in any case
Code above looks good but since it's not based on css it shouldn't matter with order.
<tr>
<td>verifyElementPresent</td>
<td>//script[contains(#src, 'p42449.js')]</td>
<td>*ga.js</td>
</tr>
<tr>
<td>storeAttribute</td>
<td>//script[contains(#src, 'p42449.js')]#src</td>
<td>source</td>
</tr>
<tr>
<td>echo</td>
<td>${source}</td>
<td></td>
</tr>
I have a webpage which contains an iframe such as this
<iframe src="iframe_src" style="border: none" scrolling="no" id="id_frame" width="100%" frameborder="0" height="1850">...</iframe>
I'm trying to storeText the iframe src attribute, but executing the following command won't do the trick:
storeText //iframe[#id='id_frame']//#src frame_src
I expect frame_src to be equal to "iframe_src"
How can I do it?
Thanks!
I expect frame_src to be equal to "iframe_src"
First off, storeText will store the innerHTML of your target. What you want, is the storeAttribute command, however we can simplify it using the verifyAttribute command.
Command | Target | Value
============================================================
verifyAttribute | //iframe[#id='id_frame']#src | frame_src
I need to click on the button automatically. Code:
<tr>
<td>click</td>
<td>css=button</td>
<td></td>
When I click "Play current test case" it does not finds the element. But when I click "Find" after that - it does, and if I click Execute - it clicks on it!
Log:
[info] Executing: |click | css=div.sometag > p | |
[info] Executing: |pause | | 2000 | // Same error with pause & without it
[info] Executing: |clickAndWait | css=button | | // Auto executing
[error] Element css=button not found // Fails
[info] Executing: |click | css=button | | // I click on "Execute" manually - OK!
Why?
Have you tried to insert "waitForElementPresent|css=button|" before the click statement? This might help.
You actually need to use the class selector. So either div.button or .button, otherwise selenium probably is looking for an ID or an element name.
You could also try using a different type of locator, such as ID or XPath.
If we were able to see the HTML of the page you are interacting with, we could provide exact examples.
I'm new to integration testing, but have had great success so far buiding up a suite of tests using Se:IDE. As I've been running my tests, it has occurred to me that I'm generating a substantial amount of data and I'd like to clean up after myself.
Most of my tests involve creating a new 'page', and the id is available in the querystring. I'd like to have Se:IDE store a querystring value and pass it to another page that calls a delete method to tidy up after I have run my verifications.
I see that I can use the command storeLocation, but I'm not sure how I would go about parsing that value for the id in the querystring, and then pass it to another page using Open.
Have I reached the point where I need to migrate my tests to c#, or is this possible using the IDE?
If you keep all your test cases inside the same test suite. They can share variables between executions without problems.
So, all you have to do is to store the desired value:
storeLocation | variable | |
and in a future test, you have to use the variable as the following:
open | ${variable} | |
Note: for more info on test suites, take a look at:
http://seleniumhq.org/docs/03_selenium_ide.html#writing-a-test-suite
Update:
You can now use javascript regular expressions to get a substring from a variable:
storeEval | reg = /substring pattern/;reg.exec(${variable}) | substring
open | ${substring} | |
Example:
store | "012la4la" | a
storeEval | re = /[0-3]*la/;re.exec(${a}) | new
echo | ${new} |
output:
[info] echo: 012la
I had a similar issue at work, and this Q&A blog helped me out a lot. In my case, I had to strip query string parameters from an aspx URL, and verify their existence.
And I used a 2 stage filter approach for verification
(1) storeLocation, storeEval and verifyExpression.
(2) verifyHTMLsource and globbing the string
<tr>
<td>verifyLocation</td>
<td>http://qa.clockstock.com/confirmation.aspx?exrc=90210&csrc=</td>
<td></td>
</tr>
<tr>
<td>storeLocation</td>
<td>urlconf</td>
<td></td>
</tr>
<tr>
<td>echo</td>
<td>${urlconf}</td>
<td></td>
</tr>
<tr>
<td>storeEval</td>
<td>storedVars['urlconf'].indexOf('exrc=90210');</td>
<td>exrcurlconf</td>
</tr>
<tr>
<td>verifyExpression</td>
<td>javascript{(storedVars['CIDurlconf']>0)}</td>
<td>true</td>
</tr>
<tr>
<td>storeEval</td>
<td>storedVars['urlconf'].indexOf('csrc=');</td>
<td>CSRCurlconf</td>
</tr>
<tr>
<td>verifyExpression</td>
<td>javascript{(storedVars['CSRCurlconf']>0)}</td>
<td>true</td>
</tr>
<tr>
<td>verifyHtmlSource</td>
<td>glob:*confirmation.aspx*exrc=90210*csrc=*</td>
<td></td>
</tr>
A quick example for extracting an id parameter from a query string would be:
storeLocation | myLocation
store | javascript{ storedVars['myLocation'].substring(storedVars['myLocation'].indexOf('id=')+3, storedVars['myLocation'].length); } | idValue
This assumes that the id parameter is the last in the query string. If it's not then you might be best splitting the location on '&' and looping through the resulting array for the 'id' parameter value.