[英]Selenium Webdriver test cases - Test cases not executing in an order
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. 我正在使用Selenium Web驱动程序来通过Maven测试我的Web测试用例,但是当我执行它们时,它们是以随机顺序执行的。 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
如果您是编写测试的新手,这应该会有所帮助
http://code.google.com/p/selenium/wiki/PageObjects http://code.google.com/p/selenium/wiki/PageObjects
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. 如果您使用的是jUnit或任何类似的框架,则不能依赖于以任何特定顺序执行的方法-至少不容易。 See for example How to run test methods in specific order in JUnit4?
例如,请参见如何在JUnit4中以特定顺序运行测试方法? for more information.
欲获得更多信息。 Up to Java 6 it used to work that way, but it was never guaranteed.
直到Java 6为止,它都是那样工作的,但从未保证过。 Java 7 breaks it.
Java 7打破了它。
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).
如果有通用的设置,那么我尝试将其纳入设置方法中(jUnit 4中的@ Before / @ BeforeClass)。
you can make a priority
for each test case. 您可以为每个测试用例设置
priority
。 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. 因此,将首先执行
test1
,然后再执行test2
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.