0

Getting following exception while executing integration tests using mvn verify against my webapp. The integration tests just loads the server url using HtmlUnit and checks for the status code 200. Not sure what I am missing here. It looks like the resource filtering is not working as expected here. Please guide.

Error Log:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.study.jenkins.it.htmlunit.PageIT
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.951 sec <<< FAILURE! - in com.study.jenkins.it.htmlunit.PageIT
testScenario(com.study.jenkins.it.htmlunit.PageIT)  Time elapsed: 0.949 sec  <<< ERROR!
java.net.MalformedURLException: no protocol: ${server.url}
        at java.net.URL.<init>(URL.java:585)
        at java.net.URL.<init>(URL.java:482)
        at java.net.URL.<init>(URL.java:431)
        at com.gargoylesoftware.htmlunit.util.URLCreator.toNormalUrl(URLCreator.java:36)
        at com.gargoylesoftware.htmlunit.util.URLCreator$URLCreatorStandard.toUrlUnsafeClassic(URLCreator.java:82)
        at com.gargoylesoftware.htmlunit.util.UrlUtils.toUrlUnsafe(UrlUtils.java:195)
        at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:359)
        at com.study.jenkins.it.htmlunit.PageIT.testScenario(PageIT.java:12)

Running com.study.jenkins.it.selenium.PageIT

pom.xml

<properties>
    <dev.tc.base.url>http://dev-server.com</dev.tc.base.url>
    <tst.tc.base.url>http://tst-server.com</tst.tc.base.url>
</properties>

<build>
    <finalName>${project.artifactId}</finalName>
    <resources>
        <resource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

<profiles>
    <profile>
        <id>dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <server.url>${dev.tc.base.url}/cicd-demo/</server.url>
        </properties>
    </profile>
    <profile>
        <id>tst</id>
        <properties>
            <server.url>${tst.tc.base.url}/cicd-demo/</server.url>
        </properties>
    </profile>
</profiles>

src/test/resources/url.properties

server.url=${server.url}
Nital
  • 5,784
  • 26
  • 103
  • 195
  • Not a Maven expert. But from the look of the stack trace, it is not able to replace the ${server.url} value with your http url to dev or tst server. – Vin Feb 17 '15 at 20:00
  • why do you expect maven to just replace keys in properties file to its value from system param – jmj Feb 17 '15 at 20:04
  • I am trying to run integration tests on different env's. One thing worth mentioning is that I when I move both the url.properties and xpath.properties to src/main/resources and udpate the element to src/main/resources things start working as expected. – Nital Feb 17 '15 at 20:39

1 Answers1

0

Found the solution to the filtering problem with test resources.

Replaced

 <resources>
        <resource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>

with

<testResources>
    <testResource>
        <directory>src/test/resources</directory>
        <filtering>true</filtering>
    </testResource>
</testResources>
Nital
  • 5,784
  • 26
  • 103
  • 195