8

I am trying to get my Selenium Grid running on Chrome driver.

At first I started hub and node: java -jar selenium-server-standalone-2.45.0.jar -role hub java -jar selenium-server-standalone-2.45.0.jar -role node -hub http://localhost:4444/grid/register

than I launch my test:

public class ChromeDriverTest {
    private WebDriver driver = null;
    String  BaseURL,NodeURL;

@Before
public void before() throws Exception{
    BaseURL="http://www.google.com";
    NodeURL="http://localhost:4444/wd/hub";
    File file = new File("C:\\Users\\pushkaryova\\Desktop\\Nexus\\driver\\chromedriver.exe");
    System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
    DesiredCapabilities capa =DesiredCapabilities.chrome();
    capa.setBrowserName("chrome");
    capa.setPlatform(Platform.ANY);
    driver=new RemoteWebDriver(new URL(NodeURL),capa);
}

@Test
public void GoogleSearch() throws Exception {
    driver.get("http://www.google.com");
    WebElement searchBox = driver.findElement(By.xpath("//div[3]/div/input[1]"));
    hightlight(searchBox);
    driver.findElement(By.xpath("//div[3]/div/input[1]")).clear();
    driver.findElement(By.xpath("//div[3]/div/input[1]")).sendKeys("Test");
    driver.findElement(By.xpath("//button")).click();

}

public void hightlight(WebElement webElement) throws InterruptedException {
    for (int i = 0; i < 2; i++) {
        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript(
                "arguments[0].setAttribute('style', arguments[1]);",
                webElement, "color: red; border: 3px solid red;");
    }
}

}

and get an error: org.openqa.selenium.WebDriverException: The path to the driver executable must be set by the webdriver.chrome.driver system property

What is wrong in my code?

Anna Puskarjova
  • 313
  • 2
  • 3
  • 6
  • did U tried solutiom from webdriver wiki??? – SkorpEN Mar 12 '15 at 16:18
  • @SkorpEN I tried a lot of solution and read a lot. But unfortunately that does not help me. Maybe you could state what exactly is wrong in my code? – Anna Puskarjova Mar 13 '15 at 10:01
  • U not set's property for chrome binary. First start with simplest working example. Yust tried to run chrome browser on grid machine, then by RemoteWebdriver. finally set system property for binary of chrom on grid machine. – SkorpEN Mar 13 '15 at 10:06
  • I have changed my method to: @Before public void before() throws Exception{ NodeURL="http://localhost:4444/wd/hub"; DesiredCapabilities c = DesiredCapabilities.chrome(); File file = new File("C:\\Users\\pushkaryova\\Desktop\\Nexus\\driver\\chromedriver.exe"); System.setProperty("webdriver.chrome.driver", file.getAbsolutePath()); c.setPlatform(Platform.ANY); c.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); driver=new RemoteWebDriver(new URL(NodeURL),c); } It works well with ChromeDriver, but not on SeleniumGrid. – Anna Puskarjova Mar 13 '15 at 12:44
  • Did other selenium grid drivers work correctly ??? – SkorpEN Mar 13 '15 at 15:04
  • As it's my first experience with the grid, I can say that I am not sure. I wanted to run one test on 2 different browsers. And I am not sure how to configure Grid so that I could managed to do that. – Anna Puskarjova Mar 16 '15 at 07:35

6 Answers6

16

The driver executable needs to be avaiable physically on node machine. You can set the path to exe while starting the node

Add this line in the command

-Dwebdriver.chrome.driver=./chromedriver.exe

I configure this from json file and found that's little easier

json file with name DefaultNode.json

{
  "capabilities":
      [
        {
          "browserName": "firefox",
          "maxInstances": 5,
          "seleniumProtocol": "WebDriver"
        },
        {
          "browserName": "chrome",
          "maxInstances": 5,
          "seleniumProtocol": "WebDriver"
        },
        {
          "platform": "WINDOWS",
          "browserName": "internet explorer",
          "maxInstances": 1,
          "seleniumProtocol": "WebDriver"
        }
      ],
  "configuration":
  {
    "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
    "maxSession": 5,
    "port": 5555,
    "host": ip,
    "register": true,
    "registerCycle": 5000,
    "hubPort": 4444,
    "hubHost": ip
  }
}

To start the node with json config

