Search code examples
javaseleniumgridipdesiredcapabilities

Selenium: Set the node thats executing by ip (or something else)


I am using the Selenium Grid with a hub on the server. To debug easier I want to execute the test on my specific pc and not on other nodes. (all Nodes are allways online) is there something like an ip-capability? (All Nodes running same Browser and Platform, etc.) Otherwise I have to do a Grid-Execution.java and a Local-Execution.java? If you have another idea how to do that, let me know! Greetings Arno


Solution

  • In our framework, there is a system property "IsLocal" and it is always true. We set it to false and pass additional parameter like hub ip and port number if we want to execute on the grid.

    Also, this value we can pass it from maven command line, if we execute from IDE then, the value is null, if it is null, the it will take default value, ie true. So it will always execute on local. if we need to test it on grid, we pass the IsLocal system value from maven or command line.

    In our driver Factory launch browser method. we always check this property if it true, we launch browser using local driver otherwise remote web driver. something like below code.

    boolean IsLocal=true;
    if(System.getProperty("IsLocal")!=null){
          IsLocal=System.getProperty("IsLocal");
    }
    
    if(IsLocal){
        driver=new FirefoxDriver();
    }
    else{
        driver= new RemoteWebDriver(HUBURL, DesiredCap);
    }