Android and iOS use appium to automate testing

Environment construction reference: python+Appium+xcode+android studio automated test environment construction_android studio installation python_Vermouth_00's blog-CSDN blog

Android

1. Connect the device

Connect the android device to the computer with the data cable, turn on the USB debugging switch and authorize it, and use the adb devices command to verify that the device is successfully connected.

Two, start the appium service

If it is the desktop version of appium:

Click start server to start;

Command line version appium:

nohup appium -p 4725 -U 4b72ec30 --session-override --allow-insecure=adb_shell > appium_a32a6a4e.log &

nohup runs in the background, - U is followed by the serial number of the device, which can be viewed with the adb devices command.

3. Appium connects with the device

desired_caps = {
            'platformName': 'Android',
            'platformVersion': '11',
            'deviceName': '4b72ec30 ',#不会进行校验,但是没有会报错
            'appActivity': 'com.autonavi.map.activity.NewMapActivity',#app的启动页面
            'appPackage': 'com.autonavi.minimap'
        }
self.driver=webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)

iOS

1. Connect the phone to the computer with the data cable

Enter the password to trust the computer

Two, start the appium service

If it is the desktop version of appium:

Click start server to start;

Command line version appium:

"start /b appium --session-override -a " + address + " -p " + Appium_port+" --webdriveragent-port “+webdriveragent_port

webdriveragent_port: the port number of the webdriveragent interacting with the iOS client, default 8010

3. Xcode compiles and runs wda

(1) Set up the Team of [WebDriverAgentLib], [WebDriverAgentRunner], [IntegrationApp], select the Apple ID you have logged in, and log in to the Apple ID: (Xcode in the upper left corner - "Preference -" click below to add or delete)

(2) Set [WebDriverAgentRunner], [IntegrationApp] the id of Product Bundle Identifier in the Packaging directory under Build Settings, just change facebook, and change it at will

  (3) Set【Product】→【Scheme】select【WebDriverAgentRunner】

 (4) Select the device you are connected to, and run command + u

 (5) For the first run, you need to set trust for the certificate in the real device settings [Settings] → [General] → [Description File and Device Management] Select the WebDriverAgent just installed under the developer APP to trust it, and it can run normally after command+u 

(6) You can see the following information in the console:

 

Some iphones cannot be accessed through the IP and port number of the mobile phone. At this time, the port of the mobile phone needs to be forwarded to the mac, and the terminal runs the following command

iproxy 8100 8100

Map the 8100 port of the mobile phone to the 8100 port of the computer. In this way, we can access the mobile phone by accessing port 8100 of the computer.

I found on the Internet that "for continuous integration", use the following method to start wda in the code, and you don't need to start it in xcode.

desiredCapabilities.setCapability("useNewWDA", true);

After running the agent on the command line , you can open http://127.0.0.1:8100/statusiproxy 8100 8100 in the browser   to check whether the iOS device can be successfully connected.

4. Appium connects with the device

parameter configuration

desired_capabilities = {
  "platformName": "ios",
  "deviceName": "iPhone7P",
  "platformVersion": "13.6.1",
  "bundleId": "com.meituan.imeituan-beta",
  "udid": "e372ee5092535ad955329aac04c450fb78b96abd"
}

Obtain the udid of the iOS phone: click the connected device in the finder, the default display is the memory and power, click here again to switch to the serial number, udid, and then right-click to copy the udid;

 

Get the bundle ID of ipa, you can use tidevice

 tidevice applist

 desired_caps = {
              "platformName": "ios",
              "deviceName": "iPhone7P",
              "platformVersion": "13.6.1",
              "bundleId": "com.meituan.imeituan-beta",
              "udid": "e372ee5092535ad955329aac04c450fb78b96abd",
              "clearSystemFiles": "true"
            }

        self.driver=webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)

It was running fine before, but today I encountered a problem:

An unknown server-side error occurred while processing the command. Original error: Could not load a driver for platformName 'ios'. Please verify your Appium installation

Solved after uninstalling and reinstalling appium.

Advanced:

Android+appium multi-machine automation reference: Android+python+appium multi-machine automation_Vermouth_00's Blog-CSDN Blog

Guess you like

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