學UI自動化首先就是定位頁面元素,玩過android版的appium小夥伴應該都知道,appium的windows版自帶的Inspector能夠定位app上的元素
Mac版的appium1.6的版本在UI上有了很大的改變,本篇詳細解決如何使用appium1.6定位iOS的app頁面元素。html
1.啓動appium後點Start New Sessionpython
2.打開後看到以下界面,剛開始看到這個界面,我也比較懵。android
1.Desired Capabilities這裏的配置,參考以前Appium+python自動化17-啓動iOS模擬器APP源碼案例這篇裏面啓動app的代碼
```python
class SimpleIOSTests(unittest.TestCase):web
def setUp(self): # set up appium app = os.path.abspath('../../apps/TestApp/build/release-iphonesimulator/TestApp.app') self.driver = webdriver.Remote( command_executor='http://127.0.0.1:4723/wd/hub', desired_capabilities={ 'app': app, 'platformName': 'iOS', 'platformVersion': '10.1', 'deviceName': 'iPhone 6' }) def tearDown(self): self.driver.quit()
```
這裏主要有四個參數:app、platforrmName、platforrmVersion、deviceName,在appium上需多加一個參數automationName
> appium1.6之前的版本是基於uiautomation框架的,1.6之後的版本是基於facebook的XCUITest,因此這個參數必須添加
- app: 這裏的地址是本地.app包的絕對路徑
- platforrmName: iOS系統版本號
- platforrmVersion: iPhone設備名稱
- platforrmVersion: iOS系統
- automationName: XCUITestwindows
2.在Desired Capabilities先填入對應的參數後,右側會自動生成JSON Representationapp
3.填好配置後,爲了下次方便使用,能夠點Sav As ..按鈕保存設置框架
1.Start Session就能啓動Inspector界面了iphone
2.接下來就能夠定位app上的元素了ui