This is REST API Python and Behave testing framework for Swagger Petstore: http://petstore.swagger.io/
Download project from github. Project can be run in eclipse or in console using following commands:
- run a runner file: python Pet_Store_API_Testing_Runner.py
- run a concrete feature scenario: python Pet_Store_API_Testing_Runner.py ./features/feature_pet/
- run tests with specific tags: python Pet_Store_API_Testing_Runner.py ./features/feature_pet/ --tags=@smoke
- run without runner (In this case report is not generated): behave features/feature_pet/Pet_Store_API_Testing.feature
- run specific scenario (In this case report is not generated): behave features/feature_pet/Pet_Store_API_Testing.feature -n 'GET pet request using pet ID'
Test cases are designed using behave python module. They have given-when-then structure.
- Structure
- Test case example with given-when-then structure:
Scenario: GET pet request using pet ID
Given "POST" api pet request endpoint is set as "pet"
When HEADER params for request and response are specified
And Pet details are specified as "Rex" and "/workspace/PetStoreAPITesting1 " and "pending"
And Request BODY form parameters are set using pet details
And "POST" HTTP request is raised
And Valid HTTP response is received
And Response http code is 200
And "GET" api pet request endpoint is set as "pet"
And HEADER params for request and response are specified
And "GET" HTTP request is raised
Then Valid HTTP response is received
And Response http code is 200
Python 3.6 Module requests version 2.19 Module behave version 1.2.6 Module hamcrest version 1.9 Eclipse + SonarLint + Pydev
-sudo pip install allure_behave
-sudo pip install PyHamcrest -> python2 which pip3 python3 -sudo pip3 install PyHamcrest -> python3
-behave should be added to the 'Forced Builtin' Window>Preferences>PyDev>Interperters>Python Interperter>Forced Builtins>New
-to turn it off, Window>Preferences>PyDev>Editor>Code Analysis>Others>Duplicated Signature>Ignore
-setup the built in run. Run>Run Configurations>Python Run Create a new run. In Main>Project set project. For the Main Module choose version of "/home/xx/bin/behave" Inside the Arguments tab set the Working Directory where .feature file exists.
You can enable/skip tests using tags:
select/enable | --tags=@smoke |Only items with this tag. not (tilde/minus) | --tags=~@smoke |Only items without this tag. logical-or | --tags=@one,@two |If @one or @two is present. logical-and | --tags=@one --tags=@two |If both @one and @two are present.
example run only smoke test cases: python Pet_Store_API_Testing_Runner.py ./features/feature_pet/ --tags=@smoke
Test reports are generated in the reporting/results directory. Each test case can have a following status: passed, failed, skipped.
Version 1.0
Agnieszka Galeza