繁体   English   中英

使用Java将用于Firefox的Selenium IDE转换为Chrome和Internet Explorer

[英]Convert selenium IDE for firefox to chrome and internet explorer using Java

我可以使用Selenium IDE对使用Firefox的任何网站进行测试。 我想使用为Selenium IDE firfox创建的脚本来使用chrome测试同一网站。 由于没有适用于IE和Chrome的可靠IDE,我考虑使用以下解决方法-

1-创建一个firefox Selenium IDE脚本/测试,并将其转换为Java(我非常了解Java)。 2-稍微修改一下Java代码,使其可以在任何浏览器而不是FF上运行。

我只需要一个大概的解决方案。 我不想详细学习Selenium Web驱动程序API,因为我不应该这样做。 我在这里得到(1)的答案- 如何将Selenium IDE中记录的命令转换为Java?

我该如何划分(2)? 我的方法可以吗? 我只想使用硒,因为有大量的文档和书籍。

您要使用selenese-runner-java (SRJ)。

特征

  • 运行使用Selenium IDE创建的测试用例或测试套件
  • 直接从Java代码运行测试
  • 从命令行运行测试
  • 支持最常见的驱动程序(firefox(默认),chrome,即phantomjs ...)
  • 通过WebDriverFactory支持自定义驱动程序
  • 可以嵌入到Maven构建过程中(也可用于连续集成过程)
  • Since 1.7.0 :使用CommandFactory的实现来支持自定义命令

样品用法

首先,使用Selenium IDE创建测试(案例和/或套件),并将其保存在磁盘上。

1)从命令行运行测试

java -jar selenese-runner.jar               \
     --driver chrome                        \
     --chromedriver path/to/chrome-driver   \
     path/to/my-test.html

2)以编程方式运行测试

public static void main(String[] args) {
    String[] myArgs = new String[] { //
    //
       "--driver chrome", //
       "--chromedriver path/to/chrome-driver", //
       "path/to/my-test.html"
    };

    jp.vmi.selenium.selenese.Main.main(myArgs);
}

3)在Maven构建过程中运行硒测试

硒测试通常在integration-test阶段运行。 此外,selenese-runner-java必须是pom.xml依赖项的一部分。

...
<properties>
    <exec.maven.plugin.version>1.3.2</exec.maven.plugin.version>
    <selenese.runner.java.version>x.y.z</selenese.runner.java.version>
    <speed>0</speed><!-- Tests speed in milliseconds (Fast: 0, Slow: 5000) -->
</properties>

...
<dependency>
    <groupId>jp.vmi</groupId>
    <artifactId>selenese-runner-java</artifactId>
    <version>${selenese.runner.java.version}</version>
</dependency>

...
<build>
    <plugins>
       <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>exec-maven-plugin</artifactId>
          <version>${exec.maven.plugin.version}</version>
          <executions>
             <execution>
                <id>Execution Tests Selenium</id>
                <phase>integration-test</phase>
                   <goals>
                      <goal>exec</goal>
                    </goals>
                    <configuration>
                        <executable>java</executable>
                        <includePluginDependencies>true</includePluginDependencies>
                        <includeProjectDependencies>true</includeProjectDependencies>
                        <classpathScope>test</classpathScope>
                        <longClasspath>true</longClasspath>
                        <commandlineArgs>
                            <!-- CDATA is crucial here... -->
                            <![CDATA[-cp selenese-runner-java-${selenese.runner.java.version}.jar jp.vmi.selenium.selenese.Main --driver chrome --chromedriver path/to/chrome-driver --baseurl http://localhost:8080 --set-speed ${speed} src/test/TestSuite.html --html-result target/selenium-reports]]>
                        </commandlineArgs>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

没有webdriver,没有简单的方法可以做到这一点。 如果您真的不想这样做,那么您可能必须编写自己的工具。 我不确定为什么您不想学习Selenium Webdriver API。 如果您知道Java,那么可能需要几天的时间才能保持良好状态

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM