Selenium +RobotFrame 教程(二):Selenium Grid

Selenium +RobotFrame 教程(二):Selenium Grid

目录

  • Selenium +RobotFrame 教程(二):Selenium Grid
  • 1.引言
  • 2.grid 集成工具包下载
  • 3.配置及启动Hub
  • 4.配置及启动Node
  • 5.编写测试脚本,测试grid是否运行正常。

1.引言

上一篇教程实现了本地的web自动测试的搭建,这里继续学习如何使用Selenium Grid实现分布式的自动化测试平台。下图详细的介绍了Grid的工作示意:
Selenium +RobotFrame 教程(二):Selenium Grid_第1张图片
Grid主要概念分2部分:HUB和NODES

  • Hub:负责接收client的任务,并分发到各个node去执行,并返回运行结果
  • Node: 任务的实际运行者

2.grid 集成工具包下载

Hub与Node的启动都集成再一个工具包里面,下载地址,下载最新稳定版本3.141.59

3.配置及启动Hub

进入步骤2下载的jar文件的路径:
cmd运行

java -jar selenium-server-standalone.jar -role hub -port 5555

可以输入http://localhost:5555/ ,发现Hub已经启动,并且提示hub的地址:
,我的地址为 http://10.30.70.182:5555/wd/hub
在这里插入图片描述

4.配置及启动Node

node的配置支持CMD或者json配置,JSON比较方便。Git的参考,注意官方的教程的配置是旧版本的,请以git为参考。

{
  "capabilities":
  [
    {
      "browserName": "firefox",
      "marionette": true,
      "maxInstances": 5,
      "seleniumProtocol": "WebDriver"
    },
    {
      "browserName": "chrome",
      "maxInstances": 5,
      "seleniumProtocol": "WebDriver"
    },
    {
      "browserName": "internet explorer",
      "platform": "WINDOWS",
      "maxInstances": 1,
      "seleniumProtocol": "WebDriver"
    },
    {
      "browserName": "safari",
      "technologyPreview": false,
      "platform": "MAC",
      "maxInstances": 1,
      "seleniumProtocol": "WebDriver"
    }
  ],
  "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
  "maxSession": 5,
  "port": -1,
  "register": true,
  "registerCycle": 5000,
  "hub": "http://10.30.70.182:5555/wd/hub",
  "nodeStatusCheckTimeout": 5000,
  "nodePolling": 5000,
  "role": "node",
  "unregisterIfStillDownAfter": 60000,
  "downPollingLimit": 2,
  "debug": false,
  "servlets" : [],
  "withoutServlets": [],
  "custom": {}
}

有几个薪的概念,maxSession=5 代表这个Node最多支持5个对话,maxInstances代表支持的最多实例子,配置为0将不会产生对应的游览器。

启动命令:

java  -jar selenium-server-standalone.jar -role node -nodeConfig node1Config.json

5.编写测试脚本,测试grid是否运行正常。

*** Settings ***
Documentation     this \ is the first test suit
Test Timeout      30 seconds
Library           SeleniumLibrary


*** Variables ***

*** Test Cases ***
case1
    [Tags]    test1
    [Setup]    Open chrome
    Maximize Browser Window
    Log		grid is ok
    [Teardown]    Close Test
    
case2
    [Tags]    test2
    [Setup]    Open edge
    Maximize Browser Window
    Log		grid is ok
    [Teardown]    Close Test

*** Keywords ***
Open chrome
    Open Browser    http://www.baidu.com/    chrome    remote_url=http://10.30.70.182:5555/wd/hub
Open edge
    Open Browser    http://rds.as.curtisinst.local/    Edge remote_url=http://10.30.70.182:5555/wd/hub
Close Test
    Capture Page Screenshot
    Close Browser

你可能感兴趣的:(robotFramework,selenium)