使用 Cucumber 框架,我的跑步者跳过所有测试

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

我创建了一个小型训练黄瓜项目。 我的项目树: project tree

pom 依赖关系:

    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

特征文件结构:

Feature: Checkout for a customer.
  They are searching for the book, add it to cart, proceeding to checkout and pay for it.

  Scenario: Proceed to checkout, fill all the details
    Given I am a new customer and I open the "Home page"
    And I search for "Head First. Java"
    And I select the product with title "Head First. Java"
    And I click "Add to basket" button for the given needed product and close the book info page
    And I click on the basket icon on "Search Results Page"
    And I am filling the details:
      | name       | test          |
      | secondName | test          |
      | phone      | 0123356885    |
      | email      | [email protected] |
      | country    | test          |
      | city       | test          |
      | address    | 22220         |
    And I select online payment option
    And I press the "Continue to payment" button
    And I feel my card details and press pay button
      | cardNumber | 1111111111111111 |
      | mm         | 11               |
      | yy         | 11               |
      | cvv        | 111              |

我的跑步者

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

@RunWith(Cucumber.class)
@CucumberOptions(
        features = {"C:/Users/Hedgehog/IdeaProjects/FinalProj/src/test/resources/features/BuyBook.feature"},
        glue = {"C:/Users/Hedgehog/IdeaProjects/FinalProj/src/test/java/steps"}
)

public class Runner {

}

所有步骤均用@Given、@And、@Then 注解。 但是,当我启动运行程序时,我会忽略所有测试以及有关如何实现缺失步骤的建议。

跑步者识别步骤和场景,因为在结果中我得到:

Test ignored.

Test ignored.

1 Scenarios (1 undefined)
9 Steps (9 undefined)
0m0,000s

另外,这是我的步骤。我没有包含定位器和导入

@Given("I am a new customer and I open the \"Home page\"")
    public void i_open_the() throws Throwable {
        driver.get("https://www.yakaboo.ua");
        throw new PendingException();
    }


    @And("I search for \"Head First. Java\"")
    public void i_search_for(String bookName) throws Throwable {
        driver.findElement(searchFieldLocator).sendKeys(bookName);
        driver.findElement(searchButton).click();
        throw new PendingException();
    }


    @And("I select the product with title \"Head First. Java\"")
    public void i_select_the_product_with_title() throws Throwable {
        driver.findElement(searchBookByTitle).click();
        throw new PendingException();
    }

    @And("I click \"Add to basket\" button for the given needed product and close the book info page")
    public void i_click_button_for_the_given_needed_product_and_close_the_book_info_page() throws Throwable {
        driver.findElement(searchByAddToCart).click();
        driver.findElement(searchCloseButton).click();
        throw new PendingException();
    }

    @And("I click on the basket icon on \"Search Results Page\"")
    public void i_click_on_the_basket_icon_on() throws Throwable {
        driver.findElement(searchCartButton).click();
        throw new PendingException();
    }

    @And("I am filling the details:")
    public void i_am_filling_the_details(DataTable dataForOrderTable) throws Throwable {
        dataForOrder = new HashMap<String, String>();
        for (DataTableRow row : dataForOrderTable.getGherkinRows()) {
            dataForOrder.put(row.getCells().get(0), row.getCells().get(1));
        }
        dataForOrder = dataForOrderTable.asMap(String.class, String.class);
        driver.findElement(firstNameInputLocator).sendKeys(dataForOrder.get("name"));
        driver.findElement(secondNameInputLocator).sendKeys(dataForOrder.get("secondName"));
        driver.findElement(phoneInputLocator).sendKeys(dataForOrder.get("phone"));
        driver.findElement(emailInputLocator).sendKeys(dataForOrder.get("email"));
        driver.findElement(deliveryMethodLocator).click();
        driver.findElement(countryInputLocator).sendKeys(dataForOrder.get("country"));
        driver.findElement(desiredCountryLocator).click();
        driver.findElement(cityInputLocator).sendKeys(dataForOrder.get("city"));
        driver.findElement(desiredCityLocator).click();
        driver.findElement(addressInputLocator).sendKeys(dataForOrder.get("address"));
        driver.findElement(desiredAddressLocator).click();
        throw new PendingException();
    }

    @And("I select online payment option")
    public void i_select_online_payment_option() throws Throwable {
        driver.findElement(paymentMethodLocator).click();
        throw new PendingException();
    }

    @And("I press the \"Continue to payment\" button")
    public void i_press_the_button(String arg0) throws Throwable {
        driver.findElement(checkoutButtonLocator).click();
        throw new PendingException();
    }

    @Then("I feel my card details and press pay button")
    public void i_feel_my_card_details_and_press_pay_button(DataTable cardDetailsTable) throws Throwable {
        cardDetails = new HashMap<String, String>();
        for (DataTableRow row : cardDetailsTable.getGherkinRows()) {
            dataForOrder.put(row.getCells().get(0), row.getCells().get(1));
        }
        cardDetails = cardDetailsTable.asMap(String.class, String.class);
        driver.findElement(cardNumberLocator).sendKeys(cardDetails.get("cardNumber"));
        driver.findElement(dueMonthLocator).sendKeys(cardDetails.get("mm"));
        driver.findElement(dueYearLocator).sendKeys(cardDetails.get("yy"));
        driver.findElement(cvvLocator).sendKeys(cardDetails.get("cvv"));
        driver.findElement(payButtonLocator).click();
        throw new PendingException();
    }

我尝试编辑

glue
路径。将现有的更改为
"src/test/java/steps"

maven cucumber cucumber-java cucumber-junit
© www.soinside.com 2019 - 2024. All rights reserved.