开发者

Selenium Test Runner and variables problem

开发者 https://www.devze.com 2022-12-31 20:16 出处:网络
In my selenium test suite (html), I define a first test case to initialize variable called in the next test case.

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 ma开发者_Go百科ven), 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


Maybe you could use cookies to store variable?

createCookie is in selenium and to read it you might use javascrpt(getEval)


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


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消