1

I've Installed Docker o my Computer and ran the following command

 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

Then I view Logs on Hub

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

I expose port 4446 on localhost Here I create Hub and 2 chrome node in the different container.So here I want to run my code on this 2 node.

In real PC I run it from Hub and my java code was

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();
        }

But here in my docker, I want to run code on docker how can I do this. I do not understand because in real pc I run code from my hub pc to another node pc.

Any suggestion for this how can I run code my pc to the different container?

Zakaria Shahed
  • 2,589
  • 6
  • 23
  • 52
  • Seems like it should work. Does the url `/grid/console` not show anything? – djangofan Jan 02 '18 at 15:47
  • http://localhost:4446/grid/console i got the all registered node but how i run it to node... – Zakaria Shahed Jan 02 '18 at 15:50
  • You should just point your tests at the hub container and let the hub handle which node to run the test on based on your `DesiredCapabilities`. It should be `http://selenium-hub/wd/hub` in your case – tehbeardedone Jan 02 '18 at 16:38
  • i have problem with this how can i run it from my pc on 2 different container – Zakaria Shahed Jan 02 '18 at 16:39
  • You just register the nodes with the hub, and point your tests at the hub and it handles the rest.You don't have to do anything special to run it on two different containers – tehbeardedone Jan 02 '18 at 16:41
  • The hub will look at the `DesiredCapabilities` you have set and determine which node to run the tests on. – tehbeardedone Jan 02 '18 at 16:43
  • thanks, here my confusion is I have 2 nodes http://172.17.0.3:5555 and http://172.17.0.4:5555 how hub will understand which node needs to run which script.i need to run my 10 site parallel – Zakaria Shahed Jan 02 '18 at 16:44
  • @zsbappa each node must be connected to a common hub instance on port 4444, then the hub will delegate instances to the nodes that subscribed to it. all handled auto-magically. some people run a node+hub as 1 single docker instance and if your running 5 threads or less, i would recommend that. – djangofan Jan 03 '18 at 05:21

1 Answers1

0

If your localhost:port/grid/console is showing up the registered nodes, then use remote webdriver to execute test on the grid.

Java syntax :

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

the hubURL is the localhost:port/wd/hub

Manmohan_singh
  • 1,776
  • 3
  • 20
  • 29
  • here my question is I have 2 nodes which are connected to the hub if I provide the hub URL then which node will run? how can I understand – Zakaria Shahed Jan 02 '18 at 16:38
  • Then this [post](https://stackoverflow.com/questions/40925012/find-which-node-my-selenium-grid-remote-driver-is-running-on) shall help you. – Manmohan_singh Jan 02 '18 at 16:44