当前位置:网站首页>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 .
边栏推荐
- 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
- leetcode134. gas station
- 路由信息协议——RIP
- 21 general principles of wiring in circuit board design_ Provided by Chengdu circuit board design
- Required String parameter ‘XXX‘ is not present
- A bug using module project in idea
- 阿里p8推荐,测试覆盖率工具—Jacoco,实用性极佳
- oracle一次性说清楚,多种分隔符的一个字段拆分多行,再多行多列多种分隔符拆多行,最终处理超亿亿。。亿级别数据量
- 平台化,强链补链的一个支点
- Greenplum6.x搭建_环境配置
猜你喜欢

AVL balanced binary search tree

Routing information protocol rip
![[MySQL] detailed explanation of trigger content of database advanced](/img/6c/8aad649e4ba1160db3aea857ecf4a1.png)
[MySQL] detailed explanation of trigger content of database advanced

Nanjing commercial housing sales enabled electronic contracts, and Junzi sign assisted in the online signing and filing of housing transactions

阿里p8推荐,测试覆盖率工具—Jacoco,实用性极佳

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

联想混合云Lenovo xCloud:4大产品线+IT服务门户
![[Yu Yue education] higher vocational English reference materials of Nanjing Polytechnic University](/img/e2/519a5267cd5425a83434d2da65ebe6.jpg)
[Yu Yue education] higher vocational English reference materials of Nanjing Polytechnic University
![Other 7 features of TCP [sliding window mechanism ▲]](/img/ff/c3f52a7b89804acfd0c4f3b78bc4a0.jpg)
Other 7 features of TCP [sliding window mechanism ▲]

JS的操作
随机推荐
go写一个在一定时间内运行的程序
Data type - floating point (C language)
基本数据类型和string类型互相转化
JEditableTable的使用技巧
Composer change domestic image
Mountaineering team (DFS)
Implementation of navigation bar at the bottom of applet
JS的操作
年薪50w阿裏P8親自下場,教你如何從測試進階
[Chongqing Guangdong education] audio visual language reference materials of Xinyang Normal University
注解@ConfigurationProperties的三种使用场景
说一个软件创业项目,有谁愿意投资的吗?
String operation
Other 7 features of TCP [sliding window mechanism ▲]
Compilation and linking of programs
National SMS center number inquiry
How to realize sliding operation component in fast application
[machine learning] watermelon book data set_ data sharing
平台化,强链补链的一个支点
Basic data types and string types are converted to each other