How to run selenium hub & node programmatically(without console)

1,427 views
Skip to first unread message

A B

unread,
Jun 19, 2015, 8:32:40 AM6/19/15
to seleniu...@googlegroups.com
I am trying to run selenium Hub & Node programmatically. I tried following code, but did not work.

    RegistrationRequest req = new RegistrationRequest();
    req.setRole(GridRole.NODE);

    Map<String, Object> nodeConfiguration = new HashMap<String,
    Object>();

    nodeConfiguration.put(RegistrationRequest.AUTO_REGISTER, true);
    nodeConfiguration.put(RegistrationRequest.HUB_HOST, "192.168.100.66");

    nodeConfiguration.put(RegistrationRequest.HUB_PORT, 4444);
    nodeConfiguration.put(RegistrationRequest.PORT, 5555);

    URL remoteURL = new URL("http://" + "<your local ip address>" + ":" + 5555);
    nodeConfiguration.put(RegistrationRequest.PROXY_CLASS, "org.openqa.grid.selenium.proxy.DefaultRemoteProxy");
    nodeConfiguration.put(RegistrationRequest.MAX_SESSION, 1);
    nodeConfiguration.put(RegistrationRequest.CLEAN_UP_CYCLE, 2000);
    nodeConfiguration.put(RegistrationRequest.REMOTE_HOST, remoteURL);
    nodeConfiguration.put(RegistrationRequest.MAX_INSTANCES, 1);

    req.setConfiguration(nodeConfiguration);

    remote = new SelfRegisteringRemote(req);
    remote.startRemoteServer();
    remote.startRegistrationProcess();

Any pointer..

A B

unread,
Jun 19, 2015, 9:42:28 AM6/19/15
to seleniu...@googlegroups.com
I tried following -
 1. Starting Hub programmatically
 2. Registering Node to Hub

Code is showing error in Step 2 while I am able to see Hub config in browser. Code used is as follows -

    private static SelfRegisteringRemote remote;
    private static Hub hub;
    @Test
    public void abc() throws Exception{
        GridHubConfiguration config = new GridHubConfiguration();
        config.setHost("localhost");
        hub = new Hub(config);
        hub.start();
        System.out.println("1");

        RegistrationRequest req = new RegistrationRequest();
        req.setRole(GridRole.NODE);
        req.loadFromJSON("NodeFfConfig.json");

        remote = new SelfRegisteringRemote(req);  // this line is throwing error
        remote.startRemoteServer();
        remote.startRegistrationProcess();
       
        remote.stopRemoteServer();
        hub.stop();
    }

Error Log is as follows -
2015-06-19 19:05:08.307:INFO:osjs.Server:jetty-7.x.y-SNAPSHOT
2015-06-19 19:05:08.416:INFO:osjsh.ContextHandler:started o.s.j.s.ServletContextHandler{/,null}
2015-06-19 19:05:08.450:INFO:osjs.AbstractConnector:Started SocketConnector@localhost:4444
1
2015-06-19 19:05:44,902 INFO  (SeleniumServer.java:766)     - Java: Oracle Corporation 25.25-b02
2015-06-19 19:05:44,919 INFO  (SeleniumServer.java:768)     - OS: Windows 7 6.1 x86
2015-06-19 19:05:44,967 INFO  (SeleniumServer.java:345)     - v2.46.0, with Core v2.46.0. Built from revision 61506a4624b13675f24581e453592342b7485d71
19:05:45.635 INFO - Driver class not found: org.openqa.selenium.opera.OperaDriver
19:05:45.638 INFO - Driver provider org.openqa.selenium.opera.OperaDriver is not registered
2015-06-19 19:05:46,103 INFO  (HttpServer.java:694)     - Version Jetty/5.1.x
2015-06-19 19:05:46,112 INFO  (Container.java:74)     - Started HttpContext[/selenium-server,/selenium-server]
2015-06-19 19:05:46,169 INFO  (Container.java:74)     - Started org.openqa.jetty.jetty.servlet.ServletHandler@5d601e
2015-06-19 19:05:46,170 INFO  (Container.java:74)     - Started HttpContext[/wd,/wd]
2015-06-19 19:05:46,171 INFO  (Container.java:74)     - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
2015-06-19 19:05:46,172 INFO  (Container.java:74)     - Started HttpContext[/,/]
2015-06-19 19:05:46,184 INFO  (SocketListener.java:203)     - Started SocketListener on 0.0.0.0:5556
2015-06-19 19:05:46,185 INFO  (Container.java:74)     - Started org.openqa.jetty.jetty.Server@14872f8
19:06:16.087 INFO - Starting auto registration thread. Will try to register every 5000 ms.
19:06:16.087 INFO - Registering the node to the hub: http://localhost:4444/grid/register
19:06:16.134 INFO - Couldn't register this node: Error sending the registration request: The hub responded with 500:Error: The registration request needs to specify either the remote host, or a valid id.
2015-06-19 19:06:16.123:WARN:osjs.ServletHandler:/grid/register
java.security.InvalidParameterException: Error: The registration request needs to specify either the remote host, or a valid id.
    at org.openqa.grid.internal.BaseRemoteProxy.getNewInstance(BaseRemoteProxy.java:432)
    at org.openqa.grid.web.servlet.RegistrationServlet.process(RegistrationServlet.java:86)
    at org.openqa.grid.web.servlet.RegistrationServlet.doPost(RegistrationServlet.java:60)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.seleniumhq.jetty7.servlet.ServletHolder.handle(ServletHolder.java:565)
    at org.seleniumhq.jetty7.servlet.ServletHandler.doHandle(ServletHandler.java:479)
    at org.seleniumhq.jetty7.server.session.SessionHandler.doHandle(SessionHandler.java:225)
    at org.seleniumhq.jetty7.server.handler.ContextHandler.doHandle(ContextHandler.java:1031)
    at org.seleniumhq.jetty7.servlet.ServletHandler.doScope(ServletHandler.java:406)
    at org.seleniumhq.jetty7.server.session.SessionHandler.doScope(SessionHandler.java:186)
    at org.seleniumhq.jetty7.server.handler.ContextHandler.doScope(ContextHandler.java:965)
    at org.seleniumhq.jetty7.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
    at org.seleniumhq.jetty7.server.handler.HandlerWrapper.handle(HandlerWrapper.java:111)
    at org.seleniumhq.jetty7.server.Server.handle(Server.java:349)
    at org.seleniumhq.jetty7.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:452)
    at org.seleniumhq.jetty7.server.BlockingHttpConnection.handleRequest(BlockingHttpConnection.java:47)
    at org.seleniumhq.jetty7.server.AbstractHttpConnection.content(AbstractHttpConnection.java:894)
    at org.seleniumhq.jetty7.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:948)
    at org.seleniumhq.jetty7.http.HttpParser.parseNext(HttpParser.java:857)
    at org.seleniumhq.jetty7.http.HttpParser.parseAvailable(HttpParser.java:235)
    at org.seleniumhq.jetty7.server.BlockingHttpConnection.handle(BlockingHttpConnection.java:66)
    at org.seleniumhq.jetty7.server.bio.SocketConnector$ConnectorEndPoint.run(SocketConnector.java:254)
    at org.seleniumhq.jetty7.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:599)
    at org.seleniumhq.jetty7.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:534)
    at java.lang.Thread.run(Thread.java:745)

