8

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

4
  • Use Selenium IDE otherwise i don't understand why you don't like to use Selenium IDE. Commented Jul 12, 2011 at 11:03
  • Because I need to make program to starting JUnit tests just from selenium HTML files. I will have a folder with selenium html files and when I start the program, it will take these files and do the JUnit test for each file... Commented Jul 12, 2011 at 11:31
  • As Selenium IDE has an export test case to JUnit option, it is clearly programmatically possible. Writing your own program which does the conversion may take more time than not using the IDE is worth. Commented Aug 3, 2011 at 12:51
  • see stackoverflow.com/questions/5951136/… Commented Dec 4, 2012 at 12:34

4 Answers 4

3

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/

Sign up to request clarification or add additional context in comments.

1 Comment

That link is not for me :/
2

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.

Comments

2

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.

Comments

0

Look at the selenese4J-maven-plugin. Similar to selenium4j (https://github.com/RaphC/selenese4j-maven-plugin).

Provides many features : Selenium 1/2 (WebDriver) conversion Test Suite generation Internationalisation of your html file Possibility to use snippet into your html file for specific test (e.g : computing working day, write custom generation of values, handle dynamic values ...) Use of tokenized properties

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.