1
我想知道是否有方法或者是否有人試圖自動化設置CTS測試設備?自動設置Android CTS測試
基本上我有以下情形
- 我使用詹金斯閃爍這使修改4.2負載的設備上
- 設備的設備已經閃現後,我要運行的CTS測試。
- 沒有用戶交互我希望能夠設置設備並運行CTS。
有沒有辦法做到這一點?或者用戶交互是設置CTS測試設備的唯一方式?
我想知道是否有方法或者是否有人試圖自動化設置CTS測試設備?自動設置Android CTS測試
基本上我有以下情形
有沒有辦法做到這一點?或者用戶交互是設置CTS測試設備的唯一方式?
是的,有一種方法可以爲CTS設置設備。我用AndroidViewClient來做到這一點。以下是一些如何實現此目標的示例:
# This must be imported before MonkeyRunner and MonkeyDevice,
# otherwise the import fails.
from com.dtmilano.android.viewclient import ViewClient, View
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyView
package = 'com.android.settings'
activity = '.Settings'
component_name = package + '/' + activity
EXCLUDE_FROM_RECENTS = 0x00800000
ap_name = "Put acces point name here"
# Connect to device with the IP received as a parameter
device, serialno = ViewClient.connectToDeviceOrExit()
width = int(device.getProperty('display.width'))
height = int(device.getProperty('display.height'))
# Press the HOME button to start the test from the home screen
device.press('KEYCODE_HOME','DOWN_AND_UP')
MonkeyRunner.sleep(2)
# Open the Settings app
device.startActivity(component = component_name, flags = EXCLUDE_FROM_RECENTS)
i = 0
while str(device.getProperty('am.current.package')) != package and i<10:
MonkeyRunner.sleep(1)
i = i + 1
if i == 10:
raise Exception('Cannot open package')
# Create the view client object
vc = ViewClient(device=device, serialno=serialno)
# Enable Wi-Fi
device.shell("svc wifi enable")
i = 0
while not vc.findViewWithText(ap_name) and i<30:
MonkeyRunner.sleep(1)
vc.dump()
i += 1
if i == 30:
print "Cannot enable Wi-Fi"
for i in range(5):
device.press('KEYCODE_DPAD_RIGHT', MonkeyDevice.DOWN_AND_UP)
MonkeyRunner.sleep(0.5)
device.press('KEYCODE_DPAD_LEFT', MonkeyDevice.DOWN_AND_UP)
MonkeyRunner.sleep(0.5)
device.press('KEYCODE_ENTER', MonkeyDevice.DOWN_AND_UP)
MonkeyRunner.sleep(2)
device.type(ap_name)
vc.dump()
if vc.findViewWithText('Save'):
vc.findViewWithText('Save').touch()
MonkeyRunner.sleep(5)
# Set Screen Lock to None
drag_start = (width*1/4, height*9/10)
drag_end = (width*1/4, height*1/10)
device.drag(drag_start, drag_end)
vc.dump()
if vc.findViewWithText('Security'):
vc.findViewWithText('Security').touch()
MonkeyRunner.sleep(1)
vc.dump()
if vc.findViewWithText('Screen lock'):
vc.findViewWithText('Screen lock').touch()
MonkeyRunner.sleep(1)
vc.dump()
if vc.findViewWithText('None'):
vc.findViewWithText('None').touch()
MonkeyRunner.sleep(1)
vc.dump()
# Activate device administrator
if vc.findViewWithText('Device administrators'):
vc.findViewWithText('Device administrators').touch()
MonkeyRunner.sleep(1)
vc.dump()
admin1 = vc.findViewWithText('android.deviceadmin.cts.CtsDeviceAdminReceiver')
if admin1:
for aux_view in admin1.parent.parent.children:
if aux_view['class'] == 'android.widget.CheckBox':
break
if aux_view['checked'] == 'false':
admin1.touch()
MonkeyRunner.sleep(1)
vc.dump()
if vc.findViewWithText('Activate'):
vc.findViewWithText('Activate').touch()
MonkeyRunner.sleep(1)
vc.dump()
admin2 = vc.findViewWithText('android.deviceadmin.cts.CtsDeviceAdminReceiver2')
if admin2:
for aux_view in admin2.parent.parent.children:
if aux_view['class'] == 'android.widget.CheckBox':
break
if aux_view['checked'] == 'false':
admin2.touch()
MonkeyRunner.sleep(1)
vc.dump()
if vc.findViewWithText('Activate'):
vc.findViewWithText('Activate').touch()
MonkeyRunner.sleep(1)
# Enable Delegating Accessibility Service
MonkeyRunner.sleep(1)
vc.dump()
if vc.findViewWithText('Accessibility'):
vc.findViewWithText('Accessibility').touch()
MonkeyRunner.sleep(1)
vc.dump()
if vc.findViewWithText('Delegating Accessibility Service'):
vc.findViewWithText('Delegating Accessibility Service').touch()
MonkeyRunner.sleep(1)
for count in range(5):
device.press('KEYCODE_DPAD_RIGHT', MonkeyDevice.DOWN_AND_UP)
MonkeyRunner.sleep(0.5)
device.press('KEYCODE_ENTER', MonkeyDevice.DOWN_AND_UP)
MonkeyRunner.sleep(1)
vc.dump()
MonkeyRunner.sleep(1)
if vc.findViewWithText('Use Delegating Accessibility Service?'):
vc.findViewWithText('OK').touch()
else:
vc.findViewWithText('Cancel').touch()
MonkeyRunner.sleep(1)
這些是爲CTS準備設備的一些步驟。按照CTS設置指南中每個部分的示例進行操作。
偉大的腳本。這對運行CTS的其他人可能非常有用。您可能希望將其添加到AndroidViewClient示例中。只需將其上傳到github,我會很樂意合併它。 –
真棒,作品像魅力! – user2569315
@dtmilano當我連接一個設備時,使用AndroidViewClient可以正常工作。但是,當我連接多個設備時,我不斷在腳本中發現錯誤。例如,當我想連接到特定設備,例如 設備,serialno = ViewClient.connectToDeviceOrExit(serialno =「016B756C1001A016」)我得到以下錯誤: vc = ViewClient(device = device,serialno = serialno) xml.parsers .expat.ExpatError:尾部不允許有內容。這可能是模塊在處理多個設備時的缺陷。 – user2569315