当前位置:网站首页>Unittest unit test (V)
Unittest unit test (V)
2022-04-21 13:48:00 【Effort volume】
One 、 Test fixture ( The firmware , Hook function , Back and forth )TestFixtrue Detailed explanation
setUp/tearDown Execute before and after the test case
setUpClass/tearDownClass Execute before and after the test class ( Must add @classmethod Decorator )
setUpModule/tearDownModule Execute before and after testing the module
Fixture packaging :
Automated testing framework Essential ideas ( When there is a lot of duplicate code )

Two 、 Ignore test cases
class TestUnittest(MyUint):
a = 18
@unittest.skip(' Unconditionally ignore ')
def test_01(self):
print(" test 01")
@unittest.skipIf(a >= 16, " If the conditions are met, ignore ")
def test_02(self):
print(" test 02")
@unittest.skipUnless(a >= 20, " If the conditions are not met, ignore ")
def test_03(self):
print(" test 03")
3、 ... and 、 Assertion ( Judge whether the use case is executed successfully )

In practice :
assertEqual(a,b)
assertIn(a,b)
assertTrue(x)
Example :
class TestShopnc(MyUint):
def test_01_add_user(self):
global driver
# Open the browser
driver = webdriver.Chrome()
driver.implicitly_wait(
10
)
# Load web page
driver.get("http://localhost:9527/login?redirect=%2Fdashboard")
# enter one user name
driver.find_element(By.CLASS_NAME, "el-input__inner").clear()
driver.find_element(By.CLASS_NAME,"el-input__inner").send_keys("")
# Input password
driver.find_element(By.NAME, "pwd").clear()
driver.find_element(By.NAME,"pwd").send_keys("")
# adopt Cookie Bypass verification code
print("------------------------------")
print(" Before landing ")
cks = driver.get_cookies()
for ck in cks:
print(ck)
# sleep 10 second , Enter the verification code manually
time.sleep(10)
print("------------------------------")
print(" After landing ")
# Print again after logging in cookie
cks = driver.get_cookies()
for ck in cks:
print(ck)
Log in and get cookie Re assign ( Bypass verification code )
class TestShopnc(MyUint):
def test_01_add_user(self):
global driver
# Open the browser
driver = webdriver.Chrome()
driver.implicitly_wait(
10
)
# Load web page
driver.get("http://localhost:9527/login?redirect=%2Fdashboard")
# adopt Cookie Bypass verification code ( Solve all login problems that do not require third-party authentication )
driver.add_cookie({'name': 'sidebarStatus', 'value': '0'})
driver.add_cookie({'name': 'Authori-zation', 'value': 'd8c81eecb1f846f1bb2d3dd3c0d57894'})
driver.add_cookie({'name': 'JavaInfo',
'value': '{%22id%22:1%2C%22account%22:%22admin%22%2C%22realName%22:%22%E8%B6%85%E7%AE%A1'
'%22%2C%22isSms%22:false%2C%22token%22:%22d8c81eecb1f846f1bb2d3dd3c0d57894%22}'})
# After sleeping for two seconds, load the web page after login
time.sleep(2)
driver.get("http://localhost:9527/dashboard")
The final actual case :
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from common.my_unit import MyUint
class TestShopnc(MyUint):
def test_01_add_user(self):
global driver
# Open the browser
driver = webdriver.Chrome()
driver.implicitly_wait(
10
)
# Load web page
driver.get("http://localhost:9527/login?redirect=%2Fdashboard")
# adopt Cookie Bypass verification code ( Solve all login problems that do not require third-party authentication )
driver.add_cookie({'name': 'sidebarStatus', 'value': '0'})
driver.add_cookie({'name': 'Authori-zation', 'value': 'd8c81eecb1f846f1bb2d3dd3c0d57894'})
driver.add_cookie({'name': 'JavaInfo',
'value': '{%22id%22:1%2C%22account%22:%22admin%22%2C%22realName%22:%22%E8%B6%85%E7%AE%A1'
'%22%2C%22isSms%22:false%2C%22token%22:%22d8c81eecb1f846f1bb2d3dd3c0d57894%22}'})
# After sleeping for two seconds, load the web page after login
time.sleep(2)
driver.get("http://localhost:9527/dashboard")
# Assert that the current path contains the home page path of the background
self.assertIn("dashboard", driver.current_url)
# Click on 【 Member management 】
time.sleep(1)
driver.find_element(By.XPATH,"//*[@id='app']/div/div[2]/section/div[1]/div[2]/div/div[6]/div/div/a").click()
# Click on 【 edit 】
time.sleep(1)
driver.find_element(By.XPATH,"//*[@id='app']/div/div[2]/section/div[1]/div[1]/div[2]/div[1]/div[4]/div[2]/table/tbody/tr[1]/td[9]/div/a/button").click()
# Input author
time.sleep(1)
driver.find_element(By.XPATH,"//*[@id='app']/div/div[2]/section/div[1]/div/div/div/form/div[2]/div/div/input").clear()
time.sleep(1)
driver.find_element(By.XPATH,"//*[@id='app']/div/div[2]/section/div[1]/div/div/div/form/div[2]/div/div/input").send_keys(" Yang liuxuan ")
# preservation
time.sleep(1)
driver.find_element(By.XPATH,"//*[@id='app']/div/div[2]/section/div[1]/div/div/div/form/div[9]/div/button").click()
# Assertion
time.sleep(1)
self.assertEqual(driver.find_element(By.CLASS_NAME,"el-message__content").text,' Edit the article successfully ')
版权声明
本文为[Effort volume]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211347166899.html
边栏推荐
- Unittest unit test (IV)
- 过滤字符串只保留串中的字母字符 (10 分)请编写一个函数fun,函数的功能是:输入一个字符串,过滤此串,只保留串中的字母字符,并统计新生成串中包含的字母个数。
- What does it mean that the AGP transform API is abandoned?
- [special topic of stack and queue] - Dual queue simulation stack
- Forced to choose an outsourcing company
- Exercise questions and answers of basic theories and relevant laws and regulations in 2022 supervision engineer examination
- Ali Tianchi competition -- street view character coding recognition
- Use of JSON server
- Markdown语法及测试
- OpenLDAP使用ldapadd手动添加用户
猜你喜欢

