该脚本具有方法=并行。但它在任何给定时间只执行一种方法,并为另一种方法提供错误。
测试脚本:
<suite name="test suite" verbose="1" parallel="methods" thread-count="3">
<test name="test on FF">
<parameter name="platform" value="local" />
<parameter name="browser" value="firefox" />
<parameter name="version" value="13" />
<parameter name="login" value="test" />
<classes>
<class name="com.auto.tests.TitlesTests" >
<methods>
<include name="testCreateNewTitle" />
<exclude name="testCreateNewTitlesFolder" />
<include name="testCreateNewTitlesUsingAuto" />
</methods>
</class>
</classes>
BeforeClass、BeforeMethod、BeforeSuite 在一个脚本中,@Test selenium webdriver 测试在另一个脚本中。
Class A
@BeforeSuite
public void beforeSuite() throws Exception {
log.info("BeforeSuite");
}
@BeforeTest
public void beforeTest() throws Exception{
setupBrowser("Default test");
}
}
@BeforeClass
public void beforeClass() throws Exception {
if(loginMethod.equalsIgnoreCase("class")){
setupBrowser(this.getClass().getSimpleName());
}
}
@BeforeMethod
public void beforeMethod(Method method) throws Exception {
log.info("BeforeMethod");
if(loginMethod.equalsIgnoreCase("method")){
setupBrowser(method.getName());
}
}
class B extends A {
@Test
public void testCreateNewtitle(){
log.info("Create new title test case1 starts");
log.info("Create folder1 worked");
}
@Test
public void testCreateNewTitlesUsingAuto(){
log.info("Create new title test case2 starts");
log.info("Create folder2 worked");
}
}
testng output
[main] 0 INFO - BeforeSuite
[main] 14 INFO - BeforeTest
[main] 16562 INFO - Browser = firefox, Version = 13, Platform = local
[main] 22953 INFO - Authenticated. HTTP/1.1 302 Moved Temporarily
[main] 22954 INFO -
[pool-1-thread-1] 31981 INFO - BeforeClass
[pool-1-thread-2] 31988 INFO - BeforeMethod
[pool-1-thread-1] 31988 INFO - BeforeMethod
[pool-1-thread-1] 32005 INFO - Create new title test case1 starts
[pool-1-thread-2] 32011 INFO - Create new title test case2 starts
[pool-1-thread-2] 32079 ERROR -
[pool-1-thread-2] 32090 INFO - AfterMethod
[pool-1-thread-1] 32091 INFO - Create folder1 worked
[pool-1-thread-1] 59100 INFO - AfterMethod
[pool-1-thread-1] 59101 INFO - AfterClass
[main] 59103 INFO - AfterTest
[main] 59778 INFO - AfterSuite
java.lang.AssertionError: null
at org.testng.Assert.fail(Assert.java:89)
at org.testng.Assert.fail(Assert.java:96)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:715)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:907)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1237)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
谢谢