在Geb框架(Groovy)中运行BDD测试时,*给定*标记未识别的特性

在Geb框架(Groovy)中运行BDD测试时,*给定*标记未识别的特性,groovy,selenium-webdriver,cucumber,bdd,geb,Groovy,Selenium Webdriver,Cucumber,Bdd,Geb,我正在尝试使用带有Cucumber的Geb框架执行web应用程序的自动化测试。然而,在运行我的第一个测试时,当程序到达“给定”标记时,我偶然发现了一个NullPointerException。我在网上搜寻线索,但没有找到答案。我还参考了Geb和Cucumber文档,在使用Cucumber时发现了许多“良好实践”的示例,但我试图调整代码并运行的每个代码示例都在同一个空指针异常中结束 下面是我的代码的重要摘录: test.groovy GebConfig.groovy HomePage.groovy

我正在尝试使用带有Cucumber的Geb框架执行web应用程序的自动化测试。然而,在运行我的第一个测试时,当程序到达“给定”标记时,我偶然发现了一个NullPointerException。我在网上搜寻线索,但没有找到答案。我还参考了Geb和Cucumber文档,在使用Cucumber时发现了许多“良好实践”的示例,但我试图调整代码并运行的每个代码示例都在同一个空指针异常中结束

下面是我的代码的重要摘录:

test.groovy

GebConfig.groovy

HomePage.groovy

testScript.feature

精确误差


总而言之,我假设问题在于给定的功能没有正确识别,但我不知道为什么,因此我来这里询问。

我现在知道我应该添加一个单独的类来运行测试

import cucumber.api.CucumberOptions
import cucumber.api.junit.Cucumber
import org.junit.runner.RunWith

@RunWith(Cucumber.class)
@CucumberOptions(features = "src", format = ["pretty", "html:build/reports/tests/cucumber/html", "json:build/reports/tests/cucumber.json"])
class RunTests {
}
import org.openqa.selenium.chrome.ChromeDriver

/**
 * Created by apoteralowicz on 2015-08-24.
 */

def newDriver
    driver =
    {
        newDriver = new ChromeDriver();
        newDriver.manage().window().maximize();
        return newDriver;
    }
System.setProperty('webdriver.chrome.driver', 'src/binary/chromedriver.exe')
import geb.Page

/**
 * Created by apoteralowicz on 2015-08-24.
 */
class HomePage extends Page {
    static url = "/";
    static at = { waitFor { title.contains('Home') } };
    static content = {

    /*Menu tab links*/
    HomeLink(to: HomePage) {
        $('.menuBarNav').find('a[href="/"]')
    };
    IntercityLink(to: IntercityPage) {
        $('.menuBarNav').find('a[href="/LiftOffer/CityOffers/0?pageSize=5"]')
    };
    EntriesLink(to: EntriesPage) {
        $('.menuBarNav').find('a[href="/LiftOffer/MyEntriesOffers/1?pageSize=5"]')
    };

    CreateDropdownButton(to: '#') {
        $('#createButton')
    };
    addOfferLink(to: AddOfferPage) {
        $('.dropdown-menu').find('a[href="/LiftOffer/Create/1"]')
    };
    addRequestLink(to: AddRequestPage) {
        $('.dropdown-menu').find('a[href="/LiftOffer/Create/2"]')
    };

    SearchLink(to: SearchOffersPage) {
        $('.menuBarNav').find('a[href="/LiftOffer/Search?type=1&pageSize=5"]')
    };
    MessageboxLink(to: MailboxPage) {
        $('.menuBarNav').find('a[href="/LiftOffer/MessageBox"]')
    };

    /*Additional Buttons*/
    ShowOffersButton(to: SearchOffersPage) {
        $('a[href="/LiftOffer/Search/?type=1"]')
    };
    ShowRequestsButton(to: SearchRequestsPage) {
        $('a[href="/LiftOffer/Search/?type=2"]')
    };
    }
}
Feature: new lift offer creation
  As an user
  I want to create a lift offer for people
  So that I could inform people that I am going somewhere and I have free seats available

  Scenario:
    Given Home page is opened
    When Add Offer button is clicked
    Then User can input some data into the Create New Lift Offer form
    And User can save the offer
Starting ChromeDriver (v2.11.298604 (75ea2fdb5c87f133a8e1b8da16f6091fb7d5321e)) on port 40529
Only local connections are allowed.
Caught: java.lang.NullPointerException
java.lang.NullPointerException
    at cucumber.api.groovy.EN.Given(EN.java:27)
    at cucumber.api.groovy.EN$Given.callStatic(Unknown Source)
    at testScript1.run(testScript1.groovy:15)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

Process finished with exit code 1
import cucumber.api.CucumberOptions
import cucumber.api.junit.Cucumber
import org.junit.runner.RunWith

@RunWith(Cucumber.class)
@CucumberOptions(features = "src", format = ["pretty", "html:build/reports/tests/cucumber/html", "json:build/reports/tests/cucumber.json"])
class RunTests {
}