Getting the below output after executing a test from TestNG runner class(Testng-Cucumber) But no tests are getting executed-
[RemoteTestNG] detected TestNG version 7.4.0 PASSED: runScenario("Positive Test of Purchasing the Order", "Purchase the order from eCommerce website") Runs Cucumber Scenarios
=============================================== Default test Tests run: 1, Failures: 0, Skips: 0
=============================================== Default suite Total tests run: 1, Passes: 1, Failures: 0, Skips: 0
It is recognizing 1 test as expected but it is not getting executed
Please Note - TestNG and Cucumber plugins for eclipse are already installed
Please find the below code -
TesNgTestRunner.java -
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
@CucumberOptions(features = {"src/test/java/cucumber"}, glue = {
"rahulshettyacademy.stepdefinitions"}, monochrome = true, plugin = {
"html:target/cucumber.html" })
public class TestNGTestRunner extends AbstractTestNGCucumberTests {
}
I have tried both entering and removing "{}" in glue and features but no luck
StepDefinitionImpl.java -
package rahulshettyacademy.stepdefinitions;
import java.io.IOException;
import java.util.List;
import org.openqa.selenium.WebElement;
import org.testng.Assert;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import rahulshettyacademy.TestComponents.BaseTests;
import rahulshettyacademy.pageobjects.LandingPage;
import rahulshettyacademy.pageobjects.MyCartPage;
import rahulshettyacademy.pageobjects.PaymentPage;
import rahulshettyacademy.pageobjects.ProductCatalog;
import rahulshettyacademy.pageobjects.ThankYouPage;
public class StepDefinitionImpl extends BaseTests{
public LandingPage landingPage;
public ProductCatalog productCatalog;
public ThankYouPage thankYouPage;
public PaymentPage paymentPage;
public MyCartPage myCartPage;
@Given("^I Landed on eCommerce page$")
public void landedOnECommercePage() throws IOException{
landingPage=launchApplication();
}
@Given("^Logged in with (.+) and (.+)$")
public void login(String username, String password) {
productCatalog=landingPage.loginApplication(username,password);
}
@When("^I Add product (.+) to cart$")
public void addProductToCart(String productName) {
List<WebElement> products=productCatalog.getProductList();
productCatalog.addProductToCart(productName);
}
@When("^Checkout (.+) and submit the order$")
public void checkoutSubmitOrder(String productName) throws InterruptedException {
myCartPage=productCatalog.goToCartPage();
Boolean match=myCartPage.verifyProductPresent(productName);
Assert.assertTrue(match);
paymentPage=myCartPage.goToCheckout();
paymentPage.selectCountry(driver,"india");
thankYouPage=paymentPage.clickSubmitButton(driver);
}
@Then("{string} is displayed on ConfirmationPage")
public void messageDisplayedConfirmationPage(String string) throws InterruptedException {
String confMessage=thankYouPage.getConfMessage();
Assert.assertTrue(confMessage.equalsIgnoreCase(string));
}
}
Tried to use "{string}" instead of (.+) but no luck. Tried with and without "^" in the beginning of each step but no luck Tried with and without "$" sign in the end but no luck.
PurchaseOrder.feature -
POM.xml - enter image description here
Your StepDefinitionImpl class extends the BaseTests class which is located under the different package. Please make sure that the package 'rahulshettyacademy.TestComponents' is included to the 'glue' in the @CucumberOptions annotation for the TestNGTestRunner class.
!EDIT!
Also, you are using ":" after the keywords Given/When/Then. This stops cucumber from recognizing the keywords, hence you basically have an 'empty' scenario.
Another point is that you have an 'Examples' section for the 'Scenario', it won't work. To use Examples you have to use the 'Scenario Outline' keyword. More info in the official docs