Appium+iOS+Mac 环境搭建

1,517 阅读2分钟

Appium+iOS+Mac环境搭建

直接选择安装桌面版本 Download Appium
通过命令行配置主要的工具环境,只针对iOS
# Get the Facebook Tap.
brew tap facebook/fb
# Install fbsimctl from master
brew install fbsimctl --HEAD
链接参考

Appium Getting Started The XCUITest Driver for iOS

appium-doctor 安装
npm install appium-doctor -g
查看iOS相关配置是否完整
appium-doctor --ios 
如果提示Xcode没有安装执行
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/
WebDriverAgent 更换
  • 执行 ./Scripts/bootstrap.sh
  • 直接用Xcode打开WebDriverAgent.xcodepro文件
  • 配置WebDriverAgentLib和WebDriverAgentRunner的证书
  • 连接并选择自己的iOS设备,然后按Cmd+U,或是点击Product->Test
  • 运行成功时,在Xcode控制台应该可以打印出一个Ip地址和端口号
  • 在浏览器上输入上一步骤的网址,如果打印出一些json格式的信息,说明运行成功。
  • 将该WebDriverAgent整个目录替换Appium安装时的自带的WebDriverAgent,具体目录查看为/Applications/Appium.app/Contents/Resources/app/node_modules/appium-xcuitest-driver/WebDriverAgent
支持python环境 Appium Python Client
brew install python
sudo chmod 777 /Library/Python/2.7/site-packages/
git clone git@github.com:appium/python-client.git 
cd python-client

python setup.py install
测试文件

import unittest
import os
from appium import webdriver
from time  import sleep


class  appiumSimpleTezt (unittest.TestCase):

	def  setUp(self):
		app = os.path.abspath('脚本打包的ipa目录')

		self.driver = webdriver.Remote(
			command_executor = 'http://127.0.0.1:4723/wd/hub',
			desired_capabilities = {
				'app':app,
				'platformName': 'iOS',
				'platformVersion': '12.0',
				'deviceName': 'iOS',
				'bundleId': '程序的bundleId',
				'udid': '真机的uuid(在Xcode的Window->Devices中获取)'
			}
			)

	def test_Login(self):
        
        #权限弹框
        self.driver.switch_to.alert.accept()
        self.driver.switch_to.alert.accept()
        sleep(1)
        #输入用户名及密码进行登录操作
        user_phone = self.driver.find_elements_by_name(name="输入手机号码")
        for phone in user_phone:
            phone.click()
            phone.send_keys("15219335287")
        user_password = self.driver.find_elements_by_name(name="输入密码")
        for pw in user_password:
            pw.click()
            pw.send_keys("abc123456")
        sleep(1)
        # 隐藏键盘
        keyboard_hide = self.driver.find_element_by_accessibility_id("Toolbar Done Button")
        keyboard_hide.click()
        #点击登录
        login_button = self.driver.find_element_by_accessibility_id("登录")
        login_button.click()
        sleep(1)
    def tearDown(self):
        sleep(1)

		# self.driver.quit()

if __name__ == '__main__':
	suite = unittest.TestLoader().loadTestsFromTestCase(appiumSimpleTezt)
	unittest.TextTestRunner(verbosity=2).run(suite)

测试文件放在项目根目录下,直接运行命令即可。
python OFRiderTest.py

######命令行打包ipa 没有用pod时直接运行就可以了

xcodebuild -sdk iphoneos -target  [targetname]  -configuration Release

######用到pod时

xcodebuild -list
xcodebuild -scheme  [shemename] -workspace [xxx.xcworkspace绝对路径] build

打包ipa时的位置.png

######通过appium定位元素

{
  "bundleId": "bundleId",
  "automationName": "XCUITest",
  "platformName": "iOS",
  "platformVersion": "12.0",
  "udid": "uuid",
  "deviceName": "苹果手机名字"
}

配置.png