Because UI tests are inherently slow, running them in parallel–that is, running multiple tests, in multiple browsers concurrently–is all but a necessity.
Luckily, it’s hilariously easy to run Geb tests in parallel, using Maven… all you need do is add the following code to you Maven pom.xml:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.17</version> <configuration> <parallel>methods</parallel> <threadCount>4</threadCount> <forkCount>4</forkCount> <threadCountSuites>5</threadCountSuites> <reuseForks>true</reuseForks> <includes> <include>**/*Spec.*</include> </includes> </configuration> </plugin> |
And then run your tests via Maven. Eg. mvn test -Dgeb.env=chrome
. You can try it for yourself by running my geb-example on GitHub.
This code will spread your tests between up to 4 threads/forks and run tests at the method (test) level. You can also swap out “methods” for “classes” if you’re prefer to run at the spec (class) level. Either way, you can dramatically speed up your automated tests with a few lines of code…
You did think about running tests in parallel when writing your tests… didn’t you?
Can you please give more details on how you suggest to run Geb tests in parallel in multiple browsers? Is there a way to specify multiple environments for one suite using Geb+Spock+Maven?
That is an excellent question, Leo. :)
Hi Brian,
I want execute tests in parallel mode (Geb,TestNG & Maven Stack), but when i tried to do,its always typing in single instance, Could you help me how can i achieve that. How to open multiple browsers in Geb (As of now from GebConfig i am able to create one instance of any browser(Chrome,Firefox,Safari etc..). The same could be done in selenium just by creating instance to different browser. Please help out how i can i do it Geb.
Regards,
Mahantesh
Hi Mahantesh,
I seem to remember reading that TestNG handles parallel runs differently? I don’t use TestNG, so StackOverflow is your best bet :) Sorry I couldn’t be more help.
Hi Brian,
How to add this plugin in gradle.
Thank you,
Sam
Hi Mahantesh,
Did you solve the problem of running tests in parallel using Geb TestNg and Maven. From GebConfig I am able to create only one instance.