• 学习selenium grid记录


    1、找两台Windows系统,一个是A,作为Hub;一个是B,作为Node;

    2、在A、B两台电脑分别下载selenium-server-standalone-2.48.0.jar,并放到指定目录

    3、先设置Hub,打开A电脑的cmd,cd进入该目录

      

    4、并执行命令:java -jar selenium-server-standalone-.jar -2.48.0role hub  ,执行-role hub 意思是将server之行为hub主服务器,可以集中控制Node,命令行窗口出现以下i,192.168.1.2是本机IP,4444是grid默认端口

     

    5、在浏览器输入 本机的IP 端口,打开grid,如:http://192.168.1.2:4444/grid/console,出现下图,代表启动成功,在B电脑的浏览器,输入A的IP端口访问grid成功

       

    6、在B电脑也打开cmd窗口,进入selenium-server-standalone-2.48.0.jar 的目录,执行命令:java -jar selenium-server-standalone-2.48.0.jar -role webdriver -hub http://192.168.1.2:4444/grid/register -port 6655 ,设置B为node节点,端口号随便写一个,比如6666,讲该节点注册到主服务器A,执行命令后如下显示:

      

      在A电脑的浏览器刷新grid地址,会出现Node的IP及配置信息

      

     7、相关代码如下:

    public static String nodeUrl = "http://192.168.1.5:6655/wd/hub";

     @BeforeMethod

    public void beforeMethod() throws MalformedURLException{
      DesiredCapabilities capability = DesiredCapabilities.firefox();//设定远程方法使用Firefox浏览器
      capability.setBrowserName("firefox");//设置node的浏览器为Firefox

      //设置node使用的操作系统为WINDOWS,设置成Win10报:org.openqa.selenium.WebDriverException: No enum constant org.openqa.selenium.Platform.WIN10,没去找具体原因,有空再分析
      capability.setPlatform(Platform.WINDOWS);

      //设置node的Firefox的路径,如果用System.setProperty("webdriver.firefox.bin", "D:\Program Files\Mozilla Firefox\firefox.exe");不起作用,设置不了远程服务器的firefox路径

      capability.setCapability("firefox_binary", "D:\Program Files\Mozilla Firefox\firefox.exe");//不设置时,报错selenium grid: Cannot find firefox binary in PATH.

      driver = new RemoteWebDriver(new URL(nodeUrl), capability);//启动node的driver
      driver.get("http://www.baidu.com/");
    }

    8、大概是这样,还有2个问题待解决

      1)用selenium-server-standalone-3.9.1.jar,执行脚本会报Driver info: driver.version: unknown,可能用高版本的grid需要再配置其他配置

      2)打开的火狐浏览器,总是默认打开火狐起始页,待解决

    参考文档:https://www.cnblogs.com/zhangyachaun/p/4409480.html ,写的很全,对我帮助很大,分享给大家

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    远程IE浏览器设置:

    1、在B服务器进行Hub节点注册使用如下命令

      java -jar selenium-server-standalone-2.48.0.jar -role webdriver -hub http://192.168.1.2:4444/grid/register -Dwebdriver.ie.dirver="C:IEDriverServer.exe" -port 6655 -maxSession 5 -browser browserName="internet explorer",maxInstances=5

    2、设置远程方法: 

      DesiredCapabilities capability = DesiredCapabilities.internetExplorer();//设定远程方法使用internetExplorer浏览器
      capability.setBrowserName("internetExplorer");//设置node的浏览器为internetExplorer

    远程Chrome设置

    1、在B服务器进行Hub节点注册使用如下命令

      java -jar selenium-server-standalone-2.48.0.jar -role webdriver -hub http://192.168.1.2:4444/grid/register -Dwebdriver.chrome.dirver="C:chromedriver.exe" -port 6655 -maxSession 5 -browser browserName="chrome",maxInstances=5

    2、设置远程方法: 

      DesiredCapabilities capability = DesiredCapabilities.chrome();//设定远程方法使用chrome浏览器
      capability.setBrowserName("chrome");//设置node的浏览器为chrome

     

  • 相关阅读:
    面向对象
    模块
    第四十课、前置操作符和后置操作符------------------狄泰软件学院
    uva -- 10766
    poj -- 3468
    poj --3264
    cstring 的重载
    hihocode ---1032
    省赛总结
    13周总结
  • 原文地址:https://www.cnblogs.com/cainiaotest/p/11788607.html
Copyright © 2020-2023  润新知