将用于Firefox的selenium IDE转换为使用Java的Chrome和Internet Explorer [英] Convert selenium IDE for firefox to chrome and internet explorer using Java

查看:174
本文介绍了将用于Firefox的selenium IDE转换为使用Java的Chrome和Internet Explorer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用硒IDE来测试任何使用Firefox的网站。我想用selenium IDE firfox创建的脚本来测试使用chrome的同一个网站。由于IE和Chrome没有可靠的IDE,所以我想使用下面的解决方法 -


$ b <1> - 创建一个firefox selenium IDE脚本/测试并将其转换为Java我很了解java)。
2 - 修改Java代码稍微在任何浏览器上运行,而不是FF。



我只需要一个粗略的解决方案。我不想详细学习硒web驱动程序API,因为我不应该。我得到了答案(1)在这里 - 如何转换记录在selenium IDE to Java?



我如何如此部分(2)?我的方法好吗?我只想使用硒因为有大量的文档和书籍。

解决方案

你想使用 selenese-runner-java (SRJ)。

特性




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



样例用法



首先使用selenium IDE创建您的测试(案例和/或套件)并将它们保存到磁盘上。
$ b

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



$ h $ 3)运行selenium测试作为Maven构建过程的一部分

Selenium测试通常在集成测试阶段运行。此外,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>
<速度> 0< /速度>< - 测试以毫秒为单位的速度(快速:0,慢速:5000)
< / properties>

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

...
< build>
< plugins>
< plugin>
< groupId> org.codehaus.mojo< / groupId>
< artifactId> exec-maven-plugin< / artifactId>
< version> $ {exec.maven.plugin.version}< / version>
< executions>
<执行>
< id>执行测试Selenium< / id>
<阶段>整合测试< /阶段>
<目标>
< goal> exec< / goal>
< /目标>
<配置>
< executable> java< / executable>
< includePluginDependencies> true< / includePluginDependencies>
< includeProjectDependencies> true< / includeProjectDependencies>
< classpathScope> test< / classpathScope>
< longClasspath> true< / longClasspath>
< commandlineArgs>
<! - CDATA在这里至关重要 - >
<![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>
< /执行>
< /执行次数>
< / plugin>
< / plugins>
< / build>


I can use selenium IDE to make a test for any website using firefox. I want to use the script created for selenium IDE firfox for testing the same website using chrome. Since there are no reliable IDEs for IE and Chrome, I thought of using the workaround below -

1 - Create a firefox selenium IDE script/test and convert it to Java (I know java well). 2 - Modify the Java code a little to run on any browser instead of FF.

I only need a rough solution. I don't want to learn selenium web driver API in detail because I am not supposed to. I got an answer to (1) here - How to convert commands recorded in selenium IDE to Java?

How do I so part (2) ? Is my approach okay ? I only want to use selenium because there is plenty of documentation and books for it.

解决方案

You want to use selenese-runner-java (SRJ).

Features

  • Run test cases or test suites created with Selenium IDE
  • Run tests from Java code directly
  • Run tests from command line
  • Support the most common drivers (firefox (default), chrome, ie, phantomjs ...)
  • Support of custom drivers through WebDriverFactory
  • Can be embedded in a maven build process (useful also for continouous integration process)
  • Since 1.7.0 : Support custom commands with the use of an implementation of CommandFactory

Sample usage

Firstly create your test (case and/or suite) with selenium IDE and save them on your disk.

1) Run tests from command line

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

2) Run tests programmatically

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) Run selenium tests as part of a Maven build process

Selenium tests are typically run during the integration-test phase. Moreover, selenese-runner-java must be part of the pom.xml dependencies.

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

这篇关于将用于Firefox的selenium IDE转换为使用Java的Chrome和Internet Explorer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