java+selenium+maven+IntelliJ IDEA 搭建简单的UI自动化测试环境
1. 用IntelliJ IDEA新建一个maven工程
2. 在pom.xml中添加依赖:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.14.0</version>
</dependency> <!-- 与 selenium-java 版本要一致 -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>3.14.0</version>
</dependency>
3. 编写自动化测试脚本(模拟打开浏览器并访问百度首页)
注:必须先安装相应浏览器版本的驱动
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.ie.InternetExplorerDriver; public class LoginTest1 {
public static void main(String[] args) { openEdge();
} public static void openFirefox() {
/**
* 打开firefox
*/
FirefoxOptions options = new FirefoxOptions();
options.setBinary("D:\\softwareInstallMenu\\Firefox\\firefox.exe");
System.setProperty("webdriver.gecko.driver", ".\\drivers\\geckodriver.exe");
WebDriver driver = new FirefoxDriver(options);
driver.get("http://www.baidu.com");
} /**
* 打开chrome
*/
public static void openChrome() {
System.setProperty("webdriver.chrome.driver", ".\\drivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.baidu.com"); } /**
* 打开IE
*/
public static void openIE() {
System.setProperty("webdriver.ie.driver", ".\\drivers\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
driver.get("http://www.baidu.com");
} /**
* 打开Edge
*/
public static void openEdge() {
// 指定MicrosoftWebDriver路径
System.setProperty("webdriver.edge.driver", ".\\drivers\\MicrosoftWebDriver.exe");
//启动 Edge浏览器
WebDriver driver = new EdgeDriver();
driver.get("http://www.baidu.com");
}
}
4. 附加说明
(1)IE浏览器的驱动---------IEDriverServer
我们可以从 http://selenium-release.storage.googleapis.com/index.html 下载,如果该地址打不开,可以用淘宝的镜像地址:https://npm.taobao.org/mirrors/selenium/。
IEDriverServer下载时得注意,你用的是什么版本的Selenium 就在对应版本里面找IEDriverServer。
(2)Chrome 浏览器驱动---------ChromeDriver
chromedriver下载时也需要下载到匹配的版本,特别是chrome浏览器和chromedriver的版本需要匹配。
可以到http://chromedriver.storage.googleapis.com/index.html,国内用户也可以到淘宝npm镜像(http://npm.taobao.org/mirrors/chromedriver)去下载对应版本的chromedriver版本。
(3)Firefox 浏览器驱动----------geckodriver
当火狐的版本<=47时,我们不需要额外的设置。但是如果安装时没有使用默认安装路径,那么和使用默认安装路径在代码处理上会有点不同:
默认安装路径,我们可以直接实例化一个FirefoxDriver,便可:
public static void main(String args[]) {
openFirefoxDef();
}
private static void openFirefoxDef(){
// 实例化 FirefoxDriver, 启动Firefox
WebDriver driver = new FirefoxDriver();
}
如果火狐不是默认安装路径,你需要指定火狐安装路径:
public static void main(String args[]) {
openFireFoxTest();
}
public void openFireFoxTest(){
// 指定firefox 安装路径
System.setProperty("webdriver.firefox.bin","C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
// 启动firefox浏览器
WebDriver driver = new FirefoxDriver();
}
当火狐版本V48+时,那么想启动火狐浏览器,我们得去下载火狐对应的geckodriver。下载地址:https://github.com/mozilla/geckodriver/releases,基本下载最新版便可。那么我看下这时我们如何启动Firefox:
#注意这里只是支持firefox默认安装C盘的情况
public static void main(String args[]) {
openFirefoxByGeck();
}
private static void openFirefoxByGeck() {
// 设置系统变量,并设置 geckodriver 的路径为系统属性值
System.setProperty("webdriver.gecko.driver", ".\\drivers\\geckodriver.exe");
// 实例化 FirefoxDriver
WebDriver driver = new FirefoxDriver();
} #要启动firefox自定义安装位置会报PATH没有firefox二进制文件,处理如下:
FirefoxOptions options = new FirefoxOptions();
options.setBinary("D:\\Firefox\\firefox.exe"); //导入firefox安装路径
System.setProperty("webdriver.gecko.driver","./driver/geckodriver.exe");
driver = new FirefoxDriver(options);
(4)Edge浏览器----------MicrosoftWebDriver
下载地址:https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
java+selenium+maven+IntelliJ IDEA 搭建简单的UI自动化测试环境的更多相关文章
- 搭建基于IDEA+Selenium+Java+TestNG+Maven+Jenkins+SVN的Web端UI自动化测试环境
第一步:工具下载安装配置 JDK安装与配置 IDEA安装与配置 Maven安装与配置 Tomcat部署与配置 Jenkins部署与配置 Svn安装与配置 各浏览器驱动下载与配置 第二步:集成各个工具到 ...
- IDEA+Java:Selenium+Maven+TestNG基本WebUI自动化测试环境搭建
IDEA+java:Selenium+Maven+TestNG 本文介绍的测试环境,应该是最基本的测试环境了,也是很多文章都有写,这里做一个完整的图文配置整理,方便阅读理解! 使用maven的好处,由 ...
- JAVA基础-----Maven项目的搭建
Maven项目的搭建 一.前言 maven官网:http://maven.apache.org/, 文章简介:本文章从三个模块来了解Maven,分别是 Maven的基本概念~, Maven项目的安装和 ...
- 转:windows下使用gvim搭建简单的IDE编译环境(支持C/C++/Python等)
原文来自于:http://www.cnblogs.com/zhuyp1015/archive/2012/06/16/2552269.html 使用gvim在windows环境下搭建简单的IDE环境可以 ...
- 简单Web UI 自动化测试框架 pyse
WebUI automation testing framework based on Selenium and unittest. 基于 selenium 和 unittest 的 Web UI自动 ...
- 【自动化基础】手把手教零基础小白搭建APP的UI自动化环境
前言 帮助零基础小白一步步搭建UI自动化环境,完成Python+Appium+模拟器/真机的UI自动化环境搭建. 环境准备: jdk1.8.0 sdk Node.js appium python Ap ...
- 基于selenium+Python3.7+yaml+Robot Framework的UI自动化测试框架
前端自动化测试框架 项目说明 本框架是一套基于selenium+Python3.7+yaml+Robot Framework而设计的数据驱动UI自动化测试框架,Robot Framework 作为执行 ...
- [java,maven] 使用 maven 来搭建简单的 netty 开发环境
大致过程是: 首先, 使用 mvn 命令在指定路径下面创建一套简单的 java 文件包. 然后, 使用 JIdea 导入 maven 项目的方式将创建好的文件包加载到 IDE 环境中.‘ 接下来, ...
- java+selenium+maven+testng框架(一)安装搭建
1.安装jdk(注意:需配置环境变量,可自行百度方法); 2.安装eclipse; 3.安装maven(注意:需配置环境变量,可自行百度方法); 4.在eclipse中新建maven项目 新建成功 注 ...
随机推荐
- Codeforces 702B【二分】
题意: 给一个a数组,输出有多少对相加是等于2^x的.1<=a[i]<=1e9,n<=1e5 思路: a[i]+a[j]=2^x 对于每个a[i],枚举x,然后二分查找a[j]; p ...
- 基础BFS+DFS poj3083
//满基础的一道题 //最短路径肯定是BFS. //然后靠右,靠左,就DFS啦 //根据前一个状态推出下一个状态,举靠左的例子,如果一开始是上的话,那么他的接下来依次就是 左,上 , 右 , 下 // ...
- Tasks 多核查找最大最小值问题
先贴下代码 _Datas.ParallelForEach(arg_nDataStartIndex, arg_nDataCount, (data) => { dMax = dMax.Max(dat ...
- 树链剖分学习笔记 By cellur925
先%一发机房各路祖传树剖大师%%%. 近来总有人向我安利树剖求LCA,然鹅我还是最爱树上倍增.然鹅又发现近年一些题目(如天天爱跑步.运输计划等在树上进行操作的题目),我有把树转化为一条链求解的思路,但 ...
- CI框架错误汇总
2017年1月13日12:09:02 [1] A PHP Error was encounteredSeverity: NoticeMessage: Undefined variable: aticl ...
- C#操作高低位
比如一个数 想把高位 与地位拆开,分别显示 可以用这个办法 x=(uint16)(x>>8) (高字节向右移动8位 相当于*256) X=(UINT16)(X &0X00FF) ...
- Centos 内存释放
原因:最近发现服务器老师提示内存不足的警报,很多时候内存都占用百分之80以上,查看运行的服务似乎并没有占用很大的内存,top查看运行的服务,然后按shift+m排名第一的才百分之1.x,看了别人的博客 ...
- mui.init()方法中可以有子页面和预加载两项内容,它们是否都在页面加载完成时创建其对应的webview对象?
subpages和preloadPages区别是什么? mui.init({ subpages: [{ url: 'subject.html', //子页面HTML地址,支持本地地址和网络地址 id: ...
- Json----Jackson 下载地址
下载地址: http://repo1.maven.org/maven2/com/fasterxml/jackson/
- the little schemer 笔记(2)
第二章 Do it, Do it Again, and Again, and Again... 假设l是 (Jack Sprat could eat no chicken fat) 那么 (lat? ...