当前位置:网站首页>DDT practice of UI automated testing
DDT practice of UI automated testing
2022-07-21 22:14:00 【Test kid】
ddt yes Python Third party library ,ddt The module provides the creation of data-driven tests , For detailed information about this module, it is recommended to check with the official , The address is :https://pypi.org/project/ddt/
PIP install ddt
cmd Open command line input pip install ddt ( The premise is already installed pip)
Pycharm install ddt
Page path :
File-Settings-Project:Python-Project Interpreter
01
Pycharm function ddt example [ ddt+unittest Come in, data processing , Third party Library ]
# -*-coding:utf-8-*-
import unittest
from selenium import webdriver
from ddt import data, unpack, ddt
# ddt+unittest Come in, data processing , Third party Library
test_data = [{"url": "http://*.com", "age": 20}, {"url": "http://*.com", "age": 22}]
@ddt # Decoration test class
class Testmethod(unittest.TestCase):
@data(*test_data)
@unpack
def test_print_data(self, url, age):
print(url)
print(age)
analysis :
@data(*test_data) Used to decorate the test method , Get a few parameters , Just execute a few use cases
Knowledge points of indefinite length parameters :* Take off your coat , There's only one layer off
@unpack
1、 Only in *test_data After use , If unpack Later parameters , Less than 5 individual , have access to unpack. Otherwise, it is not recommended
2、 Pay attention to the case of unequal parameters , Provide the number of corresponding parameters to receive the variable
3、 If you want to have a dictionary unpack, The parameter should be dictionary key value
@unpack
1、 Only in *test_data After use , If unpack Later parameters , Less than 5 individual , have access to unpack. Otherwise, it is not recommended
2、 Pay attention to the case of unequal parameters , Provide the number of corresponding parameters to receive the variable
3、 If you want to have a dictionary unpack, The parameter should be dictionary key value
02
Let's see UI In automation ddt Usefulness ,ddt Library application in UI Automated testing , Implement the code of writing a test case to verify multiple test points .
for example , The management desk you are using now , There are multiple test requirements , If the user name and password input fields are empty , User name is empty 、 The password is not empty , The password is empty. 、 User name is not empty , Different error messages will be returned respectively
# -*-coding:utf-8-*-
import unittest
from selenium import webdriver
from ddt import data, unpack, ddt
import time
@ddt
class XFDJ_login(unittest.TestCase):
@classmethod
def setUpClass(cls):
# print('start! Enter the initialization environment ')
cls.dr = webdriver.Chrome()
cls.dr.maximize_window()
# print(' The test browser is :{0}'.format(cls.dr.name))
time.sleep(1)
@classmethod
def tearDownclass(cls):
cls.dr.quit()
@data(('', '', u' Please enter a user name !'), ('20190604003', '', u' Please input a password !'), ('', '123456', u' Please enter a user name !'))
@unpack
def test_login(cls, username, password, result):
''' Verify console login '''
ulr1 = 'http://xfdj.kt3.pagoda.com.cn'
# (u' Visit the background management system of patrol service teaching and testing environment ')
cls.dr.get(ulr1)
# print(' Test address is :{0}'.format(cls.dr.current_url))
time.sleep(1)
xpath = cls.dr.find_element_by_xpath
# Click account to log in , enter one user name + password
xpath('//*[@id="app"]/div/div[2]/div[2]/div/div[1]/div').click()
time.sleep(1)
# Capture account text bar , Enter account number
xpath('//*[@id="app"]/div/div[2]/div[2]/div/form/div[1]/input').send_keys(username)
time.sleep(1)
# Capture password text bar , Enter password
xpath('//*[@id="app"]/div/div[2]/div[2]/div/form/div[2]/input').send_keys(password)
time.sleep(1)
# Click login
xpath('//*[@id="app"]/div/div[2]/div[2]/div/form/div[3]/input').click()
divText = xpath('//*[@id="app"]/div/div[2]/div[2]/div/form/div[1]/div').text
cls.assertEqual(divText, result)
if __name__ == '__main__':
unittest.main(verbosity=2)
analysis :
annotation : The above code mainly reflects ddt Application in test cases , stay @data The data type in is tuple , You can see the test data in different situations , That is, the following three test points :
1. User name and password are empty , Click on “ Sign in ” Button , Verify that the error message is “ Please enter a user name ”;
2. User name is not empty , The password is empty. , Click on “ Sign in ” Button , Verify that the error is “ Please input a password ”;
3. User name is empty , The password is not empty , Click on “ Sign in ” Button , Verify that the error is “ Please enter a user name ”.
test_login There are three parameters in , Namely username,password,result, Respectively with @data The tuple data of is mapped one by one
Running results 1 failed, 2 passed in 28.06s Here we can see that the test case with three logins is executed , success 2 strip Report errors 1 strip , The detailed reasons can be analyzed , We make use of ddt You can simply test a function multiple times to execute multiple case, This is it. ddt What's good
Finally, in my QQ The technical exchange group sorted out my 10 Some technical data sorted out by software testing career in recent years , Include : e-book , Resume module , Various work templates , Interview treasure , Self study projects, etc . If you encounter problems in your study or work , There will also be great gods in the group to help solve , Group number 798478386 ( remarks CSDN555 )
Full set of software test automation test teaching video
300G Download tutorial materials 【 Video tutorial +PPT+ Project source code 】
A complete set of software testing automation testing factory has been
边栏推荐
- 字少事大,乐鑫为什么着急发布ESP32-C3
- Raspberry pie 4b is connected with the four sound sensor Ao module of the expansion board
- 【半导体先进工艺制程技术系列】SOI技术(中)
- 沟道长度调制效应与短沟道效应
- 芯科(Silabs) Matter 全栈解决方案,附录高质量Matter培训资
- Li Mu's learning notes of hands-on learning in depth (3) Chapter 1 preparatory knowledge section 1 data operation
- 手把手教你如何使用Charles抓包
- Sonova sonova reduced the time of compliance documents by 80% using polarion
- Siemens invites you to attend the ALM webinar on July 27
- Revisiting Markov generative architectures for effective task oriented dialog sys
猜你喜欢
沟道长度调制效应与短沟道效应
nmn产品真的有其效果吗,服用几个月nmn后有哪些效果
仪器仪表控制板开发面临着哪些机遇和挑战?
Typescript学习笔记
Armv8 cortex-a programming wizard manual learning_ five
APP测试基本流程以及APP测试要点
无线充电模组开发的原理和优势
这家蓝牙芯片巨头瞄准了WiFi SOC市场,重磅发布低功耗WiFi MCU产品线
[reprint] conversation action set definition cued standard dialogue acts
数字化转型 | 壳牌采用Polarion软件,对资本项目数据进行数字化、流程化处理
随机推荐
Siemens invites you to attend the ALM webinar on July 27
Working mode of arm and register organization (review)
什么是PCBA?PCBA测试的重要性有哪些?
2021 MCU WiFi竞争新格局,国产MCU WiFi芯片盘点,附录2020/2021 MCU WiFi排行
什么是物联网控制系统?它具有哪些特点?
分享 | ISO 26262 + FMEA Concepts+Polarion Template
【半导体先进工艺制程技术系列】HKMG工艺技术(下)
Postman core function analysis - parameterization and test report
Learning notes of Li Mu's "hands on learning deep learning" (5) Chapter 1 preparatory knowledge section 3 linear algebra
手把手教你如何使用Charles抓包
Polarion用代码的方式管理需求和测试文档
海外LPWAN的王者是我,一文看懂Wi-Sun协议
物联网蓝牙模块的特点和应用领域有哪些?
Thoughts on why Bluetooth ble specification should be abstracted from GATT on the basis of att
物联网由哪些部分组成?
浅聊Matter协议 (原CHIP协议)
10个经典C语言面试基础算法
Online Collective Matrix Factorization Hashing for Large-Scale Cross-Media Retrieval
Li Mu's learning notes of hands-on learning in depth (4) Chapter 1 preparatory knowledge section 2 data preprocessing
[reprint] conversation action set definition cued standard dialogue acts