Implementation of multi-machine automation with ios+appium+python

iOS automation difficulties

The difficulty of iOS multi-machine automation is not in appium, but inwda;

Appium differentiates between different ports to start multiple services, and multi-threads or multi-processes can obtain the driver;

However, the implementation of iOS automation relies on xcode compilation and installation of wda, and xcode cannot support multiple real iOS devices at the same time, so it is blocked;

Research has revealed two ways to bypass xcode:

1. Use appium’s own wda instead of xcode wda;

2. Use tidevice instead of xcode to start wda

However, the second method relies on wda being installed on the device, and when appium starts, it will first delete the original wda on the device, so whether this method is feasible needs to be verified.

Finally decided to use appium wda instead of xcode.

The wda that comes with appium cannot be used directly. It needs to be debugged in xcode before use. You can take the wda that used to run normally and replace it in the appium directory.

​​

It can be seen from the appium log that after startup, the original wda on the phone will be deleted first, and then wda will be reinstalled. In the log, you can see the path of the wda used by appium:

/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-webdriveragent

In the terminal open /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/

​​

Replace the previously debugged wda project into it.

1. Connect multiple devices to the computer

View device list

tidevice list

2. Start multiple appium services

Open different ports and start multiple appium services;

If it is the desktop version of appium:

Find appium in the application, right-click -> Show package content,

Click on the macOS folder and you can see the appium executable file;


​​Multiple clicks can open multiple appium services;

Open a new port for each device;

Open the appium server and select advanced;

​​
Set the Sever Port, WebDriverAgent Port, increment by 1, click ‘Save As Presets’ to name and save;

The default WebDriverAgent Port is port 8100. The newly opened second appium needs to be changed to another port, such as 8101;

Click 'Presets', select the preset port you want to start, and click 'Start Server V1.21.0'. You can then start several appium services on as many iOS phones as needed;

Effect:

If the desktop version of appium is installed on the computer, it seems that it cannot be started through commands.

If it is a command line appium service:

appium -a 127.0.0.1 -p 4723 -bp 4728 --chromedriver-port 9519 -U 255d50d7 --session-override

3. Maintain equipment parameter information

Maintain parameters uniformly in a configuration file; device_config_iOS.json

[
  {
    "url": "http://127.0.0.1:4723/wd/hub",
    "desired_caps": {
      "platformName": "ios",
      "deviceName": "iPhone7P",
      "platformVersion": "13.6.1",
      "bundleId": "xxx",
      "udid": "xxxx",
      "clearSystemFiles": "true"
    }
  },
  {
    "url": "http://127.0.0.1:4725/wd/hub",
    "desired_caps": {
      "platformName": "ios",
      "deviceName": "iPhone11",
      "platformVersion": "15.1",
      "bundleId": "xxx",
      "udid": "xxxx",
      "clearSystemFiles": "true"
    }
  }]

4. Use multiple processes or threads to connect the device to appium and obtain the driver.

#获取设备信息,判断使用哪台设备
def match_devices():
    cmd = "tidevice list"
    f = os.popen(cmd,"r")
    get_device_data = f.readlines()
    f.close()
    # print(get_device_data)
    n = len(get_device_data)
    device_data = get_device_data[1:]
    print(device_data)
    device_list = []
    for ch in device_data:
        device = ch.split(' ')[0]
        print(device)
        device_list.append(device)
    print(device_list)#得到设备序列号列表
    match_list = []
    data = load_config()
    for i in range(len(data)):
        if data[i]["desired_caps"]["udid"] in device_list:
            match_list.append(i)
    print(match_list)
    return match_list


def connect_appium(url,desired_caps):
    #appium进行设备连接
    driver = webdriver.Remote(command_executor=url,desired_capabilities=desired_caps)
    return driver
    
    
    
def test_case_steps(url,desired_caps):
    # start_appium(url,desired_caps)
    device_driver = connect_appium(url,desired_caps)
    print('test start =================')
    # run_allTest.run()
    time.sleep(5)
    print("test end ===================")
    # device_driver.quit()
    
 
if __name__ == '__main__':
 
    with open("device_config.json", "r") as f:
        data = list(json.load(f))
 
    for i in match_list:
        a = threading.Thread(target=test_case_steps,args=(data[i]["url"],data[i]["desired_caps"]))
        a.start()

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Guess you like

Origin blog.csdn.net/Vermouth_00/article/details/134247590