使用selenium web驱动程序3.0后,Firefox 48未在脚本中打开任何URL

时间:2016-08-05 06:39:46

标签: firefox selenium-webdriver selenium-ide eclipse-neon

我已经将selenium webdriver版本更新到3.0 beta后我在eclipse ide中生成了一个脚本。在我运行脚本后,Firefox被打开但没有重定向到网址。

这是由selenium ide

生成的简单代码
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.testng.annotations.*;
import static org.testng.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class Selenium {
  private WebDriver driver;
  private String baseUrl;
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

  @BeforeClass(alwaysRun = true)
  public void setUp() throws Exception {
    driver = new FirefoxDriver();
    baseUrl = "https://www.google.co.in/";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }

  @Test
  public void testF() throws Exception {
    driver.get(baseUrl + "/?gws_rd=ssl");
    driver.findElement(By.id("lst-ib")).clear();
    driver.findElement(By.id("lst-ib")).sendKeys("hi");
    driver.findElement(By.id("lst-ib")).clear();
    driver.findElement(By.id("lst-ib")).sendKeys("hifi");
  }

  @AfterClass(alwaysRun = true)
  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 boolean isAlertPresent() {
    try {
      driver.switchTo().alert();
      return true;
    } catch (NoAlertPresentException e) {
      return false;
    }
  }

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

2 个答案:

答案 0 :(得分:0)

由于功能问题,就像Selenium从其他浏览器供应商那里获得的其他驱动程序一样,Mozilla已经发布了一个可执行调用geckodriver,它将与浏览器一起运行。

您需要下载最新的可执行文件geckodriver并将此下载的路径从您的计算机设置为系统属性,以使用Firefox驱动程序运行您的测试用例,如下所示:

 System.setProperty("webdriver.gecko.driver","path/to downloaded/geckodriver.exe");
 DesiredCapabilities capabilities = DesiredCapabilities.firefox();
 capabilities.setCapability("marionette", true);
 WebDriver driver = new FirefoxDriver(capabilities);

 //Now do your further stuff with Firefox driver

答案 1 :(得分:0)

  

要运行导出的IDE测试,请确保leg-rc软件包位于   类路径。

在Selenium 3更改日志中提到了。请参阅change log