[Cucumber-JVM] Defining properties value in pom for running cucumber tests

601 views
Skip to first unread message

shivi malviya

unread,
Mar 10, 2014, 7:56:02 AM3/10/14
to cu...@googlegroups.com
Hi,
I am facing problem while reading property from properties file where value of property is supplied from pom.xml.

Properties file content :
cucumber.test.url  =  ${cucumber.test.url}
cucumber.test.browser = ${cucumber.test.browser}
cucumber.selenium.url = ${cucumber.selenium.url}

pom.xml content :

<?xml version="1.0" encoding="UTF-8"?>
    <parent>
        <groupId>com.hm.about</groupId>
        <artifactId>hmabout-parent</artifactId>
        <version>1.16.3-SNAPSHOT</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>
    <artifactId>hmabout-cucumber-test</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <name>${project.groupId} - ${project.version} - ${project.artifactId}</name>

    <properties>
        <cucumber.test.url>http://acc-about.hm.com</cucumber.test.url>
        <cucumber.test.browser>Firefox</cucumber.test.browser>
        <cucumber.selenium.url>http://localhost:8888/wd/hub</cucumber.selenium.url>
    </properties>

    <dependencies>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.1.4</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.1.4</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.29.0</version>
        </dependency>
        <dependency>
            <groupId>com.hm.joshua</groupId>
            <artifactId>hmcom-automation-core</artifactId>
            <version>1.132</version>
        </dependency>
        <dependency>
            <groupId>commons-configuration</groupId>
            <artifactId>commons-configuration</artifactId>
            <version>1.9</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.5</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.5</version>
            <optional>false</optional>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-exec</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.1</version>
        </dependency>
    </dependencies>
    <profiles>
        <profile>
            <id>cucumber</id>
            <properties>
                <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                <cucumber.options>--format pretty --glue com.hm.about.stepdefs</cucumber.options>
                <cucumber.path>classpath:aboutfeatues</cucumber.path>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.10</version>
                        <configuration>
                            <skipTests>true</skipTests>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <version>1.2.1</version>
                        <executions>
                            <execution>
                                <phase>test</phase>
                                <goals>
                                    <goal>java</goal>
                                </goals>
                            </execution>
                        </executions>
                        <configuration>
                            <mainClass>cucumber.api.cli.Main</mainClass>
                            <classpathScope>test</classpathScope>
                            <arguments>
                                <argument>${cucumber.path}</argument>

                            </arguments>
                        </configuration>
                    </plugin>
                </plugins>
                <testResources>
                    <testResource>
                        <directory>src/test/resources</directory>
                        <filtering>true</filtering>
                    </testResource>
                </testResources>
            </build>
        </profile>
        <profile>
            <id>test</id>
            <properties>
                <cucumber.test.url>http://acc-about.hm.com</cucumber.test.url>
                <cucumber.test.browser>Firefox</cucumber.test.browser>
                <cucumber.selenium.url>http://localhost:8888/wd/hub</cucumber.selenium.url>
            </properties>
        </profile>
    </profiles>
</project>

Note : My code runs fine when I enter manual values in my property file.

Question : I have tried to place my properties in pom.xml, but it does not work. Where should I define my properties in pom.xml so that it is reflected correctly in my .properties file?

I have attached an image of my project structure as well.

Please help.

Thanks,

Shivi


Roberto Lo Giacco

unread,
Mar 11, 2014, 5:28:20 AM3/11/14
to cu...@googlegroups.com
Il giorno lunedì 10 marzo 2014 12:56:02 UTC+1, shivi malviya ha scritto:
Hi,
I am facing problem while reading property from properties file where value of property is supplied from pom.xml.

Properties file content :
cucumber.test.url  =  ${cucumber.test.url}
cucumber.test.browser = ${cucumber.test.browser}
cucumber.selenium.url = ${cucumber.selenium.url}

Why do you want to push some properties into a file to just read them a few millisecond after? Wouldn't it be better to just set the properties and read them from System properties avoiding the need to use a properties file?

In any case, the issue you are encountering is definitely not related to Cucumber-JVM but to Maven, so if you still want to go with this two step solution I suggest to post the same question to the maven support mailing list. As a suggestion I would double check the properties file you are trying to update is located within src/test/resources
Reply all
Reply to author
Forward
0 new messages