Selenium Test Runner 和变量问题
在我的硒测试套件(html)中,我定义了第一个测试用例来初始化下一个测试用例中调用的变量。
示例:
在第一个脚本中:
store|//div[@id="myfield"]|myvar
在我的第二个脚本中:
type|${myvar}|myvalue
但是当我启动测试运行程序(从 maven)时,它返回一个错误,告诉 ${myvar} 未找到 不使用存储的 var 中包含的值。
有什么建议吗?
非常感谢
In my selenium test suite (html), I define a first test case to initialize variable called in the next test case.
Sample :
In first script :
store|//div[@id="myfield"]|myvar
In my second script :
type|${myvar}|myvalue
But when I start test runner (from maven), it returns an error telling that ${myvar} is not found
The value contained in the stored var is not used.
Any suggestion ?
Thans a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
也许你可以使用cookie来存储变量?
createCookie 在 selenium 中,要读取它,您可以使用 javascrpt(getEval)
Maybe you could use cookies to store variable?
createCookie is in selenium and to read it you might use javascrpt(getEval)
据我所知,在运行 HTML 套件时不能引用在不同测试中声明的变量。
您需要的是测试和/或套件“安装”和“拆卸”功能。
测试设置和拆卸发生在每次测试之前和之后。套件设置和拆卸仅在套件运行之前和之后发生一次。
当您使用 Maven 时,我假设您的开发是用 Java 进行的,因此您可以使用 JUnit
http://www.junit .org/
这有测试和套件设置和拆卸:
测试设置
http://kentbeck.github.com/junit/javadoc/ latest/org/junit/Before.html
测试拆解
http://kentbeck.github.com/junit/javadoc/ latest/org/junit/After.html
套件设置
http://kentbeck.github.com/junit/javadoc/ latest/org/junit/BeforeClass.html
套件拆解
http://kentbeck.github.com/junit/javadoc/最新/org/junit/AfterClass.html
As far as I know you cannot reference variables declared in a different test when running HTML suites.
What you need is Test and/or Suite "Setup" and "Teardown" functionality.
Test setup and teardown happen before and after each test. Suite setup and teardown only happen once, before and after the suite is run.
As you are using Maven, I assume that your development is in Java, so you could use JUnit
http://www.junit.org/
This has both test and suite setup and teardown:
Test Setup
http://kentbeck.github.com/junit/javadoc/latest/org/junit/Before.html
Test Teardown
http://kentbeck.github.com/junit/javadoc/latest/org/junit/After.html
Suite Setup
http://kentbeck.github.com/junit/javadoc/latest/org/junit/BeforeClass.html
Suite Teardown
http://kentbeck.github.com/junit/javadoc/latest/org/junit/AfterClass.html
我在 Selenium IDE 中创建了单独的测试,然后将它们分批放入测试套件中
之后...当我运行它们时,测试 1 中存储的 ${variable_name} 在测试 2 中工作正常。
Damien
I've created separate tests in Selenium IDE and then batched them in a test suite
After that ... when I ran them, the ${variable_name} stored in test 1 works fine in test 2.
Damien
当前版本的 selenium 测试运行程序不会像 IDE 那样将变量从一个测试传递到另一个测试。有一个 javascript 解决方法,请查看 Nick G 的帖子 http://jira.openqa.org/浏览/SEL-605
The current version of selenium test runner doesn't pass variables from test to test like the IDE does. There is a javascript work around, check out Nick G's post on http://jira.openqa.org/browse/SEL-605