Selenium Grid和IE /Firefox各种填坑
使用selenium grid的步骤
1、确保hub和node都安装并且配置好了java jdk.
2、在hub上运行以下命令。
java -jar C:\Software\selenium\selenium-server-standalone-2.40.0.jar -role hub -port 4444
其中,-port 4444是可选的,不指定的话,默认是4444端口
3、在用作Node的电脑上运行以下命令
java -Dwebdriver.chrome.driver="C:\webdrivers\chromedriver.exe" -Dwebdriver.ie.driver="C:\webdrivers\IEDriverServer.exe" -Dwebdriver.gecko.driver="C:\webdrivers\geckodriver.exe" -jar C:\selenium-server\selenium-server-standalone-3.141.59.jar -role node -hub http://192.168.60.66:4444/grid/register -host 192.168.60.61 -port 5566
一口气把各种webdriver的地址都加进去了
问题就来了。
因为我的node电脑有两个物理网卡和两个虚拟网卡,HUB也有两个网卡,一个连外网,一个连内网。
两个物理网卡当中的一张通过网线与Hub相连,并且确定是互联互通的,但是另外一张物理网卡是WIFI,虽然WIFI与HUB在同一路由下,但WIFI与HUB的有线网卡并不是同一个局域网网段。这就导致后来执行测试脚本时各种报错。
后来我重新运行Java -jar命令,并指定了Node的IP地址和端口,如上是完整命令,下面是重点选项。
-host 192.168.60.61 -port 5566
经过这些坑,两台电脑的selenium是能够联通了。
但是有遇到了IE保护模式和ZOOM LEVEL这个破事儿,这个问题,需要改java代码。
改好的java代码在下面。
package com.qa.data;
import java.net.MalformedURLException;
import java.net.URL; import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test; public class ExcelData { @SuppressWarnings("deprecation")
@Test
public void openBrowser() throws MalformedURLException, InterruptedException { DesiredCapabilities cap=DesiredCapabilities.internetExplorer();
cap.setBrowserName("internet explorer"); //以下三句,很多网上的文章都没加,我KAO,不加这三句它们的IE是怎么跑起来的?
cap.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
cap.setCapability("ignoreZoomSetting", true);//忽略IE浏览器的ZOOM LEVEL,不加这句会报错。每次selenium打开ie都是他妈的150%放大倍数,狗日的IE+SELENIUM
cap.setPlatform(Platform.WINDOWS);
URL url=new URL("http://192.168.60.61:5566/wd/hub");
WebDriver driver=new RemoteWebDriver (url,cap);
driver.get("http://www.baidu.com");
driver.manage().window().maximize();
String t=driver.getTitle();
System.out.println(t);
Thread.sleep(3000);
driver.findElement(By.id("kw")).sendKeys("天气");
Thread.sleep(1000);
driver.findElement(By.id("su")).click();
Thread.sleep(3000);
driver.quit();
} }
关于填坑的截图,坑爹啊。

第二张图

Firefox在remote web driver打开的正确方式。
这也是一个坑,以前WebDriver driver=new FirefoxDriver()不管用了,
要使用下面的方法。
不能使用DesiredCapabilities cap=DesiredCapabilities.firefox();
package com.qa.data; import java.net.MalformedURLException;
import java.net.URL; import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test; public class FirefoxTest {
@Test
public void openFirefox() throws MalformedURLException, InterruptedException { /*这段不需要
System.setProperty("webdriver.gecko.driver",
"C:\\webdrivers\\geckodriver.exe");
*/ FirefoxOptions option=new FirefoxOptions();
String binaryPath="C:\\Program Files\\Mozilla Firefox\\firefox.exe";
//注意,是firefox.exe在远程Node电脑的路径,不是gecko.driver
option.setBinary(binaryPath); URL url=new URL("http://192.168.60.61:5566/wd/hub");
WebDriver driver=new RemoteWebDriver (url,option); driver.get("http://www.baidu.com");
driver.manage().window().maximize();
String t=driver.getTitle();
System.out.println(t);
Thread.sleep(3000);
driver.findElement(By.id("kw")).sendKeys("天气");
Thread.sleep(1000);
driver.findElement(By.id("su")).click();
Thread.sleep(3000);
driver.quit();
}
}
Selenium Grid和IE /Firefox各种填坑的更多相关文章
- 学习selenium grid记录
1.找两台Windows系统,一个是A,作为Hub:一个是B,作为Node: 2.在A.B两台电脑分别下载selenium-server-standalone-2.48.0.jar,并放到指定目录 3 ...
- F2eTest和uirecorder自动化测试环境部署填坑记录
坑1:尝试部署的时候只在opennode.bat里面填写了两个浏览器,测试通过后再增加其他浏览器,页面上一直不显示. 填坑:需要清空数据库里的`wd_browsers`和`wd_nodes`表,然后重 ...
- css 填坑常用代码分享
以下是常用的代码收集,没有任何技术含量,只是填坑的积累.转载请注明出处,谢谢. 因为提交比较麻烦,后来转置github:https://github.com/jsfront/src/blob/mast ...
- 搭建selenium grid简单配置
1.使用selenium提供的服务端独立jar包 :服务端.客户端都是运行于java7环境. 2.启动hub: hub配置文件如下: Java -jar selenium-server-standal ...
- Robot Framework + Selenium2Library环境下,结合Selenium Grid实施分布式自动化测试
最近一段时间,公司在推行自动化测试流程,本人有幸参与了自定义通用控件的关键字封装和脚本辅助编写.数据驱动管理.测试用例执行管理等一系列工具软件的研发工作,积累了一些经验,在此与大家做一下分享,也算是做 ...
- Selenium Grid Configuration
Start Hub and Node with Json config 1. Start Hub with json config file title HubWebDriver java -jar ...
- Selenium Grid 运行报错 Exception thrown in Navigator.Start first time ->Error forwarding the new session Empty pool of VM for setup Capabilities
Selenium Grid 运行报错 : Exception thrown in Navigator.Start first time ->Error forwarding the new se ...
- selenium Grid(一)
selenium grid Quick Start selenium-grid是用于设计帮助我们进行分布式测试的工具,其整个结构是由一个hub节点和若干个代理节点组成.hub用来管理各个代理节点的注册 ...
- selenium Grid
Selenium Grid 的机制是启动一个 hub,然后启动多个 Selenium RC 注册到 hub 上, 当测试请求到 hub 时,hub 会将测试分发给 Selenium RC, Selen ...
随机推荐
- mi家前端面经
已经好久没想写面经了……菜鸟面到生无可恋. 1.用CSS实现下面圆形 答案: <!DOCTYPE html> <html> <head> <style typ ...
- thymeleaf的fragment例子
fragment介绍 fragment类似于JSP的tag,在html中文件中,可以将多个地方出现的元素块用fragment包起来使用. 定义fragment 新建foot.html文件 <!D ...
- 【Centos】Postgresql连接测试(Perl和Ruby)
Centos安装了PostgreSQL之后,将考虑如何让Perl与Ruby连接它. Perl连接方式 1,安装Perl的数据库连接包 perl-DBD-Pg perl-DBI yum install ...
- 使用腾讯地图和js,html实现地理位置的获取
转自http://blog.csdn.net/eele_one/article/details/64905218<!DOCTYPE html> <html> <head& ...
- 关闭Cadence Orcad Capture CIS原理图弹出startpage页面的方法
打开原理图工具 Orcad Capture CIS 时,总是会弹出startpage 页面,有时候感觉这个东西挺碍事的,还是关了感觉好.解决方法如下:(1) View---Toolbar----Com ...
- JAVA的单元测试技术
1.选定开发工具 选定eclipse为开发工具,用JAVA进行编程,实现此次测试. 2.编写需要被测试的java类 此次我们以顺序查找与二分查找法为例. package com.mycode.tuil ...
- 获取物理内存total值和used值
1.使用 free -m 查看 2.物理内存total值 # free -m | grep Mem | awk '{print $2}' 3.物理内存used值 # free -m | grep Me ...
- lambda 和 iterable
Lambda 表达式 你可以使用 Lambda 表达式创建匿名函数,即没有名称的函数.lambda 表达式非常适合快速创建在代码中以后不会用到的函数.尤其对高阶函数或将其他函数作为参数的函数来说,非常 ...
- Linux 添加新分区和 移动 /home到新挂载分区
https://blog.csdn.net/lyd135364/article/details/78623119 https://www.cnblogs.com/saszhuqing/p/871664 ...
- Python第6天
主要内容: 递归:函数在内部自己调用自己,它的作用域没有return默认返回none 匿名函数 lambda ,与def的区别在于def可自行处理成元组,而lambda不行, func = lambd ...