当前位置:网站首页>Alibaba P8 teaches you how to realize multithreading in automated testing? Hurry up and stop
Alibaba P8 teaches you how to realize multithreading in automated testing? Hurry up and stop
2022-07-07 08:51:00 【Software testing】
process
A process is a dynamic execution of a program on a dataset , We write programs to describe what functions a process needs to perform and how to do it .
Threads
Thread footer lightweight process , He is a basic CPU execution unit , Is an implementation in process , Threads appear to reduce the trumpet of context switching , Improve the concurrency of the system .
Threads and processes
A thread can only belong to one process , And a process can have multiple threads .
But few thread resources are allocated to the process , All threads of the same process share all resources of the process .
CPU To threads , That is true. CPU Threads running on .
Application of multithreading principle
1、 Parallelism and concurrency
parallel : Each thread is assigned to a separate core , Thread running at the same time .
Concurrent : Multiple threads running on a single core , One thread runs at a time , The system keeps switching threads , It looks like it's running at the same time , It's actually thread switching .
2、Python The multithreading
GIL Global timer lock : If a thread wants to execute, it must first get GIL.
Python The multithreading : In fact, only one thread can run at a time , But it can achieve concurrency .
3、Python Multithreaded applications
Different codes run differently , We can use multithreading , Form concurrent , Achieve improved efficiency .
Case study :Web automation , Actually CPU After executing a command , Most of the time is waiting for , So this time ,CPU Will limit or do the tasks of other processes , So we can use multithreading , Realize multi browser automation and run at the same time , So as to achieve high efficiency .
from appium import webdriver
from appium.webdriver.extensions.android.nativekey import AndroidKey
from appium.webdriver.common.touch_action import TouchAction
from selenium.webdriver.support.wait import WebDriverWait
import time
from ddt import ddt,data,unpack
import threading
data_sum = [
{'sum_a': 2, 'sum_b': 3},
{'sum_a': 2, 'sum_b': 3},
{'sum_a': 5, 'sum_b': 10}
]
def run_first():
desired_caps = {
'platformName': 'Android', # The tested mobile phone is Android
'platformVersion': '7.1.2', # Mobile Android version
'deviceName': 'xiaomi_mix', # Device name , Android phones can fill in
'appPackage': 'com.chinatower.fghd.customer', # start-up APP Package name
'appActivity': 'com.ckd.fgbattery.activity.User_Login_Activity', # start-up Activity name
'unicodeKeyboard': True, # Use your own input method , When entering Chinese, fill in True
'resetKeyboard': True, # After executing the program, restore the original input method
'noReset': True, # Don't reset App
'newCommandTimeout': 5000,
'UDID':'127.0.0.1:62001',
'automationName': 'uiAutomator2'
# 'app': r'd:\apk\bili.apk',
}
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
#login_pwd(1,1)
pwd = driver.find_element_by_xpath('//*[@text = " Password to login "]')
print(pwd.get_attribute('text'))
TouchAction(driver).tap(pwd).perform()
pwd.click()
driver.find_element_by_id("user_phone_et").send_keys('1')
driver.find_element_by_id("sms_code_et").send_keys('1')
driver.find_element_by_id("btn_res").click()
# Login error , Unable to jump to page
try:
WebDriverWait(driver, 3, 1).until(lambda x: x.find_element_by_xpath("//*[@text=' Code scanning and power exchange ']"))
scan = driver.find_elements_by_xpath("//*[@text=' Code scanning and power exchange ']")
if scan:
print(" Login successful ")
return True
except:
print(" Login failed ")
return False
def run_two():
desired_caps_and5 = {
'platformName': 'Android', # The tested mobile phone is Android
'platformVersion': '5.1.1', # Mobile Android version
'deviceName': 'HuaWei P30', # Device name , Android phones can fill in
'appPackage': 'com.chinatower.fghd.customer', # start-up APP Package name
'appActivity': 'com.ckd.fgbattery.activity.User_Login_Activity', # start-up Activity name
'unicodeKeyboard': True, # Use your own input method , When entering Chinese, fill in True
'resetKeyboard': True, # After executing the program, restore the original input method
'noReset': True, # Don't reset App
'newCommandTimeout': 5000,
'UDID':'127.0.0.1:62026',
'automationName': 'uiAutomator2'
# 'app': r'd:\apk\bili.apk',
}
driver2 = webdriver.Remote('http://localhost:4725/wd/hub', desired_caps_and5)
#login_pwd(2,2)
time.sleep(10)
print(" the second ")
pwd = driver2.find_element_by_xpath('//*[@text = " Password to login "]')
print(pwd.get_attribute('text'))
TouchAction(driver2).tap(pwd).perform()
pwd.click()
driver2.find_element_by_id("user_phone_et").send_keys('1')
driver2.find_element_by_id("sms_code_et").send_keys('2')
driver2.find_element_by_id("btn_res").click()
# Login error , Unable to jump to page
try:
WebDriverWait(driver2, 3, 1).until(lambda x: x.find_element_by_xpath("//*[@text=' Code scanning and power exchange ']"))
scan = driver2.find_elements_by_xpath("//*[@text=' Code scanning and power exchange ']")
if scan:
print(" Login successful ")
return True
except:
print(" Login failed ")
return False
# @data(*data_sum)
# @unpack
# def login_pwd(sum_a,sum_b):
# pwd = driver.find_element_by_xpath('//*[@text = " Password to login "]')
# print(pwd.get_attribute('text'))
# TouchAction(self.driver).tap(pwd).perform()
# pwd.click()
# driver.find_element_by_id("user_phone_et").send_keys(sum_a)
# driver.find_element_by_id("sms_code_et").send_keys(sum_b)
# driver.find_element_by_id("btn_res").click()
# # Login error , Unable to jump to page
# try:
# WebDriverWait(driver, 3, 1).until(lambda x: x.find_element_by_xpath("//*[@text=' Code scanning and power exchange ']"))
# scan = driver.find_elements_by_xpath("//*[@text=' Code scanning and power exchange ']")
# if scan:
# print(" Login successful ")
# return True
# except:
# print(" Login failed ")
# return False
#
# # Connect Appium Server, Initialize the automation environment
# driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
# driver_p = webdriver.Remote('http://localhost:4725/wd/hub', desired_caps_and5)
#
# login_pwd(driver,1,1)
# login_pwd(driver_p,2,2)
if __name__ == '__main__':
t1 = threading.Thread(target=run_first,name = 'thread1')
t2 = threading.Thread(target=run_two,name='thread2')
start_time = time.time()
t1.start()
t1.join()
t2.start()
print(" Currently active threads are :{}".format(threading.current_thread()))
print(" All running threads :{}".format(threading.enumerate()))
print(" Number of threads running :{}".format(threading.active_count()))
t2.join()
end_time = time.time()
print(" The program takes time to run :{}".format(end_time - start_time))
The house needs to be built layer by layer , Knowledge needs to be learned at one point one . We should lay a good foundation in the process of learning , More hands-on practice , Don't talk much , The last dry goods here ! I stayed up late to sort out the stages ( function 、 Interface 、 automation 、 performance 、 Test open ) Skills learning materials + Practical explanation , Very suitable for studying in private , It's much more efficient than self-study , Share with you .
Get off w/x/g/z/h: Software testing tips dao
Typing is not easy , If this article is helpful to you , Click a like, collect a hide and pay attention , Give the author an encouragement . It's also convenient for you to find it quickly next time .
边栏推荐
- Interpolation lookup (two methods)
- Data type - integer (C language)
- 调用华为游戏多媒体服务的创建引擎接口返回错误码1002,错误信息:the params is error
- [Yugong series] February 2022 U3D full stack class 006 unity toolbar
- Redis summary
- FPGA knowledge accumulation [6]
- [Chongqing Guangdong education] accounting reference materials of Nanjing University of Information Engineering
- let const
- Category of IP address
- Introduction to data fragmentation
猜你喜欢

