Integration testing with Maven, Protractor and Selenium WebDriver - angularjs

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)?

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.

Related

TestEngine with ID 'junit-jupiter' failed to discover tests after maven repackage

I started to receive TestEngine with ID 'junit-jupiter' failed to discover tests error while running my tests by maven after configuring my plugin:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
Without this I was able to run all the tests without any issue by maven. I needed to add this to solve another issue but then I started to receive this error for my integration tests. When I enable log for maven I noticed that it cannot find domain classes(they are not test classes).
Caused by: java.lang.ClassNotFoundException: com.mypackage.domain.MyDomainObject
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 42 more
What can cause this issue any ideas?

How would I build a spring boot rest api project containing embedded reactjs front end code

I have a spring boot rest api project, using maven, into whose src folder I have a reactjs project. What I need to know is how would I change the pom.xml file so that a jar file is created that is executable for the complete application, both frontend and rest api.
This link will help you out: https://medium.com/#itzgeoff/including-react-in-your-spring-boot-maven-build-ae3b8f8826e
You just need to run the npm/yarn command from the pom.xml
Here is a sample:
<execution>
<id>yarn-install</id>
<goals>
<goal>yarn</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>build-frontend</id>
<goals>
<goal>yarn</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<arguments>build</arguments>
</configuration>
</execution>
Check this post, I highly encourage you to do a quick search in google before posting questions here
https://spring.io/guides/tutorials/react-and-spring-data-rest/

Spring boot & React production build

I created a spring boot project.After that,I created react project on spring boot project.Right now,both frontend and backend server are running.On frontend folder,I run that command npm run build.
It created a folder which is called build.What I want to do is to run all project with one server.(Example: localhost:8080).I know that I should move frontend files to under static folder.How do I do this?
I tried maven-antrun-plugin but it is not working.
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>generate-resources</phase>
<configuration>
<target>
<copy todir="${project.build.directory}/classes/public">
<fileset dir="${project.basedir}/frontend/build"/>
</copy>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Use the maven copy resources plugin

Resolving Izpack artifacts using maven dependency

I have Izpack installer which packs a pre-configured server and installs in target directory. This server is around 500Mb. Currently I have checked in this src/main/resources folder of installer maven project.But having this big server in git is making the git pulls very slow. So i am planning to keep this server as maven artifact in nexus and add its dependency to installer maven project. This way i can create a maven profile to pull this server from nexus on demand. I am yet to figure out how to copy this dependency to staging folder using a maven plugin(any help would be greatly appreciated). My question here, is it a right approach? or is there any better way to do this. Thanks in advance.
You can use the maven dependency plugin to copy a dependeny to a specific folder.
You can use it to either copy all dependencies or even unpack those dependencies.
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>unpack</id>
<phase>package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<outputDirectory>${izpack.staging}/content/ninjolibs</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
This is what i did. I uploaded wso2.zip to nexus as zip artifact and configured pom.xml of my installer module to use this dependency.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-binaries</id>
<phase>prepare-package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.wso2</groupId>
<artifactId>wso2is</artifactId>
<version>5.0.0</version>
<type>zip</type>
<overWrite>true</overWrite>
<outputDirectory>src/main/resources/wso2/binary</outputDirectory>
<destFileName>wso2is-5.0.0.zip</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>

Maven Proguard processing a library jar that other applications will depend one

Here is what my build plug in stanza looks like:
<plugin>
<groupId>com.pyx4me</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<options>
<option>-dontshrink</option>
<option>-dontnote</option>
<option>-allowaccessmodification</option>
<option>-dontskipnonpubliclibraryclasses</option>
<option>-dontskipnonpubliclibraryclassmembers</option>
</options>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
<lib>${java.home}/lib/jsse.jar</lib>
</libs>
</configuration>
</plugin>
Here is what I get from execution of mvn clean package
[proguard] Error: You have to specify '-keep' options for the shrinking step.
How do I specify the keep options for a library where I just want obfuscation?
You must define with the -keep option the entry points of your application, because you can't obfuscate it. For example if your main class is obfuscated it will be renamed and you won't be able to launch it. The same for public interfaces of your APIs.

Resources