导入testng管理测试用例
1.在pom.xml中增加testng的依赖,以导入testNG
2.在src-main-resources目录下新建xml文件,比如untitled.xml.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="testSuite1">
<test name="UITest">
<classes>
<class name="testcase.TestNG" />
<class name="testcase.testNG2" />
<class name="testcase.testNG1" />
</classes> </test>
</suite>
3.BeforeTest AfterTest BeforeClass AfterClass的区别
BeforeTest AfterTest
case1:
package testcase; import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; public class testNG3 {
@BeforeTest
public void setup(){System.out.println("case3:set up");}
@Test
public void test1(){System.out.println("case3");}
@AfterTest
public void tearup(){System.out.println("case3:tear down");}
}
case2:
package testcase; import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; public class testNG4 {
@BeforeTest
public void setup(){System.out.println("case4:set up");}
@Test
public void test1(){System.out.println("case4");}
@AfterTest
public void tearup(){System.out.println("case4:tear down");}
}
xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="testSuite1">
<test name="UITest">
<classes>
<!--<class name="testcase.TestNG" />
<class name="testcase.testNG2" />
<class name="testcase.testNG1" />-->
<class name="testcase.testNG3"/>
<class name="testcase.testNG4"/>
</classes> </test>
</suite>
执行结果:
将BeforeTest替换为BeforeClass,AfterTest替换为AfterClass
case1:
package testcase; import org.testng.annotations.*; public class testNG3 {
@BeforeClass
public void setup(){System.out.println("case3:set up");}
@Test
public void test1(){System.out.println("case3");}
@AfterClass
public void tearup(){System.out.println("case3:tear down");}
}
case2:
package testcase; import org.testng.annotations.*; public class testNG4 {
@BeforeClass
public void setup(){System.out.println("case4:set up");}
@Test
public void test1(){System.out.println("case4");}
@AfterClass
public void tearup(){System.out.println("case4:tear down");}
}
xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="testSuite1">
<test name="UITest">
<classes>
<!--<class name="testcase.TestNG" />
<class name="testcase.testNG2" />
<class name="testcase.testNG1" />-->
<class name="testcase.testNG3"/>
<class name="testcase.testNG4"/>
</classes> </test>
</suite>
执行结果:
4.使用TestNg增加断言
package testcase;
import org.testng.Assert;
import org.testng.annotations.*;
public class testNG3 {
@BeforeClass
public void setup(){System.out.println("case3:set up");}
@Test
public void test1(){
System.out.println("case3");
String actureMessage="abc";
String expectMessage="efg";
Assert.assertTrue(actureMessage.equalsIgnoreCase(expectMessage),"Expect message is "+expectMessage+".But acture message is "+actureMessage);
}
@AfterClass
public void tearup(){System.out.println("case3:tear down");}
}
将expectMessage修改为abc,结果为
5.编写基于TestNg的测试用例
Baidu.java
package testcase; import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import java.util.concurrent.TimeUnit;
public class Baidu {
private WebDriver driver;
@BeforeTest
public void setUp(){
String chromepath = System.getProperty("user.dir")+"/src/main/java/drivers/chromedriver";
System.setProperty("webdriver.chrome.driver",chromepath);
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
}
@Test
public void test(){
driver.get("https://www.baidu.com");
driver.findElement(By.xpath("//input[@class='s_ipt' and @id='kw']")).sendKeys("selenium");
driver.findElement(By.xpath("//input[@id='su']")).click();
System.out.println(driver.findElement(By.xpath("//span[@class='nums_text']")).getText()); }
@AfterTest
public void tearDown(){
driver.quit();
}
}
test.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="testSuite1">
<test name="UITest">
<classes>
<class name="testcase.Baidu" />
</classes> </test>
</suite>
测试结果:
导入testng管理测试用例的更多相关文章
- JAE京东云引擎Git上传管理代码教程和京东云数据库导入导出管理
文章目录 Git管理准备工作 Git工具上传代码 发布代码装程序 mywebsql管理 京东云引擎小结 JAE京东云引擎是京东推出的支持Java.Ruby.Python.PHP.Node.js多语 ...
- Webdriver+Testng实现测试用例失败自动截图功能
testng执行测试用例的时候,如果用例执行失败会自动截图,方便后续排查问题 1.首先定义一个截图类: package com.rrx.utils; import java.io.File;impor ...
- 【框架】用excel管理测试用例需要的参数数据(二)
一.总体思路 以类为excel名,测试方法名为sheet名,建立excel文件.用jxl包里的方法去读取excel文件里的内容,然后用testng里的dataprovider,将数据传递给测试用例 二 ...
- [Xcode 实际操作]一、博主领进门-(3)使用资源文件夹(Assets.xcassets)导入并管理图片素材
目录:[Swift]Xcode实际操作 本文将演示如何使用资源文件夹(Assets.xcassets)导入并管理图片素材. [Assets.xcassets]资源文件夹可以方便的进行图片的管理, 在读 ...
- excel+requests管理测试用例接口自动化框架
背景: 某项目有多个接口,之前使用的unittest框架来管理测试用例,将每个接口的用例封装成一个py文件,接口有数据或者字段变动后,需要去每个py文件中找出变动的接口测试用例,维护起来不方便,为了便 ...
- Jenkins+SVN+Maven+testNG管理项目
1.登录访问:http://localhost:8080/jenkins 2.系统管理 => 全局工具配置 => ADD JDK AND Add Maven 3.安装SVN插件:系统管 ...
- Robotium测试套管理测试用例
前提:已写好测试用例 新建个测试套MyTestSuite管理你需要跑的测试用例,或者将相同功能的测试用例归纳到一个测试套中 package com.robotium.test.testsuite; i ...
- TestNG执行测试用例的顺序
import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebEle ...
- TestNG设置测试用例执行优先级
@Test(priority = x)设置测试用例执行优先级.x默认为0,0的优先级最高,0>1>2>3... import org.testng.annotations.Test; ...
随机推荐
- 配置total commander 显示所有或特定文件夹 (带点的文件夹)
在配置|忽略列表 下可以添加或删除需要隐藏的文件夹通配符.
- WebGL编程指南案例解析之3D视图视区问题
var VSHADER_SOURCE = 'attribute vec4 a_Position;\n' + 'attribute vec4 a_Color;\n' + 'uniform mat4 u_ ...
- 类似select下拉选择框同时又支持手动输入的元素 datalist 介绍。
有时候我们会有这样的需求,通过使用下拉菜单给用户一定的选择范围,同时又可以使用户在找不到选择项的时候手动输入.这个时候我们就需要用到html5的datalist属性了. datalist包含<o ...
- HDU 4240
http://acm.hdu.edu.cn/showproblem.php?pid=4240 题意:求最大流和流量最大的一条路径的流量的比值 题解:流量最大的路径的流量在dinic的dfs每次搜到终点 ...
- Linux服务器没有GUI的情况下使用matplotlib绘图
最近看到关于 python3 中用matplotlib 不进行交互画图,而是直接将图保存到硬盘,主要的一个设置就是 matplotlib.use('agg') 注明: 其实不设置 matplotl ...
- C程序第四次作业
作业要求一 实践最简答的项目wordcount,必须完成其中的基本功能,若可以完成其他功能给予加分.完成后请将你的设计思路.主要代码写在本次作业博客里. 设计思路: 第一步:定义文件型指针变量fp,整 ...
- TJU Problem 2857 Digit Sorting
原题: 2857. Digit Sorting Time Limit: 1.0 Seconds Memory Limit: 65536KTotal Runs: 3234 Accepted ...
- utf-8编码的csv文件,用excel打开乱码,解决办法,在输出前加 0xEF,0xBB,0xBF三个char
转自 http://blog.csdn.net/zcmssd/article/details/6086649 是由于输出的CSV文件中没有BOM. 什么是BOM? 在UCS 编码中有一个叫做”ZERO ...
- Python的学习之-计算机编码和二进制
bit位,计算机中最小的表示单位 8bit = 1bytes字节,最小的储存单位,1bytes缩写为1b 1KB = 1024B 1MB = 1024KB 1GB = 1024MB 1TB = 102 ...
- 【洛谷P1338】末日的传说
https://www.luogu.org/problemnew/show/P1338 [题目大意:从1到n的连续自然数,求其逆序对数为m的一个字母序最小的排列.] 最开始的思路是想从逆序对数入手,然 ...