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项目 新建成功 注 ...
随机推荐
- bzoj 2435: [Noi2011]道路修建【树形dp】
dp求size和deep,然后对每条边模拟求代价即可 #include<iostream> #include<cstdio> #include<algorithm> ...
- EOS:dfuse stream 保证不会错过一个心跳
强大的 dfuse history API 给我们带来了高效的链数据获取途径,让我们的 dapp 在用户体验上了一个台阶. 官方示例 不会错过一个心跳 代码分析 函数 pendingActions 待 ...
- (数位DP)51NOD 1042 数字0-9的数量
给出一段区间a-b,统计这个区间内0-9出现的次数. 比如 10-19,1出现11次(10,11,12,13,14,15,16,17,18,19,其中11包括2个1),其余数字各出现1次. 输入 ...
- win32 寄存器
跳转指令分三类: 一.无条件跳转: JMP ;无条件跳转 二.根据CX.ECX寄存器的值跳转: JCXZ ;CX 为 0 则跳转 JECXZ;ECX 为 0 则跳转 三.根据EFLAGS寄存器的PSW ...
- UltraEdit的免费激活方法
本来前段时间用UE编辑器用的好好的,然后今天突然提示我使用到期,需要购买激活.一脸懵逼中,只好再次激活,谁知道按照原来的方法激活的时候一直提示您输入的许可证id或密码错误 请您检查注册邮件并且重试. ...
- hdu 4442 Physical Examination (2012年金华赛区现场赛A题)
昨天模拟赛的时候坑了好久,刚开始感觉是dp,仔细一看数据范围太大. 题目大意:一个人要参加考试,一共有n个科目,每个科目都有一个相应的队列,完成这门科目的总时间为a+b*(前面已完成科目所花的总时间) ...
- [洛谷p2858] 奶牛零食
题目链接: 点我 题目分析: 这是什么,区间dp吗?怎么大佬都在说区间dp的样子 完蛋区间dp都不知道是啥quq 于是使用了玄学的姿势A过了这道题 设dp[i][j][0]表示第i天,左边选了j个,当 ...
- Cake slicing UVA - 1629
UVA - 1629 ans[t][b][l][r]表示t到b行,l到r列那一块蛋糕切好的最小值d[t][b][l][r]表示t到b行,l到r列区域的樱桃数,需要预处理 #include<cst ...
- Kruskal HDOJ 1863 畅通工程
题目传送门 /* 此题为:HDOJ 1233 + HDOJ 1232 */ #include <cstdio> #include <algorithm> #include &l ...
- 制作ubuntu启动U盘:Windows,Mac osx ,Ubuntu
1.How to create a bootable USB stick on Windows https://www.ubuntu.com/download/desktop/create-a-usb ...