Nat
Nat

Reputation: 274

mvn integration-test wont run my test

I'm making automated test with Selenium, TestNG and Maven. When I execute: mvn integration-test in cmd, maven wont run my test. I'm new in Maven, I read some examples but didnt find any resolution for my problem.

Here is my pom.xml:

<dependencies>
    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <classifier>jdk15</classifier>
      <version>5.11</version>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-firefox-driver</artifactId>
        <version>2.31.0</version>
    </dependency>
  </dependencies>

    <build>
        <plugins>
            <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>selenium-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start-server</goal>
                        </goals>
                        <configuration>
                            <background>true</background>
                        </configuration>
                    </execution>
                    <execution>
                          <id>stop-selenium</id>
                          <phase>post-integration-test</phase>
                          <goals>
                              <goal>stop-server</goal>
                          </goals>
                      </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <include>**/MainPage*.java </include>                       
                </configuration>

                <executions>
                    <execution>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <configuration>
                            <skip>false</skip>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>



</project>

And here is my MainPage class:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import static org.testng.Assert.*;

public class MainPage 
{
   static WebDriver driver;

   @BeforeClass
   public void setUp() {
   driver = new FirefoxDriver();
   }

   @Test
   public void OpenRegistrationPage(){
       //GIVEN
       openPage();
       //WHEN
       clickOnRegistration();
       //THEN
       checkIfIsDirected();

   }

   private void checkIfIsDirected() {

       String elementTitle = driver.findElement(By.xpath("//td[@id='center-  col']/div/div/table/tbody/tr/td/div")).getText();
       assertEquals(elementTitle, "Rejestracja");   

        }

   private void clickOnRegistration() {

       WebElement registrationLink = driver.findElement(By.cssSelector("span.icon-rejestracja"));
       registrationLink.click();

        }

   private void openPage() {
       driver.get("https://www.x-kom.pl");

        }

   @AfterClass
   public static void tearDown() {
    driver.close();
   }



}

Thanks in advance! :)

Upvotes: 0

Views: 289

Answers (1)

khmarbaise
khmarbaise

Reputation: 97447

The first thing is to use the maven-failsafe-plugin instead of the maven-surefire-plugin, cause maven-surefire-plugin is intended for unit tests whereas maven-failsafe-plugin is intended for running integration tests. Furthermore you need to name your integration tests like

 **/IT*.java
 **/*IT.java
 **/*ITCase.java

But in your case you should having a separate module which contains the integration tests to run on the web application your a developing.

Upvotes: 1

Related Questions