Byte boss will take you to understand web automation testing in one article

1. What is web automation testing

Automation (Automation) refers to the machine equipment, system or process (production, management process) without the direct participation of people or fewer people, according to people's requirements, through automatic detection, information processing, analysis and judgment, manipulation and control, to achieve the expected target process.

This is the definition of automation in textbooks. Returning to automated testing, what is automated testing?

It refers to the test that the test process is carried out without human or less human intervention. To put it simply, it is to use a program or script to test the program. In web automated testing, it is mainly used to save testers from tedious tasks. It is liberated from the content, mainly to do some things that require multiple inputs and multiple runs. For example, we use boundary values ​​and equivalence classes to design a lot of test data that needs to be executed. For example, when the business process needs to be executed many times, we can use it. Web automation testing. At the same time, I have also prepared a software testing video tutorial for everyone, which is placed at the end of the article. If you need it, you can watch it directly, or directly click on the small card at the end of the article to get the information document for free.

2. Tools for web automation testing

Now the mainstream web testing tools we commonly use are the set of selenium tools including

The browser generally selects the driver (chromedriver) Python Selenium library
corresponding to the chrome browser

3. Environment installation for web automated testing

Install and download the browser. The next step is to follow the steps of the browser.
You can download the chromedriver at npmmirror.com/
Note: the large version of 100 is OK.

insert image description here

insert image description here

 

Fourth, the method of web automated testing

Web automated testing generally uses the same method of designing test cases as functional testing, using equivalence class division, boundary values, cause-and-effect diagrams, scenario methods, etc.

We generally use the po mode design for the implementation of web automation testing

PO is the abbreviation of page object. The core idea is to reduce redundant codes by encapsulating interface elements. At the same time, in later maintenance, if element positioning changes, you only need to adjust the code encapsulated by page elements to improve the maintainability of test cases. readability.

The PO mode can divide a page into three layers, object library layer, operation layer, and business layer.

Object library layer: Encapsulates methods for locating elements.

Operation layer: Encapsulates operations on elements.

Business layer: combine one or more operations to complete a business function.

For example, to log in: you need to enter the account number, password, and click to log in. Three operations.

The test script only needs to call the business layer code to complete

When the page needs to appear, you only need to test the code, you don’t need to modify it at all, you only need to modify the operation layer.

5. Process implementation of web automation testing

The web automation test process is basically the same as the functional test:

Below we have logged in as an example

(1) Demand analysis

Please add a picture description

Here we take mobile phone login as an example

Please add a picture description

 (2) Design test cases and test data

Automated test test cases do not need to be as detailed as manual test design

[Below is the test data] 

[
 {
    "username": "21888888888",
    "pwd": "123456",
    "code": "8888",
    "ast_msg": "账号格式不匹配",
    "desc": "用户名错误"
 },
  {
    "username": "12888888888",
    "pwd": "123456",
    "code": "8888",
    "ast_msg": "账号格式不匹配",
    "desc": "用户名错误"
  },
  {
    "username": "1088888888",
    "pwd": "123456",
    "code": "8888",
    "ast_msg": "账号格式不匹配",
    "desc": "用户名错误"
  },
  {
    "username": "138888888889",
    "pwd": "123456",
    "code": "8888",
    "ast_msg": "账号格式不匹配",
    "desc": "用户名错误"
  },
  {
    "username": "32888888888",
    "pwd": "123456",
    "code": "8888",
    "ast_msg": "账号格式不匹配",
    "desc": "用户名错误"
  },
  {
    "username": " ",
    "pwd": "123456",
    "code": "8888",
    "ast_msg": "用户名不能为空",
    "desc": "用户名错误"
  }
]

(3) Build a web automation test environment

It has been built in the above environment installation

(4) Design web automation test framework

The content of the general test po mode includes

insert image description here

 (5) Write code

Create page_login in po folder

	from selenium.webdriver.common.by import By

	from utils import UtilsDriver
	from base.page_base import BasePage

	# 界面对象层

  	class PageLogin(BasePage):

  	# 账号元素
  	def find_username(self):
     	return self.driver.find_element_by_id("username")
       	# return self.driver.find_element(*self.username)
      	# return self.get_element(self.username)

   	# 密码元素
   	def find_pwd(self):
      return self.driver.find_element(By.ID,"password")

  	# 验证码元素
    def find_vcode(self):
      return self.driver.find_element_by_id("verify_code")

    # 按钮开始登录元素
    def find_login_btn(self):
	   # return self.driver.find_element_by_name("sbtbutton")
       return self.driver.find_element(By.NAME,"sbtbutton")

	# 操作层
