Appium实战(1) - 安装,执行demo
2017-10-18 本文已影响28人
yytester
- 电脑上安装Appium app
- 下载测试demo,地址
- 运行
TestApp.xcodeproj
-
在xcode.左侧目录菜单,Products下选中xx.app,在右边栏可以看到app存放路径:
image.png - 打开下载demo文件里的Python目录 -> ios_simple.py
- 方法解析(Appium会运行脚本里text开头的方法)
def setUp(self):
# set up appium
# app里配置属性,包括app存放路径,平台选择,系统版本,模拟器型号等
app_path = os.path.abspath('/Users/xxx/Library/Developer/Xcode/DerivedData/TestApp-agajagytvfggdqaeedflvbailvkb/Build/Products/Debug-iphonesimulator/TestApp.app')
self.driver = webdriver.Remote(
command_executor='http://127.0.0.1:4723/wd/hub',
desired_capabilities={
'app': app_path ,
'platformName': 'iOS',
'platformVersion': '10.3',
'deviceName': 'iPhone 6'
})
def _populate(self):
# 找到界面里的两个文本框TextField1,TextField2,填入两个随机数
els = [self.driver.find_element_by_accessibility_id('TextField1'),
self.driver.find_element_by_accessibility_id('TextField2')]
self._sum = 0
for i in range(2):
rnd = randint(0, 10)
els[i].send_keys(rnd)
self._sum += rnd
def test_ui_computation(self):
# populate text fields with values
self._populate()
# trigger computation by using the button
self.driver.find_element_by_accessibility_id('ComputeSumButton').click()
# 判断两个随机数相加的值 , 是否等于Answer控件里的值
# sauce does not handle class name, so get fourth element
sum = self.driver.find_element_by_accessibility_id('Answer').text
self.assertEqual(int(sum), self._sum)