无法链接胶水和特征文件

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

我对Cucumber并不陌生,正在练习。我刚刚创建了一个简单的项目并尝试对其进行编译。我已经提到了黄瓜中的特征路径和胶合路径。但是无论何时我使用Junit进行编译时,仍然会显示跳过未定义方案的测试。

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(
                    "[email protected]");
            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个回答
0
投票

[在@CucumberOptions中提供的参数值可能未按照黄瓜的要求正确配置。

[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" }
)
© www.soinside.com 2019 - 2024. All rights reserved.