def cameraRebootDUTLaunchCamera20TimesTest(self): try: for i in range(20): g_common_obj2.system_reboot(90) CameraCommon().unlockScreen() self.appPrepareWithClearData() self.camera.startCameraApp() self.camera.selectMode("Camera") self.camera.switchRearOrFront("Back") self.camera.capturePhoto() self.camera.selectMode("Video") self.camera.recordVideo() if self.camera.checkModeExists("Panorama"): self.camera.selectMode("Panorama") self.camera.capturePhoto(1, False) self.camera.capturePhoto() if self.camera.checkModeExists("Lens Blur"): self.camera.selectMode("Lens Blur") self.camera.capturePhoto() if self.camera.checkModeExists("Photo Sphere"): self.camera.selectMode("Photo Sphere") self.camera.capturePhoto() self.checkFileCorrupt() except Exception as e: CameraCommon().checkCameraCrash() self.assertTrue(False, e)
def testCheck_unsupported_devices(self): """ This test case is to check : adb shell haclctl -i Test Case Precondition: None Test Case Step: 1 adb root -->adb shell 2 Type halctl -i unsupported Expect Result: 1 Connect device and root device successful 2 Bindings list is displayed """ print "[RunTest]: %s" % self.__str__() halctl_keyword = 'unsupported' g_common_obj2.system_reboot() res = g_common_obj2.root_on_device() print res cmdstr = "adb shell halctl -i %s" % halctl_keyword print cmdstr halctl_cmd = os.popen(cmdstr).read() print halctl_cmd search_result = halctl_cmd.count('unsupported') assert search_result > 0, "[ERROR]: halctl -i %s is fail" % halctl_keyword print "[INFO]: halctl -i %s is success" % halctl_keyword
def testCheck_Halctl_FirstBoot(self): """ This test case is to check : adb shell haclctl -l Test Case Precondition: None Test Case Step: 1 Power on the device with newly installed device. 2 Connect to the device using adb for a root session 3 Issue dmesg command and check its output Expect Result: 1 Device boots successfully. 2 Root session available 3 No HAL errors are identified """ print "[RunTest]: %s" % self.__str__() g_common_obj2.system_reboot() res = g_common_obj2.root_on_device() print 'root is :',res result=self.hal.search_in_dmesg('hal').count('error') print result assert result==0, "[ERROR]: halctl boot is fail" print "[INFO]: halctl boot is success"
def setUp(self): super(IterationControl, self).setUp() self._test_name = __name__ g_common_obj2.system_reboot(90) for _ in range(20): self.api = ApiImpl() self.api.d = g_common_obj.get_device() self.api.d.wakeup() if self.api.check_ui_exists("resourceId", self.api.ui.lock_clock_view): break time.sleep(5) self.api.unlock_screen() # self.api = ApiImpl() # self.api.unlock_screen() self.api.clean_tasks() if not self.api.locate_apps("Work Sample MDM"): self.api.setup_managed_profile(True) self.api.enable_system_applications(True) time.sleep(10) self.api.clean_tasks() if not self.api.locate_apps("Work Downloads"): self.api.unhide_applications(True) time.sleep(10) self.api.clean_tasks() if not self.api.locate_apps("Work Chrome"): self.api.enable_system_applications(True) time.sleep(10) self.api.clean_tasks() print "[Setup]: %s" % self._test_name
def testRebootOSADB(self): """ reboot device by 'adb reboot' while setting up work profile :return: None """ if self.api.locate_apps("Work Sample MDM"): self.api.remove_managed_profile(True) self.api.clean_tasks() self.api.api_demo_launch() self.api.click_with_timeout("resourceId", self.api.ui.setup_managed_profile) if not self.api.is_android_L_build(): self.api.click_with_timeout("text", "No", 5) self.api.click_with_timeout("text", "Set up", 10) self.api.click_with_timeout("text", "OK") self.api.click_with_timeout("text", "OK") g_common_obj2.system_reboot(90) for _ in range(20): self.api = ApiImpl() self.api.d.wakeup() if self.api.check_ui_exists("resourceId", self.api.ui.lock_clock_view): break time.sleep(5) g_common_obj.set_vertical_screen() self.api.unlock_screen() if self.api.check_ui_exists("textContains", "isn't responding", 5): self.api.click_with_timeout("text", "OK") self.api.clean_tasks() assert self.api.check_ui_exists("description", "Apps"), "Fail to detect Apps Launcher"
def testCheck_Halctl_list_SafeMode(self): """ Test Case Step: 1 Boot in safemode. 2 Have adb root session 3 Type halctl -l 4 Type halctl -li type=gralloc Expect Result: 1 Device boots successfully 2 successfully 3 Show binding list correctly 4 Gralloc entry is listed. Mount source is llvmpipe. """ print "[RunTest]: %s" % self.__str__() self.hal.wake_up() self.hal.boot_safemode() time.sleep(10) res = g_common_obj2.root_on_device() print res result = self.hal.halctl_cmd("-l", para1=None).count("modalias") assert result > 10, "[ERROR]: halctl -list is fail" print "[INFO]: halctl -list is success" g_common_obj2.system_reboot(200)
def tearDown(self): super(MultiUserSupport, self).tearDown() # reboot device since there is a chance that we get error before switch back to owner user # that will impact some later testing g_common_obj2.system_reboot(90) for _ in range(20): self.api = ApiImpl() self.api.d.wakeup() if self.api.check_ui_exists("resourceId", self.api.ui.lock_clock_view): break time.sleep(5) g_common_obj.set_vertical_screen() print "[Teardown]: %s" % self._test_name
def testReboot_OS(self): """ reboot device :return: None """ g_common_obj2.system_reboot(90) for _ in range(20): self.api = ApiImpl() self.api.d.wakeup() if self.api.check_ui_exists("resourceId", self.api.ui.lock_clock_view): break time.sleep(10) g_common_obj.set_vertical_screen() self.api.unlock_screen() if self.api.check_ui_exists("textContains", "isn't responding", 5): self.api.click_with_timeout("text", "OK") assert self.api.check_ui_exists( "description", "Apps", 5), "[ERROR]: fail to detect Apps launcher"
def testFactoryResetSupport(self): """ verify that able to factory reset device successfully :return: None """ 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() assert self.api.check_ui_exists("resourceId", "com.google.android.setupwizard:id/welcome_title"), \ "fail to detect welcome title in setup wizard" # try to skip setup wizard by click four corner for i in range(5): self.api.d.wakeup() x = self.api.d.info['displayWidth'] y = self.api.d.info['displayHeight'] self.api.click_with_timeout("text", "Allow") if self.api.check_ui_exists("text", "GOT IT"): self.api.click_with_timeout("text", "GOT IT") break self.api.d.click(50, 50) self.api.d.click(x - 50, 50) self.api.d.click(x - 50, y - 50) self.api.d.click(50, y - 50) time.sleep(5) self.api.keep_awake()
def testCreateWorkProfile_Remove_50_times(self): """ create and delete work profile for 50 times :return: None """ self.api.api_demo_launch() if self.api.check_ui_exists("textContains", "Device Owner", 5): self.api.click_with_timeout("resourceId", self.api.ui.device_provision) self.api.click_with_timeout("resourceId", self.api.ui.clear_device_owner_app) self.api.click_with_timeout("text", "Yes") g_common_obj2.system_reboot(90) for _ in range(20): self.api = ApiImpl() self.api.d = g_common_obj.get_device() self.api.d.wakeup() if self.api.check_ui_exists("resourceId", self.api.ui.lock_clock_view): break time.sleep(5) g_common_obj.set_vertical_screen() self.api.unlock_screen() for _ in range(50): if not self.api.locate_apps("Work Sample MDM"): self.api.setup_managed_profile(True) # time.sleep(5) # self.api.settings_sub_launch("Accounts") # assert self.api.check_ui_exists("text", "Accounts"), # "fail to launch settings at {0}".format(_) # assert self.api.check_ui_exists("text", "Work"), # "fail to detect work section in accounts at {0}".format(_) assert self.api.is_work_profile_enabled( ), "fail to detect work section in accounts at {0}".format(_) self.api.click_with_timeout("text", "Remove work profile") self.api.d.wait.update(timeout=3000) self.api.click_with_timeout("text", "Delete") self.api.d.wait.update(timeout=3000) assert self.api.check_ui_exists("text", "Accounts"), \ "fail to detect accounts after remove work profile at {0}".format(_) assert not self.api.check_ui_exists("text", "Work"), \ "fail to detect work section in accounts at {0}".format(_) self.api.clean_tasks()
def cameraPanoramaPowerOffBySoftwareKeyTest(self): try: self.appPrepare() self.camera.startCameraApp() self.camera.selectMode("Panorama") g_common_obj2.system_reboot() CameraCommon().unlockScreen() self.camera.startCameraApp() self.camera.selectMode("Panorama") CameraCommon().clickScreenCenter() self.camera.capturePhoto() g_common_obj2.system_reboot() CameraCommon().unlockScreen() self.camera.startCameraApp() CameraCommon().clickScreenCenter() self.camera.enterPreviewPhotos() self.camera.capturePhoto() self.camera.enterPreviewPhotos() g_common_obj2.system_reboot() CameraCommon().unlockScreen() self.camera.startCameraApp() CameraCommon().clickScreenCenter() self.camera.enterPreviewPhotos() self.checkFileCorrupt() except Exception as e: CameraCommon().checkCameraCrash() self.camera.stopCameraApp() self.assertTrue(False, e)
def testDiskEncryptionStatus(self): """ verify the encryption status of device :return: """ ret = os.popen("adb -s {0} shell getprop ro.crypto.state".format(self.api.serial)).read().strip() if ret != 'encrypted': try: self.api.keep_awake() self.api.launch_app_by_intents("android.settings.SECURITY_SETTINGS", False) assert self.api.check_ui_exists("text", "Encryption", 5), "Fail to detect Encryption option" if not self.api.check_ui_exists("text", "Encrypted", 5): if self.api.check_ui_exists("text", "Encrypt phone"): self.api.click_with_timeout("text", "Encrypt phone") else: self.api.click_with_timeout("text", "Encrypt tablet") assert not self.api.check_ui_exists("resourceId", "com.android.settings:id/warning_low_charge"), \ "fail to encrypt device due to low battery" assert not self.api.check_ui_exists("resourceId", "com.android.settings:id/warning_unplugged"), \ "fail to encrypt due to need to replug in charger" self.api.click_with_timeout("resourceId", "com.android.settings:id/initiate_encrypt") self.api.click_with_timeout("resourceId", "com.android.settings:id/execute_encrypt") for _ in range(3): self.api.d.server.stop() finally: time.sleep(600) self.api = ApiImpl() g_common_obj2.system_reboot(90) for i in range(30): self.api.d = g_common_obj.get_device() self.api.d.wakeup() if self.api.check_ui_exists("resourceId", self.api.ui.lock_clock_view) or \ self.api.check_ui_exists("resourceId", "com.google.android.setupwizard:id/welcome_title"): break time.sleep(10) g_common_obj.set_vertical_screen() self.api.unlock_screen() ret = os.popen("adb -s {0} shell getprop ro.crypto.state".format(self.api.serial)).read().strip() assert ret == 'encrypted', "fail to encrypt device"
def testCheck_Stress_kmod_i_r_overload(self): """ This test case is to check : Stress - kmod -i/-r Test Case Precondition: NoneSystemImpl Test Case Step: 1 Type kmod -r <module> 2 Check the logs 3 Type kmod -i <module> 4 Check the logs 5 Repeat steps 1 to 4 ten times Expect Result: 1 No error occurs 2 Module was unloaded 3 No error occurs 4 Module was loaded 5 Each step has the expected behavior no matter the iteration """ print "[RunTest]: %s" % self.__str__() res = g_common_obj2.root_on_device() print res self.hal.make_device_cpu_overload() cmdstr="adb shell halctl -l | grep kmod" print cmdstr halctl_cmd=os.popen(cmdstr).read().strip() print halctl_cmd kmod_model=halctl_cmd.replace('\r\n\t', ' ').split()[0].split(':')[1] print kmod_model i=5 while i>0: print "loop times: %s"%i self.hal.kmod_r(kmod_model) self.hal.kmod_i(kmod_model) i=i-1 g_common_obj2.system_reboot()
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)