Python automated testingPytest

Automated testing Pytest Introduction to Pytest framework 1 Introduction 2. Environment setup How to use Pytest 1. Rules of use 2. Execute test cases 3. Use of setup() and teardown() 4. Use of fixtures 5. mark use 6. allure generate test report 1. allure-pytest usage command 2. Valuation report Selenium + Pytest in practice Automated […]

Use pytest fixture and session to automatically add request headers to make interface testing more efficient!

Foreword When doing interface testing, most interfaces require login authentication. When conducting interface testing in the project, the author needs to add Authentication token to the request header, using requests.get(), requests.post() When the function sends a request, you usually need to pass in the parameter headers, like this requests.post(url=”, json=payload, headers={‘Authorization’: ”}), but each request […]

Use Pytest Cache Fixture to implement test result caching

Foreword During the process of automatically closing the interface, we often encounter scenarios such as “Request 2 needs to use the data responded to Request 1”. The common approach is to make use case dependencies or write the response results of Request 1 to a file. When used Read the file. Of course, this is […]

Popular on the entire network, Python+Pytest+Allure+Jenkins interface automation framework (steps + source code)

Table of Contents: Introduction Preface 1. Python programming from entry to proficiency 2. Practical implementation of interface automation projects 3. Web automation project actual combat 4. Practical implementation of App automation project 5. Resumes of first-tier manufacturers 6. Test and develop DevOps system 7. Commonly used automated testing tools 8. JMeter performance test 9. Summary […]

Encapsulation of test functions, test classes/test methods for python+pytest interface automation

Foreword Today, the author wants to talk to you about encapsulating the code in python + pytest interface automation. Only when the test code is encapsulated can it be recognized and executed by the test framework. For example, the request code for a single interface is as follows: import requests headers = { “user-agent”: “Mozilla/5.0 […]

Python interface automated testing Requests library & Pytest framework

Send get request #Guide package import requests #Define a url url = “http://xxxxxxx” #Pass parameters payload=”{“head”:{“accessToken”:””,”lastnotice”:0,\\ “msgid”:””},”body”:{“user_name”:”super_admin”,\ “password”:”b50c34503a97e7d0d44c38f72d2e91ad”,”role_type”:1}}” headers = { ‘Content-Type’: ‘text/plain’, ‘Cookie’: ‘akpsysessionid=bafc0ad457d5a99f3a4e53a1d4b32519’ } #Send get request r = requests.get( url=url,headers=headers, data=payload) #Print results print(r.text) #decoding print(r.encoding) print(r.text.encode(‘utf-8’).decode(‘unicode_escape’))#First convert the returned result into utf-8, and then decode it into Chinese encoding Send post […]

The difference between Python automated testing framework unittest and pytest

Unittest vs Pytest Mainly compare the differences between unittest and pytest in terms of use case writing rules, use case pre- and post-processing, parameterization, assertions, use case execution, failure re-run and reporting: Use case writing rules Use case pre- and post-conditions Assertion Test Report Failure rerun mechanism Parameterization Use case classification execution If it doesn’t […]

Implement automated interface testing based on Pytest+Requests+Allure

1. Overall structure Framework composition: pytest + requests + allure Design Patterns: keyword driven Project structure: Tool layer: api_keyword/ Parameter layer: params/ Use case layer: case/ Data driver: data_driver/ Data layer: data/ Logic layer: logic/ 2. Specific steps and code 1. Tool layer Secondary encapsulation of common behaviors such as get and post. The code […]