Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integration testing with Maven, Protractor and Selenium WebDriver

We develop a web application that uses Java on the back-end and Angular for the UI, with Maven as the build system.

I've been trying to set up automated integration testing with Protractor, and after loads of Googling/StackOverflowing still can't figure out how the end-2-end configuration can be achieved.

Node.js/NPM installation (failed)

I've tried using frontend-maven-plugin to handle Node.js and NPM installation, but since we're behind a corporate firewall, it doesn't seem possible to download anything directly. It could download Node from our Artifactory though, but then failed on NPM download (I don't understand why it even downloads it as it's a part of Node package). Anyway, I gave up on this idea and decided to use Node installed locally.

Starting Tomcat

Starting/stopping a Tomcat instance for e2e testing is handled nicely by

        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <url>${tomcat.manager.url}</url>
                <path>/</path>
                <server>Tomcat</server>
            </configuration>
            <executions>
                <!-- Starting Tomcat -->
                <execution>
                    <id>start-tomcat</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <!-- Fork the process, otherwise the build will be blocked by the running Tomcat -->
                        <fork>true</fork>
                        <port>${tomcat.port}</port>
                        <systemProperties>
                            <!-- We want to use the 'e2e' profile for integration testing -->
                            <spring.profiles.active>e2e</spring.profiles.active>
                        </systemProperties>
                    </configuration>
                </execution>
                <!-- Stopping Tomcat -->
                <execution>
                    <id>stop-tomcat</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>shutdown</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

Using WebDriver (failed)

I managed to start WebDriver, but the problem is it's blocking any further execution:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <executions>
                <!-- Start webdriver -->
                <execution>
                    <id>start-webdriver</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <configuration>
                        <executable>webdriver-manager</executable>
                        <arguments>
                            <argument>start</argument>
                        </arguments>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Running Protractor

Given that Node.js is installed and WebDriver is running, this shouldn't be a problem. But as I failed to start WebDriver so that it continues execution, this is blocked.

Any advice how the WebDriver can be managed (started/stopped)?

like image 491
yktoo Avatar asked Oct 31 '22 06:10

yktoo


1 Answers

Adding directConnect: true to the Protractor config file solves the issue of starting/stopping the WebDriver (as suggested by Nick). In that case any explicit control of the WebDriver has to be removed from the POM.

Available parameters are explained in detail in the reference configuration file.

like image 83
yktoo Avatar answered Nov 14 '22 23:11

yktoo