java -jar selenium-server-standalone-2.45.0.jar -role webdriver -nodeConfig DefaultNode.json -Dwebdriver.ie.driver=.\IEDriverServer.exe

Notice the IEDriverServer.exe is placed in same directory with json file

Saifur
  • 16,081
  • 6
  • 49
  • 73
  • Thank you! This worked for me quite well! But if I want to run the same test with FireFox or IE won't this be a problem? – Anna Puskarjova Mar 13 '15 at 12:56
  • You have to specify the path to the exe same way and instantiate the target driver exe from commmandline. – Saifur Mar 13 '15 at 13:03
  • You mean in such a way: java -jar selenium-server-standalone-2.45.0.jar -role node -hub http://localhost:4444/grid/register -Dwebdriver.chrome.driver=.\IEDriverServer.exe – Anna Puskarjova Mar 16 '15 at 07:33
  • Well , if this is webdrive test I am afraid you have to do ~webdriver~ instead of ~node~ – Saifur Mar 16 '15 at 13:13
  • @SkorpEN I have resolved my issue starting a node with the command - java -jar selenium-server-standalone-2.45.0.jar -role node -hub http://localhost:4444/grid/register -Dwebdriver.ie.driver=IEDriverServer.exe – Anna Puskarjova Mar 18 '15 at 08:15
  • @SkorpEN I am not sure about which one address you are talking about? I am launching hub and node locally on my machine. – Anna Puskarjova Mar 18 '15 at 08:16
4

This works for me in 3.3.1 and above

java -Dwebdriver.chrome.driver="C:\chromedriver.exe" -jar selenium-server-standalone-2.45.0.jar -role node -hub localhost:4444/grid/register -browser "browserName=chrome,version=ANY,platform=WINDOWS,maxInstances=20" -maxSession 20

Webdriver path should be placed before the -jar options

Matt
  • 68,711
  • 7
  • 155
  • 158
1

You can start your node as:

java -jar selenium-server-standalone-2.45.0.jar -role node -hub localhost:4444/grid/register -browser "browserName=chrome,version=ANY,platform=WINDOWS,maxInstances=20" -Dwebdriver.chrome.driver="C:\chromedriver.exe" -maxSession 20
Matt
  • 68,711
  • 7
  • 155
  • 158
Freya
  • 63
  • 1
  • 7
1

I could run chrome and firefox remotely using selenium grid when I added both properties in json config file like this way here: notice the last two lines

{
  "capabilities":
  [
    {
      "browserName": "firefox",
      "marionette": true,
      "maxInstances": 5,
      "seleniumProtocol": "WebDriver"
    },
    {
      "browserName": "chrome",
      "maxInstances": 5,
      "seleniumProtocol": "WebDriver"
    },
    {
      "browserName": "internet explorer",
      "platform": "WINDOWS",
      "maxInstances": 1,
      "seleniumProtocol": "WebDriver"
    },
    {
      "browserName": "safari",
      "technologyPreview": false,
      "platform": "MAC",
      "maxInstances": 1,
      "seleniumProtocol": "WebDriver"
    }
  ],
  "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
  "maxSession": 5,
  "port": -1,
  "register": true,
  "registerCycle": 5000,
  "hub": "http://192.168.1.2:4444",
  "nodeStatusCheckTimeout": 5000,
  "nodePolling": 5000,
  "role": "node",
  "unregisterIfStillDownAfter": 60000,
  "downPollingLimit": 2,
  "debug": false,
  "servlets" : [],
  "withoutServlets": [],
  "custom": {},
  "webdriver.gecko.driver":"c:/drivers/geckodriver.exe",
  "webdriver.chrome.driver":"c:/drivers/chromedriver.exe"
}
Amado Saladino
  • 2,114
  • 23
  • 25
0

You can set the path to the folder containing the chromedriver executable in your System variables (for Windows).

That got rid of the error for me.

OluLab
  • 1
0

Instead of specifying the driver executable in the cmd command, better approch would be :

java -jar **selenium-server-standalone-3.8.1.jar** -role node  -hub http://localhost:4444/grid/register

Save this as a .bat file and keep all the required Driver executable in the **same folder as the bat file**.

No when you double click the bat file to start the node, it will pick up the executables automatically.

anandhu
  • 686
  • 2
  • 13
  • 40