【发布时间】:2020-01-16 17:45:04
【问题描述】:
请给我建议。我只是在学习 Selenium WebDriver 工具并尝试在 Firefox 的窗口中运行一些测试,但第二次测试总是失败。我怎样才能避免这种情况?
壁虎驱动:v0.25.0-win32;
硒:3.141.59;
框架:JUnit;
火狐:69.0
我尝试了隐式和显式等待,但都没有帮助。
我的通用TestBase java类:
public class TestBase {
public static WebDriver driver;
public static WebDriverWait wait;
@Before
public void start() {
if (driver !=null){
return;
}
DesiredCapabilities caps = new DesiredCapabilities();
//caps.setCapability(FirefoxDriver.MARIONETTE, false);
driver = new FirefoxDriver(caps);
System.out.println(((HasCapabilities) driver).getCapabilities());
wait = new WebDriverWait(driver, 10);
Runtime.getRuntime().addShutdownHook(
new Thread(() -> { driver.quit(); driver=null;}));
}
和基于测试的类:
public class MyThirdTest extends TestBase {
@Test
public void mySecondTest() {
driver.navigate().to("https://google.com");
driver.findElement(By.name("q")).sendKeys("webdriver");
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("btnK"))).click();
wait.until(titleIs("webdriver - Поиск в Google"));
}
@Test
public void myThirdTest() {
driver.navigate().to("https://google.com");
driver.findElement(By.name("q")).sendKeys("webdriver");
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("btnK"))).click();
wait.until(titleIs("webdriver - Поиск в Google"));
}
}
我的输出是错误的:
JavaScript 错误:resource://gre/modules/XULStore.jsm,第 66 行:错误: 找不到个人资料目录。 1568573084487 木偶INFO听力 在端口 58557 上 2019 年 9 月 15 日晚上 9:44:44 org.openqa.selenium.remote.ProtocolHandshake createSession 信息: 检测到的方言:W3C
【问题讨论】:
标签: java selenium selenium-webdriver automated-tests geckodriver