-3

I need create e2e test for the my angular 5 application. We're using cucumber and protractor.

I have concrete list steps which i should do at the beginning some scenarios.

This is an example:

Scenario: I need do process below before some scenarious
    Given I load a html page
    When I filling the form
      | name | testname|
      | gender        | male|
      | date | 08/18            |
      | surmane       | TestSurname            |
 And I click the checkbox
    And I click the "SAVE AND CONTINUE" button
    And I submit the details
    Then I should be redirected to the second page

Then at the beginning other scenarios i need done the same steps from 1-st scenario.

Scenario: Scenario 2 - i need the same from scenario 1
Given All steps from scenario 1 done and i redirected to the second page
 ...
 
Scenario: Scenario 3 - i need the same from scenario 1
Given All steps from scenario 1 done and i redirected to the second page
 ...

Is there solution to put all steps into one scenario and use it?

How to create a "Before" hook for this? e.g.

Before('@copyScenario', () => {
 //.......list of steps
});

I do not want copy/paste it...any ideas?

trigger
  • 489
  • 10
  • 26
  • Please show the version of cucumber, protractor and protractor-cucumber-framework used in your project. – yong Jul 27 '18 at 16:20

2 Answers2

1

The best way to do this is to state the intent of your scenarios, instead of listing actions within the feature file.

The purpose of BDD (and thusly, cucumber as a BDD tool) is to explore the features, abilities and business needs that you are implementing, in order for the business people (usually non-technical) to have the same understanding of the feature as those who are developing and testing it.

This would mean that your scenario written in the answer would flow more like:

Scenario: Registering a user
   Given I am on the registrations page
   When I fill in my personal details
    And submit the registration form
   Then I should be taken to the dashboard

After which, you would write a new step to compile these down:

Scenario: Searching the site
   Given I have registered an account
     And I am logged in
   When I search the site for "product"
   Then I should see results for "product"

This - from the eyes of a non-technical business person, allows them to see the intent behind the tests, as well as making your life easier, by making each test step a lot more atomic (giving them the ability to be used all over the place, without copying and pasting, where the functionality is the same).

There are alternatives to this, but I'm not going to state them here, as I believe that my advice above will help you more in the long term.

KyleFairns
  • 2,947
  • 1
  • 15
  • 35
1

This can be done by a keyword known as 'Background' in cucumber. You should use like below:

  Background: Always do these steps before executing any scenarios
   Given ....
   When ....
   Then ....

Scenario 1: Do after performing Background
...
Scenario 2: Do after performing Background
...

The above script will go like this :- It will execute background steps then execute scenario 1, then after completing scenario 1 ,again background steps will execute and then scenario 2 will execute.

AnjuR
  • 91
  • 3