I have specified the number of threads as 20 for 300 test cases. When the test run starts it occupies all the 20 threads and completes over 270+ test cases, after that the thread occupancy is getting reduced to very few and by the end it is running with single thread.
This is the same case irrespective of number of threads/number of test cases, where the last 10% of the tests are occupied with minimum number of threads even though there are more test cases to run than the number_of_threads.
Test environment:
Selenium Grid v2.53.1
Ruby, Cucumber, Remotewebdriver with http::persistent client
I have searched for similar issue and there is nothing i can relate to, please let me know if there is an existing issue in Selenium for this, or is there any tweaks to resolve this?
This has got nothing to do with Selenium, especially the Selenium Grid. The Grid is merely an execution environment, which facilitates running your browser based UI tests in a remote environment.
It does not manage the test concurrency. You would need to check at the ruby level to figure out what is happening here.
Related
I have a project which contains around 50 junit tests. Each test takes about 5-6 minutes to run since it tries to assert on some data which takes about that time to be available in redshift(the test look up the data in redshift). Now I am trying to run all them in parallel and expecting all test to be run in about 15-20 minutes max. I tried to use test.runWith(){maxParallelForks} option but the tests takes more than an hour. These tests are all independent. Is there an efficient way to parallelize them?
N.B This is a neighbor test not just junits. So I don't have the option to mock the results as results to be derived from the actual interactions between our neighbor systems.
Thanks
Here is what I am using:
tasks.withType(Test) {
maxParallelForks = 50
}
Our cut off is to have them running in 20-25 minutes max but it's taking more then an hour.
Create a file named junit-platform.properties in your test/resources folder with the following data:
junit.jupiter.execution.parallel.enabled=false
junit.jupiter.execution.parallel.config.strategy=fixed
junit.jupiter.execution.parallel.config.fixed.parallelism=4
I have a 4 cores (without hyper threading). You can also try the dynamic option.
Annotate your class with #Execution(ExecutionMode.CONCURRENT)
Here is a great article on the topic. Also one here.
I have also experimented with parallel test execution and hat the following conclusions:
If the tests are short (not as in your case though) it's not worth it. When dealing with short tests the effort to setup the whole multi-threaded testing environment and the context switches later on didn't result in any performance gain. (I have had ca 150+ Unit tests)
When dealing with Spring the tests need to be configured correctly. As you start containers parallel, they must not try to use the same port etc. Also you have to be aware of context-caching. (Even if test B didn't require the component XYZ, I asked spring to initialize it, and then it realized that test A already had the same configuration, hence the context was reused with resulted in a way better performance gain than having two different containers starting on multiple threads.)
If your tests contain code (as in your case), where you "await" an event in order to complete the test, using multiple threads is the way to go.
Finally: "Sounds good, doesn't work." - On my local machine the parallel execution resulted in some degree of performance gain (IntelliJ, maven), but in our CI server we have a single virtual core machine, and there asking for fixed 4 threads resulted in a massive performance drop.
Inconsistency is the theme here. I have a large Selenium test suite that is giving me issues on a Mac. My coworkers use Windows and they are not experiencing any problems with it. Essentially when I run the whole suite using TestNG, the tests behave differently than when run individually. Individually, the tests complete without any problems. When run as a whole suite, currently about ten tests, the third test to be executed always hangs at the exact same spot. It tries to find an element and never comes out of the Selenium API. The point of no return is marked with the XXX below.
driver.manage().timeouts().pageLoadTimeout(20000, TimeUnit.MILLISECONDS);
driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
try {
element = driver.findElement(By.xpath(xpathLocator)); // XXX
} catch (NoSuchElementException | org.openqa.selenium.TimeoutException e)
The suite is not being run in parallel. The same behavior is occurring across Chrome, Firefox, and Safari although the element that is being sought when the program hangs does change between browsers. I'm currently using Mac 10.10.6 with the latest versions of Selenium, Eclipse, and TestNG. The same behavior is occurring on separate Mac machines. The behavior is also the same whether I run the TestNG suite in Eclipse or from the command line. The entire suite is executed without any problems when logging is enabled on the node via -log someFile or when the node is running on a remote machine i.e. not locally. The suite is fairly large so if there's any other code I can post here that would be helpful in diagnosing the issue please let me know. Any ideas to point me in the right direction would be very helpful.
Placing timeouts and wait's are inherently subjective since the time a page takes to load can vary. The best thing you can do is place it in a while loop, but include a large timeout to force the code out of the while loop, or throw an error if the element cannot be found since it is a test after all.
int i = 0;
while (!driver.findElement(By.xpath(xpathLocator))
{
//timeout goes here
i++;
if (i == 10) throw new exception
}
something like this should do the trick
I think you should increase implicitlyWait from '0'.
I heard there are some HTML loading issues in Mac. By increasing the time value, it will solve DOM loading issues.
Selenium Document says this about implicitlyWait.
Implicit Waits
An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instanc
I am able to execute maximum 5 test cases in parallel on one machine.
How to increase the number of test cases?
You'll typically be limited by the power of your computer (number of CPU core and memory speed and amount). This will relate to the number of browsers you open, and therefore the number of test you can run. To run more tests, faster, use a Selenium Grid, such as SauceLabs (which is free for a trial period).
I talk about this is the book I'm working on -- Selenium WebDriver In Practice.
Alex
I run grid with 2 nodes on the same Linux VM, sometimes (50%) a test fails due to NoSuchElementException, with no real reason, the Element is there - can see it on runtime,
however I can never catch this failure while debugging.
I'm pretty sure it related to parallel testing.
I use Ubuntu 12.04, with Firefox 18 & google-chrome 23.0.
My webdriver instances are initiated in the test method itself.
My testing.xml specifies parallel=methods and I can see all browsers open at the same time and tests are running together.
Is this a known issue? I intended to run even higher parallelism, but the more nodes I add to the VM and more tests I run in parallel - the bigger the failure rate.
Is there a fix for that ?
i can guess that you are running all your nodes on the same VM display, therefore - it is very likely, that your tests are interfering one another when running in parallel, 2 actions (in test) can be executed simultaneously and only one event will actually be executed (like click).
also this probably consumes high compute resources from your node HW.
it is recommended (by me, from experience) to run one node per browser/platform machine when running in parallel to prevent false negatives. (hub can still be in same machine of a node).
or - in linux only you can run different node sessions on different DISPLAY-Xs, this will still consume compute resources and probably slow down the tests if you use too many.
you can try and read this, maybe it will raise some ideas :
effective ui testing lab
we have 500+ test cases for our application. Test cases are running for 4 to 6 hours based on the CPU and RAM overhead.
For each test case Selenium will start and stop the IE. IE takes the backup of the registry for each test case. I am seeing the following statements for each test case and
14:43:38,312 INFO [org.openqa.selenium.server.browserlaunchers.WindowsProxyManager] Backing up registry settings...
14:43:40,234 INFO [org.openqa.selenium.server.browserlaunchers.WindowsProxyManager] Modifying registry settings...
There is 2 minutes time difference between above two statements.
Can we bypass the backup of the registry and run the test cases. In this way my test cases will finish less than 20min to current build.
This thread shows how to reuse a Firefox session. I haven't tried it, but I imagine there is an equivalent for Internet Explorer. You could also use Selenium Grid to speed up the duration.