Parsing URL for querystring values with Selenium IDE

╄→гoц情女王★ 提交于 2019-12-05 21:35:56

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 
Ram

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&amp;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']&gt;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']&gt;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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!