Reputation: 536
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?
Upvotes: 2
Views: 5807
Reputation: 11
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());
}
}
Upvotes: 1
Reputation: 33
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.
Upvotes: 3
Reputation: 6905
You can also download Cypress directly without npm
.
There are instructions as well as the direct download here.
Upvotes: 4