{"id":87,"date":"2019-06-17T19:29:02","date_gmt":"2019-06-17T19:29:02","guid":{"rendered":"https:\/\/www.bddtesting.com\/?page_id=87"},"modified":"2019-06-17T19:29:03","modified_gmt":"2019-06-17T19:29:03","slug":"getting-started-with-cucumber-bdd-for-automation-testing","status":"publish","type":"page","link":"https:\/\/www.bddtesting.com\/getting-started-with-cucumber-bdd-for-automation-testing\/","title":{"rendered":"Getting Started With Cucumber BDD For Automation Testing"},"content":{"rendered":"\n
In recent years, there have been more software teams increasingly implementing the Agile software methodology in their development process to adapt to this fast-changing market. This trend challenges testing teams to manage test cases and test scripts which have to be maintained according to changing requirements. Finding an appropriate testing method right from the beginning is one of the key elements for the successful Agile software project.<\/p>\n\n\n\n
In fact, many Agile teams have successfully implemented the Behavior-Driven Development (BDD) method to their testing process using Cucumber tool. So, what is Cucumber? And why is it the suitable strategy suggested for Agile projects, along with BDD?<\/p>\n\n\n\n
Cucumber<\/a> is a tool used to run automated acceptance tests created in a BDD format. One of its most outstanding features of the tool is the ability to carry out plain-text functional descriptions (written in the language called Gherkin) as automated tests. Let\u2019s take a look at the below example:<\/p>\n\n\n\n This incredible feature of Behavior-Driven Development (BDD) approach with the advantages as below:<\/p>\n\n\n\n Cucumber helps improve communication between technical and non-technical members in the same project. Let\u2019s have a look at the below requirement and its automation tests:<\/p>\n\n\n\n With TestNG, the above test scenario can be implemented as below:<\/p>\n\n\n\n The same test case can be written using Cucumber:<\/p>\n\n\n\n Both automation test scripts above perform well to complete the test automatically. But do all testers of your team make out these tests? Can other business analysts and other stakeholders use these tests again at the acceptance testing (AT) stage?<\/p>\n\n\n\n The automation test with TestNG may be difficult for most manual testers and BAs to catch up with. Moreover, it is impossible to use this test again for AT. As a result, based on these flaws mentioned before, this can not be considered as a suitable method.<\/p>\n\n\n\n In contrast, the automation test using Cucumber is created in a business domain language or in natural language, which can be easily made out by all members of the software project team. Communication is crucial for any development team, especially in the Agile team. There are usually many continuous chats, discussions, or even arguments happening among developers and testers in order to figure out what the correct behavior of a feature is. By using Cucumber, the same feature specification is now used for developing by developers, for testing by testers. It is considered to be a powerful tool because it can help lower the risk for misunderstanding as well as the communication breakdown.<\/p>\n\n\n\n The acceptance test typically is carried out by BAs\/customers to make sure that the development team has built exact features. Typical activity in this testing stage is verifying the system against the original requirements with specific, real data from production. Cucumber testing not only follows the requirements as its test scenarios but also helps BAs or Product Manager to easily adjust test data. Here is a demonstration with a little adjustment:<\/p>\n\n\n\n The automation test written in Cucumber framework:<\/p>\n\n\n\n In addition to improving communication among members of the same testing team, Cucumber also helps leverage tester\u2019s skills efficiently. Expertise gap always exists in every organization. In other words, there are some testers who have high technical expertise in programming utilizing automated testing, while others performing manual testing with limited programming skills in the same team. Thanks to Cucumber, all testers, no matter what their skill levels are, can participate in the process of performing automation tests.<\/p>\n\n\n\n Let\u2019s take a look at the above example:<\/p>\n\n\n\n There are still a few potential issues when implementing Cucumber:<\/p>\n\n\n\n These steps may be incorporated to have the following test:<\/p>\n\n\n\n The stages of the Cucumber tool are performed in an ordinary language. They can be used again in various test scenarios. This helps reduce the effort to create tests. However, maintaining the test to be both readable and reusable is really a big challenge. If the test is written at a very high level for any stakeholders to make out; few steps (bold) can be reused:Both the above scripts are correct; however, the second one is not apparent because it does too much more than expected: opening Google\u2019s website and searching with the specified text. Imagine if you want to extend the test to search more texts, you may repeat the above step, and the Google site is consequently opened twice. If you do not strictly follow the requirement, the Cucumber testing tool will cause misunderstanding sooner or later and be so difficult to maintain when being extended.<\/p>\n\n\n\n In contrast, if the test is generic and can be reused, i.e., verifying updating user\u2019s Last Name, non-technical stakeholders will have difficulty in catching up with and performing Acceptance Tests:<\/p>\n\n\n\n During the testing process, you have to adjust test scenarios regularly until they completely reach an acceptable balance where all members can understand and reuse.<\/p>\n\n\n\n Or with some more test data:<\/p>\n\n\n\n To conclude, by offering the real communication layer on top of a robust testing framework, Cucumber not only can execute automation test on a wide-ranging testing demand from backend to frontend but also create deep connections among members of the testing teams. This feature is hardly found in other testing frameworks. With many years of expertise in the field of building and applying automation tests, I suggest that Cucumber for Web UI and Web services testing should be applied for Agile software projects.\u00a0Using Cucumber-based BDD with Katalon Studio as an editor<\/a>\u00a0is a right choice which can significantly help reduce the effort to execute regression tests.<\/p>\n\n\n\nFeature: Update password\n Scenario: Admin user can update the user password\nGiven I am in the HR system with an Admin account\nWhen I update password of another user\nThen I receive a message for updating password successfully\nAnd user password is updated to the new password<\/pre>\n\n\n\n
CU<\/strong>CUMBER HELPS IMPROVE COMMUNICATION<\/strong><\/h2>\n\n\n\n
As an Admin User,\nI would like to change the password of other user's accounts.\nFeature: Update password\n Scenario: Admin user can update the user password\n Given I am in the HR system with an Admin account\n When I update password of another user\n Then I receive a message for updating password successfully\n And user's password is updated to the new password<\/pre>\n\n\n\n
@test<\/a>\npublic void testAdminUserCanUpdateUserAccountPassword() {\n \/\/ create users \n User userAdmin = new User(UserRole.ADMIN, username, password);\n User user = new User(UserRole.VIEWER, user_username, user_password);\n \n \/\/ use Admin user to update another user password\n String message = userAdmin.updatePassword(user, user_new_password);\n \n\/\/ verify password changed\n Assert.assertEquals(message, \"Password changed successfully\");\n Assert.assertEquals(user.getPassword(), user_new_password);\n}<\/pre>\n\n\n\n
Feature: Update password\n Scenario: Admin user can update the user password\n Given I am in the HR system with an Admin account\n When I update password of another user\n Then I receive a message for updating password successfully\n And user's password is updated to the new password<\/pre>\n\n\n\n
CUCUMBER IS AN AUTOMATED ACCEPTANCE TESTING TOOL<\/strong><\/h2>\n\n\n\n
As an Admin User,\nI would like to change the password of other user's accounts.\n \nFeature: Update password\n Scenario: Admin user can update the user password\n Given I am in the HR system with an Admin account\n When I update password of another user\n Then I receive a message for updating password successfully\n And user's password is updated to the new password<\/pre>\n\n\n\n
Scenario Outline: Verify Updating user password feature\n Given I am in the HR system with \"<account_type>\" account\n And there is another user with \"<old_password>\" password\n When I update password of the user to \"<new_password>\"\n Then I got the message \"<message>\"\n And the user password should be \"<final_password>\"\n\nExamples:\n|account_type |old_password |new_password |message |final_password |\n|Admin |$Test123 |@Test123<\/a> |Password changed.. |@Test123<\/a> |\n|Viewer |$Test123 |@Test123<\/a> |Invalid right access.. |$Test123 |<\/pre>\n\n\n\n
ALL TESTERS CAN TAKE PART IN AUTOMATION TEST WITH CUCUMBER<\/h2>\n\n\n\n
Scenario: performing a search on google\nGiven I am on \"www.google.com\" site\nWhen I search for \"Cucumber and BDD\"\nThen ...<\/pre>\n\n\n\n
Scenario: performing a search on google\nWhen I search for \"Cucumber and BDD\"\nThen ...<\/pre>\n\n\n\n
Feature: Update password\n Scenario: Admin user can update the user password\n Given I am in the HR system with an Admin account\n When I update password of another user\n Then I receive a message for updating password successfully\n And user's password is updated to the new password\n\n Scenario: Viewer user cannot update the user password\n Given I am in the HR system with a Viewer account\n When I update password of another user\n Then I receive a message for not able to update the user password\n And user's password remains the same<\/pre>\n\n\n\n
Scenario: Admin user can update user password:\n Given I am in the \"$System.HR_Page\" with \"admin@test<\/a>.com\" username\nand \"$Test123\" password\n And there is another user in \"$System.HR_Page\" with \"user@test<\/a>.com\" \nusername and \"$Test123\" password\n When I update \"$UserTemplate.Password\" of \"user@test<\/a>.com\" user to\"@Test123<\/a>\"\n And I save the response message as \"response_message\"\n Then \"$response_message\" should be \"Password changed successfully\"\n And the \"user@test<\/a>.com\" user's \"$UserTemplate.Password\" should be\"@Test123<\/a>\"<\/pre>\n\n\n\n
Scenario: Verify Updating user password feature\n Given I am in the HR system with \"Admin\" account\n And there is another user with \"$Test123\" password\n When I update password of the user to \"@Test123<\/a>\"\n Then I got the message \"Password changed successfully.\"\n And the user password should be \"@Test123<\/a>\"<\/pre>\n\n\n\n
Scenario Outline: Verify Updating user password feature
Given I am in the HR system with \"<account_type>\" account
And there is another user with \"<old_password>\" password
When I update password of the user to \"<new_password>\"
Then I got the message \"<message>\"
And the user password should be \"<final_password>\" Examples: |account_type |old_password |new_password |message |final_password | |Admin |$Test123 |@Test123<\/a> |Password changed.. |@Test123<\/a> | |Viewer |$Test123 |@Test123<\/a> |Invalid right access.. |$Test123 | <\/pre>\n\n\n\nIMPORTANT NOTES FOR THE TESTING TEAM WHO WANTS TO GET STARTED WITH CUCUMBER<\/strong><\/h2>\n\n\n\n