TestNG 运行Webdriver测试用例

发表于:2018-9-13 11:23

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:蓝冰lanbing    来源:博客园

  1.单击选中的新建工程的名称,按Ctrl+N组合键,弹出对话框选择"TestNG"下的"TestNG class"选项,点击“next”
   
  2.如下图填写完成后,点击“Finish”
   
  3.eclipse会自动生成如下代码:
  package cn.gloryroad;
  import org.testng.annotations.Test;
  import org.testng.annotations.BeforeMethod;
  import org.testng.annotations.AfterMethod;
  public class FirstTestNGDemo {
  @Test
  public void f() {
  }
  @BeforeMethod
  public void beforeMethod() {
  }
  @AfterMethod
  public void afterMethod() {
  }
  }
  4.补充测试用例后,脚本如下:
  package cn.gloryroad;
  import java.sql.Driver;
  import org.openqa.selenium.By;
  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.firefox.FirefoxDriver;
  import org.testng.annotations.Test;
  import org.testng.annotations.BeforeMethod;
  import org.testng.annotations.AfterMethod;
  public class FirstTestNGDemo {
  public WebDriver driver;
  String baseUrl= "http://baidu.com/";
  @Test
  public void test() {
  driver.get(baseUrl+'/');
  driver.findElement(By.id("kw")).sendKeys("selenium");
  driver.findElement(By.id("su")).click();
  }
  @BeforeMethod
  public void beforeMethod() {
  System.setProperty("webdriver.firefox.bin", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
  driver = new FirefoxDriver();
  }
  @AfterMethod
  public void afterMethod() {
  driver.quit();
  }
  }
 

  5.运用testNG运行脚本,运行结果如下:
   
  6.testNG也会输出HTML格式的测试报告,访问工程目录下的“test-output”目录下
   
   上文内容不用于商业目的,如涉及知识产权问题,请权利人联系博为峰小编(021-64471599-8017),我们将立即处理。

《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号