Quick learner
Quick learner

Reputation: 709

How to run java file exported from selenium IDE through command prompt in windows

Can some one tell me how can i run the java file which was exported from selenium IDE through command prompt.

I have used the following command: "java -jar selenium-server.jar -htmlSuite "*firefox" "http://www.google.com" "C:\mytestsuite\mytestsuite.html" "C:\mytestsuite\results.html"

Able to launch selenium functional test runner but nothing is executed there.

Upvotes: 0

Views: 4795

Answers (3)

Luis Carlos
Luis Carlos

Reputation: 343

This is the solution: Test is your Class mande by selenium

import org.junit.runner.JUnitCore;
import com.example.tests;

public static void main(String[] args) {
    Result result = JUnitCore.runClasses(Test.class);
    for (Failure failure : result.getFailures()) {
        System.out.println(failure.toString());
    }
}

Upvotes: 0

krishna5115
krishna5115

Reputation: 86

The converted tests are JUnit tests. So you should have two processes:

Your selenium server process:

java -jar lib/selenium-server-standalone-2.28.0.jar Your JUnit test runner

"java -cp /usr/share/java/junit.jar org.junit.runner.JUnitCore [test class name] " If you have several test classes, it might be better to create a TestSuite with the Suite annotation:

@RunWith(Suite.class)
@SuiteClasses({
   MyTestClass1.class,
   MyTestClass2.class})
public class TestSuite {
   ...

If you are using Spring, you can setup config containing selenium server address, browser, ...

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:my/package/seleniumConfig.xml"})
public abstract class SeleniumTestSuite {

Upvotes: 2

hack_on
hack_on

Reputation: 2522

The java test cases exported don't compile because they require at least the Selenium library to compile and may need junit or TestNG as well to actually run. I really suggest that you do this from within eclipse.

You can get eclipse 32 or 64 bit here. Then create a new Java project by going File-> New -> Java Project. You can get the Selenium client zip here. You need to get the client jar (called selenium-java-2.31.0.jar) out of this zip and put it in the lib directory of your new Java project in eclipse. You may have to create the lib directory and then right-click the jar file in the lib directory and "add to build path".

Put the java code that was generated by the Selenium IDE into the src directory of the new Java project in eclipse. (you may need to create the appropriate packages under src etc). Then right-click the test case java file that you want and select "Run As ... Junit". This should run it for you. If you get compile or run errors you can update your question above.

Upvotes: 0

Related Questions