机器学习笔记 - SVD奇异值分解(3) 在图像上应用 SVD

Benchmark cell detection scheme based on violence matching threshold

Stm32cupemx installation

JVM內存分配機制詳解

In office word 2016, omml2mml appears when the formula edited by word's own formula editor is transferred to MathType Solutions to XSL problems

c3p0的坑导致并发性能问题

EsgynDB 清理不一致对象

Ali Tianchi competition -- street view character coding recognition

Nmap usage

机器学习笔记 - Moore-Penrose 伪逆
随机推荐
An example of expert system and its skeleton system
json-server的使用
Sqlyog import SQL file
并发编程之JMM模型和并发三大特性
POI与EasyExcel读写测试
Unittest单元测试(二)
Exercise questions and answers of basic theories and relevant laws and regulations in 2022 supervision engineer examination
mysql-MVCC多版本并发版本控制和bufferPool缓存机制
Feedforward neural network
Buuctf [Chapter 3 Advanced Web] logic vulnerability
SECOND: Sparsely Embedded Convolutional Detection
List stores map values
Ali Tianchi competition -- street view character coding recognition
JVM字节码文件结构深度剖析
Accounting practice exercises and answers for the 2022 primary accounting title examination
Number II that occurs only once (hash, bit operation, logic circuit, finite state automata)
Do self media and short videos, and don't trust those mutual relations and mutual praise
The difference between thread library and ASIO Library
New technology is coming again, embrace agp7 0, are you ready to say goodbye to transform?
JVM内存分配机制详解