0

I am configuring maven project with generic archetype[selenium:webdriver-testNg-archetype] in Jenkins. I have project Hierarchy as shown in attached screenshot 1. When I configure it with jenkins every time I get "compilation error" [as show n in attached screenshot 2] but I do not get this error when I execute the test suit through eclipse.

I have another question : When I configure simple maven project with simple testcase, it runs successfully on Jenkins but when I configure project that has hierarchy[like screenshot 1] then every time I get "Compilation error" for tests package does not exists.

Do we have any settings in Jenkins where we can set path for tests package? OR What changes should I do to solve this particular issue?

enter image description here Screenshot 2

And Here is my pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.-----.dashboard</groupId>
<artifactId>dashboard</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<dependencies>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.9.10</version>
    </dependency>
    <dependency>
        <groupId>ru.stqa.selenium</groupId>
        <artifactId>webdriver-factory</artifactId>
        <version>2.0</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.53.1</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-server</artifactId>
        <version>2.53.1</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>htmlunit-driver</artifactId>
        <version>2.20</version>
    </dependency>
    <dependency>
        <groupId>com.codeborne</groupId>
        <artifactId>phantomjsdriver</artifactId>
        <version>1.3.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.14</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.14</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml-schemas</artifactId>
        <version>3.14</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-scratchpad</artifactId>
        <version>3.14</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-ie-driver</artifactId>
        <version>2.53.1</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.53.1</version>
    </dependency>
</dependencies>
<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
    <testResources>
        <testResource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
        </testResource>
    </testResources>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.7</version>
            <configuration>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
                </suiteXmlFiles>
                <systemPropertyVariables>
                    <application.properties>/application.properties</application.properties>
                </systemPropertyVariables>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>
<!-- profiles -->
<profiles>
    <!-- browsers -->
    <profile>
        <id>firefox</id>
        <properties>
            <capabilities>/firefox.capabilities</capabilities>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
    <profile>
        <id>chrome</id>
        <properties>
            <capabilities>/chrome.capabilities</capabilities>
        </properties>
    </profile>
    <profile>
        <id>ie</id>
        <properties>
            <capabilities>/ie.capabilities</capabilities>
        </properties>
    </profile>
    <profile>
        <id>safari</id>
        <properties>
            <capabilities>/safari.capabilities</capabilities>
        </properties>
    </profile>
    <profile>
        <id>phantomjs</id>
        <properties>
            <capabilities>/phantomjs.capabilities</capabilities>
        </properties>
    </profile>
    <profile>
        <id>opera</id>
        <properties>
            <capabilities>/opera.capabilities</capabilities>
        </properties>
    </profile>
    <profile>
        <id>htmlunit</id>
        <properties>
            <capabilities>/htmlunit.capabilities</capabilities>
        </properties>
    </profile>
    <!-- environments -->
    <profile>
        <id>localhost</id>
        <properties>
            <site.url>http://localhost/</site.url>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
    <profile>
        <id>devhost</id>
        <properties>
            <site.url>http://devhost/</site.url>
        </properties>
    </profile>
    <profile>
        <id>testhost</id>
        <properties>
            <site.url>http://testhost/</site.url>
        </properties>
    </profile>
    <profile>
        <id>prodhost</id>
        <properties>
            <site.url>http://prodhost.com/</site.url>
        </properties>
    </profile>
    <!-- grid -->
    <profile>
        <id>nogrid</id>
        <properties>
            <grid.url></grid.url>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
    <profile>
        <id>grid</id>
        <properties>
            <grid.url>http://localhost:4444/wd/hub/</grid.url>
        </properties>
    </profile>
</profiles>

Rohhit
  • 722
  • 3
  • 12
  • 25
  • in `SignInPage` you are referencing a class from `src/test/java`? – Apostolos Jul 12 '16 at 09:59
  • Your main classes shouldn't reference your tests, but If you want this (bad practice) to succeed you can add your test directory as a source see http://stackoverflow.com/questions/270445/maven-compile-with-multiple-src-directories – Revive Jul 12 '16 at 10:02
  • @ Apostolos : yes "CommonTest.java" – Rohhit Jul 12 '16 at 10:44
  • @ I-Love-2-REVIVE : I referred the link that you have given, but unfortunately solutions dint work for me, When I include path in resouces tag, in effect of this my hierarchy changes. – Rohhit Jul 12 '16 at 10:58

1 Answers1

1

src/test/java is a folder were you put all your tests. you shouldnt reference your test classes from within src/main/java folder Please fix your classes.

Apostolos
  • 10,033
  • 5
  • 24
  • 39
  • Ya it worked .....but I cannot change the hierarchy, tests will remain in src/test/java only. any solution in this case ? – Rohhit Jul 12 '16 at 11:01
  • what do you mean? i didnt get it. tests should remain there. what exactly do you need to do? sorry i didnt understand – Apostolos Jul 12 '16 at 11:09
  • did you remove the reference to `CommonTest` from `SignInPage` class? what is the new error? – Apostolos Jul 12 '16 at 11:16
  • If I remove CommonTest Reference then, some of the methods on SignInPage wont work. CommonTest class is extended in SignInPage – Rohhit Jul 12 '16 at 11:27
  • OK so you have a wrong structure at your project. IN order for this project to work, you should copy the test classes to `src/main/java` but this is bad practice. you should distinguish the test classes from the main classes. You can reference the main classes from the test classes but not the opposite. – Apostolos Jul 12 '16 at 11:30
  • that's the point of maven! to organize your code, your dependencies and your tests :) – Apostolos Jul 12 '16 at 11:44
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/117080/discussion-between-rohit-and-apostolos). – Rohhit Jul 12 '16 at 11:49