Idea+maven+testNG+Selenium+ReportNG自动化框架搭建
1、Idea创建一个空的Maven项目



创建后默认项目目录如图所示

2、配置pom.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>selenium-zhtx</groupId>
<artifactId>rosa-zhtx</artifactId>
<version>1.0-SNAPSHOT</version> <!-- maven 运行测试name -->
<name>test</name>
<url>http://maven.apache.org</url> <!-- maven 引用远程库 -->
<repositories>
<repository>
<id>java-net</id>
<url>http://download.java.net/maven/2</url>
</repository>
</repositories>
<!-- maven 参数配置,这里引用不同的testng.xml -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<xmlFileName>testNG.xml</xmlFileName>
</properties> <dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.9</version>
</dependency>
<dependency>
<groupId>org.uncommons</groupId>
<artifactId>reportng</artifactId>
<version>1.1.4</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>velocity</groupId>
<artifactId>velocity-dep</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>2.46.0</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>2.46.0</version>
</dependency> <dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-htmlunit-driver</artifactId>
<version>2.46.0</version>
</dependency> <dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>2.46.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
</dependencies> <build>
<plugins> <!-- 添加插件 关联testNg.xml --> <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>res/${xmlFileName}</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<!-- 添加插件,添加ReportNg的监听器,修改最后的TestNg的报告 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<properties>
<property>
<name>usedefaultlisteners</name>
<value>false</value>
</property>
<property>
<name>listener</name>
<value>org.uncommons.reportng.HTMLReporter,
org.uncommons.reportng.JUnitXMLReporter</value>
</property>
</properties>
<workingDirectory>target/</workingDirectory>
<forkMode>always</forkMode>
</configuration>
</plugin>
</plugins>
</build> </project>
pom.xml
3、创建testNG.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="false">
<test name="Test"> <!--classes>
<class name="">
<methods>
<include name="*" />
</methods>
</class>
</classes-->
<packages>
<package name="com.zhtx.autocase"/>
</packages>
</test>
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter" />
<listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
</listeners>
</suite>
testNG.xml

4、编写测试类testZhtx,Strings
package com.zhtx.autocase; import java.util.Iterator;
import com.rosa.selenium.Strings;
import org.openqa.selenium.By;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.io.File;
import java.io.IOException;
import java.util.Set;
import java.util.concurrent.TimeUnit;
public class testZhtx {
WebDriver driver;
Strings zhtx=new Strings();
@BeforeMethod
public void setUp(){
//设置驱动位置
System.setProperty("webdriver.firefox.marionette","D:\\libs\\geckodriver.exe");
System.setProperty("webdriver.firefox.bin","D:\\Program Files\\Mozilla Firefox\\firefox.exe");
//声明firebug等插件位置
// File fpath=new File("D:\\libs\\firebug-2.0.18b1.xpi");
// File fbug=new File("D:\\libs\\firepath-0.9.7-fx.xpi");
driver=new FirefoxDriver();//声明用户信息后,声明驱动方法中要引用该profile
//最大化窗口
driver.manage().window().maximize();
driver.get(zhtx.getCsurl());
}
@AfterMethod
public void tearDown(){
driver.quit();
}
@Test
public void login(){
WebDriver newWindow;
String current_Handles=driver.getWindowHandle();
driver.findElement(By.xpath(".//*[@id='myform']/div/div[2]/div/div[1]/ul/li[1]/input")).clear();
driver.findElement(By.xpath(".//*[@id='myform']/div/div[2]/div/div[1]/ul/li[1]/input")).sendKeys(zhtx.getLoginname());
WebElement pwd=driver.findElement(By.xpath(".//*[@id='myform']/div/div[2]/div/div[1]/ul/li[2]/input"));
pwd.clear();
pwd.sendKeys(zhtx.getLoginpassword());
driver.findElement(By.xpath(".//*[@id='btn_login']")).click();
Set<String>all_handles=driver.getWindowHandles();
Iterator<String> it=all_handles.iterator();
while (it.hasNext()){
String sonHandle=it.next();
if(current_Handles==sonHandle)continue;
WebDriver window=driver.switchTo().window(sonHandle);
}
}
}
testZhtx
package com.rosa.selenium; /**
* Created by Administrator on 2017/7/6.
*/
public class Strings {
//public String url="https://passport.cnblogs.com/user/signin?ReturnUrl=%2F";
String csurl="http://cs.ccoop.cn";
String url="http://www.baidu.com";
public String loginname="*****";
public String loginpassword="****";
public String ghsNameKey="****"; public String getCsurl(){
return csurl;
}
public void setCsurl(){
this.csurl=csurl;
}
public String getUrl(){
return url;
}
public void setUrl(String url){
this.url=url;
}
public String getLoginname(){
return loginname;
}
public void setLoginname(){
this.loginname=loginname;
}
public String getLoginpassword(){
return loginpassword;
}
public void setLoginpassword(){
this.loginpassword=loginpassword;
}
public String getGhsNameKey(){
return ghsNameKey;
}
public void setGhsNameKey(){
this.ghsNameKey=ghsNameKey;
}
}
Strings

5、配置运行文件



