使用chromedriver进行硒

时间:2013-11-19 09:22:34

标签: java selenium selenium-chromedriver

我正在尝试让chromeDriver与selenium一起使用。但即使使用路径设置,我也无法使其工作。

我正在使用gradle任务

按如下方式下载chrome-driver和selenium-server
webtestsCompile 'org.seleniumhq.selenium:selenium-chrome-driver:2.32.0'
webtestsCompile 'org.seleniumhq.selenium:selenium-server:2.35.0'

这两个是maven中央存储库上可用的最新版本

我正在设置

webdriver.chrome.driver to 

/home/bhavya/.gradle/caches/artifacts-26/filestore/org.seleniumhq.selenium/selenium-server/2.35.0/jar/e3f840bdd41ad805fac202695c93f7861fdf4552/selenium-server-2.35.0.jar

chrome驱动程序和selenium服务器存在于classPath中,类路径的片段是:

 /home/bhavya/.gradle/caches/artifacts-26/filestore/org.seleniumhq.selenium/selenium-chrome-driver/2.35.0/jar/e1e66d33eb849c1e721b4937da1eda96789a59f3/selenium-chrome-driver-2.35.0.jar:/home/bhavya/.gradle/caches/artifacts-26/filestore/org.seleniumhq.selenium/selenium-server/2.35.0/jar/e3f840bdd41ad805fac202695c93f7861fdf4552/selenium-server-2.35.0.jar

我正在尝试使用此代码启动并运行chromeDriver:

        ChromeDriverService cds =
                 ChromeDriverService.createDefaultService();
        try {
            cds.start();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
         driver = new ChromeDriver(cds); 
         driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);

当我运行我的测试用例时,我看到以下错误:

无效文件(错误幻数):执行格式错误 Gradle Worker 1完成了测试。

heimdall.ui.admin.UserEditControllerWebTest> initializationError FAILED     java.lang.ExceptionInInitializerError

    Caused by:
    org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
    Build info: version: '2.35.0', revision: '8df0c6bedf70ff9f22c647788f9fe9c8d22210e2', time: '2013-08-17 12:46:41'
    System info: os.name: 'Linux', os.arch: 'i386', os.version: '3.5.0-43-generic', java.version: '1.7.0_45'
    Driver info: driver.version: unknown
        at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:165)
        at heimdall.ui.webtest.DriverUtil.getDriver(DriverUtil.java:75)
        at heimdall.ui.webtest.DriverUtil.createDriver(DriverUtil.java:55)
        at heimdall.ui.admin.UserEditControllerWebTest.<clinit>(UserEditControllerWebTest.java:32)

        Caused by:
        org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:7826/status] to be available after 20003 ms
            at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:104)
            at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:163)
            ... 3 more

            Caused by:
            com.google.common.util.concurrent.UncheckedTimeoutException: java.util.concurrent.TimeoutException
                at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:143)
                at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:79)
                ... 4 more

                Caused by:
                java.util.concurrent.TimeoutException
                    at java.util.concurrent.FutureTask.get(FutureTask.java:201)
                    at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:130)
                    ... 5 more
 Process 'Gradle Worker 1' finished with exit value 0 (state: SUCCEEDED)

编辑2:

重新评估Chrome浏览器的更多信息 -

bhavya@bhavya-ums:~/git/heimdall_06_11$ ls -ltr /usr/bin/google-chrome
lrwxrwxrwx 1 root root 42 Nov 19 12:05 /usr/bin/google-chrome -> /usr/lib/chromium-browser/chromium-browser
bhavya@bhavya-ums:~/git/heimdall_06_11$ which chrome 
< does not return anything> I think by default on ubuntu it makes use of the chromium browser

1 个答案:

答案 0 :(得分:0)

将webdriver二进制文件放入/ usr / bin /

你的chrome实例会打开吗?