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自动化框架搭建的更多相关文章

  1. 基于Python3.7 Robot Framework自动化框架搭建

    一.Robot Framework 和 Selenium 的区别(面试常问) 主流自动化测试框架有Robot Framework 和 Selenium,请根据实际场景选用不同的框架,以下总结各自优缺点 ...

  2. UI自动化框架搭建之Python3

    UI自动化框架搭建--unittest 使用的代码是Python3版本,与时俱进哈哈 解释一下我的框架目录接口(每个人框架的目录接口不一样,根据实际要求) common目录:公共模块,这个地方可以存放 ...

  3. Jmeter+ant+Jenkins接口自动化框架搭建

    摘自:https://testerhome.com/topics/13389 一.背景  上一篇讲了Jmeter 接口自动化-脚本数据分离实例,我们知道怎么利用Jmeter去编写接口自动化脚本,但是接 ...

  4. IDEA+Java:Selenium+Maven+TestNG基本WebUI自动化测试环境搭建

    IDEA+java:Selenium+Maven+TestNG 本文介绍的测试环境,应该是最基本的测试环境了,也是很多文章都有写,这里做一个完整的图文配置整理,方便阅读理解! 使用maven的好处,由 ...

  5. Appium TestNg Maven Android Eclipse java自动化环境搭建

    1.环境准备 1)Eclipse + maven + appium + TestNg 确保已经在Eclipse 上面安装maven TestNg的插件 2)打开Eclipse,新建一个maven项目 ...

  6. 3分钟手把手带你搭建基于selenium的自动化框架

    1 .什么是seleniumSelenium 是一个基于浏览器的自动化工具,它提供了一种跨平台.跨浏览器的端到端的web自动化解决方案.Selenium主要包括三部分:Selenium IDE.Sel ...

  7. Selenium+Java完整框架搭建(2019完整版)

    一.WebDriver框架开发实战 1.框架的思想 (1)什么是框架? 框架是可以被应用开发者定制的应用骨架 (2)为什么要写框架? 提高脚本可维护性 提高编写脚本的速度 提高脚本可阅读性 (3)框架 ...

  8. selenium+testN自动化测试框架搭建

    自动化测试框架搭建 1 Java环境的搭建 1.1访问oracle的官网下载最新版本的jdk http://www.oracle.com/technetwork/java/javase/downloa ...

  9. Web自动化框架搭建——前言

    1.web测试功能特性 a.功能逻辑测试(功能测试),这一块所有系统都是一致的,比如数据的添加.删除.修改:功能测试案例设计感兴趣和有时间的话可以另外专题探讨: b.浏览器兼容性测试,更重要的是体验这 ...

随机推荐

  1. 关于set_input_delay的用法分析

    关于set_input_delay的用法分析 数据分为了系统同步和源同步: 对于下降沿采集数据的情况,当下降沿时钟延迟dv_afe到达无效数据最左端时,图中1位置,为最小延时,即采集不到有效数据的临界 ...

  2. TSP-UK49687

    Copied From:http://www.math.uwaterloo.ca/tsp/uk/index.html Shortest possible tour to nearly every pu ...

  3. Hexo-Next6.7.0主题优化

    Hexo-Next6.7.0主题优化 效果预览:Next6.7.0主题个人博客 一.下载next主题 $ cd your-hexo-site $ git clone https://github.co ...

  4. Ubuntu16.04安装Truffle和TestRPC

    系统环境 Ubuntu16.04;   NodeJS: v6.10.2;    NPM: 3.10.10: Truffle: 2.0.8; TestRPC: 3.0.5 安装步骤 注意:以root用户 ...

  5. IIS6.0+win2003部署MVC网站的一些问题

    安装iis,framework环境不谈.MVC网站部署 步骤: 1.为程序新建一个应用程序池(将default的那个程序池作为模板就可以了) 2.web服务扩展一些启用一些必要的服务 3.新建网站 描 ...

  6. python之路——12

    王二学习python的笔记以及记录,如有雷同,那也没事,欢迎交流,wx:wyb199594 复习 1.装饰器 开发原则:开放封闭原则 作用:不改变原函数的调用方式,为函数前后扩展功能 本质:闭包函数 ...

  7. MongoDB复制集技术

    复制集搭建 没毛病: https://www.cnblogs.com/nicolegxt/p/6841442.html?utm_source=itdadao&utm_medium=referr ...

  8. “永恒之蓝”(Wannacry)蠕虫全球肆虐 安装补丁的方法

    “永恒之蓝”利用0day漏洞 ,通过445端口(文件共享)在内网进行蠕虫式感染传播,没有安装安全软件或及时更新系统补丁的其他内网用户就极有可能被动感染,所以目前感染用户主要集中在企业.高校等内网环境下 ...

  9. WPF canvas设置旋转角度和偏移位置

    /// <summary> /// 设置旋转角度和位置 /// </summary> /// <param name="Angle">角度< ...

  10. Java应用常用性能分析工具

    Java应用常用性能分析工具 好的工具有能有效改善和提高工作效率或加速分析问题的进度,笔者将从事Java工作中常用的性能工具和大家分享下,如果感觉有用记得投一票哦,如果你有好的工具也可以分享给我 工具 ...