零.前提
首先atx對于UI的操作是基于wda的郭厌。
因此對應(yīng)atx和wda來研究一下他們是如何獲取UI的茴肥,又是如何對UI控件進(jìn)行操作的择吊。
哪些控件可以用哪些api進(jìn)行操作长酗。
一.ios_webdriveragent.py
1.啟動關(guān)閉app
d.start_app("Buddle ID") #啟動app
d.stop_app() #關(guān)閉app
2.鏈接狀態(tài)
d.status()
{u'ios': {u'simulatorVersion': u'10.0.2'}, u'state': u'success', u'os': {u'version': u'10.0.2', u'name': u'iOS'}, u'build': {u'time': u'Oct 13 2016 10:27:46'}}
返回的是一個元組,我們可以獲取任意值腌逢,如圖:
Paste_Image.png
3.獲取屏幕尺寸
d.display #Get screen width and height
#屬性函數(shù)(property) :http://python.jobbole.com/80955/
Paste_Image.png
4.BundleID的獲取
d.bundle_id
5.能取到session
s = d._session #發(fā)現(xiàn)app啟動后芒划,atx 調(diào)用wda接管session :self._session = self._wda.session(bundle_id)
#這樣,我們就可以進(jìn)一步操作session的一些東西了
demo:
s.window_size() #返回 Size(width=375, height=667)
6.屏幕尺寸比例
d.scale #屏幕: width/height
#作用:click函數(shù)調(diào)用這個函數(shù)來計算一個button的中心點(diǎn)蚤蔓,因為要點(diǎn)擊在中心的坐標(biāo)上
7.Rotation 屏幕方向(橫屏 還是 豎屏)
d.Rotation #返回int型
設(shè)備會旋轉(zhuǎn)卦溢,橫屏1 豎屏0
源碼:
#rs = dict(PORTRAIT=0, LANDSCAPE=1, UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT=3)return
rs.get(self._session.orientation, 0)
8.d.click(x, y)
d.click(120, 424) #點(diǎn)擊屏幕坐標(biāo)點(diǎn)(x,y)
#python -m atx gui --serial http://100.80.29.124:8100 啟動ATX 的 UI工具 ,獲取坐標(biāo)點(diǎn)
s = d._session # tap的坐標(biāo)要做轉(zhuǎn)換才能用昌粤,跟click的坐標(biāo)要進(jìn)行換算
s.tap(120, 424) #raw_size = self._session.window_size()
#self.__scale = min(self.display) / min(raw_size)rx, ry = x/self.__scale, y/self.__scale
9.home鍵
d.home()
d._wda.home()
10.截屏
d.screenshot("mm.png")
二.image.py
三.wda.py
1.selector介紹
self._base_url = base_url
self._text = unicode(text) if text else None
self._class_name = unicode(class_name) if class_name else None
self._xpath = unicode(xpath) if xpath else None
1.text獲取控件
#查找滑動
d(text=u"發(fā)現(xiàn)城市特色酒店").scroll() #滑動直到找到value=“發(fā)現(xiàn)城市特色酒店”的地方
2.class_name獲取控件
d(class_name="StaticText")[0].click()
3.xpath獲取控件
d(xpath="http://XCUIElementTypeButton[@label='lblseven']").click() #用@name也行
4.baseurl
暫時不知道有什么用
附錄:
[wda支持元素類型]
xcui_element = [
'Any', 'Other', 'Application', 'Group', 'Window',
'Sheet', 'Drawer', 'Alert', 'Dialog', 'Button', 'RadioButton',
'RadioGroup', 'CheckBox', 'DisclosureTriangle', 'PopUpButton',
'ComboBox', 'MenuButton', 'ToolbarButton', 'Popover', 'Keyboard',
'Key', 'NavigationBar', 'TabBar', 'TabGroup', 'Toolbar', 'StatusBar',
'Table', 'TableRow', 'TableColumn', 'Outline', 'OutlineRow', 'Browser',
'CollectionView', 'Slider', 'PageIndicator', 'ProgressIndicator',
'ActivityIndicator', 'SegmentedControl', 'Picker', 'PickerWheel',
'Switch', 'Toggle', 'Link', 'Image', 'Icon', 'SearchField', 'ScrollView',
'ScrollBar', 'StaticText', 'TextField', 'SecureTextField', 'DatePicker',
'TextView', 'Menu', 'MenuItem', 'MenuBar', 'MenuBarItem', 'Map', 'WebView',
'IncrementArrow', 'DecrementArrow', 'Timeline', 'RatingIndicator',
'ValueIndicator', 'SplitGroup', 'Splitter', 'RelevanceIndicator',
'ColorWell', 'HelpTag', 'Matte', 'DockItem', 'Ruler', 'RulerMarker', 'Grid',
'LevelIndicator', 'Cell', 'LayoutArea', 'LayoutItem', 'Handle', 'Stepper', 'Tab'
]