Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium - convert html to junit programmatically

Is it possible to programmatically, in java, convert Selenium HTML file to JUnit test source code?

I need my own program which gets only resources of these html files, converts them to java code and automatically runs the JUnit test. Is there any way to do that?

In Selenium IDE, it is possible to export test cases to JUnit, I know that, but I don't want to use IDE, I need to do this programmatically as I said once before.

I believe that someone needed this before and someone can help me...

like image 609
jantobola Avatar asked Jul 12 '11 10:07

jantobola


3 Answers

How about http://code.google.com/p/selenium4j/ ??

How does Selenium4j work?

In short Selenium4j translates the HTML tests to Java JUnti tests.

UPDATE

Maven port of this project available through https://github.com/willwarren/selenium-maven-plugin:

<dependency>
    <groupId>com.gbi.maven</groupId>
    <artifactId>selenium-maven-plugin</artifactId>
    <version>1.0.2</version>
    <scope>test</scope>
</dependency>

Also it mirrored at warious MVN repos:

http://mojo.codehaus.org/selenium-maven-plugin/

like image 99
gavenkoa Avatar answered Nov 19 '22 22:11

gavenkoa


There exists a Firefox plugin for the Selenium IDE called Test Suite Batch Converter which can convert batches of HTML files to any export format the IDE supports.

like image 32
timginn Avatar answered Nov 19 '22 23:11

timginn


I took the selenium4j project and turned it into a maven plugin for those who want to take the html test cases and automatically have them run with your maven test phase. You can also separate the tests out using a profile override with surefire.

Readme is here: https://github.com/willwarren/selenium-maven-plugin

The short version of the readme:

Converts this folder structure:

./src/test/selenium
    |-signin
        |-TestLoginGoodPasswordSmoke.html
        |-TestLoginBadPasswordSmoke.html
        |-selenium4j.properties

Into

./src/test/java
    |-signin
        |-firefox
            |-TestLoginGoodPasswordSmoke.java
            |-TestLoginBadPasswordSmoke.java

This is only tested on windows with Firefox and Chrome.
I couldn't get the IE version to pass a test, but I'm new to selenium so hopefully, if you're a selenium guru, you can get past this.

like image 2
Will Avatar answered Nov 20 '22 00:11

Will