使用 Selenium IDE 解析查询字符串值的 URL
我是集成测试的新手,但到目前为止,我已经使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果将所有测试用例保留在同一个测试套件中。他们可以毫无问题地在执行之间共享变量。
因此,您所要做的就是存储所需的值:
并且在将来的测试中,您必须按如下方式使用该变量:
注意:有关测试套件的更多信息,请查看:
http://seleniumhq.org/docs/03_selenium_ide.html#writing- a-test-suite
更新:
您现在可以使用 JavaScript 正则表达式从变量中获取子字符串:
示例:
输出:
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:
and in a future test, you have to use the variable as the following:
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:
Example:
output:
我在工作中遇到了类似的问题,这个问答博客对我帮助很大。就我而言,我必须从 aspx URL 中删除查询字符串参数,并验证它们的存在。
我使用了 2 级过滤器方法进行验证
(1) storeLocation、storeEval 和 verifyExpression。
(2) verifyHTMLsource 并通配字符串
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
从查询字符串中提取 id 参数的一个简单示例是:
假设 id 参数是查询字符串中的最后一个。如果不是,那么您最好将位置拆分为“&”并循环遍历结果数组以获取“id”参数值。
A quick example for extracting an id parameter from a query string would be:
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.