def sleep_method1():
    try:
        log.info('sleep by wait time')
        power_manager = PowerManagerFactory("AC")
        power_manager.AC.open_power_manager_from_control_panel()
        power_manager.AC.switch()
        power_manager.AC.set(pms=pms.AC.Minutes_before_system_sleep,
                             radio="on",
                             text="{}".format('1'))
        with PrepareWakeUp(time=80) as w:
            power_manager.AC.apply()
            w.wait(60)
        to_os = ScreenSaver()
        to_os.resume_lock_screen_by_mouse()
        time_gap = w.get_max_time_gap()
        w.set_max_time_gap(0)
        power_manager.AC.set(pms=pms.AC.Minutes_before_system_sleep,
                             radio="on",
                             text="{}".format('30'))
        power_manager.AC.apply()
        time.sleep(5)
        power_manager.AC.close_all_power_manager()
        return time_gap
    except:
        log.warning(traceback.format_exc())
        return '0'
def preparewakeup(t=120):
    with PrepareWakeUp(time=t) as w:
        w.wait(t)
    t_gap = w.get_max_time_gap()
    print(t_gap)
    if t_gap > 11:
        return True
    return False
Beispiel #3
0
def preparewakeup(t=15):
    with PrepareWakeUp(time=t) as w:
        open_window("sleep")
    t_gap = w.get_max_time_gap()
    print(t_gap)
    if t_gap > 11:
        return True
    return False
def sleep_method2(f):
    try:
        with PrepareWakeUp(time=0) as w:
            f()
        to_os = ScreenSaver()
        to_os.resume_lock_screen_by_mouse()
        time_gap = w.get_max_time_gap()
        w.set_max_time_gap(0)
        return time_gap
    except:
        log.warning(traceback.format_exc())
        return '0'
def step5(*args, **kwargs):
    case_name = kwargs.get("case_name")
    report_file = kwargs.get("report_file")
    lock_screen()
    time.sleep(2)
    log.info('start to power off the tc by screen lock dialog')
    with PrepareWakeUp(time=0) as w:
        pyautogui.press('enter')
        click_icon('menu', count=1)
        click_icon('power', count=1)
        click_icon('poweroff', count=1)
        cur_time = time.time()
        with open(path, 'a', encoding='utf-8') as f:
            f.write(str(int(cur_time)))
            f.write('\n')
Beispiel #6
0
def start(case_name, **kwargs):
    try:
        result_file = os.path.join(
            common_function.get_current_dir(), r'Test_Report',
            '{}.yaml'.format(common_function.check_ip_yaml()))
        log.info('Begin to start test {}'.format(case_name))
        common_function.new_cases_result(result_file, case_name)
        SwitchThinProMode(switch_to='admin')
        sleep_time = check_ac_default_value()
        if sleep_time == '30':
            steps = {
                'step_name': 'check the default value on AC',
                'result': 'Pass',
                'expect': '30',
                'actual': '30',
                'note': ''
            }
            common_function.update_cases_result(result_file, case_name, steps)
        else:
            steps = {
                'step_name': 'check the default value on AC',
                'result': 'Fail',
                'expect': '30',
                'actual': 'The default value is wrong',
                'note': ''
            }
            common_function.update_cases_result(result_file, case_name, steps)
            log.info('case {} is end'.format(case_name))
            return False
        with PrepareWakeUp(time=1810) as w:
            w.wait(1810)
        to_os = ScreenSaver()
        to_os.resume_lock_screen_by_mouse()
        last_time_gap = int(w.get_max_time_gap())
        if last_time_gap > 5:
            steps = {
                'step_name':
                'check the os go to verify_s3_work afer 30 minutes',
                'result': 'Pass',
                'expect': 'sleep',
                'actual': 'it is go to sleep',
                'note': ''
            }
            common_function.update_cases_result(result_file, case_name, steps)
        else:
            steps = {
                'step_name':
                'check the os go to verify_s3_work afer 30 minutes',
                'result': 'Fail',
                'expect': 'sleep',
                'actual': 'it is not go to sleep',
                'note': 'time gap: {}, must more than 5'.format(last_time_gap)
            }
            common_function.update_cases_result(result_file, case_name, steps)
            return False
        if last_time_gap > 5:
            steps = {
                'step_name': 'check the os wake up',
                'result': 'Pass',
                'expect': 'wake up',
                'actual': 'System can wake up immediately',
                'note': ''
            }
            common_function.update_cases_result(result_file, case_name, steps)
        else:
            steps = {
                'step_name': 'check the os wake up',
                'result': 'Fail',
                'expect': 'wake up',
                'actual': 'System not wake up immediately',
                'note': ''
            }
            common_function.update_cases_result(result_file, case_name, steps)
        log.info('case {} is end'.format(case_name))
    except:
        log.error(traceback.format_exc())
        error_pic = os.path.join(common_function.get_current_dir(),
                                 r'Test_Report', 'img',
                                 '{}.png'.format(case_name.replace(' ', '_')))
        capture_screen(error_pic)
        pass
# import os, re
# import subprocess

# def get_info(eth="eth0"):
#     """
#     :return: [eth, mac, ip, gateway]
#     """
#     result = subprocess.getoutput(r"ifconfig | grep {} -A 2 -B 1|grep -i 'inet' -A 2 -B 1".format(eth))
#     print(result)
#     g_ip = re.search(r"(?i)(?:inet|inet addr)[: ]([\\.\d]+)", result)
#     g_mac = re.search(r"(?i)(?:HWaddr|ether)[: ](..:..:..:..:..)", result)
#     assert g_ip, "Get IP Fail"
#     assert g_mac, "Get Mac Fail"
#     gate_way = subprocess.getoutput(r"route -n|grep {} -m 1".format(eth))
#     g_way = re.search(r"[.\d]+ +([.\d]+)", gate_way)
#     assert g_way, "Get Gate Way Fail"
#     return eth, g_mac.group(1), g_ip.group(1), g_way.group(1)
from Test_Script.ts_power_manager.common_function import PrepareWakeUp
import time
with PrepareWakeUp(time=0):
    time.sleep(20)

print("ok")