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项目 新建成功 注 ...
随机推荐
- python 容器 生成器 迭代器 总结
一.容器 容器是一种把多个元素组织在一起的数据结构,容器中的元素可以逐个地迭代获取,可以用in, not in关键字判断元素是否包含在容器中.通常这类数据结构把所有的元素存储在内存中. >> ...
- bzoj1725: [Usaco2006 Nov]Corn Fields牧场的安排(状压dfs)
1725: [Usaco2006 Nov]Corn Fields牧场的安排 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1122 Solved: 80 ...
- web移动端下拉加载数据简单实现
//下拉加载在移动端会经常使用,有些小伙伴不清楚一些原理下面就简答的介绍一下 //首先需要监听window的滚动事件,下拉其实就是在监听window滚动事件 var pageNum = 1;//分页第 ...
- django相关命令
1 安装django pip3 install django 2 django-admin命令 django-admin startproject mysite #创建一个项目 3 manage.py ...
- Python递归和迭代
递归 在函数内部,调用函数自身的编程技巧称为递归( recursion).递归函数结构清晰,很直观的理解计算过程,但也有严重缺点:相对于普通循环而言,递归运行效率较低,经过很多冗余的计算,递归会消耗大 ...
- Codeforces Round #402 (Div. 2) C
Description Igor found out discounts in a shop and decided to buy n items. Discounts at the store wi ...
- h5-19-文件操作-文件域
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 3个解析url的php函数
通过url进行传值,是php中一个传值的重要手段.所以我们要经常对url里面所带的参数进行解析,如果我们知道了url传递参数名称,例如 /index.php?name=tank&sex=1#t ...
- 05.NopCommerce给Topic表添加排序及类别字段
在用到Nopcommerce中静态页面表时,发现Topic表没有排序字段和类别字段,导致如果Page文件很多的话,无法区分是哪个类别,为此我稍微扩展了一下字段,在此记录一下操作流程,方便以后自己查看, ...
- SpringBoot 2.x (8):模板引擎
SpringBoot中有很多的starter:本质是多个JAR包集合 比如我们常用的: <dependency> <groupId>org.springframework.bo ...