Parsing URL for querystring values with Selenium IDE - selenium

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.

Related

Selenium check for gotoif when statement is false

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>

Find string from javascript code with selenium IDE

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>

Select a particular characters from an element in selenium ide

exact:Hardcover: $79.99
This was the total element. I need to get only the value $79.99.
store / exact:Hardcover: $79.99 /i storeEval
/storedVars['i'].search($79.99) /result
I have tried the above one but it is not working.
Best thing to do here would be to store the full element, and then break it down with a regex.
So to mirror your example here:
<tr>
<td>store</td>
<td>exact:Hardcover: $79.99</td>
<td>full</td>
</tr>
<tr>
<td>storeEval</td>
<td>storedVars['full'].match(/[^: ]+$/)</td>
<td>price</td>
</tr>
<tr>
<td>echo</td>
<td>${price}</td>
<td></td>
</tr>
Which gives the following output
[info] Playing test case Untitled
[info] Executing: |store | exact:Hardcover: $79.99 | full |
[info] Executing: |storeEval | storedVars['full'].match(/[^: ]+$/) | price |
[info] script is: storedVars['full'].match(/[^: ]+$/)
[info] Executing: |echo | ${price} | |
[info] echo: $79.99
[info] Test case passed
For info on how the regex is broken down refer here

Getting value from div which contains exact string using Selenium IDE

I am trying to get a value from a nested div in a web page using Selenium IDE where class names are repeated but contain unique strings, such as the structure below, but am having no luck.
<div class='ClassName'>
<div class="col_Num">1 </div>
<div class="col_Val">5.00 </div>
</div>
<div class='ClassName'>
<div class="col_Num">2 </div>
<div class="col_Val">2.00 </div>
</div>
How do I get the value of 'Col_Val' from only the div that contains "col_Num = 1"? (the value 5.00 should be returned and saved to a variable)
Thanks,
J
From your question, it seems that you want to be able to store the column value based on the number you input. The best way to do this would be
<tr>
<td>storeText</td>
<td>css=div:contains("1")+[class=col_Val]</td>
<td>value</td>
</tr>
Which will store the column value located immediately after the div containing the value you input (in this case 1)
In Selenium IDE enter as: Command | Target | Value
storeText | //div[#class='col_Num' and contains(text(), '1')]/following-sibling::div | value
echo | ${value}
Output is:
[info] Executing: |storeText | //div[#class='col_Num' and contains(text(), '1')]/following-sibling::div | value |
[info] Executing: |echo | ${value} | |
[info] echo: 5.00
[info] Test case passed

Selenium IDE: Selenium script execution stops at the first missing link

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>