XCode
git clone https://github.com/appium/ios-uicatalog
#use xcode to open
面向模拟器构建app
CodeSign /Users/seveniruby/Library/Developer/Xcode/DerivedData/UICatalog-dfavfehsvaabuqdpmxouzqphclvl/Build/Products/Debug-iphonesimulator/UICatalog.app (in target: UICatalog)
cd /Users/seveniruby/temp/appium/ios/ios-uicatalog
export CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
Signing Identity: "-"
/usr/bin/codesign --force --sign - --entitlements /Users/seveniruby/Library/Developer/Xcode/DerivedData/UICatalog-dfavfehsvaabuqdpmxouzqphclvl/Build/Intermediates.noindex/UICatalog.build/Debug-iphonesimulator/UICatalog.build/UICatalog.app.xcent --timestamp=none /Users/seveniruby/Library/Developer/Xcode/DerivedData/UICatalog-dfavfehsvaabuqdpmxouzqphclvl/Build/Products/Debug-iphonesimulator/UICatalog.app
GenerateDSYMFile /Users/seveniruby/Library/Developer/Xcode/DerivedData/UICatalog-dfavfehsvaabuqdpmxouzqphclvl/Build/Products/Debug-iphonesimulator/UICatalog.app.dSYM /Users/seveniruby/Library/Developer/Xcode/DerivedData/UICatalog-dfavfehsvaabuqdpmxouzqphclvl/Build/Products/Debug-iphonesimulator/UICatalog.app/UICatalog (in target: UICatalog)
cd /Users/seveniruby/temp/appium/ios/ios-uicatalog
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/dsymutil /Users/seveniruby/Library/Developer/Xcode/DerivedData/UICatalog-dfavfehsvaabuqdpmxouzqphclvl/Build/Products/Debug-iphonesimulator/UICatalog.app/UICatalog -o /Users/seveniruby/Library/Developer/Xcode/DerivedData/UICatalog-dfavfehsvaabuqdpmxouzqphclvl/Build/Products/Debug-iphonesimulator/UICatalog.app.dSYM
Touch /Users/seveniruby/Library/Developer/Xcode/DerivedData/UICatalog-dfavfehsvaabuqdpmxouzqphclvl/Build/Products/Debug-iphonesimulator/UICatalog.app (in target: UICatalog)
cd /Users/seveniruby/temp/appium/ios/ios-uicatalog
/usr/bin/touch -c /Users/seveniruby/Library/Developer/Xcode/DerivedData/UICatalog-dfavfehsvaabuqdpmxouzqphclvl/Build/Products/Debug-iphonesimulator/UICatalog.app
面向真机
CodeSign /Users/seveniruby/Library/Developer/Xcode/DerivedData/UICatalog-dfavfehsvaabuqdpmxouzqphclvl/Build/Products/Debug-iphoneos/UICatalog.app (in target: UICatalog)
cd /Users/seveniruby/temp/appium/ios/ios-uicatalog
export CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
Signing Identity: "iPhone Developer: yansheng huang (LJGDR784H2)"
Provisioning Profile: "iOS Team Provisioning Profile: *"
(0c3891ec-b6a3-4bd8-bb3c-1774087952ff)
/usr/bin/codesign --force --sign A747E05F425FF31AA6180C146F9BE554AA1983B6 --entitlements /Users/seveniruby/Library/Developer/Xcode/DerivedData/UICatalog-dfavfehsvaabuqdpmxouzqphclvl/Build/Intermediates.noindex/UICatalog.build/Debug-iphoneos/UICatalog.build/UICatalog.app.xcent --timestamp=none /Users/seveniruby/Library/Developer/Xcode/DerivedData/UICatalog-dfavfehsvaabuqdpmxouzqphclvl/Build/Products/Debug-iphoneos/UICatalog.app
两者的重要区别点
- 签名与privisionning profile文件
- Debug-iphoneos/UICatalog.app Debug-iphonesimulator/UICatalog.app
调试app
创建模拟器
开发者工具
instruments工具包
iOS专项测试必备
app文件的结构
localhost:UICatalog.app seveniruby$ ls -l
total 43384
-rw-r--r-- 1 seveniruby staff 21646568 2 28 20:23 Assets.car
drwxr-xr-x 4 seveniruby staff 128 2 28 20:23 Base.lproj
-rw-r--r-- 1 seveniruby staff 1451 2 28 20:23 Info.plist
-rw-r--r-- 1 seveniruby staff 14942 2 28 20:23 LaunchImage-700-568h@2x.png
-rw-r--r-- 1 seveniruby staff 8 2 28 20:23 PkgInfo
-rwxr-xr-x 1 seveniruby staff 525712 2 28 20:23 UICatalog
drwxr-xr-x 3 seveniruby staff 96 2 28 20:23 _CodeSignature
-rw-r--r-- 1 seveniruby staff 7615 2 28 20:23 embedded.mobileprovision
drwxr-xr-x 3 seveniruby staff 96 2 28 20:23 en.lproj
-rw-r--r-- 1 seveniruby staff 2921 2 28 20:23 uicatalog-info.md
开发者中心
- https://developer.apple.com/account
- Team ID 96NJEQL7Y2
- 本地调试不需要购买,如果要分发给别人需要付费
购买mac
- 一次性使用:windows + mac虚拟机 (基本跑不起来)
- 穷人版:mac mini 2500 + 显示器 2000
- 平民版:mac air
- 中产阶级:mbp
- 高配版:苹果垃圾桶
常用命令
依赖工具包安装:
brew install --HEAD ideviceinstaller
brew install --HEAD libimobiledevice
brew install ios-deploy
查看模拟器列表:instruments -s devices
查看真机列表:idevice_id -l
安装app:
ideviceinstaller -i demo.app
ios-deploy
命令行编译:
xcodebuild -scheme UICatalog -target iOS clean build
xcodebuild -scheme UICatalog -target iOS archive
测试框架
- XCTest 要求使用swift oc,只有开发工程师才适合使用
- Facebook开源的WDA
- Appium基于WDA做了一次兼容封装
模拟器自动化
{
"platformName": "ios",
"platformVersion": "12.1",
"deviceName": "iPhone X",
"app": "/Users/seveniruby/Library/Developer/Xcode/DerivedData/UICatalog-dfavfehsvaabuqdpmxouzqphclvl/Build/Products/Debug-iphonesimulator/UICatalog.app"
}
注意app是面向模拟器构建的,还是面向真机构建的。
[iOSSim] Starting Simulator UI with command: open -Fn /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app --args -CurrentDeviceUDID 6F79DA37-DE1E-434D-A9DC-239C4B2DC8E9 -ConnectHardwareKeyboard 0
[debug] [XCUITest] Beginning test with command 'xcodebuild build-for-testing test-without-building -project /usr/local/lib/node_modules/appium/node_modules/_appium-xcuitest-driver@2.104.0@appium-xcuitest-driver/WebDriverAgent/WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination id=6F79DA37-DE1E-434D-A9DC-239C4B2DC8E9 IPHONEOS_DEPLOYMENT_TARGET=12.1' in directory '/usr/local/lib/node_modules/appium/node_modules/_appium-xcuitest-driver@2.104.0@appium-xcuitest-driver/WebDriverAgent'
page source
<?xml version="1.0" encoding="UTF-8"?><AppiumAUT><XCUIElementTypeApplication type="XCUIElementTypeApplication" name="UICatalog" label="UICatalog" enabled="true" visible="true" x="0" y="0" width="375" height="812">
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="false" x="0" y="0" width="375" height="812"/>
<XCUIElementTypeWindow type="XCUIElementTypeWindow" enabled="true" visible="true" x="0" y="73" width="375" height="666">
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="73" width="375" height="666">
<XCUIElementTypeNavigationBar type="XCUIElementTypeNavigationBar" name="Buttons" enabled="true" visible="true" x="0" y="96" width="375" height="53">
<XCUIElementTypeButton type="XCUIElementTypeButton" name="UICatalog" label="UICatalog" enabled="true" visible="true" x="0" y="96" width="121" height="53"/>
<XCUIElementTypeOther type="XCUIElementTypeOther" name="Buttons" label="Buttons" enabled="true" visible="true" x="150" y="110" width="75" height="25"/>
</XCUIElementTypeNavigationBar>
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="73" width="375" height="666">
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="73" width="375" height="666">
<XCUIElementTypeTable type="XCUIElementTypeTable" enabled="true" visible="true" x="0" y="73" width="375" height="666">
<XCUIElementTypeOther type="XCUIElementTypeOther" name="SYSTEM (TEXT)" enabled="true" visible="true" x="0" y="148" width="375" height="66">
<XCUIElementTypeOther type="XCUIElementTypeOther" name="SYSTEM (TEXT)" label="SYSTEM (TEXT)" enabled="true" visible="true" x="0" y="148" width="375" height="66"/>
</XCUIElementTypeOther>
<XCUIElementTypeCell type="XCUIElementTypeCell" enabled="true" visible="true" x="0" y="213" width="375" height="52">
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="213" width="375" height="1"/>
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="264" width="375" height="1"/>
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="17" y="263" width="358" height="2"/>
<XCUIElementTypeButton type="XCUIElementTypeButton" name="Button" label="Button" enabled="true" visible="true" x="160" y="221" width="55" height="36"/>
</XCUIElementTypeCell>
<XCUIElementTypeOther type="XCUIElementTypeOther" name="SYSTEM (CONTACT ADD)" enabled="true" visible="true" x="0" y="276" width="375" height="45">
<XCUIElementTypeOther type="XCUIElementTypeOther" name="SYSTEM (CONTACT ADD)" label="SYSTEM (CONTACT ADD)" enabled="true" visible="true" x="0" y="276" width="375" height="45"/>
</XCUIElementTypeOther>
<XCUIElementTypeCell type="XCUIElementTypeCell" enabled="true" visible="true" x="0" y="320" width="375" height="53">
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="320" width="375" height="2"/>
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="372" width="375" height="1"/>
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="17" y="371" width="358" height="2"/>
<XCUIElementTypeButton type="XCUIElementTypeButton" enabled="true" visible="true" x="174" y="333" width="27" height="27"/>
</XCUIElementTypeCell>
<XCUIElementTypeOther type="XCUIElementTypeOther" name="SYSTEM (DETAIL DISCLOSURE)" enabled="true" visible="true" x="0" y="384" width="375" height="45">
<XCUIElementTypeOther type="XCUIElementTypeOther" name="SYSTEM (DETAIL DISCLOSURE)" label="SYSTEM (DETAIL DISCLOSURE)" enabled="true" visible="true" x="0" y="384" width="375" height="45"/>
</XCUIElementTypeOther>
<XCUIElementTypeCell type="XCUIElementTypeCell" enabled="true" visible="true" x="0" y="428" width="375" height="53">
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="428" width="375" height="2"/>
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="479" width="375" height="2"/>
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="17" y="479" width="358" height="2"/>
<XCUIElementTypeButton type="XCUIElementTypeButton" name="More Info" label="More Info" enabled="true" visible="true" x="174" y="441" width="27" height="27"/>
</XCUIElementTypeCell>
<XCUIElementTypeOther type="XCUIElementTypeOther" name="IMAGE" enabled="true" visible="true" x="0" y="491" width="375" height="46">
<XCUIElementTypeOther type="XCUIElementTypeOther" name="IMAGE" label="IMAGE" enabled="true" visible="true" x="0" y="491" width="375" height="46"/>
</XCUIElementTypeOther>
<XCUIElementTypeCell type="XCUIElementTypeCell" enabled="true" visible="true" x="0" y="536" width="375" height="53">
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="536" width="375" height="1"/>
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="587" width="375" height="2"/>
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="17" y="586" width="358" height="3"/>
<XCUIElementTypeButton type="XCUIElementTypeButton" name="X Button" label="X Button" enabled="true" visible="true" x="139" y="544" width="97" height="36"/>
</XCUIElementTypeCell>
<XCUIElementTypeOther type="XCUIElementTypeOther" name="ATTRIBUTED TEXT" enabled="true" visible="true" x="0" y="599" width="375" height="46">
<XCUIElementTypeOther type="XCUIElementTypeOther" name="ATTRIBUTED TEXT" label="ATTRIBUTED TEXT" enabled="true" visible="true" x="0" y="599" width="375" height="46"/>
</XCUIElementTypeOther>
<XCUIElementTypeCell type="XCUIElementTypeCell" enabled="true" visible="true" x="0" y="644" width="375" height="52">
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="644" width="375" height="1"/>
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="695" width="375" height="1"/>
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="17" y="694" width="358" height="2"/>
<XCUIElementTypeButton type="XCUIElementTypeButton" name="Button" label="Button" enabled="true" visible="true" x="160" y="652" width="55" height="36"/>
</XCUIElementTypeCell>
</XCUIElementTypeTable>
</XCUIElementTypeOther>
</XCUIElementTypeOther>
</XCUIElementTypeOther>
</XCUIElementTypeWindow>
<XCUIElementTypeWindow type="XCUIElementTypeWindow" enabled="true" visible="false" x="0" y="73" width="375" height="666">
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="false" x="0" y="73" width="375" height="666"/>
</XCUIElementTypeWindow>
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="73" width="375" height="24">
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="false" x="0" y="73" width="375" height="24"/>
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="73" width="375" height="24"/>
</XCUIElementTypeOther>
<XCUIElementTypeWindow type="XCUIElementTypeWindow" enabled="true" visible="true" x="0" y="0" width="375" height="812">
<XCUIElementTypeStatusBar type="XCUIElementTypeStatusBar" enabled="true" visible="true" x="0" y="0" width="375" height="44">
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="0" width="375" height="44">
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="0" y="0" width="375" height="44">
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="6" y="-5" width="180" height="12"/>
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="190" y="-5" width="180" height="12"/>
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="6" y="17" width="180" height="12"/>
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="13" y="14" width="67" height="15">
<XCUIElementTypeStaticText type="XCUIElementTypeStaticText" value="9:42 PM" name="9:42 PM" label="9:42 PM" enabled="true" visible="false" x="30" y="14" width="34" height="18"/>
</XCUIElementTypeOther>
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="21" y="8" width="56" height="22"/>
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="190" y="17" width="180" height="12"/>
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="false" x="294" y="14" width="67" height="15">
<XCUIElementTypeOther type="XCUIElementTypeOther" value="No signal" name="Cellular" label="Cellular" enabled="true" visible="false" x="294" y="17" width="17" height="12"/>
<XCUIElementTypeOther type="XCUIElementTypeOther" value="SSID, 3 of 3 Wi-Fi bars" name="3 of 3 Wi-Fi bars" enabled="true" visible="false" x="316" y="17" width="16" height="12"/>
<XCUIElementTypeOther type="XCUIElementTypeOther" value="Not charging" name="100% battery power" label="100% battery power" enabled="true" visible="false" x="336" y="17" width="25" height="12"/>
</XCUIElementTypeOther>
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="true" x="294" y="14" width="67" height="15"/>
</XCUIElementTypeOther>
<XCUIElementTypeOther type="XCUIElementTypeOther" enabled="true" visible="false" x="8" y="24" width="82" height="14"/>
</XCUIElementTypeOther>
</XCUIElementTypeStatusBar>
</XCUIElementTypeWindow>
</XCUIElementTypeApplication></AppiumAUT>
python示例代码
# This sample code uses the Appium python client
# pip install Appium-Python-Client
# Then you can paste this into a file and simply run with Python
import unittest
from appium import webdriver
class TestUicatalog(unittest.TestCase):
def setUp(self):
caps = {}
caps["platformName"] = "ios"
caps["platformVersion"] = "12.1"
caps["deviceName"] = "iPhone X"
caps["app"] = "/Users/seveniruby/Library/Developer/Xcode/DerivedData/UICatalog-dfavfehsvaabuqdpmxouzqphclvl/Build/Products/Debug-iphonesimulator/UICatalog.app"
self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)
def test_buttons(self):
el2 = self.driver.find_element_by_accessibility_id("Buttons")
el2.click()
print(self.driver.page_source)
self.driver.find_element_by_accessibility_id("UICatalog").click()
def tearDown(self):
self.driver.quit()
真机测试
真机webview测试
真机浏览器测试
课后作业