Home > database >  How to make Background keyword as a runner scenario in cucumber?
How to make Background keyword as a runner scenario in cucumber?

Time:02-03

I am trying to test Amazon website with 3 scenarios on selenium with cucumber. For writing gherkin structure. I concat my login functionality with other scenarios with the Background keyword. But this time the problem is that my scenario number is decreased from 3 to 2. Basically, I want to also test the login functionality and make the terminal close and go to the other test scenarios. Instead, the code behaves login and searching product functionality as one scenario and closes its terminal.

The below gherkin language is my Amazon.feature;

 Feature: To be able to shop through the website in e-commerce platform, Amazon.


  Background:
    Given User is on homepage
    When Click accept cookies
    When User click login button
    When User click EmailBlank
      And Enter e-mail address
      And User press continue button
    When User click PasswordBlank
      And Enter password
      And Click SignIn button



  Scenario: Finding the product from the website
    When Click the search button
    When Write product name
    When Click search button
    When Filter for Shipped by Amazon
    When Filter for Apple


  Scenario: Adding and deleting product to cart
         #the upper scenario
    When Click the search button
    When Write product name
    When Click search button
    When Filter for Shipped by Amazon
    When Filter for Apple
          #the upper scenario
    When Click the first product
    When Add to Cart
      And Close the Cart
      And Click the Cart
    When Check at cart page
    When Delete the product

I tried to put the Scenario below the Background but this time 2nd scenario is run without logging into the website. I also put Scenario before the Background and get the syntax error.

CodePudding user response:

You can write an Scenario with 1 step that not exist in Background:

Scenario: Login with valid credentials
    Then check some extra data here belongs to login function thaat is not included it background

CodePudding user response:

Instead of writing

Given User is on homepage
    When Click accept cookies
    When User click login button
    When User click EmailBlank
      And Enter e-mail address
      And User press continue button
    When User click PasswordBlank
      And Enter password
      And Click SignIn button

write

Given I am signed in

and push HOW you sign in down into the step definitions. Once you have done that go further and push HOW you sign in down into helper methods called from your step definitions.

  • Related