51Testing软件测试论坛

标题: seleninum + testNG + reportNG在Windows7搭建自动化测试环境 [打印本页]

作者: 测试积点老人    时间: 2018-11-29 15:00
标题: seleninum + testNG + reportNG在Windows7搭建自动化测试环境
Environment
1)OS:Window7 64bit
  1. OS 名称:          Microsoft Windows 7 旗舰版
  2. OS 版本:          6.1.7601 Service Pack 1 Build 7601
  3. OS 制造商:        Microsoft Corporation
复制代码
2)Eclipse:Oxygen Release (4.7.0)
3)java:1.8.0
  1. C:\Users\Administrator>java -version
  2. java version "1.8.0"
  3. Java(TM) SE Runtime Environment (build 1.8.0-b132)
  4. Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)
复制代码
3)Software:Subclipse, subversion for eclipse -- 代码管理
             selenium-server-standalone-2.53.0
             testNG6.12
             reportNG1.1.4

Deployment
1)下载并安装Eclipse
2)testNG插件:Help --> Eclipse Marketplace --> Search testNG: TestNG for Eclipse
3)reportNG插件:reportng-1.1.4.jar(http://www.grepcode.com/snapshot ... mons/reportng/1.1.4
4)新建Java测试项目:File --> New --> Java Project: seAuto
5)新建package:src --> testSuite: testSuite
6)新建testNG:File --> Other --> TestNG --> TestNG class
      Note: testNG具体说明,参考官方文档
7)引入testNG lib库
      此时提示“The import org.testng cannot be resolved”,需要引用testNG lib库
     Select Project --> Build Path --> Configure Build Path --> Libraries --> Add Library --> TestNG
8)验证testNG
      testSuite.xml --> Run As --> TestNG Suite
      此时会执行预设的测试,即testSuite.java中的标记为@test的测试 -- 参见,testSuite.java -- TestNG插件安装完毕
  1. [RemoteTestNG] detected TestNG version 6.12.0
  2. [TestNGContentHandler] [WARN] It is strongly recommended to add "<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >" at the top of your
  3.                               file, otherwise TestNG may fail or not work as expected.
  4. ===============================================
  5. Suite
  6. Total tests run: 2, Failures: 0, Skips: 0
  7. -
复制代码
使用reportNG插件
9)使用reporNG作为listeners: Window --> Preferences --> TestNG
10)testSuite.xml中注册reportNG
  1. <!-- add listener -->
  2. <listeners><listener class-name="org.uncommons.reportng.HTMLReporter"></listener></listeners>
复制代码
11)使用reportNG
        执行测试工:testSuite.xml --> Run As --> TestNG Suite,提示如下
  1. [RemoteTestNG] detected TestNG version 6.12.0
  2. org.testng.TestNGException:
  3. Listener org.uncommons.reportng.HTMLReporter was not found in project's classpath
  4.         at org.testng.TestNG.addListeners(TestNG.java:1009)
  5.         at org.testng.TestNG.initializeConfiguration(TestNG.java:976)
  6.         at org.testng.TestNG.initializeEverything(TestNG.java:1108)
  7.         at org.testng.remote.support.RemoteTestNG6_12.initialize(RemoteTestNG6_12.java:22)
  8.         at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:97)
  9.         at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
  10.         at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
复制代码
  1. 添加reportNG lib库
  2.     * Window --> Preferences --> Java --> Build Path --> User Libraries --> lib
  3.     * Select Project --> Build Path --> Configure Build Path --> Libraries --> Add Library --> User Library: reportng1.1.4.jar
  4. 12)验证reportNG
  5.     testSuite.xml --> Run As --> TestNG Suite
  6. [RemoteTestNG] detected TestNG version 6.12.0
  7. ===============================================
  8. Suite
  9. Total tests run: 2, Failures: 0, Skips: 0
  10. ===============================================
  11. 生成test-output目录,即reportNG报告
  12. Note: 在执行过程中会提示安装velocity 和 guice 插件,具体可参考Question 2

  13. 至此,Selenium + testNG + reportNG环境部署完成。
复制代码








欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2