Interpolation lookup (two methods)

为什么要选择云原生数据库

Greenplum 6.x monitoring software setup

ncs成都新電面試經驗

如何在快应用中实现滑动操作组件

Lenovo hybrid cloud Lenovo xcloud: 4 major product lines +it service portal

leetcode134. gas station

Greenplum 6.x build_ install
![Upload an e-office V9 arbitrary file [vulnerability recurrence practice]](/img/e7/278193cbc2a2f562270f99634225bc.jpg)
Upload an e-office V9 arbitrary file [vulnerability recurrence practice]

调用华为游戏多媒体服务的创建引擎接口返回错误码1002,错误信息:the params is error
随机推荐
Appeler l'interface du moteur de création du service multimédia de jeu Huawei renvoie le Code d'erreur 1002, le message d'erreur: les paramètres sont l'erreur
南京商品房买卖启用电子合同,君子签助力房屋交易在线网签备案
go写一个在一定时间内运行的程序
Gson converts the entity class to JSON times declare multiple JSON fields named
Opencv converts 16 bit image data to 8 bits and 8 to 16
redis故障处理 “Can‘t save in background: fork: Cannot allocate memory“
详解华为应用市场2022年逐步减少32位包体上架应用和策略
Quick sorting (detailed illustration of single way, double way, three way)
let const
[Chongqing Guangdong education] organic electronics (Bilingual) reference materials of Nanjing University of Posts and Telecommunications
Analysis of using jsonp cross domain vulnerability and XSS vulnerability in honeypot
Why choose cloud native database
登山小分队(dfs)
A bug using module project in idea
mysql分区讲解及操作语句
Upload an e-office V9 arbitrary file [vulnerability recurrence practice]
JS的操作
Mountaineering team (DFS)
Newly found yii2 excel processing plug-in
数据分析方法论与前人经验总结2【笔记干货】