当前位置:网站首页>Selenium Grid 安装
Selenium Grid 安装
2022-07-20 12:41:00 【全栈程序员站长】
大家好,又见面了,我是全栈君。
Selenium Grid
Selenium Grid允许同时并行地、在不同的环境上运行多个 测试任务。这里主要演示一下怎么使用Selenium Grid。
准备:
1、需要两台机子
2、两台机子分别安装好JDK环境
3、两台机子需要从 http://code.google.com/p/selenium/downloads/list下载selenium-server-standalone-*.jar包
开始:
Grid需要一台机子做为主节点,然后其它机子做为子节点连接到这个主节点上来。所以首先要启动主节点。
启动主节点:
选一台机子做为主节点。打开命令行,cd至selenium-server-standalone-*.jar包的目录下,然后用下面的命令启动主节点服务:
java -jar selenium-server-standalone-2.24.1.jar -role hub
默认启动默认端口为4444。如果要改这个端口,可以再上面的命令后面加上 -port XXXX。启动完后,你可以用浏览 器 打开 http://localhost:4444/grid/console 这个网址查看主节点的状态。
启动完主节点之后,要做的就是启动子节点。
启动子节点:
先另一台机子做为子节点。同样打开命令行,cd至selenium-server-standalone-*.jar包的目录下,然后用下面的命令启动次节点服务:
java -jar selenium-server-standalone-2.24.1.jar -role node -hubhttp://192.168.4.124:4444/grid/register
其中192.168.4.124为主节点机子的ip地址,可以使用ipconfig命令在命令行查看得到。上面命令默认启动5555端口,可使用-port 更改。
启动完成连接到主节点后,可以在主节点机子上 ,http://localhost:4444/grid/console网址查看到这个子节点状态。使用同样的方法,可以链接其它的子节点。
运行一个简单的例子:
上面已经把grid弄成功了,现在我们用Grid来运行一个很简单的例子。代码如下:
import java.net.MalformedURLException; import java.net.URL; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; public class GridTest { /** * @throws MalformedURLException */ public static void main(String[] args) throws MalformedURLException { DesiredCapabilities test = DesiredCapabilities.firefox(); WebDriver dr = new RemoteWebDriver(new URL(“http://192.168.4.137:5555/wd/hub”),test); dr.get(“http://www.baidu.com”); } } |
---|
在主节点机子上运行上面的代码,你可以在次节点机子上看到firefox浏览器被启动,然后打开了www.baidu.com这个网址。
值得注意的是:
WebDriver dr = new RemoteWebDriver(newURL(“http://192.168.4.137:5555/wd/hub”),test);
这一句中的192.168.4.137为次节点的ip地址。 Selenium Grid
Selenium Grid允许同时并行地、在不同的环境上运行多个 测试任务。这里主要演示一下怎么使用Selenium Grid。
准备:
1、需要两台机子
2、两台机子分别安装好JDK环境
3、两台机子需要从 http://code.google.com/p/selenium/downloads/list下载selenium-server-standalone-*.jar包
开始:
Grid需要一台机子做为主节点,然后其它机子做为子节点连接到这个主节点上来。所以首先要启动主节点。
启动主节点:
选一台机子做为主节点。打开命令行,cd至selenium-server-standalone-*.jar包的目录下,然后用下面的命令启动主节点服务:
java -jar selenium-server-standalone-2.24.1.jar -role hub
默认启动默认端口为4444。如果要改这个端口,可以再上面的命令后面加上 -port XXXX。启动完后,你可以用浏览 器 打开 http://localhost:4444/grid/console 这个网址查看主节点的状态。
启动完主节点之后,要做的就是启动子节点。
启动子节点:
先另一台机子做为子节点。同样打开命令行,cd至selenium-server-standalone-*.jar包的目录下,然后用下面的命令启动次节点服务:
java -jar selenium-server-standalone-2.24.1.jar -role node -hubhttp://192.168.4.124:4444/grid/register
其中192.168.4.124为主节点机子的ip地址,可以使用ipconfig命令在命令行查看得到。上面命令默认启动5555端口,可使用-port 更改。
启动完成连接到主节点后,可以在主节点机子上 ,http://localhost:4444/grid/console网址查看到这个子节点状态。使用同样的方法,可以链接其它的子节点。
运行一个简单的例子:
上面已经把grid弄成功了,现在我们用Grid来运行一个很简单的例子。代码如下:
import java.net.MalformedURLException; import java.net.URL; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; public class GridTest { /** * @throws MalformedURLException */ public static void main(String[] args) throws MalformedURLException { DesiredCapabilities test = DesiredCapabilities.firefox(); WebDriver dr = new RemoteWebDriver(new URL(“http://192.168.4.137:5555/wd/hub”),test); dr.get(“http://www.baidu.com”); } } |
---|
在主节点机子上运行上面的代码,你可以在次节点机子上看到firefox浏览器被启动,然后打开了www.baidu.com这个网址。
值得注意的是:
WebDriver dr = new RemoteWebDriver(newURL(“http://192.168.4.137:5555/wd/hub”),test);
这一句中的192.168.4.137为次节点的ip地址。
最新内容请见作者的GitHub页:http://qaseven.github.io/
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/108373.html原文链接:https://javaforall.cn
边栏推荐
- 玫瑰通行证发放中!
- Lesson 2 WiFi experiment of hi3861 -api-4
- Are you interested in grabbing a sofa
- LeetCode - 回文数
- 插件qrcode和ityped
- C language practice item: Sanzi chess
- R language uses the aggregate function of epidisplay package to divide numerical variables into different subsets based on factor variables, calculate the summary statistics of each subset, and calcul
- [golang] go parse XMIND
- 从0到1 拿下C语言—程序结构及使用示例
- RENIX_IPv6自动配置——网络测试仪实操
猜你喜欢
第2讲 Hi3861的WiFi实验-AP模式
Redis learning notes (1) - power node of station B
Five things you need to know about renting servers in Hong Kong
同步原语:锁
From giving up to mastering, these 13 recommended system papers must be read! [attached data]
干货丨重中之重:数据分析中常用指标及术语!
After Huawei, no one can stop apple. It is expected that iphone14 will be popular with hundreds of millions of domestic users
【机器学习】模型选择(交叉验证)原理及实战
史上最全的mysql数据类型汇总-(上)
There are 450million 5g network users and more than 900million 5g package users. Why are users still unwilling to accept 5g?
随机推荐
R language ggplot2 visualization: visualize the scatter diagram and add text labels to the data points in the scatter diagram, using geom of ggrep package_ text_ The repl function avoids overlapping l
R language Kolmogorov Smirnov test compares whether the two samples come from the same distribution: ks The test function performs Kolmogorov Smirnov test to compare whether the two samples are from t
Grafana visual configuration chart time series
Sorting out and solutions of common problems in pytorch
常用的10款数据可视化工具软件
Can't the job of SQL command insert into be started through savepoint? Or when my cluster is shut down and restarted
插件qrcode和ityped
Recommend a WordPress paid theme station
[web vulnerability exploration] external entity injection vulnerability
上海文旅局局长:安全是文旅业的生命线,正抢抓元宇宙新赛道
《流浪(Stray)》工人外套与安全帽获得方法 工人安全帽怎么获得
Sax解析xml及pull解析xml
V853 development board hardware data - risc-v core e907 user manual
Image operation and transformation of machine learning foundation (3)
模块学习(四)——超声波测距
租用香港服务器您需要知道的5件事
R language uses the mean function to calculate the relative frequency of the specified variables in the sample (observation) data: calculate the proportion of the value of the specified data column in
Insightface paddle User Guide (1)
#yyds干货盘点# 解决名企真题:小招喵跑步
VPS、独服和云服务器哪种最适合您的业务?