Home > Article > Backend Development > BDD automated testing using PHP WebDriver and Behat
BDD (Behavior-Driven Development) is a software development method that emphasizes communication and collaborative work between the development team and business personnel and other stakeholders to achieve better software quality and adaptability. BDD automated testing uses automated testing tools in the BDD framework to execute and verify tests. In this article, we will discuss how to use PHP WebDriver and Behat for BDD automation testing.
In Behat, we can use different extensions to integrate with automated testing tools to perform automated testing.
The following software and libraries must be installed:
Installation is as follows:
composer require behat/behat composer require behat/mink composer require behat/mink-extension
Once the necessary software and libraries are installed, we will Create a Behat configuration file. Run the following command in the command line:
php bin/behat --init
This will create a default Behat configuration file, we need to edit this file to use PHP WebDriver.
Open the default behart.yml file and replace it with the following content:
default: extensions: BehatMinkExtension: base_url: 'https://www.google.com' sessions: default: selenium2: wd_host: "http://localhost:4444/wd/hub" browser: "chrome"
In the above code, "base_url" is the base URL of the website to be tested, and "sessions" is Session configuration, "default" is the name of the Session. We use selenium2 as the default Session driver and the Chrome driver for PHP WebDriver.
Now that we have completed the integration of PHP WebDriver and Behat, we can use Behat to write test scenarios and use PHP WebDriver to perform automated tests.
Feature: Google Search Scenario: Searching for Behat Given I am on "/" When I fill in "q" with "Behat" And I press "Google Search" Then I should see "Behat"
In the above scenario, "Feature" is the title used to describe the feature and "Scenario" is the test scenario of the expected output when using the given input and operation. In this scenario, we search for the keyword "Behat" and make sure it exists in the search results page.
php bin/behat
This will execute the tests and give you the result.
This will execute the tests and give you the result. Tests should be run automatically in Chrome browser using PHP WebDriver. If the test passes, you will see a message stating that the test passed.
The above is the detailed content of BDD automated testing using PHP WebDriver and Behat. For more information, please follow other related articles on the PHP Chinese website!