Selenium+TestNG+ReportNG Demo

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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值