6、创建test-output文件夹,存放测试报告
7、build项目
8、运行测试类

执行结果如图所示

也可以进入test-output目录查看html结果

Idea+maven+testNG+Selenium+ReportNG自动化框架搭建的更多相关文章
- 基于Python3.7 Robot Framework自动化框架搭建
一.Robot Framework 和 Selenium 的区别(面试常问) 主流自动化测试框架有Robot Framework 和 Selenium,请根据实际场景选用不同的框架,以下总结各自优缺点 ...
- UI自动化框架搭建之Python3
UI自动化框架搭建--unittest 使用的代码是Python3版本,与时俱进哈哈 解释一下我的框架目录接口(每个人框架的目录接口不一样,根据实际要求) common目录:公共模块,这个地方可以存放 ...
- Jmeter+ant+Jenkins接口自动化框架搭建
摘自:https://testerhome.com/topics/13389 一.背景 上一篇讲了Jmeter 接口自动化-脚本数据分离实例,我们知道怎么利用Jmeter去编写接口自动化脚本,但是接 ...
- IDEA+Java:Selenium+Maven+TestNG基本WebUI自动化测试环境搭建
IDEA+java:Selenium+Maven+TestNG 本文介绍的测试环境,应该是最基本的测试环境了,也是很多文章都有写,这里做一个完整的图文配置整理,方便阅读理解! 使用maven的好处,由 ...
- Appium TestNg Maven Android Eclipse java自动化环境搭建
1.环境准备 1)Eclipse + maven + appium + TestNg 确保已经在Eclipse 上面安装maven TestNg的插件 2)打开Eclipse,新建一个maven项目 ...
- 3分钟手把手带你搭建基于selenium的自动化框架
1 .什么是seleniumSelenium 是一个基于浏览器的自动化工具,它提供了一种跨平台.跨浏览器的端到端的web自动化解决方案.Selenium主要包括三部分:Selenium IDE.Sel ...
- Selenium+Java完整框架搭建(2019完整版)
一.WebDriver框架开发实战 1.框架的思想 (1)什么是框架? 框架是可以被应用开发者定制的应用骨架 (2)为什么要写框架? 提高脚本可维护性 提高编写脚本的速度 提高脚本可阅读性 (3)框架 ...
- selenium+testN自动化测试框架搭建
自动化测试框架搭建 1 Java环境的搭建 1.1访问oracle的官网下载最新版本的jdk http://www.oracle.com/technetwork/java/javase/downloa ...
- Web自动化框架搭建——前言
1.web测试功能特性 a.功能逻辑测试(功能测试),这一块所有系统都是一致的,比如数据的添加.删除.修改:功能测试案例设计感兴趣和有时间的话可以另外专题探讨: b.浏览器兼容性测试,更重要的是体验这 ...
随机推荐
- paramiko实现上传目录
使用paramiko上传目录,重点是上传的那个过程,想了一上午才想出来,可能有点奇葩,但是还是实现了这个功能 #!/usr/bin/python import paramiko import os d ...
- linux中telnet后退出连接窗口的方法?
linux中telnet后退出连接窗口 [root@a cron]# telnet www.baidu.com 80Trying 115.239.211.112...Connected to www. ...
- 知识图谱实战开发案例剖析-番外篇(1)- Neo4j是否支持按照边权重加粗和大数量展示
一.前言 本文是<知识图谱实战开发案例完全剖析>系列文章和网易云视频课程的番外篇,主要记录学员在知识图谱等相关内容的学习 过程中,提出的共性问题进行展开讨论.该部分内容原始内容记录在网易云 ...
- globals和locals的区别
Python的两个内置函数,locals 和globals,它们提供了基于字典的访问局部和全局变量的方式. 1.locals()是只读的.globals()不是.这里说的只读,是值对于原有变量的只读. ...
- Java 泛型的作用及其基本概念
一.泛型的基本概念 java与c#一样,都存在泛型的概念,及类型的参数化.java中的泛型是在jdk5.0后出现的,但是java中的泛型与C#中的泛型是有本质区别的,首先从集合类型上来说,java 中 ...
- seleniuim面试题1
seleniuim面试题1 乙醇 创建于 4 个月 之前 最后更新时间 2018-09-11 selenium中如何判断元素是否存在? selenium中没有提供原生的方法判断元素是否存在,一般我们可 ...
- MySQL视图-(视图创建,修改,删除,查看,更新数据)
视图是一种虚拟存在的表,对于使用视图的用户来说基本上是透明的.视图并不在数据库中实际存在,行和列数据来自定义视图的查询总使用的表,并且是在使用视图时动态生成的. 视图相对于普通表的优势: 简单:使用视 ...
- AlexNet实践
注释: CNN使用TF搭建比较简单,就像Hough检测使用CV很简单一样.但是怎么使用CNN去做一些实际操作,或者说怎么使用现有的方法进行慢慢改进,这是一个很大的问题! 直接跟着书本或者视频学习有点膨 ...
- MSB8013
解决方案: 去掉勾选
- itextsharp图片生成pdf模糊问题解释
I forget to mention that I' am using itextsharp 5.0.2. It turned out that PDF DPI = 110, which means ...