【问题标题】:Running Selenium 2.0 Selenese tests through Google Chrome using Selenium-Maven plugin使用 Selenium-Maven 插件通过 Google Chrome 运行 Selenium 2.0 Selenese 测试
【发布时间】:2011-06-16 17:59:00
【问题描述】:

我正在尝试通过 Google Chrome(版本 12.0.742.100)上的 selenium maven 插件(版本 1.1)运行一些 Selenium 2.0 HTML 测试,但我收到错误,无法调用未定义的方法“indexOf”,在尝试执行打开命令之后。

经过搜索,我们似乎应该使用 --disable-web-security 参数执行我们的 chrome 可执行文件,这对于 Selenese 目标来说并不容易。看起来插件允许我们将 chrome 可执行文件的文件路径指定为 Selenium-Maven-plugin 中参数的一部分,但它不允许我附加 --disable-web-security 来电。如果我尝试这样做,它会给出一个 Maven 构建错误。

我试图做的是将调用放入批处理文件中,然后指向我的 POM 中的批处理文件,这很有效。然而,最终发生的事情是 chrome 浏览器启动并且没有进入测试运行器,它停留在我的主页上。

我的问题是,有没有办法克服我在 Chrome 中使用 Selenium-Maven 插件通过 Selenese 测试指出的错误?如果不是,除了将测试转换为 JUnits/TestNg 测试之外,最好的解决方法是什么。

请看下面我的 POM 文件的 sn-p。

....
<properties>
    <selenium.version>2.0b3</selenium.version>
</properties>
<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>selenium-maven-plugin</artifactId>
            <version>1.1</version>
            <dependencies>
                <dependency>
                    <groupId>org.seleniumhq.selenium</groupId>
                    <artifactId>selenium</artifactId>
                    <version>${selenium.version}</version>
                    <type>pom</type>
                    <exclusions>
                        <!-- prevent ant:ant versus org.apache.ant:ant collision -->
                        <exclusion>
                            <groupId>ant</groupId>
                            <artifactId>ant</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <id>Run-googlechrome-Script</id>
                    <phase>integration-test</phase>
                    <goals>
                        <goal>selenese</goal>
                    </goals>
                    <configuration>
                        <browser>*googlechrome</browser>
                        <suite>src/test/selenium/html/TestSuite.html</suite>
                        <startURL>http://localhost:5555/</startURL>
                        <results>${project.build.directory}/results/googlechrome-smoke-results.html</results>
                        <port>5555</port>
                        <timeoutInSeconds>5000</timeoutInSeconds>
                        <multiWindow>true</multiWindow>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
....

谢谢,

胡安

【问题讨论】:

    标签: google-chrome maven-2 selenium selenium-rc selenium-webdriver


    【解决方案1】:

    尝试所需的功能 - 请参阅此处:http://code.google.com/p/selenium/wiki/ChromeDriver

    所以我建议你在 @BeforeClass 函数中使用类似的东西:

     @BeforeClass
     public static void createAndStartService() {
      service = new ChromeDriverService.Builder()
        .usingChromeDriverExecutable(new File("path/to/my/chromedriver"))
      DesiredCapabilities capabilities = DesiredCapabilities.chrome();
      capabilities.setCapability("chrome.switches", Arrays.asList("--disable-web-security"));
      WebDriver driver = new ChromeDriver(capabilities);
    

    顺便说一句,最好的方法是将 chromedriver.exe 存储在您的 maven /src 子目录中

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-04
      相关资源
      最近更新 更多