まあ、私は時々ドライバを切り替える必要がないので、私はこれをしなかった:
私は自分のクラスにセレン関連のものを初期化 - アプリケーションの名前で呼ばれ、ドライバがゲッターにより近づいています。私のクラスのコンストラクタを呼び出すときに、私は初期化するために、ドライバの列挙型を使用します。
private WebDriver driver;
public TestUI(Environment.DriverToUse drv){
switch (drv){
case CHROME:{
ChromeDriverService service = ChromeDriverService.createDefaultService();
File file = new File(TestUI.class.getResource("/chromedriver.exe").toURI());
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, file.getAbsolutePath());
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
driver = new ChromeDriver(service,options);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
break;
}
case FIREFOX:{
FirefoxProfile ffProfile = new FirefoxProfile();
ffProfile.setPreference("browser.safebrowsing.malware.enabled", false);
driver = new FirefoxDriver(ffProfile);
driver.manage().window().setPosition(new Point(0, 0));
java.awt.Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension dim = new Dimension((int) screenSize.getWidth(), (int) screenSize.getHeight());
driver.manage().window().setSize(dim);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
break;
}
public WebDriver getDriver(){
return driver;
}
もちろん私Environment
クラスは、この
public class Environment {
public enum DriverToUse {FIREFOX, CHROME};
// .. and some other stuff, because I need to test on different environments, so I store here Environment URL for example
のように見え、私のテストクラスは、この
@Before
public static final Environment.DriverToUse USED_DRIVER = Environment.DriverToUse.FIREFOX;
@Test
public void testVersionNumber() throws Exception{
TestUI testUI= new TestUI(USED_DRIVER);
WebElement version = testUI.getDriver().findElement(By.id("the Id of element"));
version.click();
//...
}
ようになります
これはローカルマシンでも動作すると思いますか?私は試してみます – dermoritz
私はdocu(http://code.google.com/p/selenium/wiki/Grid2)を読んでいるだけで、問題が残っているようです。セレンのサーバーと私はまた、 "機能"(特定のブラウザ)で "webdriver"をインスタンス化する必要があります。現時点では、rcサーバーを使用すると構成のオーバーヘッドのみを意味します。 – dermoritz