私は基本的なMavenとSeleniumのプロジェクトでopenGmailを2つ使用しています。私はFirefox 47.0.1とGecodriver 0.18でSelenium 3.5を使用しています。コードで定義されている場合でもGeckodriverエラーが発生する
私の主なクラスがある:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class MainClass {
WebDriver driver = new FirefoxDriver();
public void setup() {
String Path_GecoDriver="C:/Personal/Selenium/setup/geckodriver-v0.18.0-win64";
System.setProperty("webdriver.firefox.marionette", Path_GecoDriver+"/geckodriver.exe");
System.setProperty("webdriver.gecko.driver", Path_GecoDriver+"/geckodriver.exe");
}
public void OpenBrowser() {
String url="http://google.co.in";
driver.get(url);
}
public void LoginGmail() throws InterruptedException {
String username ="username";
String passwd = "passwd";
driver.findElement(By.linkText("Gmail")).click();
driver.findElement(By.id("identifierId")).sendKeys(username);
WebElement cli=driver.findElement(By.xpath("//*[text()='Next']"));
cli.click();
Thread.sleep(1000);
driver.findElement(By.xpath("//input[@name='password']")).sendKeys(passwd);
driver.findElement(By.xpath("//*[text()='Next']")).click();
}
public void CloseBrowser() {
driver.close();
}
}
私の他のクラスがある: -
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class TestngClass {
MainClass mc=new MainClass();
@Before
public void sp() {
mc.setup();
mc.OpenBrowser();
}
@Test
public void LG() throws InterruptedException {
mc.LoginGmail();
}
@After
public void CB() {
mc.CloseBrowser();
}
}
私はでそれをテストを実行しようとした
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information
エラーを取得しています私のSystem.setProperty(prop、path/to/driver)を@Beforeと@ testに入れても、変更はしませんが、まだエラーが出ています。
私は単一のクラスを使用する場合、すべて正常に動作するので、私は間違った場所に私のsystem.setPropertyを配置していると思う。
私は最近、JavaとSeleniumを使い始めました。私もあなたが以下のようにプロパティを2回設定しているIn System.setProperty("webdriver.gecko.driver", "<Path to your WebDriver>"), what is meant by "Path to your WebDriver"?
それは "webdriver.gecko.driver" ではなく "webdriver.firefox.marionette" でなければなりません。それを変えればあなたは大丈夫でしょう。 –
私の回答を更新 –
'IllegalStateException'を取り除くことができるかどうか教えてください – DebanjanB