anarche
anarche

Reputation: 536

Adding cypress test framework to Maven pom.xml

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

Answers (3)

Ivan Sidorenko
Ivan Sidorenko

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

Dave Clarke
Dave Clarke

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

Jennifer Shehane
Jennifer Shehane

Reputation: 6905

You can also download Cypress directly without npm.

There are instructions as well as the direct download here.

Upvotes: 4

Related Questions