class StartRPCServer(unittest.TestCase): def setUp(self): self._test_name = __name__ print print "[Setup]: %s" % self._test_name self.func = Function() def tearDown(self): print "[Teardown]: %s" % self._test_name def testStartRPCServer(self): """ Start RPC server """ print "[RunTest]: %s" % self.__str__() self.func.push_uiautomator_jar()
class ProvisionDevice(UIATestBase): """ @summary: Test cases for provision device """ def setUp(self): super(ProvisionDevice, self).setUp() self._test_name = __name__ self.function = Function() self.api = ApiImpl() self.api.unlock_screen() print "[Setup]: %s" % self._test_name def tearDown(self): super(ProvisionDevice, self).tearDown() print "[Teardown]: %s" % self._test_name def testProvision_Device_with_Device_Owner(self): """ provision device with device owner during OOBE :return: None """ self.api.d.wakeup() self.function.push_uiautomator_jar() g_common_obj.set_vertical_screen() if not self.api.check_ui_exists("packageName", "com.google.android.setupwizard"): self.api.d.press.home() if self.api.check_ui_exists("description", "Apps"): self.api.clean_tasks() self.api.factory_reset() time.sleep(1200) self.api = ApiImpl() self.api.d.wakeup() g_common_obj.set_vertical_screen() else: while not self.api.check_ui_exists( "resourceId", "com.google.android.setupwizard:id/welcome_title"): self.api.d.press.back() assert self.api.check_ui_exists("resourceId", "com.google.android.setupwizard:id/welcome_title"), \ "[ERROR]: Please run test cases at the beginning of OOBE" # for unencrypted device, just bypass encryption when provision device # the encryption test cases will raise this problem if os.popen("adb -s {0} shell getprop ro.crypto.state".format( self.api.serial)).read().strip() == "unencrypted": os.popen("adb -s {0} root".format(self.api.serial)).read().strip() time.sleep(5) os.popen( "adb -s {0} shell setprop persist.sys.no_req_encrypt true". format(self.api.serial)).read().strip() time.sleep(5) self.api.oobe_setup(True) self.api.unlock_screen() self.api.clean_tasks() self.api.d.press.home() time.sleep(5) self.api.click_with_timeout("text", "GOT IT") try: self.api.api_demo_launch() assert self.api.check_ui_exists("textContains", "Device Owner", 5), \ "[ERROR]: fail to provision device as device owner" g_common_obj.set_vertical_screen() finally: self.api.keep_awake() def testWiFi_Connection_Pretest(self): """ Check WiFi connection in pretest :return: None """ # read wifi info from /etc/oat/sys.conf by default if it exist assert os.path.isfile( "/etc/oat/sys.conf" ), "[ERROR]: Missing config file /etc/oat/sys.config in host" cfg_file = "/etc/oat/sys.conf" self.ssid = self.config.read(cfg_file, 'wifisetting').get("ssid") self.password = self.config.read(cfg_file, 'wifisetting').get("passwd") self.security = self.config.read(cfg_file, 'wifisetting').get("security") self.retry_wifi = self.config.read('tests.tablet.dut_init.conf', 'init_list').get("connect_wifi") # check ui element "Apps" to make sure we are at oobe stage self.api.d.press.home() if self.api.check_ui_exists("description", "Apps"): self.api.set_lock_swipe() self.api.clean_tasks() self.api.settings_sub_launch("Backup & reset") assert self.api.check_ui_exists( "text", "Factory data reset", 5), "fail to detect factory data reset" self.api.click_with_timeout("text", "Factory data reset") self.api.click_with_timeout( "resourceId", "com.android.settings:id/initiate_master_clear") assert self.api.check_ui_exists("resourceId", "com.android.settings:id/execute_master_clear", 5), \ "fail to detect erase everything" self.api.click_with_timeout( "resourceId", "com.android.settings:id/execute_master_clear") time.sleep(600) # reboot device g_common_obj2.system_reboot(90) for _ in range(30): self.api = ApiImpl() self.api.d = g_common_obj.get_device() self.api.d.wakeup() if self.api.check_ui_exists( "resourceId", "com.google.android.setupwizard:id/welcome_title"): break time.sleep(10) self.api.d.wakeup() g_common_obj.set_vertical_screen() # keep device awake # self.api.keep_awake() # enable unknown sources self.api.unknown_source_control(True) # will check for 10 times and will back to welcome page if it's not for _ in range(10): if self.api.check_ui_exists( "resourceId", "com.google.android.setupwizard:id/welcome_title"): break # just back to welcome page self.api.d.press.back() # launch WiFi Settings by intent self.api.launch_app_by_intents("android.settings.WIFI_SETTINGS", False) assert self.api.check_ui_exists( "textMatches", "Wi.Fi"), "[ERROR]: fail to launch wifi settings" # try to connect wifi for retry in range(int(self.retry_wifi)): # turn on wifi if it is off if self.api.check_ui_exists("text", "Off"): self.api.d(text="Off").right(text="OFF").click() time.sleep(10) if self.api.d(resourceId="android:id/list").scrollable: self.api.d(scrollable=True).scroll.vert.to( text=self.ssid) # scroll to ssid if self.api.check_ui_exists("text", self.ssid): # if wifi ap is not hidden if self.api.check_ui_exists( "text", "Connected"): # break if wifi is connected break self.api.click_with_timeout("text", self.ssid) # input password if needed if self.api.check_ui_exists( "resourceId", "com.android.settings:id/password"): self.api.d(resourceId="com.android.settings:id/password" ).set_text(self.password) # click "Connect": a)first time to connect b)reconnect to wifi if failed before if self.api.check_ui_exists("text", "Connect"): self.api.click_with_timeout("text", "Connect") # click "Done" if wifi is connecting if self.api.check_ui_exists("text", "Done"): self.api.click_with_timeout("text", "Done") else: # connect to hidden wifi ap self.api.d.press.menu() self.api.d(text="Add network").click.wait() self.api.d(text="Enter the SSID").set_text(self.ssid) self.api.d(resourceId="com.android.settings:id/security", index=1).click.wait() self.api.d(text=self.security).click.wait() self.api.d( resourceId="com.android.settings:id/password").set_text( self.password) self.api.d(text="Save").click.wait() time.sleep(10) # wifi should be connected now assert self.api.check_ui_exists( "text", self.ssid), "[ERROR]: WiFi SSID does't exist" assert self.api.check_ui_exists( "text", "Connected"), "[ERROR]: Fail to connect WiFi" # back to oobe self.api.d.press.back() def testPretest_for_reliability(self): """ provision device if needed """ # read wifi info from /etc/oat/sys.conf by default if it exist assert os.path.isfile( "/etc/oat/sys.conf" ), "[ERROR]: Missing config file /etc/oat/sys.config in host" cfg_file = "/etc/oat/sys.conf" self.ssid = self.config.read(cfg_file, 'wifisetting').get("ssid") self.password = self.config.read(cfg_file, 'wifisetting').get("passwd") self.security = self.config.read(cfg_file, 'wifisetting').get("security") self.retry_wifi = self.config.read('tests.tablet.dut_init.conf', 'init_list').get("connect_wifi") # check ui element "Apps" to make sure we are at oobe stage self.api.d.press.home() self.api.d.wait.update(timeout=5000) if self.api.check_ui_exists("description", "Apps"): # self.api.set_lock_swipe() # self.api.clean_tasks() # self.api.settings_sub_launch("Backup & reset") # assert self.api.check_ui_exists("text", "Factory data reset", 5), "fail to detect factory data reset" # self.api.click_with_timeout("text", "Factory data reset") # self.api.click_with_timeout("resourceId", "com.android.settings:id/initiate_master_clear") # assert self.api.check_ui_exists("resourceId", "com.android.settings:id/execute_master_clear", 5), \ # "fail to detect erase everything" # self.api.click_with_timeout("resourceId", "com.android.settings:id/execute_master_clear") self.api.factory_reset() time.sleep(600) # reboot device g_common_obj2.system_reboot(90) for _ in range(30): # self.api = ApiImpl() self.api.d = g_common_obj.get_device() self.api.d.wakeup() if self.api.check_ui_exists( "resourceId", "com.google.android.setupwizard:id/welcome_title"): break time.sleep(10) self.api.d.wakeup() g_common_obj.set_vertical_screen() # keep device awake # self.api.keep_awake() # enable unknown sources self.api.unknown_source_control(True) # will check for 10 times and will back to welcome page if it's not for _ in range(10): if self.api.check_ui_exists( "resourceId", "com.google.android.setupwizard:id/welcome_title"): break # just back to welcome page self.api.d.press.back() # launch WiFi Settings by intent self.api.launch_app_by_intents("android.settings.WIFI_SETTINGS", False) assert self.api.check_ui_exists( "textMatches", "Wi.Fi"), "[ERROR]: fail to launch wifi settings" # try to connect wifi for retry in range(int(self.retry_wifi)): # turn on wifi if it is off if self.api.check_ui_exists("text", "Off"): self.api.d(text="Off").right(text="OFF").click() time.sleep(10) if self.api.d(resourceId="android:id/list").scrollable: self.api.d(scrollable=True).scroll.vert.to( text=self.ssid) # scroll to ssid if self.api.check_ui_exists("text", self.ssid): # if wifi ap is not hidden if self.api.check_ui_exists( "text", "Connected"): # break if wifi is connected break self.api.click_with_timeout("text", self.ssid) # input password if needed if self.api.check_ui_exists( "resourceId", "com.android.settings:id/password"): self.api.d(resourceId="com.android.settings:id/password" ).set_text(self.password) # click "Connect": a)first time to connect b)reconnect to wifi if failed before if self.api.check_ui_exists("text", "Connect"): self.api.click_with_timeout("text", "Connect") # click "Done" if wifi is connecting if self.api.check_ui_exists("text", "Done"): self.api.click_with_timeout("text", "Done") else: # connect to hidden wifi ap self.api.d.press.menu() self.api.d(text="Add network").click.wait() self.api.d(text="Enter the SSID").set_text(self.ssid) self.api.d(resourceId="com.android.settings:id/security", index=1).click.wait() self.api.d(text=self.security).click.wait() self.api.d( resourceId="com.android.settings:id/password").set_text( self.password) self.api.d(text="Save").click.wait() time.sleep(10) # wifi should be connected now assert self.api.check_ui_exists( "text", self.ssid), "[ERROR]: WiFi SSID does't exist" assert self.api.check_ui_exists( "text", "Connected"), "[ERROR]: Fail to connect WiFi" # back to oobe self.api.d.wakeup() self.function.push_uiautomator_jar() g_common_obj.set_vertical_screen() while not self.api.check_ui_exists( "resourceId", "com.google.android.setupwizard:id/welcome_title"): self.api.d.wakeup() self.api.d.press.back() assert self.api.check_ui_exists("resourceId", "com.google.android.setupwizard:id/welcome_title"), \ "[ERROR]: Please run test cases at the beginning of OOBE" # for unencrypted device, just bypass encryption when provision device # the encryption test cases will raise this problem if os.popen("adb -s {0} shell getprop ro.crypto.state".format( self.api.serial)).read().strip() == "unencrypted": os.popen("adb -s {0} root".format(self.api.serial)).read().strip() time.sleep(5) os.popen( "adb -s {0} shell setprop persist.sys.no_req_encrypt true". format(self.api.serial)).read().strip() time.sleep(5) self.api.d.wakeup() self.api.oobe_setup(True) self.api.unlock_screen() self.api.clean_tasks() self.api.d.press.home() time.sleep(5) self.api.click_with_timeout("text", "GOT IT") try: self.api.unlock_screen() self.api.launch_app("Sample MDM") assert self.api.check_ui_exists("textContains", "Device Owner", 5), \ "[ERROR]: fail to provision device as device owner" g_common_obj.set_vertical_screen() finally: self.api.keep_awake() self.api.clean_tasks() self.api.enable_system_applications(False)
class AospAppsInit(object): def __init__(self): self.success = False self.d = g_common_obj.get_device() self.config = TestConfig() self.func = Function() cfg_file = 'tests.tablet.dut_init.conf' self.username = self.config.read(cfg_file, 'google_account').get("username") self.passwd = self.config.read(cfg_file, 'google_account').get("password") def check_if_app_not_first_init(self, applaunchname): """ Not fit for Photos,because it's in google plus package.welcome to use check others and report defect on this methods :param applaunchname: :return: """ g_common_obj.launch_app_am('com.android.settings', 'com.android.settings.Settings') self.d(text="Apps").click.wait() self.d(resourceId="com.android.settings:id/tabs").swipe.left() self.d(resourceId="com.android.settings:id/tabs").swipe.left() self.d(scrollable=True).scroll.to(textContains=applaunchname) self.d(textContains=applaunchname).click() print self.d(text="Clear data").enabled return self.d(text="Clear data").enabled def init_playstore(self): g_common_obj.adb_cmd("am start -S com.android.vending/.AssetBrowserActivity") time.sleep(3) if self.d(textStartsWith="Just a sec").exists or self.d(text="Couldn't sign in").exists: self.d.press.back() for i in range(30): if self.d(text="Accept").exists: self.d(text="Accept").click.wait() if self.d(className="android.widget.ImageButton").exists: break time.sleep(2) self.d(className="android.widget.ImageButton").click.wait() self.d(text="Settings").click.wait() self.d(text="Auto-update apps").click.wait() self.d(text="Do not auto-update apps").click.wait() g_common_obj.adb_cmd("am force-stop com.android.vending") def init_chrome(self): # init chrome's two options g_common_obj.launch_app_from_home_sc("Chrome") time.sleep(5) while self.d(text="Accept & continue").exists: self.d(text="Accept & continue").click.wait() if self.d(text="Done").exists: self.d(text="Done").click.wait() if self.d(text="No thanks").exists: self.d(text="No thanks").click.wait() if self.d(text="No Thanks").exists: self.d(text="No Thanks").click.wait() if self.d(description="More options").exists: self.d(description="More options").click.wait() if self.d(text="Cancel").exists: self.d(text="Cancel").click.wait() if self.d(resourceId="com.android.chrome:id/menu_button").exists: self.d(resourceId="com.android.chrome:id/menu_button").click.wait() if self.d(text="Settings").exists: self.d(text="Settings").click.wait() if self.d(text="Sign in to Chrome").exists: self.d(text="Sign in to Chrome").click.wait() if self.d(text="Add a Google Account").exists: self.d(text="Cancel").click.wait() else: self.d(text="Sign in").click.wait() if self.check_if_app_not_first_init("Chrome") is False: self.d.press.recent() self.d(text="Chrome", resourceId="com.android.systemui:id/activity_description").click.wait() if self.d(text="Basics").down(resourceId="com.android.chrome:id/header_title", textContains="@gmail.com") != None: self.d(text="Basics").down(resourceId="com.android.chrome:id/header_title", textContains="@gmail.com").click.wait() if self.d(textContains="Auto sign").right(resourceId="android:id/checkbox").checked: self.d(textContains="Auto sign").right(resourceId="android:id/checkbox").click() else: self.d.press.recent() self.d(text="Chrome", resourceId="com.android.systemui:id/activity_description").click.wait() pass if self.d(resourceId="com.android.chrome:id/menu_button").exists: self.d(resourceId="com.android.chrome:id/menu_button").click.wait() self.d(text="Privacy").click.wait() if self.d(textContains="Navigation").right(resourceId="android:id/checkbox").checked: self.d(textContains="Navigation").right(resourceId="android:id/checkbox").click.wait() if self.d(textContains="Search and").right(resourceId="android:id/checkbox").checked: self.d(textContains="Search and").right(resourceId="android:id/checkbox").click.wait() if self.d(textContains="Usage and crash reports").right(resourceId="android:id/checkbox").checked: self.d(textContains="Usage and crash reports").right(resourceId="android:id/checkbox").click.wait() if self.d(text="CLEAR BROWSING DATA...").exists: self.d(text="CLEAR BROWSING DATA...").click.wait() # if self.d(text="Clear browsing data").exists: if self.d(text="Clear browsing history").exists: if not self.d(text="Clear browsing history").checked: self.d(text="Clear browsing history").click.wait() if self.d(text="Clear the cache").exists: if not self.d(text="Clear the cache").checked: self.d(text="Clear the cache").click.wait() if self.d(textContains="Clear cookies").exists: if not self.d(textContains="Clear cookies").checked: self.d(textContains="Clear cookies").click.wait() if self.d(text="Clear").exists: self.d(text="Clear").click.wait() if self.d(text="Accept").exists: self.d(text="Accept").click.wait() self.d.press.back() self.d.press.back() url = "http://www.youtube.com/watch?v=OYotwvVzBm4" for i in range(3): self.d(resourceId="com.android.chrome:id/url_bar").clear_text() if self.d(resourceId="com.android.chrome:id/website_settings_connection_message").exists: self.d.press.back() self.d(resourceId="com.android.chrome:id/url_bar").set_text(url) self.d.press.enter() time.sleep(2) for i in range(10): if self.d(resourceId="com.android.chrome:id/url_bar", text="m.youtube.com").exists: g_common_obj.adb_cmd("am force-stop com.android.chrome") return if self.d(textStartsWith="Open with", resourceId="android:id/title").exists: self.d(textContains="Chrome").click.wait() if self.d(text="Always").exists: self.d(text="Always").click.wait() if self.d(description="Web View").exists: self.d.press.back() time.sleep(5) if self.d(text="OK").exists: self.d(text="OK").click.wait() g_common_obj.adb_cmd("am force-stop com.android.chrome") return time.sleep(3) g_common_obj.adb_cmd("am force-stop com.android.chrome") def enable_developer_option(self): # enable developer option g_common_obj.adb_cmd("am start -S com.android.settings/.Settings") self.d(scrollable=True).scroll.vert.to(textContains="About tablet") if self.d(textContains="Developer options").exists: return self.d(textContains="About tablet").click() for i in range(8): self.d(textContains="Build number").click() self.d.press.back() self.d(scrollable=True).scroll.vert.to(textContains="Developer options") assert self.d(textContains="Developer options").exists def init_hangout(self): g_common_obj.adb_cmd("am start com.google.android.talk/com.google.android.talk.SigningInActivity") time.sleep(5) if self.d(text="Sign in").exists: time.sleep(5) self.d.wait.update() # self.d(text="Sign in").click.wait() if self.d(text="Skip").exists: self.d(text="Skip").click.wait() elif self.d(text="Got it").exists: self.d(text="Got it").click.wait() def init_googlemap(self): g_common_obj.adb_cmd("am start -a android.intent.action.VIEW com.google.android.apps.maps/" "\com.google.android.maps.MapsActivity -d \"geo:47.6,-122.3\"") if self.d(text="Accept & continue").exists: self.d(text="Accept & continue").click.wait() if self.d(text="Sign in").exists: time.sleep(5) self.d(text="Sign in").click.wait() def init_playmusic(self): g_common_obj.adb_cmd( "am start -S com.google.android.music/com.android.music.activitymanagement.TopLevelActivity") for i in range(30): time.sleep(2) if not self.d(resourceId="com.google.android.music:id/tutorial_logo").exists: break assert not self.d(resourceId="com.google.android.music:id/tutorial_logo").exists if self.d(text="Skip").exists: self.d(text="Skip").click.wait() if self.d(text="Use Standard").exists: self.d(text="Use Standard").click.wait() if self.d(text="Done").exists: self.d(text="Done").click.wait() if self.d(resourceId="com.google.android.music:id/play_drawer_list").exists: self.d.press.back() if self.d(text="Got it").exists: self.d(text="Got it").click.wait() def keep_awake(self): """# keep screen awake""" if g_common_obj.adb_cmd("dumpsys power | grep 'mStayOn=true'") == 0: if g_common_obj.adb_cmd("dumpsys power | grep 'mScreenOffTimeoutSetting=1800000'") == 0: return g_common_obj.adb_cmd("am start -S com.android.settings/.Settings") self.d(scrollable=True).scroll.vert.to(textContains="Developer options") if self.d(textContains="Developer options").exists: self.d(textContains="Developer options").click.wait() if self.d(text="Stay awake").right(resourceId="android:id/checkbox") is not None: if not self.d(text="Stay awake").right(resourceId="android:id/checkbox").checked: self.d(text="Stay awake").right(resourceId="android:id/checkbox").click() else: if not self.d(text="Stay awake").right(resourceId="android:id/switchWidget").checked: self.d(text="Stay awake").right(resourceId="android:id/switchWidget").click() self.d.press.back() self.d(scrollable=True).scroll.vert.to(text="Display") self.d(text="Display").click.wait() if not self.d(text="After 30 minutes of inactivity").exists: self.d(text="Sleep").click.wait() self.d(text="30 minutes").click.wait() assert self.d(text="After 30 minutes of inactivity").exists def add_google_account(self): """ add_google_account """ for i in range(5): try: self.func.add_google_account(self.username, self.passwd) break except Exception as e: print e def init_dut_squeence(self): """ seqeueence of predebugplan """ self.__init__() SampleApiDemoImpl().unlock() self.func.push_uiautomator_jar() g_common_obj.set_vertical_screen() self.enable_developer_option() self.keep_awake() self.func.wake_up() self.add_google_account() self.init_playstore() self.func.init_camera() self.init_chrome() self.func.init_photo() self.init_googlemap() self.init_hangout() self.init_playmusic() self.func.init_youtube()
class InitFlashDevices(object): def __init__(self): formatter = "[%(asctime)s - %(levelname)s] %(message)s" self.logger = Logger("Security", formatter) self.relay = None self.func = Function() self.cfg_file = "tests.tablet.security.conf" self.conf_path = os.path.join(os.environ.get('TEST_DATA_ROOT', ''), self.cfg_file) self.x = d.info["displayWidth"] self.y = d.info["displayHeight"] self.retry_num = 3 def init_main(self): print "[RunTest]: init DUT setup" # after flash eng-build, start init setup self.init_AdbRoot() self.init_StartRPCServer() self.init_ConfigFirstBootWizard() self.init_wakeUpUnlock() self.init_EnableDeveloperOption() self.init_KeepAwake() self.init_DisableVerifyApp() #self.init_set_date_time_language_US() def check_product(self): cmd = "getprop ro.product.name" product = g_common_obj.adb_cmd_capture_msg(cmd) return product def check_version(self): cmd = "getprop ro.build.version.incremental" version = g_common_obj.adb_cmd_capture_msg(cmd) return version def check_build_release(self): cmd = "getprop ro.build.version.release" release = g_common_obj.adb_cmd_capture_msg(cmd) return release def unlock_screen(self): if d(description="Unlock").exists: d.press("menu") def single_swipe_to_app_list(self): info = d.info x = info["displayWidth"] / 2 y = info["displayHeight"] d.swipe(x, y, x, 0) time.sleep(2) def check_home_ui_user_safely_O(self): if d(text="Drive safely").exists: if d(text="Owner").exists: d(text="Owner").click.wait() if d(text="Owner").exists: d(text="Owner").click.wait() else: if d(text="Owner").exists: d(text="Owner").click.wait() g_common_obj.adb_cmd_capture_msg("input tap 310 1007") def check_home_ui_skip_got_it(self): if d(textContains="Welcome").exists: if d(textContains="GOT IT").exists: d(textContains="GOT IT").click.wait() if d(text="OK").exists: d(text="OK").click.wait() def adb_root(self): g_common_obj.root_on_device() def init_AdbRoot(self): """ Switch to adb root mode """ print "[RunTest]: init dut root" succeed = False for i in range(5): try: time.sleep(3) self.func.root_DUT() succeed = True break except Exception as e: print e #assert succeed def init_StartRPCServer(self): """ Start RPC server """ print "[RunTest]: init dut start RPC server" try: self.func.push_uiautomator_jar() d.orientation = 'natural' d.freeze_rotation() except Exception as e: print e def init_wakeUpUnlock(self): print "start to wakeup and unlock screen" d.wakeup() if d(resourceId="com.android.keyguard:id/keyguard_selector_view_frame" ).exists: d(resourceId="com.android.keyguard:id/keyguard_selector_view_frame" ).swipe.down() if d(description="Unlock").exists: d(description="Unlock").drag.to( resourceId="com.android.systemui:id/clock_view") product_name = self.check_product() print "[INFO]product_name: %s" % product_name if "gordon_peak" in product_name: self.check_home_ui_user_safely_O() else: self.unlock_screen() self.check_home_ui_skip_got_it() def init_ConfigFirstBootWizard(self): """ Config first boot wizard """ print "[RunTest]: init_ConfigFirstBootWizard" d.wakeup() d.press("home") time.sleep(2) if d(textContains="Drive safely").exists: d(text="Owner").click.wait() return if d(textContains="START DRIVING").exists: d(textContains="START DRIVING").click.wait() return release = g_common_obj.adb_cmd_capture_msg( "getprop |grep 'version.release'") if ('[8.0.0]' in release) or ('[8.1.0]' in release): return if d(textContains="Chrome").exists or d( textContains="Play Store").exists: return d.wakeup() if d(resourceId="com.android.systemui:id/lock_icon"): self.func.close_lock_screen() return print "[Info]------Wizard is exists, need to click four point..." succeed = False for i in range(self.retry_num): try: if d(text="OK").exists: d(text="OK").click.wait() if d(resourceId="com.google.android.setupwizard:id/language_picker").exists or \ d(resourceId="com.google.android.setupwizard:id/welcome_title").exists or \ d(resourceId="com.google.android.setupwizard:id/start").exists: for _ in range(3): d.click(100, 100) d.click(self.x - 100, 100) d.click(self.x - 100, self.y - 100) d.click(100, self.y - 100) time.sleep(2) if not d( resourceId= "com.google.android.setupwizard:id/language_picker" ).exists: break if d(text="OK").exists: d(text="OK").click.wait() d(text="OK").wait.gone(timeout=3000) self.check_home_ui_skip_got_it() self.func.close_lock_screen() succeed = True return if d(text="Welcome") or \ d(resourceId="com.google.android.setupwizard:id/welcome_title") or \ d(resourceId="com.google.android.setupwizard:id/start"): self.func.setup_guideline() if d(text="OK").exists: d(text="OK").click.wait() succeed = True self.check_home_ui_skip_got_it() break except Exception as e: print e assert succeed def init_EnableDeveloperOption(self): """ Enable developer option """ print "[RunTest]: init_EnableDeveloperOption" succeed = False for i in range(self.retry_num): try: os.system( "adb shell input keyevent 82;adb shell input keyevent 3") g_common_obj.launch_app_am("com.android.settings", ".Settings") time.sleep(2) ui = d.dump() if 'scrollable="true"' in ui: d(scrollable=True).scroll.toEnd() if d(textContains="Developer options").exists: return time.sleep(2) ui = d.dump() if 'System' in ui: system_or_about = 'System' elif 'About ' in ui: system_or_about = 'About' print 'click ' + system_or_about + ' ...' d(textContains=system_or_about).click.wait() if d(textContains="Developer options").exists: return if d(textContains="About ").exists: d(textContains="About ").click() # Fix ui not detected on bxt-p # Change structure to try/except try: d(scrollable=True).scroll.vert.to( textContains="Build number") time.sleep(1) except: print "No need scroll." for _ in range(8): d(textContains="Build number").click() time.sleep(.5) succeed = True break except Exception as e: print e assert succeed, "Enable Developer Option fail" def init_KeepAwake(self): """ Keep system stay awake """ print "[RunTest]: init_KeepAwake" succeed = False for i in range(self.retry_num): try: os.system("adb shell am force-stop com.android.settings") os.system( "adb shell am start -a android.settings.APPLICATION_DEVELOPMENT_SETTINGS" ) self.func.settings_ON_OFF("Stay awake", enable=True) succeed = True break except Exception as e: print e assert succeed def init_DisableVerifyApp(self): """ Disable verify apps """ print "[RunTest]: init_DisableVerifyApp" succeed = False for i in range(self.retry_num): try: os.system( "adb shell input keyevent 82;adb shell input keyevent 3") os.system("adb shell am force-stop com.android.settings") os.system( "adb shell am start -a android.settings.APPLICATION_DEVELOPMENT_SETTINGS" ) d(scrollable=True).scroll.vert.to( textContains="Verify apps over USB") self.func.settings_ON_OFF("Verify apps over USB", enable=False) succeed = True break except Exception as e: print e assert succeed def init_set_date_time_language_US(self): print "[RunTest]: init_set_date_time_language_US" succeed = False for i in range(self.retry_num): try: self.func.set_language() self.func.set_timedate() succeed = True break except Exception as e: print e assert succeed