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”目录下

TestNG 运行Webdriver测试用例的更多相关文章

  1. 持续集成:TestNG组织如何测试用例

    持续集成:TestNG组织如何测试用例   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣,请大家咨询qq:90 ...

  2. 持续集成:TestNG组织如何测试用例 1

    持续集成:TestNG组织如何测试用例   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣,请大家咨询qq:90 ...

  3. testng入门教程11 TestNG运行JUnit测试

    现在,您已经了解了TestNG和它的各种测试,如果现在担心如何重构现有的JUnit代码,那就没有必要,使用TestNG提供了一种方法,从JUnit和TestNG按照自己的节奏.也可以使用TestNG执 ...

  4. 使用testng.xml组织测试用例

    测试用例类TeseNG.java: import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.open ...

  5. Testng 运行Cannot find class in classpath

    用Testng运行多个class,结果报: org.testng.TestNGException: Cannot find class in classpath: Salesman     at or ...

  6. Python3.x:chrome运行webdriver脚本提示--ignore-certificate-errors

    Python3.x:chrome运行webdriver脚本提示--ignore-certificate-errors 1,分析原因: 根本原因是Chromedriver和Chrome的版本不兼容: 网 ...

  7. TestNG简单的学习-TestNG运行

    转载:http://topmanopensource.iteye.com/blog/1983735 TestNG简单的学习-TestNG运行 文档来自官方地址: http://testng.org/d ...

  8. 记录java+testng运行selenium(四)--- 运行代码

    涉及的文件有: .\medical\BusinessFile.java :实例化excel及xml文件操作对象以及将list变成Map .\medical\manual\business\LoginB ...

  9. testng入门教程1在testng运行一个简单的testcase

    在eclips运行java,创建一个Java类文件名TestNGSimpleTest  C:\ > TestNG_WORKSPACE import org.testng.annotations. ...

随机推荐

  1. 解决android studio no debuggable process

    这个问题可能是由多种因素造成的. 一.可能是buildtypes配置或选择错误,在对应module的build.gradle中确认如下配置 debug { debuggable true//一定要配置 ...

  2. 如何下载哔哩哔哩、爱奇艺、腾讯视频、优酷、斗鱼、TED、YouTube网页视频

    这里使用you-get工具进行下载 github地址:https://github.com/soimort/you-get/ github项目文档:https://github.com/soimort ...

  3. Hibernate使用distinct返回不重复的数据,使用group by 进行分组

    //distinct使用 public List<String> distinctDutyDate() { String hql="select distinct(dutyDat ...

  4. C++ 获取函数耗时

    C++ 记录耗时 #include <sys/timeb.h> #include <stdio.h> long long getSystemTime() { struct ti ...

  5. c++11之find 和 find_if 和 find_if_not 用法

    时刻提醒自己 Note: vector的释放 0.头文件 #include <algorithm> 1.区别 返回范围 [first, last) 中满足特定判别标准的首个元素: 函数 功 ...

  6. 【LeetCode】541. Reverse String II 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 题目地址:ht ...

  7. 【LeetCode】11. Container With Most Water 盛最多水的容器

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 个人公众号:负雪明烛 本文关键词:盛水,容器,题解,leetcode, 力扣,python ...

  8. 【LeetCode】77. Combinations 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:递归 方法二:回溯法 日期 题目地址:htt ...

  9. D. Ability To Convert

    http://codeforces.com/contest/758/problem/D D. Ability To Convert time limit per test 1 second memor ...

  10. 【剑指Offer】二叉搜索树的后序遍历序列 解题报告(Python)

    [剑指Offer]二叉搜索树的后序遍历序列 解题报告(Python) 标签(空格分隔): 剑指Offer 题目地址:https://www.nowcoder.com/ta/coding-intervi ...