0
votes

I am writing several different selenium tests as page objects, and want to be able to run them from within a single, central class. I have figured out how to run one test from a different class, but when I try to run multiple tests, only a single one will complete.

I have tried running them sequentially with org.junit.runner.JUnitCore.main("com.etc"), but after testing the first class, the entire test ends. In the code:

org.junit.runner.JUnitCore.main("com.etc.test.HomePageCheck");
System.out.print("test");

the print command is never run, even if the test runs successfully

I have also tried creating multiple threads, but once any test completes, the whole process seems to end and leave the remaining tests hanging.

To reiterate, I have Class1 with several jUnit tests, and Class2 with other jUnit tests. I want to be able to run a Class3, whcih will run both Class1 and Class2 and complete all tests for those other classes. I do not think I want to use Selenium Grid, I would rather just run the tests locally on a machine, either in sequence or, preferably, in parallel.

1
Maybe Suite is what you're looking for: github.com/junit-team/junit/wiki/Aggregating-tests-in-suites Also you should probably post some of your code so we can see what you did wrong.user1071777
Selenium grid could be an opition. docs.seleniumhq.org/docs/07_selenium_grid.jspbcar

1 Answers

0
votes

I figured it out, here is the code(second line is key, the others are just to get the output)

Result aTest;
aTest= org.junit.runner.JUnitCore.runClasses(new Class<?>[]
{
    Events.class,SearchCheck.class});
    for(Failure i:aTest.getFailures())
    {
        System.out.println(i.getException()+"\nat: "+i.getDescription());
        System.out.println("trace: "+i.getTrace());
        System.out.println();
    }
}

Thanks everyone

Edit: actually testSuite also works extremely, and is probably the better way to do this.