Appium 从安装到应用

来源:互联网 发布:巨人网络市值 编辑:程序博客网 时间:2024/06/03 22:04

来自付老师整理的笔记~


因为最近公司战略以app为主,时间紧,所以需要一个自动化测试的环境,那么我们搭建一个出来吧:
0.介绍:
     Appium 是一个自动化测试开源工具,支持 iOS 平台和 Android 平台上的原生应用,web 应用和混合应用.Appium 是一个跨平台的工具:它允许测试人员在不同的平台(iOS,Android)使用同一套API来写自动化测试脚本.
     在window下安装
1.首先下载node.js: https://nodejs.org/en/download/
     安装node,直接安装下一步
     确定安装成功:在cmd中输入 npm 显示 "where..."表示已经安装成功
2.通过 npm 安装 Appium
     a. 因为现在的系统上装过 .netFramework,
     b. https://bitbucket.org/appium/appium.app/downloads/     下载AppiumForWindows_1_4_16_1.zip安装
     c. 安装sdk: http://dl.google.com/android/android-sdk_r23.0.2-windows.zip 
          配置环境变量:
               变量名:ANDROID_HOME
               变量值:D:\ProgramFiles\android-sdk-windows
          path变量名—>“编辑”添加
               变量名:PATH
               变量值:;%ANDROID_HOME%\platform-tools;%ANDROID_HOME%\tools;
     d. 将 appium 的 D:\ProgramFiles\Appium\node_modules\.bin ,放入 PATH 环境变量中
3.去找个 sdk, 安装模拟器(之前研究react native时候安装过)
参考 http://bbs.reactnative.cn/topic/10/%E5%9C%A8windows%E4%B8%8B%E6%90%AD%E5%BB%BAreact-native-android%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83 
http://www.cnblogs.com/rainboy2010/p/6387770.html
4.安装 appium 的客户端,这里使用 Python 版本
     a. 安装 Python 环境 
     b. 使用 pip install Appium-Python-Client
5.测试一个吧:
     a. 启动android模拟器
     b. 启动Appium,点选自己需要的东西
     c. 通过Python编写自动化测试脚本
          #coding=utf-8
          from appium import webdriver
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.4.2'
desired_caps['deviceName'] = 'Android Emulator'
desired_caps['appPackage'] = 'com.android.calculator2'
desired_caps['appActivity'] = '.Calculator'
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
driver.find_element_by_name("1").click()
driver.find_element_by_name("5").click()
driver.find_element_by_name("9").click()
driver.find_element_by_name("delete").click()
driver.find_element_by_name("9").click()
driver.find_element_by_name("5").click()
driver.find_element_by_name("+").click()
driver.find_element_by_name("6").click()
driver.find_element_by_name("=").click()
driver.quit()

新demo

#coding=utf-8from appium import webdriverimport timedesired_caps = {    'platformName':'Android',    'deviceName':'Android Emulator',    'platformVersion':'23',    'appPackage':'com.manyiaby',    'appActivity':'com.manyiaby.welcome.WelcomeActivity'}driver = webdriver.Remote('http://localhost:4723/wd/hub',desired_caps)time.sleep(5)# 获取屏幕宽和高def getSize():    x = driver.get_window_size()['width']    y = driver.get_window_size()['height']    return (x ,y)# 向上滑动def swipeUp(t):    l = getSize()    x1 = int(l[0]*0.5)    y1 = int(l[1]*0.75)    y2 = int(l[1]*0.25)    driver.swipe(x1,y1,x1,y2,t)# 向下滑动def swipeDown(t):    l = getSize()    x1 = int(l[0]*0.5)    y1 = int(l[1]*0.25)    y2 = int(l[1]*0.75)    driver.swipe(x1,y1,x1,y2,t)swipeUp(2000)print 'hahaha'swipeUp(2000)swipeDown(2000)swipeDown(2000)swipeDown(2000)driver.find_elements_by_id('com.manyiaby:id/home_edet')[0].click()time.sleep(1)driver.find_elements_by_id('com.manyiaby:id/search_close')[0].click()time.sleep(1)container = driver.find_elements_by_id('com.manyiaby:id/fixed_bottom_navigation_container')for i in range(len(container)):    print container[i]    container[i].click()    time.sleep(2)    if i == 2 :        driver.keyevent(4)  # 返回time.sleep(2)driver.quit()


原创粉丝点击