Selenium ChromeDriver do no start on linux

2019-07-25 18:07发布

Im trying to run my tests in junit, but im encountering the following error:

>org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.33.0', revision: '4e90c97', time: '2013-05-22 15:32:38'
System info: os.name: 'Linux', os.arch: 'i386', os.version: '3.2.0-45-generic-pae', java.version: '1.7.0_21'
Driver info: driver.version: RemoteWebDriver
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:111)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:129)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:119)
    at br.com.xact.xmanager.xdesk.administracao.LoginPageChrome.setUp(LoginPageChrome.java:23)
[...]

My code:

package br.com.xact.xmanager.xdesk.administracao;

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;

public class LoginPageChrome {
    private WebDriver driver;
    private String baseUrl;
    private boolean acceptNextAlert = true;
    private StringBuffer verificationErrors = new StringBuffer();

    @Before
    public void setUp() throws Exception {
        System.setProperty("webdriver.chrome.driver", "/usr/bin/google-chrome");
        driver = new ChromeDriver();
        driver.get("http://m01fab0054:8080/xmanager/hel.cadGruposSituacaoChamados.x");
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }

    @Test
    public void testConfiguraOLogin() throws Exception {
        driver.findElement(By.id("dsLogin")).clear();
        driver.findElement(By.id("dsLogin")).sendKeys("suporte");
        driver.findElement(By.id("dsSenha")).clear();
        driver.findElement(By.id("dsSenha")).sendKeys("senha");
        driver.findElement(By.id("loginButton")).click();
    }

    @After
    public void tearDown() throws Exception {
        driver.quit();
        String verificationErrorString = verificationErrors.toString();
        if (!"".equals(verificationErrorString)) {
        fail(verificationErrorString);
    }
}

private boolean isElementPresent(By by) {
    try {
        driver.findElement(by);
        return true;
    } catch (NoSuchElementException e) {
    return false;
}
}

private boolean isAlertPresent() {
    try {
        driver.switchTo().alert();
        return true;
    } catch (NoAlertPresentException e) {
        return false;
    }
}

private String closeAlertAndGetItsText() {
    try {
        Alert alert = driver.switchTo().alert();
        String alertText = alert.getText();
        if (acceptNextAlert) {
            alert.accept();
        } else {
            alert.dismiss();
        }
        return alertText;
    } finally {
        acceptNextAlert = true;
    }
}
}

1条回答
虎瘦雄心在
2楼-- · 2019-07-25 19:13
  1. Download the ChromeDriver from here: https://code.google.com/p/chromedriver/downloads/list
  2. You need to specify the file in the property:

    System.setProperty("webdriver.chrome.driver", "Path to driver you've downloaded in step 1");

查看更多
登录 后发表回答