How do i run my serenityJS tests in parallel? - cucumberjs

I want to run my tests in parallel so it could save time, i did find an option in serenity where we can run the tests in batch but not parallel, also cucumber-parallel seems to be promising,
the below link is for maven project,
Running Serenity -Cucumber Test cases in parallel
Any suggestion for Serenity/JS with npm?

When Serenity/JS works with Protractor, it's Protractor that you'll need to configure to run your tests in parallel.
To do that, add the shardTestFiles and maxInstances properties to the capabilities (or multiCapabilities, if you're using different types of browsers) section of your protractor.conf.js files:
exports.config = {
capabilities: {
// execute tests using 2 browsers running in parallel
shardTestFiles: true,
maxInstances: 2
// ... other config
},
};
Here's an example config file you might find useful.
If this answer helps, please mark it as accepted, thank you!

Related

Maven Tests not Running in sequential Order

I'm using a TestNG framework for my automation project.
While running from command line i'm giving the following command.
mvn clean test -Dtest=Login,OpenImage,Logout
By running the above command it the order of execution was Login->Logout->OpenImage (may be in alphabetical order).
Can anyone help me how to run tests in the given order.
Note: As per my requirement I need to run my tests in the above way it self.
If it was through testNG.xml file then i guess preserve-order will work.
can anyone help me on this.....!!!!!
Thank you in advance..
First why do you need to run tests in a particula order because units should never rely on a particular order. But your question looks like more an integration tests.
If you need to run in order defined dependencies between the tests
#Test
public void serverStartedOk() {}
#Test(dependsOnMethods = { "serverStartedOk" })
public void method1() {}
The above defines the order that serverStartedOk will run before method1..based on the dependsOnMethods...

Step definition folder structure in cypress cucumber preprocessor

Versions
Cypress version: 8.4.0
Preprocessor version: 4.2.0
Node version: 12.18.2
Hi all, apologies if this is a stupid question, I'm quite new/noob with cypress, let alone cypress + cucumber.
So I wrote some automation tests in cucumber, and they work fine. I have the feature files in the integration folder, and the step definition folders in the integration folder too. Now I'm trying to have some structure where under integration I have a folder named step_definitions (will show better in screenshot).
folder structure
In package.json I put the following:
"cypress-cucumber-preprocessor": { "nonGlobalStepDefinitions": true, "nonGlobalStepBaseDir": "step_definitions", "commonPath": "common", "stepDefinitions": "step_definitions" }
When I try to run the tests, I get the below error:
Error: We've tried to resolve your step definitions at step_definitions, but that doesn't seem to exist. As of version 2.0.0 it's required to set step_definitions in your cypress-cucumber-preprocessor configuration. Look for nonGlobalStepDefinitions and add stepDefinitions right next to it. It should match your cypress configuration has set for integrationFolder. We no longer rely on getting information from that file as it was unreliable and problematic across Linux/MacOS/Windows especially since the config file could have been passed as an argument to cypress.
Any pointers are appreciated :)
It seems to me that the problem in your case in "stepDefinitions": "step_definitions" have you tried to give the full path like "stepDefinitions": "cypress/integration/step_definitions"?
You should set nonGlobalStepDefinitions to false or remove this setting, as you don't have a separate folder for the step_definitions but it is inside the integration folder instead.
So, in order to use your structure, please modify that section in the package.json file to:
"cypress-cucumber-preprocessor": {
"commonPath": "cypress/integration/step_definitions/common",
"stepDefinitions": "cypress/integration/step_definitions"
}
That would be enough. It works.

Gradle. Running tests in parallel from one Class

