---restore content starts---
Appium automated in-house testing training 1-Environment building
Course Purpose
First, Python + Appium environment construction
Course Content
1 Pre-Installation preparation work
The installation files needed to build the environment are already downloaded, and can be extracted from SVN, as follows
2 Appium Environment Construction
Appium is an open-source, open-source automated testing framework for native or mobile networks and hybrid applications on IOS and Android platforms.
2.1 Installing node. js
Click Install file, next step to install directly, after successful installation, enter CMD open windows command prompt, enter node-v , you can see the version of node. JS, see:
Appears above, indicating that the first step installation was successful.
2.2 Installing the JDK
Click on the file below to install
Next step, install directly
My installation path is C:\Program files\java\jdk1.7.0_17
After the installation is complete, you need to set environment variables to make the compiler work. Right-click Computer, select Properties, select Advanced System settings on the left, and select the Advanced tab above click the Environment Variables button in the lower right corner.
The following popup dialog box will appear with user variables and system variables. The user variable is valid for the current login account, the system variable is valid for all users, and the reader can set it as needed.
How to configure environment variables/steps:
1. In the system variable click New, variable name fill java_home, variable value fill in the JDK installation path, here to fill out "C:\Program files\java\jdk1.7.0_17".
2. In the system variable, click the new variable name to fill in the Classpath, the variable value is filled ".; %java_home%\lib;%java_home%\lib\tools.jar ", be careful not to forget the front dot and the middle semicolon.
3. Locate the path variable in the system variable, which is the system's own, not new. Double-click Path, because the original variable value already exists, it should be added ";%java_home%\bin;%java_home%\jre\bin" after the existing variable. Note the preceding semicolon.
authentication method : Enter cmd command in the Run box, enter Javac after carriage return, press ENTER to display the following screen
2.3 Android Environment Build-up
Unzip the adt-bundle-windows-x86_64-20140702 package and rename it: ADT
For example: I unzip to the E-drive
Configuration of the Android environment variable:
1. Configure Android_home
My Computer Right-click menu---> Properties---> Advanced---> Environment variables---> System variables--new.
2. Add%android_home%\platformtools;%android_home%\tools to path; After configuring the Post environment variable
environment variable validation : CMD open Window's command prompt, enter android-h
2.4 Installing the. NET Framework 4.6
Double-click the next step to install directly.
Note: If the machine is already installed, you do not need to install it.
2.5 Installing the Appium server
Unzip the file, double-click the installation file to install the default path
C:\Program Files (x86) \appium
Environment variable configuration:
Add C:\Program Files (x86) \appium\node_modules\.bin in path;
Verify:
CMD Open command prompt, enter Appium-doctor, see:
After installation, start the Appium server in the desktop or application, start the Appium server in the upper right corner or enter the Appium in DOS.
2.6 Installing the Appium client
Enter CMD to open a command prompt for Windows, enter
Pip Install-u appium-python-client
Note:
The above is based on the Python and PIP environment already installed, if it is the first time to directly build the environment of the mobile phone, you need to install the following several:
1. Install Python
2. Installing Setuptools
3. Install Pip
The Python+appium environment is set up here.
3 Device (mobile or tablet) connected to PC
After the environment is set up, if you need to access the real machine for testing, you need the following steps:
3.1 Device access to the computer settings
3.2 Viewing devices
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-l view Udid as shown in:
If there is an output, the connection is successful.
3.3 Viewing the PackageName and activity name of your phone or tablet
The first method:
Steps:
1. Switch from DOS to ADT Path: E:\adt\sdk\build-tools\android-4.4W
2. Execute AAPT dump badging {Local package full path}
3. View App-package Name
4. View app-activity activity Name
The second method:
Under E:\adt\sdk\tools, there is a hierarchyviewer file that you can view
Note: Root over the phone or tablet, here is not see the package name and activity name.
3.4 Launching the app under DOS
Run command: adb shell
$ am Start-n {Package] name}/}.{activity name}
Example: $ am start-n
4 Writing the first appium use case
Code implementation:
#-*-coding:utf-8-*- fromappium Import Webdriver fromSelenium Import Webdriver fromselenium.webdriver.common.by Import by fromselenium.webdriver.support.expected_conditions Import Nosuchelementexceptionimport unittest, time, OSGlobalDriverclassloginandroidtests (unittest. TestCase): def setUp (self): #初始化测试平台 desired_caps={} desired_caps['PlatformName']='Android'desired_caps['platformversion']='4.4.2'desired_caps['devicename']='UE1'#老师平板 desired_caps['Apppackage']='Com.uet.teacherspad'desired_caps['appactivity']='com.uet.teacherspad.activity.common.LauncherActivity'#学生平板 # desired_caps['Apppackage']='Com.uet.studentpad'# desired_caps['appactivity']='com.uet.studentpad.activity.LauncherActivity'Self.driver=webdriver. Remote ("Http://127.0.0.1:4723/wd/hub", Desired_caps) def test_login (self):" "Login" "Time.sleep (2) #学生登录 # self.driver.find_element (by.id,'Com.uet.studentpad:id/edittxt_login_username'). Clear () # self.driver.find_element (By.id,'Com.uet.studentpad:id/edittxt_login_username'). Send_keys ('13732650301') # # self.driver.find_element (by.id,'Com.uet.studentpad:id/edittxt_login_password'). Clear () # self.driver.find_element (By.id,'Com.uet.studentpad:id/edittxt_login_password'). Send_keys ('123123') # self.driver.find_element (By.id,'Com.uet.studentpad:id/btn_login_login'). Click () #老师登录 self.driver.find_element (By.id,'Com.uet.teacherspad:id/edittxt_login_username'). Clear () self.driver.find_element (By.id,'Com.uet.teacherspad:id/edittxt_login_username'). Send_keys ('13732650301') self.driver.find_element (By.id,'Com.uet.teacherspad:id/edittxt_login_password'). Clear () self.driver.find_element (By.id,'Com.uet.teacherspad:id/edittxt_login_password'). Send_keys ('123123') Time.sleep (6) self.driver.find_element (By.id,'Com.uet.teacherspad:id/btn_login_login'). Click () time.sleep (3) self.driver.find_element (By.name,u'Classroom Teaching'). Click () time.sleep (3) self.driver.find_element (By.name,u'Classroom Exercises'). Click () time.sleep (3) def tearDown (self): Self.driver.quit ()if__name__ = ='__main__': Unittest.main (verbosity=2)
---restore content ends---
Python + Appium Environment Building