如果是:多个测试类 只使用同一个浏览器,同一个driver对象, 或者同一个页面的对象,
只需要:
1. 创建一个基本的测试类(BaseTest),具有一个公共静态的driver属性, public static WebDriver driver
2. 给BaseTest类一个@Test(groups={"functionTests","checkinTests"})方法,
3. BaseTest类中创建@beforeTest,@afterTest注解的方法, 不要创建@Test注解的方法,
4. 其实,如果是PageObject设计模式,每个页面的对象创建也可以放在基础类BaseTest中,
5. 其他的测试类继承这个基本的测试类BaseTest, 此时,所有的测试类就具有了一个共同的唯一的" driver ", 页面对象句柄。
6. 给其他类中的方法也加上@Test(groups={"functionTests","checkinTests"})的注解,注解根据需要来设置。
7. 当前也可以在其他类的类上声明@Test(groups={"functionTests","checkinTests"})注解。
8. 如果某个测试类中有多个@Test注解的方法,则需要指定所有类中方法的执行顺序,而不是单个类中的,priority=0,开始
9. 经过实验,发现每个测试类执行都是从默认的priority=0开始,
如果只指定一个类中的测试方法的顺序,此时一起执行全部测试类时,不会按照类的顺序进行执行,而是会按照默认的priority来执行
由于每个测试中的测试方法默认的priority=0,所以testng会先将priority=0的方法执行完毕后,才会执行priority=1,2,3...

基础测试类

@Test(groups={"functionTests","checkinTests"})
public class BaseTest {
public static WebDriver driver; @BeforeTest
public void before(){
System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.sogou.com/");
} @AfterTest
public void after() throws Exception{
Thread.sleep(2000);
driver.close();
driver.quit();
}
}

测试类

@Test(groups={"functionTests","checkinTests"})
public class TEST2 extends BaseTest{ @Test(priority=0)
public void TWO1(){
System.out.println("TWO1");
driver.findElement(By.className("sec-input")).sendKeys("testTWO--1--"); }
@Test(priority=1)
public void TWO2(){
System.out.println("TWO2");
driver.findElement(By.className("sec-input")).sendKeys("testTWO--2--"); }
@Test(priority=2)
public void TWO3(){
System.out.println("TWO3");
driver.findElement(By.className("sec-input")).sendKeys("testTWO--3--"); }
}

测试类

public class TEST3 extends BaseTest{

    @Test(groups={"functionTests","checkinTests"},priority=3)
public void THREE(){
System.out.println("33333333333333333");
driver.findElement(By.className("sec-input")).sendKeys("testTHREE----"); }
}

测试类

public class TEST4 extends BaseTest{

    @Test(groups={"functionTests","checkinTests"},priority=4)
public void FOUR(){
System.out.println("444444444");
driver.findElement(By.className("sec-input")).sendKeys("testFOUR----"); }
}

testng.xml文件配置如下

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="classes" thread-count="1"> <test verbose="10" preserve-order="true" name="TestDebug">
<groups>
<run>
<exclude name="brokenTests" />
<include name="functionTests" />
</run>
</groups> <classes>
<class name = "com.test.ztest.Test.TEST2"/>
<class name = "com.test.ztest.Test.TEST3"/>
<class name = "com.test.ztest.Test.TEST4"/> </classes> </test> <!-- Test -->
</suite> <!-- Suite -->

分享完成,如有更好的方法,请不令赐教。

最新文章

  1. Linux常用命令操作
  2. Javascript学习笔记
  3. Ubuntu 安装 CLI 并运行 ASP.NET Core 1.0
  4. ArcGIS Javascript查询数据库并添加到地图上
  5. jquery总结03-遍历节点
  6. Android 连接webservice(利用谷歌提供的jar包)
  7. linux中使用top获取进程的资源占用信息
  8. jquery 源码剖析1
  9. SQL SERVER中的流程控制语句
  10. 编译器神vim改头换面
  11. ●BZOJ 1855 [Scoi2010]股票交易
  12. Android监听自身卸载,弹出用户反馈调查
  13. java http post/get 服务端和客户端实现json传输
  14. MVC设计模式的简单理解
  15. python之路day02--格式化输出、初始编码、运算符
  16. MySQL Limit优化(转)
  17. form表单的提交方式
  18. nginx 、springMvc(非分布式)相应的限流、消峰
  19. 【BZOJ4552】【TJOI2016】【HEOI2016】排序
  20. JVM gc介绍

热门文章

  1. c#Message多功能用法
  2. 给xcode项目修改名字
  3. java for循环
  4. 64位Win10系统安装Mysql5.7.11
  5. 历年NOIP中的搜索题
  6. 关于Mongo的一些坑
  7. MySQL oracle 分页
  8. 狙杀ES6之开光篇
  9. Linux Redis自动启动,Redis开机启动,Linux Redis设置开机启动
  10. PHP闭包和高阶函数