【问题标题】:How can I setup Fluentlenium to run in different browser drivers?如何设置 Fluentlenium 以在不同的浏览器驱动程序中运行?
【发布时间】:2013-06-08 20:58:25
【问题描述】:

我正在尝试在不同的浏览器驱动程序中运行 Fluentlenium。我想我需要从 Fluentlenium 配置 getDefaultDriver() 但我不完全确定如何做到这一点。任何示例代码都会很棒。这是我的代码,它不起作用。我在 Eclipse 中收到的消息是:

"java.lang.IllegalStateException:驱动程序可执行文件的路径必须由webdriver.chrome.driver系统属性设置;更多信息请参见http://code.google.com/p/selenium/wiki/ChromeDriver。最新版本可以从http://code.google.com/p/chromedriver/downloads/list下载 在 com.google.common.base.Preconditions.checkState(Preconditions.java:176) 在 org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:105) 在 org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:75) 在 org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:107) 在 com.picklist.tests.PicklistCreate.(PicklistCreate.java:32) 在 sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 在 sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) 在 sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 在 java.lang.reflect.Constructor.newInstance(Constructor.java:525) 在 org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:195) 在 org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:244) 在 org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 在 org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:241) 在 org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) 在 org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) 在 org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) 在 org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) 在 org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) 在 org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) 在 org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) 在 org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) 在 org.junit.runners.ParentRunner.run(ParentRunner.java:309) 在 org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) 在 org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

"

我的代码如下:

public WebDriver driver = new ChromeDriver();

// Overrides the default driver
@Override
public WebDriver getDefaultDriver() {
    System.setProperty("webdriver.chrome.driver", "C:/chromeDriver/chromedriver.exe"); // Set for ChromeDriver
    //return driver;
    return driver;
}

如果我执行以下代码,它可以工作,但是不再定义驱动程序,并且我得到了一个使用 driver.xxx 的大量 od 代码:

// Overrides the default driver
@Override
public WebDriver getDefaultDriver() {
    return new ChromeDriver();
}

【问题讨论】:

    标签: selenium webdriver fluentlenium


    【解决方案1】:

    这是我解决这个问题的方法:

    公共 WebDriver 驱动程序;

    // Overrides the default driver
    @Override
    public WebDriver getDefaultDriver() {
        System.setProperty("webdriver.chrome.driver", "C:/chromeDriver/chromedriver.exe"); // Set for ChromeDriver
        driver = new ChromeDriver();
        return driver;
    }
    

    【讨论】:

    【解决方案2】:

    FluentTest 中没有getDefaultDriver,可以使用这段代码:

    @Override
    public WebDriver newWebDriver() {
        System.setProperty("webdriver.chrome.driver", "path-to-chrome-driver/chromedriver");
        Map<String, Object> chromeOptions = new HashMap<String, Object>();
        chromeOptions.put("binary", "/usr/bin/chromium-browser");
        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
        return new ChromeDriver(capabilities);
    }
    

    【讨论】:

      【解决方案3】:

      有一个抽象的createDriver() 函数,它被每种类型的驱动程序覆盖。每个驱动都应该返回一个正确配置的驱动,然后存储起来,调用getDefaultDriver();时返回

      【讨论】:

        猜你喜欢
        • 2016-05-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-06
        • 2015-03-28
        • 2016-08-16
        • 1970-01-01
        • 2016-03-17
        相关资源
        最近更新 更多