Selenium grid Avec pilote Chrome (WebDriverException: le chemin vers l'exécutable du pilote doit être défini par le webdriver.chrome.propriété du système de conduite)

j'essaie de faire tourner ma grille de sélénium sur Chrome driver.

au début j'ai commencé hub and node: java-jar sélénium-serveur-autonome-2.45.0.jar-rôle hub java-jar sélénium-serveur-autonome-2.45.0.jar-rôle de nœud -hub http://localhost:4444/grid/register

que je lance mon 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:UserspushkaryovaDesktopNexusdriverchromedriver.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;");
    }
}

}

et obtenir un erreur: org.openqa.nium.WebDriverException: le chemin vers l'exécutable du pilote doit être défini par le webdriver.chrome.pilote du système de la propriété

Qu'est-ce qui ne va pas dans mon code?

6
demandé sur Anna Puskarjova 2015-03-12 18:15:06

4 réponses

l'exécutable driver doit être physiquement disponible sur la machine à noeuds. Vous pouvez définir le chemin vers exe tout en démarrant le node

ajouter cette ligne à la commande

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

j'ai configuré ceci à partir du fichier json et j'ai trouvé que c'est un peu plus facile

fichier json avec nom 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
  }
}

pour commencer le noeud avec la config json

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

Notez le IEDriverServer.exe est placé dans le même répertoire avec json fichier

14
répondu Saifur 2015-03-12 15:21:26

cela fonctionne pour moi dans 3.3.1 et plus

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

le chemin Webdriver doit être placé avant les options-jar

3
répondu Tamilarasan Rathinam Thangamut 2017-11-06 23:06:04

vous pouvez démarrer votre noeud comme:

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
1
répondu Freya 2017-11-06 23:05:38

vous pouvez définir le chemin vers le dossier contenant l'exécutable chromedriver dans les variables de votre système (pour Windows).

qui a éliminé l'erreur pour moi.

0
répondu OluLab 2016-04-05 18:35:51