Automation Testing Using Cucumber Tool and Selenium – Selenium Tutorial #3. In last Selenium tutorial we introduced you to Selenium Grid which is a distributed test execution environment to speed up the execution of a test pass. Now at the end of this comprehensive Selenium training series we are learning advanced Selenium testing and related concepts. In this and the next tutorial we will be introducing you to the Cucumber – a Behavior Driven Development (BDD) framework which is used with Selenium for performing acceptance testing. Cucumber Introduction: Cucumber is a tool based on Behavior Driven Development (BDD) framework which is used to write acceptance tests for web application. It allows automation of functional validation in easily readable and understandable format (like plain English) to Business Analysts, Developers, Testers, etc. Interview with Testers. Administrator Ajoy is the founder and editor of Testing Circus magazine which is read and subscribed by thousands. Software Testing Interview Questions. There are a multitude of other advantages and features associated with Selenium web testing tool which can be reaped during usage. Selenium Interview Questions and answers for freshers and experience,selenium interview questions and answers pdf download,selenium interview. As you know Selenium is a free ware open source testing tool. Cucumber feature files can serve as a good document for all. There are many other tools like JBehave which also support BDD framework. Initially Cucumber was implemented in Ruby and then extended to Java framework. Both the tools support native JUnit. Behavior Driven Development is extension of Test Driven Development and it is used to test the system rather than testing the particular piece of code. We will discuss more about the BDD and style of writing BDD tests. Cucumber can be used along with Selenium, Watir, and Capybara etc. Cucumber supports many other languages like Perl, PHP, Python, . Net etc. In this tutorial we will concentrate on Cucumber with Java as a language. Cucumber Basics: In order to understand cucumber we need to know all the features of cucumber and its usage.#1) Feature Files: Feature files are essential part of cucumber which is used to write test automation steps or acceptance tests. This can be used as live document. The steps are the application specification. All the feature files ends with . Sample feature file: Feature: Login Functionality Feature. In order to ensure Login Functionality works,I want to run the cucumber test to verify it is working. Scenario: Login Functionality. What is Test management tools? What are the disadvantages of using Selenium as testing tool? One more alternative to Selenium is Sahi. Selenium interview questions for developers Sample Selenium interview questions for software developer. Given user navigates to SOFTWARETETINGHELP. COMWhen user logs in using Username as “USER” and Password “PASSWORD”Then login should be successful. Scenario: Login Functionality. Given user navigates to SOFTWARETETINGHELP. COMWhen user logs in using Username as “USER1” and Password “PASSWORD1”Then error message should be thrown#2) Feature: This gives information about the high level business functionality (Refer to previous example) and the purpose of Application under test. Everybody should be able to understand the intent of feature file by reading the first Feature step. This part is basically kept brief.#3) Scenario: Basically a scenario represents a particular functionality which is under test. By seeing the scenario user should be able to understand the intent behind the scenario and what the test is all about. Each scenario should follow given, when and then format. This language is called as “gherkin”. Given: As mentioned above, given specifies the pre- conditions. It is basically a known state. When: This is used when some action is to be performed. As in above example we have seen when the user tries to log in using username and password, it becomes an action. Then: The expected outcome or result should be placed here. For Instance: verify the login is successful, successful page navigation. Background: Whenever any step is required to perform in each scenario then those steps needs to be placed in Background. For Instance: If user needs to clear database before each scenario then those steps can be put in background. And: And is used to combine two or more same type of action. Example: Feature: Login Functionality Feature. Scenario: Login Functionality. Given user navigates to SOFTWARETETINGHELP. COMWhen user logs in using Username as “USER”And password as “password”Then login should be successful. And Home page should be displayed. Example of Background: Background: Given user logged in as databases administrator. And all the junk values are cleared#4) Scenario Outline: Scenario outlines are used when same test has to be performed with different data set. Let’s take the same example. We have to test login functionality with multiple different set of username and password. Feature: Login Functionality Feature. In order to ensure Login Functionality works,I want to run the cucumber test to verify it is working. Scenario Outline: Login Functionality. Given user navigates to SOFTWARETESTINGHELP. COMWhen user logs in using Username as < username> and Password < password> Then login should be successful. Examples. Vertical pipes are used to separate two different columns. Example can contain many different columns.#5) Tags: Cucumber by default runs all scenarios in all the feature files. In real time projects there could be hundreds of feature file which are not required to run at all times. For instance: Feature files related to smoke test need not run all the time. So if you mention a tag as smoke. Test in each feature file which is related to smoke test and run cucumber test with @Smoke. Test tag . Cucumber will run only those feature files specific to given tags. Please follow the below example. You can specify multiple tags in one feature file. Example of use of single tags: @Smoke. Test. Feature: Login Functionality Feature. In order to ensure Login Functionality works,I want to run the cucumber test to verify it is working. Scenario Outline: Login Functionality. Given user navigates to SOFTWARETESTINGHELP. COMWhen user logs in using Username as < username> and Password < password> Then login should be successful. Examples. When you intend to run your script for smoke test then use @Smoke. Test. Similarly when you want your script to run for Login test use @Login. Test tag. Any number of tags can be mentioned for a feature file as well as for scenario.@Smoke. Test @Login. Test. Scenario Outline: Login Functionality. Given user navigates to SOFTWARETETINGHELP. COMWhen user logs in using Username as < username> and Password < password> Then login should be successful. Examples. Please check below example to run specific scenario. Feature: Login Functionality Feature. In order to ensure Login Functionality works,I want to run the cucumber test to verify it is working@positive. Scenario. Scenario: Login Functionality. Given user navigates to SOFTWARETETINGHELP. COMWhen user logs in using Username as “USER” and Password “PASSWORD”Then login should be successful@negavive. Scenario. Scenario: Login Functionality. Given user navigates to SOFTWARETETINGHELP. COMWhen user logs in using Username as “USER1” and Password “PASSWORD1”Then error message should throw#6) Junit Runner: To run the specific feature file cucumber uses standard Junit Runner and specify tags in @Cucumber. Multiple tags can be given by using comma separate. Here you can specify the path of the report and type of report you want to generate. Example of Junit Runner. Cucumber; < /pre>. Run. With. @Run. With(Cucumber. Cucumber. Options(format=. Below example illustrates how to use multiple tags in cucumber to run different scenarios. However better reporting can be done using Jenkins or bamboo tool. Details of reporting are covered in next topic of cucumber. Cucumber Project Setup: Detail explanation of cucumber project set up is available separately in next tutorial. Please refer to Cucumber Tutorial Part. Remember there is no extra software installations required for cucumber. Implementation of Feature file: We have to implement these steps in Java in order to test the feature files. Need to create a class which contains those given, when and then statements. Cucumber uses its annotations and all the steps are embedded in those annotations (given, when, then). Each phrase starts with “^” so that cucumber understands the start of the step. Similarly each step ends with “$”. User can use regular expressions to pass different test data. Regular expressions take data from feature steps and passes to step definitions. The order of parameters depends how they are passed from feature file. Please refer next tutorial for project setup and mapping between feature files and java classes. Example: Below example is to illustrate how feature files can be implemented. In this example we have not used any selenium API. This is to just show how cucumber works as standalone framework. Please follow next tutorial for selenium integration with cucumber. For example, when you execute @smoke. Test, cucumber will read Feature step and Given statement of scenario. As soon as cucumber finds Given statement, same Given statement will be searched in your java files. If same step is found in java file then cucumber executes the function specified for the same step otherwise cucumber will skip the step. Conclusion: In this tutorial, we have covered features of cucumber tool and its usage in real time scenario. Cucumber is a most favorite tool for many projects as it is easy to understand, readable and contains business functionality. In the next chapter we will cover how to setup a cucumber – java project and how to integrate Selenium Web. Driver with Cucumber.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2016
Categories |