测试/场景未使用 testng Cucumber 执行

问题描述 投票:0回答:1

从 TestNG 运行程序类(Testng-Cucumber)执行测试后获得以下输出,但没有执行任何测试 -

[RemoteTestNG] 检测到 TestNG 版本 7.4.0 PASSED: runScenario("购买订单正测试","从电商网站购买订单") 运行黄瓜场景

================================================== 默认测试 测试运行:1,失败:0,跳过:0

================================================== 默认套件 运行的测试总数:1,通过:1,失败:0,跳过:0

它按预期识别 1 个测试,但没有执行

请注意 - Eclipse 的 TestNG 和 Cucumber 插件已安装

请找到以下代码 -

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 {

}

我尝试过在胶水和功能中输入和删除“{}”,但没有成功

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));
    }
}

尝试使用“{string}”代替(.+),但没有成功。 尝试在每个步骤的开头使用或不使用“^”,但没有运气 最后尝试了带或不带“$”符号,但没有成功。

采购订单.功能 -

enter image description here

POM.xml - enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

cucumber testng cucumber-java testng-eclipse testng-annotation-test
1个回答
0
投票

您的 StepDefinitionImpl 类扩展了位于不同包下的 BaseTests 类。请确保包“rahulshettyacademy.TestComponents”包含在 TestNGTestRunner 类的 @CucumberOptions 注释中的“粘合剂”中。

© www.soinside.com 2019 - 2024. All rights reserved.