0

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.

3
  • Hope this post will help you. Commented Feb 19, 2013 at 10:33
  • As per the post i have already set classpath in environment variables in windows. when am running like "javac filename.java" its giving me errors why because its a selenium testcase. Commented Feb 20, 2013 at 5:09
  • hey any one know about this thing.please help me if anyone knows about it.Thanks in advance. Commented Feb 26, 2013 at 5:22

3 Answers 3

2
+50

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 {
Sign up to request clarification or add additional context in comments.

1 Comment

I guess you haven't search when you are asking question actually i have posted this answer that was already commented in SO. Anyways thanks for awarding.
0

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.

2 Comments

As of now am doing the same thing with eclipse. I just want to know whether we can o that using command line as we do for htmlsuite as stated in question.
If you right-click the project in eclipse and select "export" a dialog comes up. If you then select General -> Ant Buildfiles, it will generate a build.xml file that ant can use to build from the command line. In here you will see all the definitions for libraries etc and if it is a simple build, you can probably use javac with a few command-line parameters
0

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

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.