0

Mac OS Sierra ( 10.12.5 ) When I start selenium server with hub role from command line as below

 java -jar selenium-server-standalone-3.4.0.jar -role hub

After this opening grid console with url http://localhost:4444/grid/console, show info within couple of seconds.

But same url either doesn't load or take really long time to load, when I start hub with java programme as below

Hub hub = null;
 public void startSeleniumHub(){
 try{
                String strIP = "localhost";

                GridHubConfiguration config = new GridHubConfiguration();

                config.host = strIP;
                config.port = 4444;


                hub = new Hub(config);
                hub.start();

                if(isSeleniumHubRunning(10)){
                    System.out.println("Selenium Grid is Running");
                }else{
                    System.err.println("*** Selenium Grid is down");
                }

 }catch(Exception e){
     e.printStackTrace();
 }
 }

 public boolean isSeleniumHubRunning(int timeOut){
     int count = 0 ;
     while(count < timeOut){
              try{    
                         Thread.sleep(1000);
                         URL u = new URL ( "http://localhost:4444/grid/console");
                         HttpURLConnection huc =  ( HttpURLConnection )  u.openConnection (); 
                         huc.setRequestMethod ("GET");  //OR  huc.setRequestMethod ("HEAD"); 
                         huc.connect () ; 
                         int code = huc.getResponseCode() ;
                         System.out.println(code);
                         return true;
                 }catch(Exception e){
                 System.err.println("Selenium Grid is still down.....");         
                 count++;
                 //return false;
                 } 
     }
     System.err.println("Selenium Grid failed to start up even after   " + timeOut + "  seconds");
     return false;
      }

I tried searching for root cause but didn't find any answer.

Thanks in advance.

EDIT: Below solution from krishnan-mahadevan ONLY works with Eclipse 4.6.0 and NOT with IDEA Community Edition 2017.2 I'm going to open new question for IDEA regarding this.

vikramvi
  • 3,312
  • 10
  • 45
  • 68
  • Can you show us your complete implementation please? Thanks – undetected Selenium Jul 24 '17 at 12:17
  • @DebanjanB I've edited the question and added 2 methods which does the job of starting and checking the hub is up & running. – vikramvi Jul 24 '17 at 13:08
  • How much time is Hub taking for you to start? Your code is taking @1412ms on my PC whereas the default time through `java -jar` sometimes clocks @2757ms. I guess your code is pretty optimum. – undetected Selenium Jul 24 '17 at 14:27
  • @DebanjanB query is about grid console url not opening at all. – vikramvi Jul 24 '17 at 14:28
  • Do you mean that you are unable to access the URL manually through any of the browser? – undetected Selenium Jul 24 '17 at 14:50
  • @DebanjanB please let me know if my question is not clear enough, will edit it. – vikramvi Jul 24 '17 at 15:35
  • I am still not sure about the problem you are facing. But with your code with some simple modifications I am able to start the Hub. The console also shows up with in 2 seconds of providing the URL. Let me know if we're on the same page. Thanks – undetected Selenium Jul 24 '17 at 17:15
  • "...But same url either doesn't load or take really long time to load, when I start hub with java programme as below..." let me know which part of this sentence is not clear to you ? – vikramvi Jul 24 '17 at 19:11

1 Answers1

0

I am going to consolidate all that I have shared so far as part of this Google forum thread which also has the same discussion with OP.

  1. On the Sierra OS, there's a known issue that sometimes it takes a very long time to resolve IP address for localhost. For fixing that, you would need to add the output of hostname command to the /etc/hosts file and then try. See this SO post for more details.
  2. If you are on a CORPORATE network and have a proxy server sitting between you and the internet, then you may have to try and configure the Proxy settings to by pass traffic that is meant for either localhost or the IP Address of your machine from Network Preferences > Advanced (Click "Advanced" button) > Proxies (tab) > Bypass proxy settings for these hosts & domains

Once you have done both of the above, you can try one of the below mentioned combinations for booting up and loading up the Grid console:

  1. Provide the host name explicitly as localhost (which your code is already doing) and then load up the grid console via http://localhost:4444/grid/console (or)
  2. Repeat step (1) by skipping setting of the hostname, and loading the URL as returned by hub.getUrl().

My hunch is that you are perhaps on a company provided MAC and it has a proxy server configured. So when you open up the browser and try loading the console URL, the traffic is first being routed to the Proxy server which is trying to resolve the page and fails eventually after taking a long time because your proxy knows neither localhost nor the IP address of your machine (I am guessing that you are ending up using an internal IP address which is perhaps not exposed outside)

Hope that helps!

Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66