您的位置:首页 > 其它

Selenium+TestNG+ReportNG Demo

2015-12-01 16:30 441 查看
1.安装 TestNG 的eclipse插件
eclispe-->Help-->Install new software, 输入http://beust.com/eclipse
选中TestNG并且进行安装

2.新建一个Java工程,导入Selenium的jar包和TestNG的library
3.新建TestCase(注解是关键)
   
private WebDriver driver;
private String baseUrl;

@BeforeTest
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");
driver = new ChromeDriver();
baseUrl = "http://172.18.1.210";
}

@Test
public void testSeleniumIDE() throws Exception {
driver.get(baseUrl );
driver.findElement(By.id("logName")).clear();
driver.findElement(By.id("logName")).sendKeys("testtest");
driver.findElement(By.id("logPwd")).clear();
driver.findElement(By.id("logPwd")).sendKeys("1111111");
driver.findElement(By.id("loginBtn")).click();
driver.findElement(By.id("logPwd")).click();
driver.findElement(By.id("logPwd")).clear();
driver.findElement(By.id("logPwd")).sendKeys("111111");
driver.findElement(By.id("loginBtn")).click();
}

@AfterTest
public void tearDown() throws Exception {
driver.quit();
}


4.配置要跑的测试用例

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="com.cpms.testcase.Driver">
<test name="test12">
<classes>
<class name="com.cpms.testcase.CPMS001.Login" />
</classes>
</test>
</suite>


5.testng.xml,右键-->Run as TestNG Suite
6.运行结束后,刷新工程,会生成test-ouput文件夹,打开index.html就能看日志

ReportNG部分(Optional):

RepotNG部分(Optional,只为了能生成更加直观好看的报告):
1.    下载ReportNG相关包,并且加到build path

2.    配置Window--> Preferences-->TestNG

3. 所有的测试用例执行完后会生成更加直观的报告
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  selenium testng