首页 技术 正文
技术 2022年11月6日
0 收藏 722 点赞 357 浏览 1930 个字

前提:根据前面的环境搭建介绍,安装好相关环境

step1:启动android模拟器

step2:启动Appium服务端

step3:演示代码执行

  这里执行的是官方的演示代码:通讯录管理app,安装打开app,并添加一个联系人保存的操作

  a.首先去下载ContactManager.apk放到E盘   E:\ContactManager.apk

    https://github.com/appium/sample-code/blob/master/sample-code/apps/ContactManager/ContactManager.apk

  b.将官网的示例代码 android_contact.py 下载下来 放在 Python的目录

    https://github.com/appium/sample-code/blob/master/sample-code/examples/python/android_contacts.py

  c.对python代码进行部分修改

#!/usr/bin/env python
# -*- coding: utf-8 -*-import os
import unittest
from appium import webdriver
from time import sleep# Returns abs path relative to this file and not cwd
PATH = lambda p: os.path.abspath(
os.path.join(os.path.dirname(__file__), p)
)class ContactsAndroidTests(unittest.TestCase):
def setUp(self):
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.4.2'
desired_caps['deviceName'] = 'Android Emulator'
desired_caps['app'] = PATH(
'E:\ContactManager.apk'
)
desired_caps['appPackage'] = 'com.example.android.contactmanager'
desired_caps['appActivity'] = '.ContactManager' self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps) def tearDown(self):
self.driver.quit() def test_add_contacts(self):
el = self.driver.find_element_by_accessibility_id("Add Contact")
el.click() textfields = self.driver.find_elements_by_class_name("android.widget.EditText")
textfields[0].send_keys("Appium User")
textfields[2].send_keys("someone@appium.io") self.assertEqual('Appium User', textfields[0].text)
self.assertEqual('someone@appium.io', textfields[2].text) self.driver.find_element_by_accessibility_id("Save").click() # for some reason "save" breaks things
alert = self.driver.switch_to_alert() # no way to handle alerts in Android
self.driver.find_element_by_android_uiautomator('new UiSelector().clickable(true)').click() self.driver.press_keycode(3)if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(ContactsAndroidTests)
unittest.TextTestRunner(verbosity=2).run(suite)

Appium 自动化测试(4)– 脚本开发:官方demo演示 android_contacts.py

***微信扫一扫,关注“python测试开发圈”,了解更多测试教程!***

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,487
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,736
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,487
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,127
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,289