{"id":72,"date":"2019-06-17T19:19:19","date_gmt":"2019-06-17T19:19:19","guid":{"rendered":"https:\/\/www.bddtesting.com\/?page_id=72"},"modified":"2019-06-17T19:20:07","modified_gmt":"2019-06-17T19:20:07","slug":"using-the-behave-framework-for-selenium-bdd-testing-a-tutorial","status":"publish","type":"page","link":"https:\/\/www.bddtesting.com\/using-the-behave-framework-for-selenium-bdd-testing-a-tutorial\/","title":{"rendered":"Using the behave Framework for Selenium BDD Testing: A Tutorial"},"content":{"rendered":"\n

Let\u2019s say you have a task to automate the testing of an application. Where should you start? The first step is to choose an approach to test automation<\/a>, which will be the basis for your test development. When you are searching for possible options, you will find out that there are many of them, like unit testing, test-driven development, keyword-driven development, behavior-driven development and so on. In this article, we are going to talk about one of the most popular approaches to test automation \u2013 BDD or behavior-driven development. Follow the examples here on GitHub.<\/a><\/p>\n\n\n\n

Explaining BDD<\/h1>\n\n\n\n

I suspect you might have a question here: \u201cThere is nothing about testing in the technique\u2019s name, so how it can be used for testing?\u201d. BDD originates from the test-driven development technique (TDD). This technique defines that before any functionality is implemented, tests should be created first. Usually TDD is useful for short term iterations when you need to keep your functionality safe from regression for a single unit that is under development.<\/p>\n\n\n\n

But what about integration with other modules? Integration tests are more complex and require more knowledge and time to implement them. As this point when we need to turn our focus to BDD, where instead of module tests, behavior tests are automated.<\/p>\n\n\n\n

What are considered as \u201cbehavior tests\u201d? Behavior tests come from specification and business requirements. Business stakeholders, QA engineers, analysts, application and test developers work together to identify the correct flow and test it. With this approach, every new requirement and functionality can be added so they are covered by tests in the same iteration. Seems promising!<\/p>\n\n\n\n

BDD Scenarios in Gherkin<\/h1>\n\n\n\n

Let\u2019s have a look at BDD in action. In python, the behave<\/a> framework is a great implementation of that technique. Scenarios in behave are written using the Gherkin syntax. A simple scenario in Gherkin looks like this:<\/p>\n\n\n\n

Feature:  User authorization and authorization\nScenario: The user can log into the system\nGiven The user is registered in the system\nWhen The user enters a login\nAnd enters a password\nThen the user is logged in\n<\/pre>\n\n\n\n