Selenium grid运行到docker容器

时间:2018-01-02 15:36:17

标签: selenium docker selenium-grid

我在计算机上安装了Docker并运行了以下命令

 root@DESKTOP-51NFMIM:~# docker run -d -p 4446:4444 --name selenium-hub selenium/hub
   & 

 docker run -d -P -e no_proxy=localhost -e HUB_ENV_no_proxy=localhost --link selenium-hub:hub selenium/node-firefox-debug

然后我查看集线器上的日志

10:08:05.520 INFO - Selenium build info: version: '3.8.1', revision: '6e95a6684b'
10:08:05.521 INFO - Launching Selenium Grid hub
2018-01-02 10:08:06.102:INFO::main: Logging initialized @833ms to org.seleniumhq.jetty9.util.log.StdErrLog
10:08:06.115 INFO - Will listen on 4444
2018-01-02 10:08:06.157:INFO:osjs.Server:main: jetty-9.4.7.v20170914
2018-01-02 10:08:06.187:INFO:osjs.session:main: DefaultSessionIdManager workerName=node0
2018-01-02 10:08:06.187:INFO:osjs.session:main: No SessionScavenger set, using defaults
2018-01-02 10:08:06.189:INFO:osjs.session:main: Scavenging every 660000ms
2018-01-02 10:08:06.202:INFO:osjsh.ContextHandler:main: Started o.s.j.s.ServletContextHandler@23f7d05d{/,null,AVAILABLE}
2018-01-02 10:08:06.213:INFO:osjs.AbstractConnector:main: Started ServerConnector@2e457a5e{HTTP/1.1,[http/1.1]}{0.0.0.0:4444}
2018-01-02 10:08:06.213:INFO:osjs.Server:main: Started @944ms
10:08:06.213 INFO - Nodes should register to http://172.17.0.2:4444/grid/register/
10:08:06.214 INFO - Selenium Grid hub is up and running
10:10:04.000 INFO - Registered a node http://172.17.0.3:5555
10:10:04.000 INFO - Registered a node http://172.17.0.4:5555

我在localhost上公开了端口4446这里我在不同的容器中创建了Hub和2个chrome节点。所以我想在这个2节点上运行我的代码。

在真正的PC中,我从Hub运行它,我的java代码是

if (browser.equalsIgnoreCase("firefox")) {
            System.out.println(" Executing on FireFox");
            String Node = "http://172.17.0.3:5555/wd/hub";
            DesiredCapabilities cap = DesiredCapabilities.firefox();
            cap.setBrowserName("firefox");

            driver = new RemoteWebDriver(new URL(Node), cap);
            // Puts an Implicit wait, Will wait for 10 seconds before throwing
            // exception
            wd.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

            // Launch website

            wd.manage().window().maximize();
        }

但是在我的docker中,我想在docker上运行代码我该怎么做呢。我不明白,因为在真正的电脑中我将代码从我的集线器pc运行到另一个节点pc。

对此的任何建议如何将我的电脑代码运行到不同的容器?

1 个答案:

答案 0 :(得分:0)

如果 localhost:port / grid / console 显示已注册的节点,则使用远程webdriver在网格上执行测试。

Java语法

WebDriver driver = new RemoteWebDriver(new URL(hubURL), capability);
driver.get("http://www.google.com");

hubURL localhost:port/wd/hub