Search code examples
mavenselenium-webdriverautomationcucumbertestng

Learning Cucumber with testng. To automate to load google.com I am getting config error and it says no tests were found


What is wrong I can't really find out. Could anyone please tell me what I am doing wrong.

my test is running perfectly if I run the feature file. But running the testng.xml file is getting me error.

the error. this is the work tree.

this is the stepdefinition

package com.example.StepDefinitions;

import io.cucumber.java.en.Given;
import io.cucumber.java.en.When;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;

public class GoogleStepDefs {
    int x = 0;
    ChromeDriver driver;

    @Given("^Launch Google Home Page$")
//    @Test(priority = 1)
    public void launchgoogle(){
        WebDriverManager.chromedriver().setup();
        driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.get("https://www.google.com/");
        Assert.assertTrue(driver.getTitle().equals("Google"));

        x=1;
        driver.close();
    }


}

this is the test runner

package com.example;

import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;

//@RunWith(Cucumber.class)
@CucumberOptions(
        plugin = {"html:target/cucumber-reports/cucumber.html"} ,
        features = {"src/test/resource/features/"} ,
        glue = {"StepDefinitions"}
)

public class TestRunner extends AbstractTestNGCucumberTests{

}

This is the cucumber feature file

Feature: Google Test
  Scenario: Open Google Page
    Given Launch Google Home Page

This is the testng.xml file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="All Test Suite">
    <test verbose="2" preserve-order="true" name="G:/Abul Hossain Chowdhury/Projects/testCucumberproject">
        <classes>
            <class name="com.example.StepDefinitions.GoogleStepDefs"> </class>
        </classes>
    </test>
</suite>

Solution

  • in the testrunner The directory of the stepDefinition might be an issue. For an example glue = {"org.example.StepDefinitions"} is the correct directory for my projectenter image description here