【问题标题】:Unable to Link Glue and Feature File无法链接胶水和特征文件
【发布时间】:2020-05-26 14:25:00
【问题描述】:

我是 Cucumber 的新手并且正在练习它。我刚刚创建了一个简单的项目并尝试编译它。我已经提到了黄瓜中的特征路径和粘合路径。但是,每当我使用 Junit 进行编译时,仍然会一直显示 test is skipped Undefined 场景。

TestRunner     


 package runner;

    import org.junit.runner.RunWith;

    import io.cucumber.junit.CucumberOptions;
    import io.cucumber.junit.Cucumber;


    @RunWith(Cucumber.class)
    @CucumberOptions(
            features = "src/test/resources/feature/feature.feature"
            ,glue = {"src/test/java/stepDefinition"} //have tried with "/HomeWork/src/test/java/stepDefinition/" also. but not working. giving error message like undefined scenarios
            ,monochrome = true
            ,plugin = {"html:target/Report/cucumber-html-report", "json:target/Report/cucumber-json-report.json" }
    )
    public class TestRunner {

    }



    stepDefinition File: 



package stepDefinition;

    import io.cucumber.java.en.Then;
    import io.cucumber.java.en.When;

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.chrome.ChromeOptions;

    import cucumber.api.java.en.Given;

    public class firstLogin {
        WebDriver driver;



        // TODO Auto-generated method stub
        @Given("^User sets the property^")
        public void User_sets_the_property() {
            System.setProperty("webdriver. chrome.driver",
                    "C:\\Arnab\\Softwares\\ChromeDriver\\chromedriver.exe");
            ChromeOptions options = new ChromeOptions();
            options.setBinary("C:\\Program Files (x86)\\Google\\Chrome\\Application");

            driver = new ChromeDriver();
            driver.get("https://www.facebook.com/");
        }

        @When("^User navigates to login page^")
        public void User_navigates_to_login_page() {
            driver.findElement(By.xpath("//input[@type=émail']")).sendKeys(
                    "arnab.test1115@gail.com");
            driver.findElement(
                    By.xpath("//input[@class='inputtext login_form_input_box']"))
                    .sendKeys("mandira1990");
            driver.findElement(By.cssSelector("input[value='Log In']")).click();
        }

        @Then("user is on Homepage^")
        public void user_is_on_Homepage() throws InterruptedException {
            String Title = driver.getTitle();
            System.out.println(Title);
            Thread.sleep(5000);
        }


        // driver.close();

    }

功能文件:

 Feature: User is on Facebook Login Page

    Scenario: User Needs to Login

    Given User sets the property

    When User navigates to login page

    Then user is on Homepage

【问题讨论】:

标签: java selenium junit cucumber testng


【解决方案1】:

您在@CucumberOptions中提供的参数值可能没有按照Cucumber的要求正确配置。

features 用于可以找到功能文件的文件系统文件夹路径,而不是完整文件路径。

glue 是您的步骤定义类所在的包名,而不是包本身的文件系统路径。

所以你的配置应该是这样的:

    @CucumberOptions(
        features = "src/test/resources/feature"
        ,glue = {"stepDefinition"} 
        ,monochrome = true
        ,plugin = {"html:target/Report/cucumber-html-report", "json:target/Report/cucumber-json-report.json" }
)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-31
    • 2023-01-26
    • 2018-10-20
    • 1970-01-01
    • 2018-10-15
    相关资源
    最近更新 更多