Trying to use the new cypress framework with a maven project - the documentation has only an npm module setup example (npm install cypress) and a package.json usage example.
How would this be converted to usage in a maven dependency?
You can also download Cypress directly without npm.
There are instructions as well as the direct download here.
Here's a great article on using maven to run Cypress tests.
You should be able to use a Docker container for Cypress via the maven Testcontainers plugin.
Here is a good article that allows you to execute cypress tests as a part of mvn build, so you can have your backend app up and running during the cypress testing. But I did a slight change because the solution in the article doesn't take any feedback about tests execution into consideration. So, this is what I've changed:
Container creation part:
#SneakyThrows
#NotNull
private GenericContainer<?> createCypressContainer()
{
var container = new GenericContainer<>(DockerImageName.parse("cypress/included:3.4.0"));
container.withClasspathResourceMapping("e2e", "/e2e", BindMode.READ_WRITE);
container.setWorkingDirectory("/e2e");
container.withCreateContainerCmdModifier(it -> it.withEntrypoint("cypress", "open").withWorkingDir("/e2e"));
container.addEnv("CYPRESS_baseUrl", "http://host.testcontainers.internal:" + port);
return container;
}
Test execution and results evaluation:
#Test
public void runCypressTests() throws InterruptedException, IOException
{
Testcontainers.exposeHostPorts(port);
try (GenericContainer<?> container = createCypressContainer()) {
container.start();
Container.ExecResult execResult = container.execInContainer("/bin/sh", "-c", "cypress run");
log.warn(execResult.getStdout());
assertEquals("End to end tests are failed. Execution exit code returned non 0 value",
0, execResult.getExitCode());
}
}
Related
I am trying to convert a maven project to gradle, and am struggling to get integration tests running. I am trying to use the recommended JVMTestSuite plugin, but the integration tests do not run correctly.
Using the example on the documentation, the current setup I have is this:
testing {
suites {
test {
useJUnitJupiter()
}
integrationTest(JvmTestSuite) {
testType.set(TestSuiteType.INTEGRATION_TEST)
dependencies {
implementation project()
}
targets {
all {
testTask.configure {
shouldRunAfter(test)
}
}
}
}
}
}
tasks.named('check') {
dependsOn(testing.suites.integrationTest)
}
When I run ./gradlew integrationTest, the build succeeds but no tests are being executed. When I run ./gradlew test, all the unit tests and integration tests run, but the integration tests fail as the Spring context is not set up correctly.
End result I would like is:
test command runs only unit tests
integrationTest sets up Spring context and executes tests
Each set of tests is filtered by name (eg. filtering "*IT.java" rather than using separate folder structures)
Is someone able to help with this? The documentation does not seem to lead to a working example. Thank you :)
I am using Jenkins Ver:2.176.3 for declarative multibranch pipeline.
I have junit test in my application code base and using maven surefire plugin to run unit test using maven command.
Multibranch job page shows 'Test Result' link and 'Test Result Trend' graph also.
I think this is being displayed/published here due to plugin 'test-results-analyzer'.
In declarative pipeline we have two stages as shown in code sample and we use maven commands.
Now my problem is that this test result count same unit test for each stage of pipeline so the count of unit tests are being double on this Test Result of Jenkins job page.
I tried skipping unit test in stage 'package-IT' using maven option -DskipTests and as per log it does skip unit testing but still see the duplicate test results.
if know please suggest
stages{
stage('compile-N-test') {
agent {label 'agent'}
steps {
script {
// mvn clean test
}
}
}
stage('packaging-IT') {
agent {label 'agent'}
steps {
script {
//mvn verify
}
}
}
Finally i got the solution: in pipeline we are using withMaven() which invoke test result and keep adding it so increasing count.
I try to use the rerunFailingTestsCount option to deal with flaky tests. In order to display these in the junit results, I use the flaky test handler plugin which would theoretically deal with displaying flaky tests
In my jenkins file this looks like
pipeline {
stages {
stage('tests') {
steps{
// sh mvn verify here
}
post {
always {
junit testResults: 'target/failsafe-reports/**/*.xml', testDataPublishers: [[$class:
'JUnitFlakyTestDataPublisher']]
}
}
}
}
}
the test run fine, flaky ones are repeated but when it comes to publishing the junit results, i get an
Error when executing always post condition: java.lang.AbstractMethodError: you must override contributeTestData
Google wasn't very helpful, maybe someone here had the same problem and can help me or at least can confirm that this plugin works as pipeline script (there is a pull request regarding pipeline support, so I am not sure...)
I want to run the SOAPUI project xmls using Gradle script. The GRADLE script should read the project xmls from soapuiInputs.properties file and run automatically all. Please guide me step by step how to create Gradle script to run the SOAPUI projects in Linux server.
Note: We use SOAPUI version 5.1.2.
Probably the simple way is to call the SOAPUI testrunner directly from gradle as Exec task, like you can do from cli.
In gradle you can define the follow tasks (Note that I try it on windows but to do the same on linux as you ask simply you've to change the paths):
// define exec path
class SoapUITask extends Exec {
String soapUIExecutable = 'C:/some_path/SoapUI-5.2.1/bin/testrunner.bat'
String soapUIArgs = ''
public SoapUITask(){
super()
this.setExecutable(soapUIExecutable)
}
public void setSoapUIArgs(String soapUIArgs) {
this.args = "$soapUIArgs".trim().split(" ") as List
}
}
// execute SOAPUI
task executeSOAPUI(type: SoapUITask){
// simply pass the project path as argument,
// note that the extra " are needed
soapUIArgs = '"C:/location/of/project.xml"'
}
To run this task use gradle executeSOAPUI.
This task simply runs a SOAPUI project, however testrunner supports more parameters which you can pass to soapUIArgs string in executeSOAPUI task, take a look here.
Instead of this if you want to deal with more complex testing there is a gradle plugin to launch SOAPUI project, take a look on it here
Hope this helps,
I'm using JUnit and Selenium2 to test my application. I execute the tests using Maven with the surefire plugin running in Jenkins. The test where fine some weeks and I added more and more tests and now the tests fails with this message:
Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.11:test (default-test) on project guitest: Failure or timeout
...
Process leaked file descriptors
I first thought I'm just leave files open in my code, for example when taking screenshots using the WebDriver (and apache commons IO to copy them):
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
File destFile = new File(...);
FileUtils.copyFile(scrFile, destFile);
But the problem persists even after removing the screenshot recording.
Do you guys have any pointers what's wrong here and/or how to tackle this problem?
EDIT:
I've implemented a WebdriverPool, to reuse WebDrivers / browser instances. I use a shutdown hook to close all open instances when the test has finished:
Runtime.getRuntime().addShutdownHook(new Thread(){
#Override
public void run(){
for (WebDriver driver : drivers.values())
driver.close();
if (!driversInUse.isEmpty())
throw new IllegalStateException("There are still drivers in use (" + driversInUse.size() + ")");
}
});
Might this be the problem?