1

我正在尝试在 Maven 项目中运行 Selenium。不幸的是,程序在初始化时挂起,WebDriver没有错误消息

WebDriver driver = new FirefoxDriver();

以下是我已经尝试解决的问题:

  • 添加Selenium-server为依赖项->不起作用
  • 添加Selenium-server-standalone为依赖项->不起作用
  • 手动开始Selenium-server-standalone->不工作
  • 添加Selenium-server-standalone到 ClassPath(在 Eclipse 中)->工作

即使我找到了我的测试项目在 Eclipse 中运行的方法,我仍然需要使用“纯”Maven 项目运行所有内容。这是由于 CI 集成,而且我更喜欢使用 Netbeans 而不是 Eclipse。

我想到的另一件事是,当我使用无头浏览器 ( ) 时一切正常HtmlUnitDriver

有人可以给我一个提示,让我使用纯 Maven 项目和真正的浏览器运行所有东西吗?先谢谢了!

  • 硒服务器版本:2.33.0
  • Selenium-server-standalone 版本:2.33.0
  • 版本火狐:21
  • 版本 Netbeans:7.3
  • Eclipse 版本:Juno Service Release 2
4

1 回答 1

1

我在 Maven 项目中使用 webdriver。但我使用它的旧版本。我的驱动程序设置:

 protected static WebDriver driver;

    @BeforeClass
    public static void setUp() throws MalformedURLException {
        DesiredCapabilities capability = DesiredCapabilities.firefox();

        driver = new FirefoxDriver();  //for local check
        driver.manage().window().setSize(new Dimension(1920, 1080));
}

POM.xml 中可用于 webDriver 初始化的依赖项:

 <dependencies>
      <dependency> <groupId>org.seleniumhq.selenium</groupId>
          <artifactId>selenium-java</artifactId>
          <version>2.29.1</version>
      </dependency>

      <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.8.2</version>


      </dependency>
  </dependencies>

希望这对您有所帮助。

于 2013-06-10T12:25:28.107 回答