Selenium+TestNG+ReportNG Demo

来源:互联网 发布:西安天互数据业绩 编辑:程序博客网 时间:2024/04/29 02:00
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. 所有的测试用例执行完后会生成更加直观的报告







0 0
原创粉丝点击