A recent project has been tested with behave because it has not been contacted before, so write a summary of recent experiences. The people who do the automation estimate are not very unfamiliar to selenium, but for behave tools, it is estimated that few people have heard of it. Behave is the framework for BDD (Behavior Drive development-behavior driven development). This framework is used to do more agile development. QA, developers, customers and product managers can all join behave. Where behave includes the feature part, which is usually written by the customer or someone who does not understand the code, then QA writes the test code according to the customer's behavior.
Behave can be used to test the functionality of a Web page or to test the developer's code for a unit test.
Preparatory work:
1. Download Python and add the c:\Python2.7 to path inside the environment variable---------see http://weixiaolu.iteye.com/blog/1617440
2. Download Pip tool (basically download tool in Python with PIP)
3. Open the CMD window and use the PIP Install behave command to install behave------behave's official website: http://pythonhosted.org/behave/
4. Install selenium using the PIP install Selenium command
5. Install hamcrest using the PIP install pyhamcrest command. Why install Hamcrest? We are familiar with the assert statements that are used in the test, but the Hamcrest API can be used to judge actual value and expected value.
Okay, basically prepare for the job, and then we'll start with the first simple automation script.
First, create a new folder named feature, in this file to create a new example01 folder, the Example01 file inside the new Example01.feature file
#.. /feature/example01/example01.feature
Feature:show off behave
Scenario:show off behave
Given Behave Install
When I pass 5 to number variables
Then parameter number must is bigger than 4
Create a new steps folder inside the Example01 folder, and then create a new example01.py file in the steps folder
#.. /feature/example01/steps/example01.py
@Given (' Behave install ')
def step_impl (context):
Pass
@when (' I pass {NUMBER:D} to number variables ')
def step_impl (context, number):
Context.number = number
@Then (' parameter number must be bigger than 4 ')
def step_impl (context):
Assert 5>4
Three, the last step to open cmd, and then CD to your feature directory, execute the behave command, the results come out:
Problem solving:
1. If you encounter the following problem, it is the reason that the tab is in your code and space is mixed with indentation. Please standardize your code, either tab indent or Space indent. tab indentation is generally used.
Behave + Selenium (Python) One: