4

I hope my second question on SO is well scripted. I am trying to automate test cases using Gherkin, TestNG and Selenium in Java. Using a Maven project with Intellij.

I am able to launch my Test Case when I launch them in the .feature file but when I use the testng.xml file or the Test Runner class, it somehow ignores the Test Case.

I have already checked the project settings which seems to be properly configured. Also checked that I have proper dependencies in my pom.xml (I hope I do)

My test.feature

Feature: Xray Jira

  @TEST_01 @STC
  Scenario: Xray Jira Testing
    Given The user login to the application
    When the credentials are entered
    Then the homepage is viewed

My test Runner

package Runners;

import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
import org.testng.annotations.DataProvider;

@CucumberOptions(
        features = "src/test/resources/",
        glue = {"src/test/Steps/"},
        plugin = {
                "pretty",
                "html:target/cucumber-reports/cucumber-pretty",
                "json:target/cucumber-reports/CucumberTestReport.json"
        })
public class UITest extends AbstractTestNGCucumberTests {

}

My step definition - the following code in the step definitions are working when I launch the test case from the feature file

package Steps;

import Pages.BasePage;
import Pages.HomePage;
import Pages.LoginPage;
import Helper.ConfigFileReader;
import io.cucumber.java.en.*;
import org.openqa.selenium.WebDriver;
import org.testng.Assert;

public class MyStepdefs extends BasePage {
    private WebDriver driver = null;
    private Hooks lHooks;

    public MyStepdefs(Hooks lHooks) {
        this.driver = lHooks.driver;
    }

    @Given("The user login to the application")
    public void the_user_login_to_the_application() {
        LoginPage loginObject = new LoginPage(driver);
        resultValue = loginObject.VerifyUrl();
        Assert.assertTrue(resultValue);
    }

    @When("the credentials are entered")
    public void the_credentials_are_entered() {
        ConfigFileReader config = new ConfigFileReader();
        String userID = config.getUserID();
        String userPassword = config.getUserPassword();
        LoginPage loginObject = new LoginPage(driver);
        loginObject.enterName(userID);
        loginObject.enterPassword(userPassword);
        loginObject.clickLoginButton();
        HomePage lHome = new HomePage(driver);
        resultValue=lHome.verifyMenuIsDisplayed();
        Assert.assertTrue(resultValue);
    }

    @Then("the homepage is viewed")
    public void the_homepage_is_viewed() {

        HomePage homeObject = new HomePage(driver);
        resultValue=homeObject.verifyMenuIsDisplayed();
        Assert.assertTrue(resultValue);

    }

My POM.xml

//Below is my POM.xml I usually followed different tutorials online to get the dependencies. I had issues with compatibility of different version of the dependencies. I was able to correct them. Not sure if it is still the problem

<?xml version="1.0" encoding="UTF-8"?>
<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>execute_auto</groupId>
    <artifactId>execute_auto</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-core -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>4.7.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>4.7.1</version>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.cucumber/gherkin -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>gherkin</artifactId>
            <version>5.0.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-jvm-deps -->
        <dependency>    
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-jvm-deps</artifactId>
            <version>1.0.6</version>
            <scope>provided</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-testng</artifactId>
            <version>4.7.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.0.0</version>
            <scope>test</scope>
        </dependency>


        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>4.7.1</version>
        </dependency>


        <!-- Web driver manager dependency -->

        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>3.6.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>3.6.2</version>
            <scope>compile</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>4.1.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.1.0</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.21.0</version>
                <configuration>
                    <suiteXmlFiles>testng.xml</suiteXmlFiles>
                </configuration>
            </plugin>
            <plugin>
                <groupId>net.masterthought</groupId>
                <artifactId>maven-cucumber-reporting</artifactId>
                <version>3.15.0</version>
                <executions>
                    <execution>
                        <id>execution</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <projectName>POC-language-testing</projectName>
                            <outputDirectory>target/cucumber-reports/advanced-reports</outputDirectory>
                            <cucumberOutput>target/cucumber-reports/CucumberTestReport.json</cucumberOutput>
                            <buildNumber>1</buildNumber>
                            <parallelTesting>false</parallelTesting>
                        </configuration>
                    </execution>
                </executions>
            </plugin>


        </plugins>


    </build>

</project>

My expected result should be that the test is passed. But it is always ignored when launched via testng.xml or the runner class. I would be more than glad if anyone could he be of help

PS: My final objective is to automate and launch test cases on Intellij with Cucumber and Java using Page Object Model. This should update the test cases on Xray in Jira. If anyone has any useful link with respect to such functionalities, it would be much appreciated.

Sureshmani Kalirajan
  • 1,938
  • 2
  • 9
  • 18
automaticien
  • 153
  • 5
  • 14

1 Answers1

1

The glue element should be a package name, not a directory. So if your steps are in the package Steps then the glue should be Steps.

Additionally TestNG swallows the message in the SkipException exceptions thrown by Cucumber so you should add the summary plugin to see why Cucumber skipped the test (most likely due to an undefined step because you didn't have the glue configured properly).

@CucumberOptions(
        features = "src/test/resources/",
        glue = {"Steps"},
        plugin = {
                "summary"
                "pretty",
                "html:target/cucumber-reports/cucumber-pretty",
                "json:target/cucumber-reports/CucumberTestReport.json"
        })
public class UITest extends AbstractTestNGCucumberTests {

}

As an aside: You should not include transitive dependencies in your pom. You can and should remove the cucumber-core, gherkin and cucumber-jvm-deps dependencies.

M.P. Korstanje
  • 10,426
  • 3
  • 36
  • 58
  • it does not work. If I remove all three dependencies, I am not able to launch tests neither from the testng.xml nor from the feature file. Removing Gherkin and cucumber-core dependencies, I am able to launch the the test from feature but not from the testng.xml. Adding the summary plugin does not show any different error message. It always displays me the following error message:Test ignored. Feature: Xray Jira – automaticien Aug 29 '19 at 06:46
  • 1
    Make sure to reimport your maven project. And when running the test in IDEA, select the suit, and scroll all the way down. Failing that add `strict = true` to your `@CucumberOptions`. – M.P. Korstanje Aug 29 '19 at 07:23
  • I added strict in my cucumber options as well, nothing changed. Same result! Test ignored – automaticien Aug 29 '19 at 07:46
  • You can open `TestNGCucumberRunner` and puts some break points in the `runScenario` method and see what happens. – M.P. Korstanje Aug 29 '19 at 08:25
  • I did it and it shows me an error that "Source code does not meet byte code" – automaticien Aug 29 '19 at 08:38
  • @automaticien Have you solved this problem somehow ? I am asking because I am struggling with the same "Test ignored" error.. – user523956 Oct 30 '19 at 09:54
  • @user523956 Yes. In the Edit configuration of my intellij, the test step definition Glue was missing. The same has to be applied in the test runner. Plus, if you're using Intellij, make sure you keep the most updated version – automaticien Oct 30 '19 at 16:56