Used JSON file is attached -
NodeFfConfig.json

Krishnan Mahadevan

unread,
Jun 19, 2015, 11:17:03 PM6/19/15
to Selenium Users

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/3351ccfd-76e1-4d78-a744-7a24c78bd985%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

A B

unread,
Jun 20, 2015, 8:12:46 AM6/20/15
to seleniu...@googlegroups.com
Hi Krishnan,

Thanks a lot. With your help, I managed to launch Hub & register Node programmatically. I have a one query, how do we write log for each node. For example -

 I have 3 nodes -
1. First Node having Chrome browser
2. Second Node having Firefox browser
3. Third Node having IE browser

How do we track execution happening on each browser or generate log for each browser/Node separately at a central location.

Happy Learning,
Abhay

Krishnan Mahadevan

unread,
Jun 22, 2015, 12:02:08 AM6/22/15
to Selenium Users
Can you please elaborate what is your use case ?
Why do you want to be exploring the option of spawning a Hub/Node via code and then complicating all of this stuff into it ?
Wouldn't it be better for you to just spawn a node/hub separately and plug-in a logger property and get done with it ?

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

chetan lashkari

unread,
Jan 15, 2016, 9:22:01 AM1/15/16
to Selenium Users
Hi Krishnan,

Looks like you have a very good idea about selenium grid.

I am having some problems while Selenium Grid so I will try to explain, please help me in case you have  idea about it.

Scenario 1 :  Running HUB on 1 machine (linux based)
Scenario 2 : Running 2 nodes, MAC & Windows
Scenario 3 : I am registered 3 browsers (safari, ff, chrome) on MAC
Scenario 4 : I am registered 3 browsers (ie, ff, chrome) on Windows 

So problem is when I am running test on mac,ff and windows,ff or mac,chrome and windows,chrome. Test is running on only one node which registers first on HUB.

Hence I want when I run test on mac,ff it should pick mac node. If I run test on window,ff it should pick windows node. Similarly for chrome.
Also is there anyway I can get node url or name or anything related to node programmatically?

Please let me know if you have any solutions. 

Krishnan Mahadevan

unread,
Jan 15, 2016, 11:01:43 AM1/15/16
to Selenium Users
Chetan,

>>>>>>Also is there anyway I can get node url or name or anything related to node programmatically?
You can maybe take a look at this blog post which talks about extracting the node information programmatically : https://rationaleemotions.wordpress.com/2016/01/15/where-did-my-test-run/

>>>>>>So problem is when I am running test on mac,ff and windows,ff or mac,chrome and windows,chrome. Test is running on only one node which registers first on HUB.
This can be happening due to:
  1. You are not specifying the PLATFORM in your DesiredCapabilities. So the Grid is free to route your test to any node that is available which satisfies the browserName capability.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages