简体   繁体   中英

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

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>

There is no easy way of doing it without webdriver. If you really don't want to do it then you probably have to write your own tool. I am not sure why you don't want to learn selenium webdriver api. If you know Java it would take you couple of days to be in a good shape

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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