不使用 Maven 执行黄瓜功能文件

您好,我在 Eclipse 中使用 Maven 设置了一个 Java 项目.

Hi I have setUp a Java project using Maven in eclipse.

每当我尝试运行脚本时都会遇到问题.它是通过不打开我从功能文件中解析的所需网站来执行的.

I am facing an issue whenever I am trying to run the script. Its is executed by the not opening the desired website which I am parsing from the feature file.

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

Please have a look to the following code and Image of my directories setup in 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();
    }
}

这是我的 RunCukeTest.java 代码

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

任何帮助都会很棒.

提前致谢.扎因

推荐答案

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

I think I know the problem. As per your comment, the '/' from feature file is getting parsed to your step correctly. So this is not a cucumber issue. The issue I think is with your url. The url you have is incorrectly formed. URL should start with http://

我认为如果您将 localhost 变量更改为 String localhost="http://www.google.com";

I think everything will work fine if you change your localhost variable to String localhost="http://www.google.com";

相关文章