How to run a test case on a real machine
One, turn on your phone USB Debug Mode
Two, Connect your phone to your computer
Connect your phone with a data cable to your computer and authorize USB debug mode. To view the effect of the connection, run the command under CMD: ADB devices view Udid as shown in:
If there is an output, the connection is successful.
Three, Start Appium Service
Start the Appium service according to the Udid that is found, run the command:
#>appium-a 127.0.0.1-p 4723–u 6207febc--no-reset
A string of characters followed by the-u parameter is the udid of the phone, which is checked by the second step.
When the program outputs such as information, indicating that the Appium started successfully, you can run the test script at this time.
Four, writing and running test scripts
The test scripts run by the real machine are almost identical to those of the simulator, but some are not quite the same. The detailed script is detailed below:
#! /usr/bin/env python
#coding =utf-8
From selenium import Webdriver
Desired_caps = {}
desired_caps[' platformname ' = ' Android '
desired_caps[' platformversion '] = ' 5.1.2 '
desired_caps[' devicename '] = ' Lenovo p1c72 '
desired_caps[' apppackage '] = ' com.xiangchao.starspace '
desired_caps[' appactivity '] = '. Starspace '
Driver = Webdriver. Remote (' Http://localhost:4723/wd/hub ', desired_caps)
Driver.quit ()
Open a separate CMD window and run the test script (Python xxxx.py). At this point the server will have output, the program is running on the phone.
Note: To install Appium Settings on your phone while the test case is running, follow the prompts to allow installation. (Why does the script always prompt Android settings and unlock??) )
Appium desired capabilities is an extension of the desired capabilities of webdriver, some of the following common configurations are required:
- Automationname: What kind of automation engine is used. Appium (default) or Selendroid?
- PlatformName: which mobile platform to use.
iOS, Android , orFirefoxOS?
- DeviceName: Which device is started, is it a real machine or an emulator? ,,,,
iPhone Simulator iPad Simulator iPhone Retina 4-inch Android Emulator Galaxy S4 , etc ...
- App: Absolute path of application, note must be absolute path. If you specify Apppackage and Appactivity, this property is not set. In addition, this property and the Browsername attribute are conflicting.
- Browsername: The name of the mobile browser. such as Safari ' for IOS and ' Chrome ', ' Chromium ', or ' Browser ' for Android, and app properties are mutually exclusive.
- UDID: The ID of the physical machine. Like 1ae203187fc012g.
The following properties are specific to the Android platform:
- Appactivity: The activity name of the app to be tested. Like Mainactivity,. Settings. Note that the native app should add a "." Before the activity.
- Apppackage: The Java package for the app to be tested. Like Com.example.android.myApp, Com.android.settings.
Get the Android app Appactivity
A. Launch the apk you want to test
b, turn on the log output: adb logcat>d:/log.txt
C, turn off the log output: Ctrl + C
D. View Logs
Find:
Apppackage = Com.xiangchao.starspaceappActivity =. Starspace
How to run a test case on a real machine