Using Java 11, Gradle 6.5.1
In the build.gradle there is an option:
maxParallelForks = 8
I have two classes, first has 2 tests and second has 30 tests.
When I run tests using Gradle it runs only in 2 threads:
./gradlew clean test
One thread - tests for the first class, second thread - tests for the second class.
But, how to make Gradle to execute all tests in parallel?
So tests from the same class could be run in parallel in 8 threads.
If you're using JUnit 5, you can do this using JUnit's parallel execution instead of Gradle's. Note that this will be within the same JVM (I believe Gradle's maxParallelForks uses separate JVMs).
E.g. in your Gradle script:
test {
...... (your existing stuff here)
systemProperties = [
'junit.jupiter.execution.parallel.enabled': 'true'
'junit.jupiter.execution.parallel.mode.default': 'concurrent'
]
}
Different test frameworks may have equivalents.
Other than that, a workaround might be to split your tests into a separate class per test case. You can use things like test class inheritance to avoid duplication with this.
If you have more than the 2 test classes you've mentioned here, you'd only need to split up the few longest running classes to get most of the benefit.

in webstorm how to create a mocha test configuration for a single test

I want to debug just a single test in webstorm. The mocha options specify a test directory, but I can't seem to point it to just a single test.js file.
How can I debug/run configure a single mocha test using the webstorm debug configuration options?
As a hack, you could configure the mocha command directly with the CLI option:
mocha --grep login-failure.js
Also, you can use the only function to skip all other tests:
describe(function () {
// these tests will be skipped
});
describe.only(function () {
// these tests will run
});
Source: http://jaketrent.com/post/run-single-mocha-test/
As far as I'm aware it's not currently supported.
https://youtrack.jetbrains.com/issue/WEB-10067 -- watch this ticket (star/vote/comment) to get notified on progress.
I solved this by pointing to a random non-test directory as the test directory and passing my single test filename in as an "extra mocha option"
Why not just create a test folder and create your .js test file inside?

Why do my Gradle tests run repeatedly?

I have a pretty standard Gradle build that's building a Java project.
When I run it for the first time, it compiles everything and runs the tests. When I run it a second time without changing any files, it runs the tests again.
According to this thread, Gradle is supposed to be lazy by defaut and not bother running tests if nothing has changed. Has the default behaviour here been changed?
EDIT:
If I run gradle test repeatedly, the tests only run the first time and are subsequently skipped. However, if I run gradle build repeatedly, the tests get re-run every time, even though all other tasks are marked as up-to-date.
the gradle uptodate check logs on info level why a task is not considered to be up-to-date. please rerun the "gradle build -i" to run with info logging at check the logging output.
cheers,
René
OK, so I got the answer thanks to Rene prompting me to look at the '-i' output...
I actually have 2 test tasks: the 'test' one from the Java plugin, and my own 'integrationTest' one. I didn't mention this in the question because I didn't think it was relevant.
It turns out that these tasks are writing their output (reports, etc.) to the same directory, so Gradle's task-based input and output tracking was thinking that something had changed, and re-running the tests.
So the next question (which I will ask separately) becomes: how do I cleanly (and with minimal Groovy/Gradle code) completely separate two instances of the test task.
You need to create test tasks in your build.gradle and then call those specific tasks to run a specific set of tests. Here is an example that will filter out classes so that they don't get run twice (such as when running a suite and then re-running its child classes independently):
tasks.withType(Test) {
jvmArgs '-Xms128m', '-Xmx1024m', '-XX:MaxPermSize=128m'
maxParallelForks = 4 // this runs tests parallel if more than one class
testLogging {
exceptionFormat "full"
events "started", "passed", "skipped", "failed", "standardOut", "standardError"
displayGranularity = 0
}
}
task runAllTests(type: Test) {
include '**/AllTests.class'
testReportDir = file("${reporting.baseDir}/AllTests")
testResultsDir = file("${buildDir}/test-results/AllTests")
}
task runSkipSuite(type: Test) {
include '**/Test*.class'
testReportDir = file("${reporting.baseDir}/Tests")
testResultsDir = file("${buildDir}/test-results/Tests")
}
Also, concerning your build question. The "build" task includes a clean step which is cleaning tests from your build directory. Otherwise the execution thinks the tests have already been ran.

Resources