I am using selenium web driver to test my web test cases with maven, But when I am executing they are executed in random order. I have tried many examples but all is vain.It's increasing my headache.
Are you using some kind of pattern ? Best way would be to configure a test Suite that would run these individual tests ? If you are newbie to writing tests , this should help
If you are using jUnit or any similar framework, then you can not rely on methods being executed in any particular order - at least not easily. See for example How to run test methods in specific order in JUnit4? for more information. Up to Java 6 it used to work that way, but it was never guaranteed. Java 7 breaks it.
I try to not rely on execution order at all. This makes it easier to run individual tests and to restructure them. If there is common setup, then I try to factor it out into setup methods (@Before/@BeforeClass in jUnit 4).
you can make a priority
for each test case. so that for each test case the min priority means that it will be executed first.
For example:
@Test(priority = 0)
public void test1() {
// your code
}
@Test(priority = 1)
public void test2() {
// your code
}
So, test1
will be executed first, then test2
will be executed after it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.