【问题标题】:Selenium test wont launch Firefox (java with Netbeans)Selenium 测试不会启动 Firefox(带有 Netbeans 的 java)
【发布时间】:2013-11-13 00:31:01
【问题描述】:

我在 Firefox 上安装了 Selenium IDE,我对其进行了简单的测试,并将测试用例导出到 Java/JUNIT4/WebDriver 下的 Netbeans。当我将代码放入 Netbeans 并尝试运行它时,它不会启动 firefox。我有另一个简单的程序,它将启动 Firefox 并去谷歌搜索奶酪,但是当我尝试导出我使用 Selenium IDE 运行的测试时,我无法让它运行。我没有收到任何错误,并且当我运行它时我得到“成功构建”,只是没有任何反应。这是我的代码。谢谢

> Blockquotepackage firstpackage;

import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
//import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
//import org.openqa.selenium.support.ui.Select;

public class FirstPackage {
private WebDriver driver;
private String baseUrl;
//private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
private boolean acceptNextAlert;
public static void main(String args[]){}

@Before
public void setUp() throws Exception {

  driver = new FirefoxDriver();

 driver.get("http://google.com");
 baseUrl = "https://www.google.com/";
 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
// WebDriver driver = new FirefoxDriver();

   System.out.println(driver.getTitle());


}

@Test
public void testGoogleSearch() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.id("gbqfq")).clear();
driver.findElement(By.id("gbqfq")).sendKeys("Google");
driver.findElement(By.id("gbqfb")).click();
}

@After
public void tearDown() throws Exception {
 driver.quit();
 String verificationErrorString = verificationErrors.toString();
 if (!"".equals(verificationErrorString)) {
  fail(verificationErrorString);
}

}

private boolean isElementPresent(By by) {
try {
  driver.findElement(by);
  return true;
} catch (NoSuchElementException e) {
  return false;
}


}



 private String closeAlertAndGetItsText() {
 try {
  Alert alert = driver.switchTo().alert();
  if (acceptNextAlert) {
    alert.accept();
  } else {
    alert.dismiss();
  }
  return alert.getText();
 } finally {
   acceptNextAlert = true;
 }

}

}


    // TODO code application logic h

 > Blockquote

【问题讨论】:

  • 你得到什么错误?
  • 您使用的是哪个版本的 Selenium 库和 Firefox 浏览器?

标签: netbeans selenium


【解决方案1】:

此问题可能是由于 FirefoxSelenium Firefox WebDriver 的版本不兼容造成的。

我的猜测是,您的工作程序(去 Google 并搜索奶酪的程序)在其路径中具有不同版本的 Selenium,而不是 NetBeans 最终用于从 IDE 导入的测试。

有关如何处理版本兼容性问题的更多信息,请参阅my answer to this question

【讨论】:

    【解决方案2】:

    我刚刚在我的机器上运行了您的代码,它按预期工作。确保您使用正确的 jar 文件并在项目中正确映射。

    【讨论】:

      猜你喜欢
      • 2015-05-04
      • 1970-01-01
      • 1970-01-01
      • 2013-11-08
      • 1970-01-01
      • 2023-03-16
      • 1970-01-01
      • 2020-07-26
      • 1970-01-01
      相关资源
      最近更新 更多