使用 Selenium IDE 解析查询字符串值的 URL

发布于 2024-08-04 00:11:44 字数 313 浏览 6 评论 0原文

我是集成测试的新手,但到目前为止,我已经使用 Se:IDE 构建了一套测试,取得了巨大的成功。当我运行测试时,我突然意识到我正在生成大量数据,并且我想自己清理。

我的大多数测试都涉及创建一个新的“页面”,并且 id 在查询字符串中可用。我想让 Se:IDE 存储一个查询字符串值并将其传递到另一个页面,该页面在运行验证后调用删除方法进行整理。

我看到我可以使用命令 storeLocation,但我不确定如何解析查询字符串中 id 的值,然后使用 Open 将其传递到另一个页面。

我是否已经到了需要将测试迁移到 C# 的地步,或者可以使用 IDE 实现这一点吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

红墙和绿瓦 2024-08-11 00:11:44

如果将所有测试用例保留在同一个测试套件中。他们可以毫无问题地在执行之间共享变量。
因此,您所要做的就是存储所需的值:

storeLocation | variable | |

并且在将来的测试中,您必须按如下方式使用该变量:

open | ${variable} | |

注意:有关测试套件的更多信息,请查看:
http://seleniumhq.org/docs/03_selenium_ide.html#writing- a-test-suite

更新:

您现在可以使用 JavaScript 正则表达式从变量中获取子字符串:

storeEval | reg = /substring pattern/;reg.exec(${variable}) | substring
open | ${substring} | |

示例

store | "012la4la" | a
storeEval | re = /[0-3]*la/;re.exec(${a}) | new
echo | ${new} | 

输出

[info] echo: 012la 

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 
长不大的小祸害 2024-08-11 00:11:44

我在工作中遇到了类似的问题,这个问答博客对我帮助很大。就我而言,我必须从 aspx URL 中删除查询字符串参数,并验证它们的存在。

我使用了 2 级过滤器方法进行验证
(1) storeLocation、storeEval 和 verifyExpression。
(2) verifyHTMLsource 并通配字符串

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

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>
葮薆情 2024-08-11 00:11:44

从查询字符串中提取 id 参数的一个简单示例是:

storeLocation | myLocation
store | javascript{ storedVars['myLocation'].substring(storedVars['myLocation'].indexOf('id=')+3, storedVars['myLocation'].length); } | idValue

假设 id 参数是查询字符串中的最后一个。如果不是,那么您最好将位置拆分为“&”并循环遍历结果数组以获取“id”参数值。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文