当前位置:网站首页>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 .
边栏推荐
- About using CDN based on Kangle and EP panel
- Frequently Asked Coding Problems
- Greenplum6.x搭建_安装
- Problems encountered in the use of go micro
- Frequently Asked Coding Problems
- How to add a mask of a target in a picture
- Tips for using jeditabletable
- IP地址的类别
- Oracle makes it clear at one time that a field with multiple separators will be split into multiple rows, and then multiple rows and columns. Multiple separators will be split into multiple rows, and
- Database storage - table partition
猜你喜欢
Greenplum6.x重新初始化
快速集成认证服务-HarmonyOS平台
How to realize sliding operation component in fast application
Pointer advanced, string function
调用华为游戏多媒体服务的创建引擎接口返回错误码1002,错误信息:the params is error
How to realize the high temperature alarm of the machine room in the moving ring monitoring system
平台化,强链补链的一个支点
指针进阶,字符串函数
PPT模板、素材下载网站(纯干货,建议收藏)
leetcode134. gas station
随机推荐
【微信小程序:缓存操作】
测试人一定要会的技能:selenium的三种等待方式解读,清晰明了
[hard core science popularization] working principle of dynamic loop monitoring system
Teach you how to select PCB board by hand (II)
Mock.js用法详解
对API接口或H5接口做签名认证
Analysis of abnormal channel number information before and after AGC re signature service
Oracle makes it clear at one time that a field with multiple separators will be split into multiple rows, and then multiple rows and columns. Multiple separators will be split into multiple rows, and
[Yugong series] February 2022 U3D full stack class 005 unity engine view
cmake命令行使用
Category of IP address
Find the original code, inverse code and complement of signed numbers [C language]
使用AGC重签名服务前后渠道号信息异常分析
QT charts use (rewrite qchartview to realize some custom functions)
基本数据类型和string类型互相转化
Greenplum 6.x version change record common manual
Problems encountered in the use of go micro
数据库存储---表分区
Quick sorting (detailed illustration of single way, double way, three way)
Basic data types and string types are converted to each other