class HandleLogin(object):
    def __init__(self):
       self.page_login=PageLogin()

    def input_username(self,username):
        self.page_login.find_username().send_keys(username)

    def input_pwd(self,pwd):
      self.page_login.find_pwd().send_keys(pwd)

    def input_vcode(self,code):
       self.page_login.find_vcode().send_keys(code)
	
    def click_login_btn(self):
        self.page_login.find_login_btn().click()

	# 业务层
	# 输入用户名密码验证码 点击登录
class LoginProxy(object):
   def __init__(self):
     self.handle_login = HandleLogin()

  def login(self,username,pwd,code):
    self.handle_login.input_username(username)
    self.handle_login.input_pwd(pwd)
    self.handle_login.input_vcode(code)
    self.handle_login.click_login_btn()

Script execution code to create test_login

# from selenium import webdriver
	from po.page_home import HomeProxy
	from po.page_login import LoginProxy
	from utils import UtilsDriver,get_data
	import time
	import pytest
	import allure
	
	@allure.feature("登录功能")
	class Test_login:
	    def setup_class(self):
	        self.login_p=LoginProxy()
	        self.home_p=HomeProxy()
	    def setup(self):
	        
	        # 进入首页
	        UtilsDriver.get_driver().get("http://127.0.0.1/")
	      
	        # 进入到login界面
	        self.home_p.go_login_page()
	    def teardown_class(self):
	        time.sleep(2)
	        UtilsDriver.quit_driver()
	
	    @pytest.mark.parametrize(["username","pwd","code","asrt_msg"],get_data())
        @allure.story("登录用户名错误")
	    def test_login_username_error(self,username,pwd,code,asrt_msg):
	        self.login_p.login(username,pwd,code)
	        time.sleep(1)
	        # 登录是否成功的预期结果
	        res = UtilsDriver.get_msg()
	        assert asrt_msg in res

(6) Execute test cases

You can use pytest to control the execution of test cases

@pytest.mark.parametrize([“username”,“pwd”,“code”,“asrt_msg”],get_data())

[pytest]
addopts = -s --alluredir report
testpaths = ./script
python_files = test_*.py *test.py
python_classes = Test_*
python_functions = test_*

(7) Generate test report

You can use allure to generate test reports

insert image description here

 

PS: Here is a collection of self-study tutorials for software testing. It should be very helpful to friends who are developing in the testing industry. For friends in need, you can [click the small card at the end of the article to get it for free]. In addition to basic entry-level resources, bloggers also collect a lot of advanced automation resources. From theory to actual combat, the unity of knowledge and action can truly master it. The full set of content has been packaged to the network disk, and the total content is close to 300 G.

☑ 215 episodes - a full set of video courses from zero foundation to proficiency
☑ [Courseware + source code] - complete supporting tutorials
☑ 18 sets - test actual project source code
☑ 37 sets - test tool package
☑ 268 questions - real interview questions
☑ 200 templates - Interview resume template, test plan template, software test report template, test analysis template, test plan template, performance test report, performance test report, performance test script use case template (complete information)

These materials should be the most comprehensive and complete preparation warehouse for friends who do [software testing]. This warehouse has also accompanied me through the most difficult journey, and I hope it can help you too! Everything should be done as early as possible, especially in the technical industry, we must improve our technical skills.

Watch free video tutorials at:

A very perverted but allows you to quickly master automated testing (Web/interface automation/APP/Selenium/performance testing, etc.) Automation/APP/Selenium/Performance testing, etc.) magical methods totaling 100 videos, including: [Automated testing] How to design interface test cases? 、【Automated Testing】Automated testing framework design ideas, a full set of software testing materials and learning routes, etc., for more exciting videos from the UP master, please pay attention to the UP account. https://www.bilibili.com/video/BV1hj411z71j/?vd_source=74d0257ec7066cc4f9013524f0bb7013

 

Guess you like

Origin blog.csdn.net/HUA1211/article/details/132250101