APPnium-IOS自动化测试

Appium下载与安装
关于Appium:
详细介绍见Appium官方网站:http://appium.io

安装步骤:
安装node.js&npm
安装Appium
安装Selenium WebDriver
网上有很多关于Appium安装的教程,这里就不再详述。

http://www.cnblogs.com/enjoytesting/p/3513637.html

检查Appium安装环境:
打开Appium,点击诊断图标
在这里插入图片描述

通过Appium doctor检查安装环境,如果没有安装xcode command line tools,appium会自动安装。

安装成功后,如下图所示,(ps:主要用于iOS自动化测试,只需保证iOS检查通过即可)
在这里插入图片描述

Appium自动化测试——模拟器
1.在xcode中运行代码,生成.app文件
ps:运行时要注意,模拟器及系统版本

2.配置iOS设置
点击苹果图标,设置app path(第1步生成的.app文件的路径),设置force device和platform version(两者要与第1步中的设置保持一致)。
在这里插入图片描述

3.录制脚本,生成python脚本
点击launch按钮,然后点击放大镜图标
在这里插入图片描述

即可启动iOS模拟器,并弹出appium inspector窗口

点击record开始录制python脚本。

在UIAWindow中找到相应的界面元素,及并执行相应操作

例如:在TextField1中输入23,在TextField2中输入78,点Compute Sum计算结果
在这里插入图片描述

生成的python脚本如下:

from selenium.webdriver.firefox.webdriver import WebDriver
from selenium.webdriver.common.action_chains import ActionChains
import time

success = True
desired_caps = {}
desired_caps[‘appium-version’] = ‘1.0’
desired_caps[‘platformName’] = ‘iOS’
desired_caps[‘platformVersion’] = ‘8.0’
desired_caps[‘deviceName’] = ‘iPhone 6’
desired_caps[‘app’] = os.path.abspath(’/Users/liuyan/Desktop/ios-test-app-master/Build/Products/Debug-iphonesimulator/TestApp.app’)

wd = webdriver.Remote(‘http://0.0.0.0:4723/wd/hub’, desired_caps)
wd.implicitly_wait(60)

def is_alert_present(wd):
try:
wd.switch_to_alert().text
return True
except:
return False

try:
wd.find_element_by_name(“TextField1”).send_keys(“23”)
wd.find_element_by_name(“TextField2”).send_keys(“78”)
wd.find_element_by_name(“ComputeSumButton”).click()
finally:
wd.quit()
if not success:
raise Exception(“Test failed.”)
但是appium生成的python脚本不能直接运行,需要添加引用
from selenium import webdriver
import os
4.关闭iOS模拟器和appium inspector窗口
一定要关闭iOS模拟器和appium inspector窗口!!!

一定要关闭iOS模拟器和appium inspector窗口!!!

一定要关闭iOS模拟器和appium inspector窗口!!!

重要的事情说三遍,否则python脚本不能运行

5.运行Python脚本,进行自动化测试
打开终端,cd到.py文件位置,执行Python脚本

此时,iOS模拟器将自动打开,并开始执行测试脚本。

如果要测试多个不同的iOS设备、iOS系统版本,只需要更改python脚本中的相应设置即可,省去了大量的重复劳动