Integration Tests on Geb / Spock + Selenium Grid do not run in parallel - selenium-grid

I have the following set-up: an integration tests project which has a suite of tests written in Groovy/Geb + Spock, which are running perfectly both using Selenium WebDriver and Selenium Grid (RemoteWebDriver).
The problem is that no matter how much I try to tweak the "system", I can't get the tests to run in parallel (i.e. although I have 3 slaves [nodes] registered to the hub, only one of the slaves actually receives the requests). I've enforced maxSession=1 to the Selenium nodes and tried different combinations of parallel=classes|methods, threadCount and fork settings in failsafe plugin configuration (pom.xml file).
I have the feeling that the problem lies somewhere between the maven configuration and selenium grid, probably in relation to Geb/Spock config.
Does any of you have any insight on this issue?
PS: someone suggested that running tests in parallel using Geb / Spock is not possible - because for some reason ?Geb? locks the JUnitRunner (not sure what this means).

Add following configuration to your build.gradle file:
tasks.withType(Test) {
maxParallelForks = 3 // here three forks shall open in parallel
forkEvery = 1
include '**/*TestName*.class' // name of your test class
}

There are test frameworks, TestNG for example, that support parallel testing on the method level out of the box.
Spock, as an example to the contrary, does not support it.
But you do not have to have multithreading implemented by your test framework to make this work.
You can use your build tool to run test classes in parallel, both Maven and Gradle support this.
If you are using Maven, this documentation page and examples might help you:
https://maven.apache.org/surefire/maven-surefire-plugin/examples/fork-options-and-parallel-execution.html
Specifically have a look at "Forked Test Execution".

You can run it for sure, The point is you have to put them (your tests) in threads. Here is the link.

Related

Running a single feature file before and after a test run

Was looking for a solution to run a feature file at the end of the suite
My workflow (In parallel Run)
karate.callSingle('Login.feature') so at the beginning i do one
login and then use the cookies/token for the whole suite
Run tests in Parallel
Runs the Logout.feature file
There is no direct support for this currently. By the way no one has ever requested this. If this is so important, kindly open a feature request.
One workaround is to set a singleton / Java static variable from callSingle and then in your JUnit / Java parallel runner, call the feature to logout using the Java API (search the docs for this) and you can pass arguments / access the static variable.
EDIT: just realized that the #AfterClass JUnit annotation may be more than sufficient for your needs.

Parallel execution of features files : maven-failsafe-plugin vs cucumber-jvm-parallel-plugin

Currently I'm using maven-failsafe-plugin to run multiple feature files in parallel with Selenium Grid + nodes ( all running in docker containers )
I'm basic questions as below
when to use cucumber-jvm-parallel-plugin ?
what benefits / disadvantages of cucumber-jvm-parallel-plugin over maven-failsafe-plugin parallel execution ?
Thanks in advance.
Below is the answer
"A common approach for running Cucumber features in parallel is to create a suite of Cucumber runners, one for each suite of tests you wish to run in parallel. For maximum parallelism, there should be a runner per feature file.
This is a pain to maintain and not very DRY."
https://github.com/temyers/cucumber-jvm-parallel-plugin/issues/139
additional details -
..Despite its name cucumber-jvm-parallel-plugin does not run any tests, it just automatically generates the Cucumber runners for you. This saves you time from making empty runner files and also just by changing the config of the cucumber-jvm-parallel-plugin you can have brand new set of runner files..
copied from http://automationrhapsody.com/running-cucumber-tests-in-parallel/#comment-3455579028

serenity jbehave multiple browsers

I am trying to setup a test project that uses serenity and jbehave
I am noticing that all examples use serenity.properties that define a browser in it
I would like to structure my tests in a way so that same test can be executed in IE/firefox/chrome etc
How do I do this?
You can pass in properties as command line properties, so you can rerun the same tests with different browsers by passing in different settings for webdriver.driver, e.g.
$ mvn verify -Dwebdriver.driver=firefox
$ mvn verify -Dwebdriver.driver=chrome
etc.
I think you are able to get this to work by creating multiple Junit test classes with each its own driver and execute them all in a single run.
Every test class should be able to assign a specific 'managed' driver (e.g. PhantomJS, Chrome, Firefox). This is documented here: http://www.thucydides.info/docs/serenity/#_serenity_webdriver_support_in_junit
I don't know what the impact this would have on the generated report, hopefully you are still able to identify the feature/driver combination.

Running WEbDriver tests

So i have been writing Selenium tests for a while now and i have been running the only from the IDE untill now.
i would like to be able to write a script that runs all my tests sequentialy.
I am using the testng framework with eclipse and selenium-2.0b3 jar.
What i'd like is eventually to have a file like "runSeleniumTests.bat" witch just runs them and gives me some sort of report when in finishes.
if anyone has an idea, it will be very greatly appreciated, thanks :)
This has 4 options for how to run testng tests the xml file should include all your tests
http://testng.org/doc/documentation-main.html#running-testng
You could also try to use maven and as long as your tests are annotated correctly and in /src/test/java they will all be run for you with mvn integration-test (as long as you have the proper dependencies defined and I believe maven-surefire-plugin). This might be more difficult to setup initially but usually pays off.

Running single integration test quickly in Grails

Is it possible to quickly run single/all integration test in a class quickly in Grails. The test-app comes with heavy baggage of clearing of all compiled files and generating cobertura reports hence even if we run single integration test, the entire code base is compiled,instrumented and the cobertura report is getting generated. For our application this takes more than 2 minutes.
If it was possible to quickly run one integration test and get a rapid feedbck, it would be immensely helpful.
Also, is it important to clean up all the compiled files once the test is complete? This cleaning is fine if we run the entire set of integration test, but if we are going to run one or two tests in a class this cleaning and re-compiling seems to be a big bottleneck for quicker feedback to developers.
Thanks
If you have an integration test class
class SimpleControllerTests extends GrailsUnitTestCase {
public void testLogin() {}
public void testLogin2() {}
public void testLogin3() {}
}
You can run just one test in this class using:
grails test-app integration: SimpleController.testLogin
However, you will still have to incurr the time penalty required for integration testing (loading config, connecting to DB, instantiating Spring beans, etc.)
If you want your tests to run quickly, then try to write unit tests rather than integration tests.
It is the intention of the integration test to do this whole compiling, data base creation, server starting, etc. because the tests should run in an integrated environment, as the name implies.
Maybe you can extract some tests to unit tests. These you can run in Eclipse.
You can switch off Cobertura by placing the following code in your grails-app/conf/BuildConfig.groovy:
coverage {
enabledByDefault = false
}
Like you stated, the majority of time is setting up the application environment, injecting beans and doing the dynamic class annotations. You can speed up your integration test cycle by only loading this once, by running your tests in the grails REPL.
However, the tradeoff is that there are dynamic reloading issues in the REPL. If you see random weirdness, exit the REPL and reload.
$> ./grailsw --plain-output
|Loading Grails 2.5.3
|Configuring classpath
|Enter a script name to run. Use TAB for completion:
grails> test-app -integration
... (loads some things)
...
grails> test-app -integration
... (faster loading)
And to reply to the other commenters - integration tests are useful as well, there is some code that cannot be tested with a unit test (for instance, testing HQL or SQL queries).