Java Cucumber功能文件不使用Maven执行

Java Cucumber功能文件不使用Maven执行,java,maven,cucumber,cucumber-jvm,cucumber-junit,Java,Maven,Cucumber,Cucumber Jvm,Cucumber Junit,您好,我已经在eclipse中使用Maven设置了一个Java项目 每当我试图运行脚本时,都会遇到一个问题。它是通过不打开我正在从功能文件解析的所需网站来执行的 请看一下eclipse中我的目录设置的以下代码和图像 这是我的PageStepsDefs.java代码 package com.workshop.airport.workshop.airport; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chr

您好,我已经在eclipse中使用Maven设置了一个Java项目

每当我试图运行脚本时,都会遇到一个问题。它是通过不打开我正在从功能文件解析的所需网站来执行的

请看一下eclipse中我的目录设置的以下代码和图像

这是我的PageStepsDefs.java代码

package com.workshop.airport.workshop.airport;

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

import cucumber.api.java.After;
import cucumber.api.java.Before;
import cucumber.api.java.en.Given;

public class PageStepsDefs {

    public String ChromeDriverPath="C:\\Users\\zain.jamshaid\\Desktop\\chromedriver.exe";
    public WebDriver driver;
    String localhost="www.google.com";

    @Before
    public void deleteAllCookies() {
        driver.manage().deleteAllCookies();
        driver.manage().window().maximize();
    }

    @Before
    public void setup(){
        System.setProperty("webdriver.chrome.driver",ChromeDriverPath);
        driver = new ChromeDriver();    
    }

    @Given("^I browse to the (.+) page$")
    public void open_page(String url)
    {

        driver.get(localhost+url);
        System.out.println(localhost+url);
    }

    @After
    public void tearDown(){
        driver.quit();
    }
}
package com.workshop.airport.workshop.airport;

import cucumber.api.junit.*;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@Cucumber.Options(
        tags={"@mysingle"},
        format={"pretty", "html:target/cucumber-html-report"},
        monochrome=true,
        features={"."}, 
        strict=true)

public class RunCukeTest {

}
这是我的RunCukeTest.java代码

package com.workshop.airport.workshop.airport;

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

import cucumber.api.java.After;
import cucumber.api.java.Before;
import cucumber.api.java.en.Given;

public class PageStepsDefs {

    public String ChromeDriverPath="C:\\Users\\zain.jamshaid\\Desktop\\chromedriver.exe";
    public WebDriver driver;
    String localhost="www.google.com";

    @Before
    public void deleteAllCookies() {
        driver.manage().deleteAllCookies();
        driver.manage().window().maximize();
    }

    @Before
    public void setup(){
        System.setProperty("webdriver.chrome.driver",ChromeDriverPath);
        driver = new ChromeDriver();    
    }

    @Given("^I browse to the (.+) page$")
    public void open_page(String url)
    {

        driver.get(localhost+url);
        System.out.println(localhost+url);
    }

    @After
    public void tearDown(){
        driver.quit();
    }
}
package com.workshop.airport.workshop.airport;

import cucumber.api.junit.*;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@Cucumber.Options(
        tags={"@mysingle"},
        format={"pretty", "html:target/cucumber-html-report"},
        monochrome=true,
        features={"."}, 
        strict=true)

public class RunCukeTest {

}
这是功能文件中的语句

Feature: Login Functionality
@mysingle
Scenario: user successfully logins to the application

    Given I browse to the / page
任何帮助都会很棒

提前谢谢。
Zain

它真的在执行您的功能文件吗?尝试将
test.feature
放在
src/test/resources/com/workshop/airport/workshop/airport
下:JUnit运行时使用单元测试包作为查找功能文件的位置。

我想我知道问题所在。根据您的评论,功能文件中的“/”被正确解析为您的步骤。所以这不是黄瓜问题。我认为问题在于你的网址。您的url格式不正确。URL应以http://


如果将localhost变量更改为
stringlocalhost=,我认为一切都会正常工作。”http://www.google.com";

这里的输出是什么-System.out.println(localhost+url);好的,我也会试试,很快就会回来找你。现在谢谢你