使用 Selenium-Maven 插件通过 Google Chrome 运行 Selenium 2.0 Selenese 测试

发布于 2024-11-15 22:42:09 字数 2903 浏览 1 评论 0原文

我试图通过 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 浏览器启动后并没有进入测试运行程序,而是停留在我的主页上。

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

请参阅下面我的 POM 文件的片段。

....
<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>
....

谢谢,

胡安

I am trying to run through some Selenium 2.0 HTML tests through the selenium maven plugin (version 1.1) on Google Chrome (version 12.0.742.100) and I get the error, Cannot call method 'indexOf' of undefined, after trying to execute the Open Command.

After searching, it seems that we should be executing our chrome executable with the --disable-web-security parameter, which isn't easy to do with the Selenese goal. It looks like the plugin allows us to specify the file path for the chrome executable as a part of the parameter in the Selenium-Maven-plugin, but it doesn't allow me to append the --disable-web-security to the call. It will give out a maven build error if I try to do so.

What I tried to do is put the call in a batch file, and then point to the batch file in my POM, and that worked. However, what ends up happening is that the chrome browser starts up and doesn't go to the test runner, it stays on my home page.

My question here, is there anyway to get over the errors that I pointed through the Selenese tests in Chrome using the Selenium-Maven plugin? If not, what is the best way to approach this besides converting the tests to JUnits/TestNg tests.

Please see the snippet of my POM file below.

....
<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>
....

Thanks,

Juan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

走过海棠暮 2024-11-22 22:42:09

尝试所需的功能 - 请参阅此处: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 子目录中

Try the desiredCapabilities - see here: http://code.google.com/p/selenium/wiki/ChromeDriver

So I would suggest you using something like this in your @BeforeClass function:

 @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);

BTW best way is to store chromedriver.exe in your maven /src subdirectory

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文