Running Selenium Tests in Parallel - testing

I have selenium test that takes 1 minute to complete . If I want to run this 1000 times I have to wait 16 hours . Is there any way I can run 5 tests in parallel so that it can be done in 3 hours ? I have generated a JUnit test scrip and tried to run in with multiple threads but they end up using the same Firefox window . I don't want to run this on grid cause running 5 Firefox window is not that resource intensive.
Thanks

By using below logic you can run your junit cases in parallel.
Class[] cls={test1.class,test2.class,test3.class,test4.class};
JUnitCore.runClasses(new ParallelComputer(true,false),cls);
In above method first parameter of ParallelComputer() indicates classes and second one is for methods. Here I'm running classes in parallel but not methods.
ParallelComputer Class documentation
http://junit-team.github.io/junit/javadoc/4.10/org/junit/experimental/ParallelComputer.html

Try with this example
http://mycila.googlecode.com/svn/sandbox/src/main/java/com/mycila/sandbox/junit/runner/
The file to launch is MySuite.java. Works well for me.

Related

Is there a way to control how tests are distributed with pytest --dist loadfile and loadscope

I am trying to figure out if there is a way I can control/ understand how the tests are distributed between different workers when I use the --dist=loadfile or loadscope feature.
The structure of my project is
tests
tests_a.py
.
.
.
.
.
tests_h.py
And each test module has a random number of tests defined in it. Let's say I have a particular test in tests_b.py that I want to run at the end of test suite and marked it by using #pytest.mark.last.
I also have the mechanism in that particular test implemented where if it is run by the worker and there are other workers running other tests, it will wait until they all are done. (By using --dashboard function where it updates number of tests are untested)
The problem I am facing is sometimes tests are randomly assigned to different workers and all the other workers complete the tests as expected but the worker working on tests_b.py which has the tearDown()(the function that I want to happen at the very end) runs the test even though there are other modules it needs to complete (lets say tests_f.py is assigned to this same worker). All other workers complete running and close. But this worker runs the tearDown() which waits for all other tests to be completed and is stuck in a loop because the other untested tests are assigned to this same worker and they never get executed. Is there a way to actually make this particular test to run at the end of all the tests that are assigned to the worker?
Thank you

How to run nightwatch.js tests in parallel?

I came across this question:
How can I run multiple tests in parallel with JS/nightwatchjs?
But I want to execute multiple tests in parallel in the chrome browser only, in multiple chrome driver sessions.
I am used to java-testng-selenium based test suites where I can specify in the testng.xml file that I want to run multiple test classes or test methods in parallel and the framework does that exactly. If I specify in testng.xml that I want multiple test methods to execute in parallel in 4 threads, 4 chrome browser sessions pop-up and 4 test methods are executed in parallel.
Here's an example with a thread-count=2: https://github.com/adityai/testng-parallelsample/blob/master/methods-test-testng.xml
How can I do the same with nightwatch.js?
You might want to try the test_workers configuration, although I haven't tried it myself it should do exactly what you are looking for.
And a nice article that demostrates it in action:
https://markus.oberlehner.net/blog/speeding-up-nightwatch-powered-acceptance-tests/

Is it possible to run multiple tests in parallel on same browser (IE) using Selenium Grid?

I have a selenium java code which executes tests on IE. I want to try executing these tests in parallel using the same browser. How can I achieve this? And will I need to use multiple nodes to do so?
You need to setup a selenium grid which has atleast 2 nodes attached to it.
When it comes to IE support, you can run ONLY 1 test at any given point in time on one selenium node.
So if you need to run two parallel IE tests, then you would need to have atleast 2 nodes attached to your grid.
This blog post of mine gives you a complete overview of the selenium grid.
https://rationaleemotions.github.io/gridopadesham/

Running the same junit test case using selenium webdriver in multiple instances of the same browser (load testing)

I'm trying to simulate a firefox load testing situation. I want my to test how 10 simultaneous logins would play out on my system. I already have a connected selenium grid hub and 10 open nodes.
So far, I know I can write the test case and run it 10 times which isn't what I need because it isn't automated. I also know that I can use invocation count on the test to make it run as many times as i want but this only works on the same browser node.
Does anyone have any ideas on how to automatically distribute the same test case to multiple instances of the same driver profile?
i.e. Run a login case test times on the same firefox profile open in 10 different nodes in parallel.
Gracias!
P.S. I built my tests using testNG if that matters.
Basically selenium and testNG is not for such requiurement. You should use some dedicated tool for that like jmeter.
However you can run n methods parrallel let say if you want to login with 10 dif user in 10 thread/browser you can create test data driven and configure to run method in parrallel. Make sure you are providing proper value of parrallel thread count.
How about combining threadpoolsize with invocationcount. - http://testng.org/doc/documentation-main.html#parallel-running
Grid would take care to distribute on the 10 nodes.
use headless browser like GHOST and then invoke multiple threads as ghost has no UI so it would work in your case

How to reduce the time in executing Selenium test cases?

I'm writing the Selenium test cases for each screen to test the different scenarios. In our project for each build in Jenkins, its Selenium test cases (QA) also runs automatically.
My problem is even though it's automated, it's taking a lot of time to run. I have 380 test cases and it's taking 20-25 minutes. How can I reduce the time? Are there any other ways or techniques to follow?
you can check for the Selenium grid option, which will help you to run the tests in parallel.
http://selenium-grid.seleniumhq.org/
In the 380 testcases you have , check if all the testcases are really required . If all the testcases are required , check if u are having any repeated validations and see if you can remove any one of them .
If you are using wait time in your testcases , see if you can reduce the wait times with out affecting the output of the testcases .
The best thing would be to split them in to seperate groups and run them in different machines using Grid . Or use TestNg/JUnit to run the testCases parallely .
In TestNg , in the testng.xml file , u can use the following to run them in parallel
<suite name="ParallelTests" verbose="5" parallel="methods" thread-count="10">