Appium Demo

 
  
import unittest
import time
from appium import webdriver
from public import config
import os


#类继承unittest.TestCase 类,从TestCase类继承是告诉unittest模块的方式,这是一个测试案例。
class ContactsAndroidTests(unittest.TestCase):
#setUp 用于设置初始化的部分,在测试用例执行前,这个方法中的函数将先被调用。
def setUp(self):
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '4.3'
desired_caps['deviceName'] = '127.0.0.1:5554'
# 版本小于4.2.2(api17)都需要指定selendroid
# desired_caps['automationName'] = 'selendroid'
# 安装APP
PATH = lambda p: os.path.abspath(os.path.join(os.path.dirname(__file__), p))
desired_caps['app'] = PATH('..\\apk\\test.apk')
#包名
desired_caps['appPackage'] = 'com.android.calculator2'
#activity
desired_caps['appActivity'] = '.Calculator'
#支持中文输入法
desired_caps['unicodeKeyboard'] = True
#运行结果后还原输入法
desired_caps['resetKeyboard'] = True
#跳过重签名
desired_caps['noSign'] = True
self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)

#启动activity
# self.driver.start_activity('com.android.calculator2','.Calculator')

#earDown 方法在每个测试方法执行后调用,这个地方做所有清理工作,如退出
def tearDown(self):
now = time.strftime('%H_%M_%S',time.localtime(time.time()))
self.driver.save_screenshot(""+config.screenshotpath+"test_demo"+now+".png")
self.driver.close_app()
self.driver.quit()

#放置的就是我们的测试脚本了,这部分我们并不陌生;因为我们执行的脚本就在这里。
def test_add_contacts(self):
self.driver.find_element_by_id("com.android.calculator2:id/digit7").click()
self.driver.find_element_by_id("com.android.calculator2:id/mul").click()
self.driver.find_element_by_id("com.android.calculator2:id/digit9").click()
self.driver.find_element_by_id("com.android.calculator2:id/equal").click()
text = self.driver.find_element_by_class_name("android.widget.EditText").text
self.assertEqual(text,'63','结果有误!')


#unitest.main()函数用来测试 类中以test开头的测试用例
if __name__ == '__main__':
pass
 

 

转载于:https://www.cnblogs.com/ai594ai/p/6494735.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值