如何设置Fluentlenium在不同的浏览器驱动程序中运行?

时间:2013-06-12 16:32:44

标签: selenium webdriver fluentlenium

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

“java.lang.IllegalStateException:驱动程序可执行文件的路径必须由webdriver.chrome.driver系统属性设置;有关详细信息,请参阅http://code.google.com/p/selenium/wiki/ChromeDriver。最新版本可从{{3 }}     在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)     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)     at 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的代码:

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

3 个答案:

答案 0 :(得分:3)

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

公共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;
}

答案 1 :(得分:1)

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);
}

答案 2 :(得分:0)

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

时返回