class ChargingLongTime(UIATestBase): """ Connecting CDP charger in MOS and wait one night for 12 hours, check battery increase. """ def setUp(self): self._test_name = __name__ print "[Setup]: %s" % self._test_name self.emImpl = EMImpl() self.emImpl.set_screen_status("on") self.emImpl.unlock_screen() g_common_obj.close_background_apps() super(ChargingLongTime, self).setUp() def tearDown(self): super(ChargingLongTime, self).tearDown() print "[Teardown]: %s" % self._test_name def check_charging_12h(self, charger_type, device_mode=MOS): level = self.emImpl.get_battery_level() if device_mode == COS: self.emImpl.power_off_device() else: self.emImpl.set_screen_status("off") time.sleep(5) # charge 12h if charger_type == CDP: self.emImpl.enable_cdp_charging() elif charger_type == DCP: self.emImpl.enable_dcp_charging() print "Sleep 12h." time.sleep(12 * 3600) if charger_type != SDP: self.emImpl.enable_sdp_charging() time.sleep(30) if device_mode == COS: self.emImpl.boot_up_device() self.emImpl.adb_root() level = self.emImpl.get_battery_level() assert level >= FULL, "charging for 12 hours is not full." def check_charging_1h(self, charger_type): level1 = self.emImpl.get_battery_level() self.emImpl.set_screen_status("off") time.sleep(5) if charger_type == CDP: self.emImpl.enable_cdp_charging() elif charger_type == DCP: self.emImpl.enable_dcp_charging() print "Sleep 1h." time.sleep(36) if charger_type != SDP: self.emImpl.enable_sdp_charging() level2 = self.emImpl.get_battery_level() assert level2 >= min(FULL, level1 + 10) def test_charging_CDP_MOS_12_hours(self): self.check_charging_12h(CDP, MOS) def test_charging_CDP_COS_12_hours(self): self.check_charging_12h(CDP, COS) def test_charging_DCP_MOS_12_hours(self): self.check_charging_12h(DCP, MOS) def test_charging_DCP_COS_12_hours(self): self.check_charging_12h(DCP, COS) def test_charging_SDP_MOS_12_hours(self): self.check_charging_12h(SDP, MOS) def test_charging_SDP_COS_12_hours(self): self.check_charging_12h(SDP, COS) def test_CDP_charging_1_hour(self): self.check_charging_1h(CDP) def test_DCP_charging_1_hour(self): self.check_charging_1h(DCP) def test_SDP_charging_1_hour(self): self.check_charging_1h(SDP)
class LowBatteryPerformance(UIATestBase): def setUp(self): self._test_name = __name__ print "[Setup]: %s" % self._test_name self.emImpl = EMImpl() self.emImpl.adb_root() self.emImpl.set_screen_status("on") self.emImpl.unlock_screen() self.emImpl.set_sleep_mode("30 minutes") self.enable_wifi_adb() super(LowBatteryPerformance, self).setUp() def tearDown(self): print "[Teardown]: %s" % self._test_name self.emImpl.three_way_cutter_reconnect_sdp(3, 2, 5) super(LowBatteryPerformance, self).tearDown() def enable_wifi_adb(self): ssid, passwd = self.emImpl.read_wifi_conf() self.emImpl.connect_wifi(ssid, passwd) serial_wifi = self.emImpl.enable_wifi_adb() self.emImpl_wifi = EMImpl(serial_wifi) def prepare_battery_level(self, target_level): actual_level = self.emImpl.get_battery_level() if actual_level < target_level - 1: self.emImpl.set_screen_status("off") self.emImpl.enable_dcp_charging(2, 2) cycles = 20 for i in range(1, 1 + cycles): wait_time = 60 * (target_level - actual_level) print "Cycle: %d/%d, wait %ds" % (i, cycles, wait_time) time.sleep(wait_time) actual_level = self.emImpl_wifi.get_battery_level() if actual_level >= target_level: break else: assert False self.emImpl.three_way_cutter_reconnect_sdp(3, 2, 5) self.emImpl.set_screen_status("on") self.emImpl.unlock_screen() elif actual_level > target_level + 1: video_file = self.emImpl.push_artifactory_resource( "video", "/mnt/sdcard/Movies") self.emImpl.play_media_file("video/*", "file://" + video_file) time.sleep(5) self.emImpl.set_three_way_cutter_usb(0) cycles = 20 for i in range(1, 1 + cycles): wait_time = 60 * (actual_level - target_level) print "Cycle: %d/%d, wait %ds" % (i, cycles, wait_time) time.sleep(wait_time) actual_level = self.emImpl_wifi.get_battery_level() if actual_level <= target_level: break else: assert False self.emImpl.three_way_cutter_reconnect_sdp(3, 2, 5) self.emImpl.stop_focused_activity() def check_low_battery_warning(self, low_level): cycles = 20 for i in range(1, 1 + cycles): print "Check low battery warning: %d/%d" % (i, cycles) time.sleep(60) if self.emImpl_wifi.get_battery_level() <= low_level: break else: assert False, "battery level higher than 15%" assert self.emImpl_wifi.check_lowbattery_notification() def test_low_battery_warning_15_play_video(self): """ Test low battery warning 15% play video """ print "[RunTest]: %s" % self.__str__() self.prepare_battery_level(17) video_file = self.emImpl.push_artifactory_resource( "video", "/mnt/sdcard/Movies") self.emImpl.play_media_file("video/*", "file://" + video_file) time.sleep(5) self.emImpl.set_three_way_cutter_usb(0) self.check_low_battery_warning(15) self.emImpl.stop_focused_activity() def test_low_battery_warning_15(self): """ Test low battery warning 15 """ print "[RunTest]: %s" % self.__str__() self.prepare_battery_level(17) self.emImpl.set_three_way_cutter_usb(0) self.check_low_battery_warning(15) def test_low_battery_warning_5(self): """ Test low battery warning 5 """ print "[RunTest]: %s" % self.__str__() self.prepare_battery_level(7) self.emImpl.set_three_way_cutter_usb(0) time.sleep(5) self.emImpl_wifi.clean_notification() self.check_low_battery_warning(5) def test_battery_20_discharge_util_shutdown(self): print "[RunTest]: %s" % self.__str__() self.prepare_battery_level(20) video_file = self.emImpl.push_artifactory_resource( "video", "/mnt/sdcard/Movies") self.emImpl.play_media_file("video/*", "file://" + video_file) time.sleep(5) self.emImpl.set_three_way_cutter_usb(0) for _ in range(20): if not self.emImpl_wifi.get_state(): break try: level = self.emImpl_wifi.get_battery_level() except: break wait_time = 60 * level + 5 print "Wait %ds" % wait_time time.sleep(wait_time) else: assert False self.emImpl.enable_dcp_charging(2, 2) time.sleep(600) self.emImpl.enable_sdp_charging(2, 2) time.sleep(60) self.emImpl.boot_up_device() self.emImpl.adb_root()