So, this is another one article abut cucumber, but I’ll try to describe SDLC methodology. If you skipped posts about correct Gherkin/Cucumber format , please have a look here: Cucumber — bridge or another one abyss between BA and QA
If you would like to try Java+Cucumber, please, have a look here: Create a Cucumber Project by Integrating maven-cucumber-selenium-eclipse
Feature File Naming Convention
But if you would like to get a overview on a process, please, continue reading. As every educated Analysts, as a result of our work, we got a list of requirements. We know that we could have functional and non-functional requirements. This is my typical workflow to deliver requirement to QAs:
- Usually I’m starting my IT Projects with Vision document where I got User Stories as a key entity,
- I’m doing idealization via Use Cases.
- QA adding extra details for my Use Case steps. In general – they are adding steps to add data like “qweqweqwe” in date and number fields and all that kind of negative testing.
If we would like to test particular requirement, then you are:
- Searching for a User Story
- Searching for a related Use Cases (via matrix, if I already spent some time to create and maintain it)
- Searching for a Test Cases, related to this Use Cases
- Open Eclipse, configure TestNG xml file to run required test.
- Run selected tests
So, it would be great to find one particular Use Case and run it from the one place, without tons of Word document (+ xls tables as an option). The problem is – Cucumber is not about User Stories, Use Cases, etc. Let’s answer couple important questions:
- What is the difference between Use Cases and Features? Features are descriptions of high-level product functionality. We then derive one or more use cases from each feature.
- What is the difference between Feature and User Story? A user story can be a specific justification for a feature, or a specific way to do it. Or it could be a totally different thing, like, for example: User story: as a customer, I want to pay with the most popular credits cards. While Feature: support the GOV-TAX-02 XML API of the government.
I would place User story and Feature at the same detail level, but the problem is: User Story is way too long for the Cucumber Feature. Why? Because Cucumber Feature is a simple text file, while Feature Name is a name of this file! This looks nice on the different demo, where teachers got “MyFeature1” and “MyFeature2”, but in fact, we should split feature files into groups via packaging, otherwise this will be a disaster.But anyway, we will not be able to put all these “As a User”, so, here is the key thing why they got features, because if we are using User Stories, we got space only for ” < some goal >” from “As a < type of user >, I want < some goal > so that < some reason >”.
There is also another one method we could use – add requirement number, this will extremely help us to support consistency and traceability.
So, I guess we good with naming convention here. It will be like:
- Package “R3_Account_Management”
- R3_1_Update_Name.feature
- R3_2_Update_EMail.feature
- R3_3_Update_Avatar.feature
- R3_4_Change_Password.feature
- R3_5_Forget_Password.feature
- R3_6_Delete_Account.feature
- Package “R4_Friends_Management”
- R5_1_Delete_Friend.feature
- R5_2_Ignore_Friend.feature
- R5_3_Send_Friendship_Requests.feature
- R5_4_Search_For_Friend.feature
- R5_5_Review_Friendship_Requests.feature
- R5_6_Approve_Friendship_Requests.feature
- R5_7_Decline_Friendship_Requests.feature
How To Describe Steps?
This is an example, there could be feature files to recommend friends, follow user, etc. However, let’s go to the next step and discuss
Now let’s compare what we got in UC steps and gherkin. In fact we are comparing dialog between User and System like (fragment):
and here i a transferred gerkin:
PRECONDITIONS: [GIVEN] the user has an active account
MAIN FLOW:
- [WHEN] the user searches for course
- [THEN] display list of courses
- [WHEN] the user selects <number> course(s)
- [AND] submits his selection
- [THEN] if failed to register to any course – alternative flow 2 starts
- [AND] register user for selected course
- [AND] display confirmation message
ALTERNATIVE FLOWS
2a. No Courses Available
- [WHEN] there are no available courses
- [THEN] the system displays an error message “…”
- …
But, if you read previous articles about gerkin syntax – there is no IF statement and this meant that we will have 3 flows here (instead of a main and 2 alternative flows). Here is a proof of my concept, just in case. So, that’s how our feature file will looks like
How to Start With IntelliJ Idea
This will be our very first step to create our tests for our abstract friendship management component. So, to see this particular result, all you need to do, is to start InelliJ Idea (not Eclipse, and I’ll show you why). Then:
- Create a project from scratch, and select module type Maven. Do not create a Maven module from archetype!
- Open for editing
pom.xml
file of the new project or module. - In the
pom.xml
, create and expand the sectiondependencies
, and add the following code:<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<scope>test</scope>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm</artifactId>
<version>1.2.2</version>
<type>pom</type>
</dependency>
- Add Cucumber plug-in (I would also recommend to have Pipe Table Formatter plugin):
- Create package “features.account_Management”, create a text file text file with .feature extension: “Update_Name.feature“.
Eclipse vs InelliJ Idea
On create a new feature file InelliJ Idea will generate empty file, while Eclipse will generate file with example and tips, but it will be no glue class there.
The problem is, that after glue file creation, on Feature Run, Eclipse will generate something like this:
@tag Feature: Title of your feature I want to use this template for my feature file @tag1 Scenario: Title of your scenario # D:/akworkspace - oxy/cucuDemo/src/test/java/features/account_Management/Update_Name.feature:6 Given I want to write a step with precondition And some other precondition When I complete action And some other action And yet another action Then I validate the outcomes And check more outcomes @tag2 Scenario Outline: Title of your scenario outline # D:/akworkspace - oxy/cucuDemo/src/test/java/features/account_Management/Update_Name.feature:16 Given I want to write a step with <name> When I check for the <value> in step Then I verify the <status> in step Examples: @tag @tag2 Scenario Outline: Title of your scenario outline # D:/akworkspace - oxy/cucuDemo/src/test/java/features/account_Management/Update_Name.feature:23 Given I want to write a step with name1 When I check for the 5 in step Then I verify the success in step @tag @tag2 Scenario Outline: Title of your scenario outline # D:/akworkspace - oxy/cucuDemo/src/test/java/features/account_Management/Update_Name.feature:24 Given I want to write a step with name2 When I check for the 7 in step Then I verify the Fail in step 3 Scenarios (3 undefined) 13 Steps (13 undefined) 0m0.000s You can implement missing steps with the snippets below:
@Given("^I want to write a step with precondition$") public void i_want_to_write_a_step_with_precondition() throws Throwable { // Write code here that turns the phrase above into concrete actions throw new PendingException(); } @Given("^some other precondition$") public void some_other_precondition() throws Throwable { // Write code here that turns the phrase above into concrete actions throw new PendingException(); } @When("^I complete action$") public void i_complete_action() throws Throwable { // Write code here that turns the phrase above into concrete actions throw new PendingException(); } @When("^some other action$") public void some_other_action() throws Throwable { // Write code here that turns the phrase above into concrete actions throw new PendingException(); } @When("^yet another action$") public void yet_another_action() throws Throwable { // Write code here that turns the phrase above into concrete actions throw new PendingException(); } @Then("^I validate the outcomes$") public void i_validate_the_outcomes() throws Throwable { // Write code here that turns the phrase above into concrete actions throw new PendingException(); } @Then("^check more outcomes$") public void check_more_outcomes() throws Throwable { // Write code here that turns the phrase above into concrete actions throw new PendingException(); } @Given("^I want to write a step with name(\\d+)$") public void i_want_to_write_a_step_with_name(int arg1) throws Throwable { // Write code here that turns the phrase above into concrete actions throw new PendingException(); } @When("^I check for the (\\d+) in step$") public void i_check_for_the_in_step(int arg1) throws Throwable { // Write code here that turns the phrase above into concrete actions throw new PendingException(); } @Then("^I verify the success in step$") public void i_verify_the_success_in_step() throws Throwable { // Write code here that turns the phrase above into concrete actions throw new PendingException(); } @Then("^I verify the Fail in step$") public void i_verify_the_Fail_in_step() throws Throwable { // Write code here that turns the phrase above into concrete actions throw new PendingException(); }
But we want to create methods in class one by one in automatic mode, like shown here, and this is why IntelliJ Idea is our choice:
Create Our First Test
Let’s create our first package and feature file with IntelliJ Idea. You should use Ctrl+Shift+Alt+L to automatically format your text or use Pipe Table.
@R3_1 Feature: Update User's Name As a User, I want to change my Full Name Author: Alexey Kiselev @R3_1_1 Scenario Outline: Update first name and last name Given I navigates to "My Account" page When I change First Name to <first_name> And I change Last Name to <last_name> Then System updates my name And Shows message "First Name and Last Name Updated" Examples: | first_name | last_name | | Alex | Kiselev |
This code is executable with the almost the same result as with Eclipse.
At this step, I could say that we done with our Analysts part and it’s time for testers to start their work. The key thing here os to get a correct Test report after test execution (because we need to know – which features are already implemented). So, I’ll tell you how to work with Cucumber + EtentReport next time.