https://www.cnblogs.com/zouzou-busy/p/11440175.html
In front of us is to use a machine to test the app do the automation, we want to test different models, that is, compatibility testing, if one one device to perform, it is obvious too much trouble. So often we need to launch multiple devices while running automated test cases to run when multiple devices, we must first start multiple appium service.
Services start more appium
We are all entered before the command line to start appium appium service, so start the default port is 4723, we can use the -p parameter to specify the port number, enter appium equivalent to appium -p 4723
Start another service
appium -p 4725
So we started the two appium service.
To partition a service number, such as port 4723, the port number 4724 is connected Android device, so the next services 4725
appium parameters
appium more than one parameter -p, there are other parameters
parameter | Defaults | meaning |
-U,--udid | null | Physical devices connected to a unique device identifier |
-a,--address | 0.0.0.0 | Listening ip address |
-p,--port | 4723 | Listening port |
-bp,--bootstrap-port | 4724 | Android device connected port number (Android-only) |
-g,--log | null | The log output to the specified file |
--no-reset | false | Application session state is not reset between |
--session-override | false | Allowing the session to be covered (if the conflict) |
--app-activity | null | When you open Android application, start the Activity name |
--app | null | Path local or remote installation package app |
Other parameters can be used to view appium -h
Multi-device start
Prerequisites:
1. Connecting two machines
2. Start two services
yaml file
platformName: Android platforVersion: 6.1.1 deviceName: 127.0.0.1:62001 appPackage: com.jgw.csca appActivity: com.jgw.csca.view.activity.LoginActivity unicodeKeyboard: True resetKeyboard: True Moresheth: False ip: address 127.0.0.1 port : 4723
script
Import the webdriver appium from Import YAML devices_list = [ '127.0.0.1:62001', '127.0.0.1:62025'] # two devices ' '' after the equipment is udid, if a real machine, that must have udid deviceName you can easily write a port is appium port services, I started that 4723 and 4725 '' ' DEF desiredCaps (UDID, port): with Open (' ../ conf / capability.yaml ',' r ', encoding = 'UTF-. 8') AS File: Data = yaml.load (File, Loader = yaml.FullLoader) desired_caps = {} desired_caps [ 'PlatformName'] = Data [ 'PlatformName'] desired_caps [ 'platforVersion'] = Data [ ' platforVersion '] desired_caps [' deviceName '] = Data [' deviceName '] desired_caps [' UDID '] = udid desired_caps['appPackage'] = data['appPackage'] desired_caps['appActivity'] = data['appActivity'] desired_caps['unicodeKeyboard'] = data['unicodeKeyboard'] desired_caps['resetKeyboard'] = data['resetKeyboard'] desired_caps['noReset'] = data['noReset'] driver = webdriver.Remote('http://' + str(data['ip']) + ':' + str(port)+ '/wd/hub', desired_caps) ''' 第一次启动 driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) 第二次启动 driver = webdriver.Remote('http://127.0.0.1:4725/wd/hub', desired_caps) ''' return driver if __name__ == '__main__': desiredCaps(devices_list[0], 4723) desiredCaps(devices_list[1], 4725)
Thus, after the first execution device executes on the second device
Multi-process startup of several devices
You can use python multi-threaded or multi-process implementation, multiple processes are recommended for the following reasons
Multi-process, the same variables, each of which has a copy exists in each process, independently of each other. The multi-threaded, all variables shared by all threads, so that any variable can be any one thread modifies, therefore, the amount of data shared between threads biggest danger is that multiple threads at the same time to modify a variable, easy to to change the data chaos
Pre-conditions, and the same as above
from appium import webdriver import yaml import multiprocessing devices_list = ['127.0.0.1:62001', '127.0.0.1:62025'] # 两个设备 def desiredCaps(udid, port): with open('../conf/capability.yaml', 'r', encoding='utf-8') as file: data = yaml.load(file, Loader=yaml.FullLoader) desired_caps = {} desired_caps['platformName'] = data['platformName'] desired_caps['platforVersion'] = data['platforVersion'] desired_caps['deviceName'] = data['deviceName'] desired_caps['udid'] = udid desired_caps['appPackage'] = data['appPackage'] desired_caps['appActivity'] = data['appActivity'] desired_caps['unicodeKeyboard'] = data['unicodeKeyboard'] desired_caps['resetKeyboard'] = data['resetKeyboard'] desired_caps['noReset'] = data['noReset'] driver = webdriver.Remote('http://' + str(data['ip']) + ':' + str(port)+ '/wd/hub', desired_caps) return driver desired_process = [] # 存储多设备 for i in range(len(devices_list)): port = 4723 + 2*i desired = multiprocessing.Process(target=desiredCaps, args=(devices_list[i], port)) desired_process.append(desired) # 将设备添加到里面,ip和端口 if __name__ == '__main__': for desired in desired_process: desired.start() for desired in desired_process: desired.join()
In front of us is to use a machine to test the app do the automation, we want to test different models, that is, compatibility testing, if one one device to perform, it is obvious too much trouble. So often we need to launch multiple devices while running automated test cases to run when multiple devices, we must first start multiple appium service.
Services start more appium
We are all entered before the command line to start appium appium service, so start the default port is 4723, we can use the -p parameter to specify the port number, enter appium equivalent to appium -p 4723
Start another service
appium -p 4725
So we started the two appium service.
To partition a service number, such as port 4723, the port number 4724 is connected Android device, so the next services 4725
appium parameters
appium more than one parameter -p, there are other parameters
parameter | Defaults | meaning |
-U,--udid | null | Physical devices connected to a unique device identifier |
-a,--address | 0.0.0.0 | Listening ip address |
-p,--port | 4723 | Listening port |
-bp,--bootstrap-port | 4724 | Android device connected port number (Android-only) |
-g,--log | null | The log output to the specified file |
--no-reset | false | Application session state is not reset between |
--session-override | false | Allowing the session to be covered (if the conflict) |
--app-activity | null | When you open Android application, start the Activity name |
--app | null | Path local or remote installation package app |
Other parameters can be used to view appium -h
Multi-device start
Prerequisites:
1. Connecting two machines
2. Start two services
yaml file
platformName: Android platforVersion: 6.1.1 deviceName: 127.0.0.1:62001 appPackage: com.jgw.csca appActivity: com.jgw.csca.view.activity.LoginActivity unicodeKeyboard: True resetKeyboard: True Moresheth: False ip: address 127.0.0.1 port : 4723
script
Import the webdriver appium from Import YAML devices_list = [ '127.0.0.1:62001', '127.0.0.1:62025'] # two devices ' '' after the equipment is udid, if a real machine, that must have udid deviceName you can easily write a port is appium port services, I started that 4723 and 4725 '' ' DEF desiredCaps (UDID, port): with Open (' ../ conf / capability.yaml ',' r ', encoding = 'UTF-. 8') AS File: Data = yaml.load (File, Loader = yaml.FullLoader) desired_caps = {} desired_caps [ 'PlatformName'] = Data [ 'PlatformName'] desired_caps [ 'platforVersion'] = Data [ ' platforVersion '] desired_caps [' deviceName '] = Data [' deviceName '] desired_caps [' UDID '] = udid desired_caps['appPackage'] = data['appPackage'] desired_caps['appActivity'] = data['appActivity'] desired_caps['unicodeKeyboard'] = data['unicodeKeyboard'] desired_caps['resetKeyboard'] = data['resetKeyboard'] desired_caps['noReset'] = data['noReset'] driver = webdriver.Remote('http://' + str(data['ip']) + ':' + str(port)+ '/wd/hub', desired_caps) ''' 第一次启动 driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps) 第二次启动 driver = webdriver.Remote('http://127.0.0.1:4725/wd/hub', desired_caps) ''' return driver if __name__ == '__main__': desiredCaps(devices_list[0], 4723) desiredCaps(devices_list[1], 4725)
Thus, after the first execution device executes on the second device
Multi-process startup of several devices
You can use python multi-threaded or multi-process implementation, multiple processes are recommended for the following reasons
Multi-process, the same variables, each of which has a copy exists in each process, independently of each other. The multi-threaded, all variables shared by all threads, so that any variable can be any one thread modifies, therefore, the amount of data shared between threads biggest danger is that multiple threads at the same time to modify a variable, easy to to change the data chaos
Pre-conditions, and the same as above
from appium import webdriver import yaml import multiprocessing devices_list = ['127.0.0.1:62001', '127.0.0.1:62025'] # 两个设备 def desiredCaps(udid, port): with open('../conf/capability.yaml', 'r', encoding='utf-8') as file: data = yaml.load(file, Loader=yaml.FullLoader) desired_caps = {} desired_caps['platformName'] = data['platformName'] desired_caps['platforVersion'] = data['platforVersion'] desired_caps['deviceName'] = data['deviceName'] desired_caps['udid'] = udid desired_caps['appPackage'] = data['appPackage'] desired_caps['appActivity'] = data['appActivity'] desired_caps['unicodeKeyboard'] = data['unicodeKeyboard'] desired_caps['resetKeyboard'] = data['resetKeyboard'] desired_caps['noReset'] = data['noReset'] driver = webdriver.Remote('http://' + str(data['ip']) + ':' + str(port)+ '/wd/hub', desired_caps) return driver desired_process = [] # 存储多设备 for i in range(len(devices_list)): port = 4723 + 2*i desired = multiprocessing.Process(target=desiredCaps, args=(devices_list[i], port)) desired_process.append(desired) # 将设备添加到里面,ip和端口 if __name__ == '__main__': for desired in desired_process: desired.start() for desired in desired_process: desired.join()