TestNG 安装及使用入门(webDriver+java环境)
来源:互联网 发布:淘宝乐高霍比特人玩具 编辑:程序博客网 时间:2024/05/22 08:29
1、TestNG介绍
是java的一个测试框架,类似于JUnit,java中已经有一个JUnit的测试框架,测试人员用TestNG来写自动化测试,开发人员一般用JUnit写单元测试,其实TestNG也可以理解为Eclipse的一个插件。
TestNG的官方网站:http://testng.org/doc/index.html
2、TestNG的安装
两种方式可以安装TestNG 在Eclipse中
第一种:离线安装
TestNG 下载地址:http://testng.org/doc/download.html
从官网上下载的安装时老报错,所以从其他地方得到一个离线的安装包
分别将【features】文件夹下的文件放到eclipse的【features】目录下,将【org.testng.eclipse_6.8.6.20130607_0745】文件夹放在Eclipse的【plugins】目录下
然后从新启动Eclipse即可
验证安装是否成功
打开Eclipse工具,在“文件—新建—其它”结构下有【testNG】目录,如下图所示:
第二种:在线安装
选择菜单:help—install new software,然后在弹出的窗口中点击Add进行添加,如下图所示:
版本不同下载的网址不同,http://beust.com/eclipse1
3、使用testNG新建一个测试案例
3.1、新建一个testNG类,同时生成一个testNG.xml,如下图所示:
3.2、testNG类中测试代码如下:
import java.io.File;import org.openqa.selenium.WebDriver;import org.openqa.selenium.ie.InternetExplorerDriver;import org.testng.annotations.Test;public class testNG { @Test public void f() { File file =new File("C:/Program Files/Internet Explorer/IEDriverServer.exe");System.setProperty("webdriver.ie.driver",file.getAbsolutePath());WebDriver driver = new InternetExplorerDriver();driver.get("http://www.baidu.com");driver.quit(); }}
3.3、 testNG.xml 代码如下(会自动生成)
<?xml version="1.0" encoding="UTF-8"?><suite name="Suite" parallel="false"> <test name="Test"> <classes> <class name="selenium2.testNG"/> </classes> </test> <!-- Test --></suite> <!-- Suite -->
3.4、testNG中如何运行测试
第一种:直接执行
第二种,在testNG.xml中执行
运行testNG.xml ,结果如下所示:
信息: I/O exception (java.net.SocketException) caught when processing request: Software caused connection abort: recv failed2015-7-18 11:57:20 org.apache.http.impl.client.DefaultRequestDirector tryExecute信息: Retrying request===============================================SuiteTotal tests run: 1, Failures: 0, Skips: 0===============================================
3.5、运行多个案例时,修改testNG.xml,例如像同时运行【TestNGSimpleTest】和【testNG】这两个类,将testNG.xml修改如下图所示:
<?xml version="1.0" encoding="UTF-8"?><suite name="Suite" parallel="false"> <test name="Test"> <classes> <class name="selenium2.testNG"/> <class name="selenium2.TestNGSimpleTest"/> </classes> </test> <!-- Test --></suite> <!-- Suite -->
3.6、运行结果如下:
Listening on port 255722015-7-18 12:01:47 org.apache.http.impl.client.DefaultRequestDirector tryExecute信息: I/O exception (java.net.SocketException) caught when processing request: Software caused connection abort: recv failed2015-7-18 12:01:47 org.apache.http.impl.client.DefaultRequestDirector tryExecute信息: Retrying requestthis is testng test case===============================================SuiteTotal tests run: 2, Failures: 0, Skips: 0===============================================
3.7、报告运行完上面的操作后,在项目下会有个test.output文件夹,打开index.html可以看到一个简单的报告
- TestNG 安装及使用入门(webDriver+java环境)
- Selenium2(webdriver)入门之TestNG的安装与简单使用
- webdriver+java+maven+testng环境搭建
- 使用Webdriver+TestNG,设置FireFox安装路径。
- Testng + Webdriver 入门篇
- Eclipse中使用Maven配置WebDriver+TestNg自动化测试环境(一)
- Eclipse中使用Maven配置WebDriver+TestNg自动化测试环境(二)
- Ant+TestNG+Webdriver环境搭建
- selenium webdriver的testNG框架的介绍及使用
- Windows环境ProtocolBuffer安装及入门使用
- BlackBerry Java 开发环境安装及入门(一)
- BlackBerry Java 开发环境安装及入门(二)
- BlackBerry Java 开发环境安装及入门(三)
- TestNG环境设置(配置安装)
- TestNG环境配置(安装过程)
- WebDriver入门及提高
- webDriver入门及提高
- IDEA 单元测试testng入门及testng.xml
- WSDL详解
- C++智能指针
- error 0152: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.
- 算法导论中的数论算法(一)
- 卡片游戏
- TestNG 安装及使用入门(webDriver+java环境)
- leetcode 76: Minimum Window Substring
- 大数据爬虫实习面试题
- 欢迎使用CSDN-markdown编辑器
- Android:剖析源码,随心所欲控制Toast显示
- H264编码原理以及I帧B帧P帧
- 凸包初学(POJ1113)
- 银行储蓄系统
- 【bzoj1509】 NOI2003 逃学的小孩 树的直径