這個腳本,它可以自動使用AndroidViewClient/culebra,然後稍微編輯處理ON/OFF情況下產生究竟你需要的東西:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
'''
Copyright (C) 2013-2014 Diego Torres Milano
Created on 2014-12-05 by Culebra v8.18.1
__ __ __ __
/\/\/\/\
____________________/ __\/ __\/ __\/ __\_____________________________
___________________/ /__/ /__/ /__/ /________________________________
|/\ /\ /\ /\ \___
|/ \_/ \_/ \_/ \ o \
\_____/--<
@author: Diego Torres Milano
@author: Jennifer E. Swofford (ascii art snake)
'''
import re
import sys
import os
import unittest
from com.dtmilano.android.viewclient import ViewClient, CulebraTestCase
class CulebraTests(CulebraTestCase):
@classmethod
def setUpClass(cls):
cls.kwargs1 = {'ignoreversioncheck': False, 'verbose': False, 'ignoresecuredevice': False}
cls.kwargs2 = {'startviewserver': True, 'forceviewserveruse': False, 'autodump': False, 'ignoreuiautomatorkilled': True}
cls.options = {'start-activity': None, 'multi-device': False, 'unit-test-class': True, 'save-screenshot': None, 'use-dictionary': False, 'dictionary-keys-from': 'id', 'scale': 1, 'find-views-with-content-description': True, 'window': -1, 'orientation-locked': None, 'save-view-screenshots': None, 'find-views-by-id': True, 'do-not-verify-initial-screen-dump': True, 'use-regexps': False, 'auto-regexps': None, 'use-jar': False, 'verbose-comments': False, 'gui': True, 'find-views-with-text': True, 'prepend-to-sys-path': False, 'output': '/Users/diego/tmp/settings-wifi.py', 'unit-test-method': None, 'interactive': False}
cls.sleep = 5
def setUp(self):
super(CulebraTests, self).setUp()
def tearDown(self):
super(CulebraTests, self).tearDown()
def preconditions(self):
if not super(CulebraTests, self).preconditions():
return False
return True
def testSomething(self):
if not self.preconditions():
self.fail('Preconditions failed')
self.vc.dump(window=-1)
self.vc.findViewWithTextOrRaise(re.compile(u'Wi.Fi')).touch()
self.vc.sleep(CulebraTests.sleep)
self.vc.dump(window=-1)
try:
self.assertIsNotNone(self.vc.findViewWithText(u'OFF'))
except:
self.vc.findViewWithTextOrRaise(u'ON').touch()
if __name__ == '__main__':
CulebraTests.main()
我創建它使用culebra
GUI,點擊Wi-Fi項目,使用culebra的CTRL-T檢查狀態,然後單擊切換。然後我手動編輯它以添加try/except
塊爲ON/OFF。
謝謝,我正試圖獲得WiFi狀態。 是否有可能做某事: activity =「android.settings.WIFI_SETTINGS」 my_device.startActivity(action = activity) – Empario 2014-12-30 04:55:22
是的,試試'culebra --help',你會看到'-a,--start -activity = COMPONENT在dump'之前啓動Activity – 2014-12-30 06:00:38