def verify_cpu_mhz(mode, case_name, power_manager):
    try:
        if mode == 'ondemand':
            low_mhz = linux_get_cpu_mhz(mode)
            select_mode('performance', power_manager)
            time.sleep(15)
            high_mhz = linux_get_cpu_mhz('performance')
            log.info("ondemand mode:{}, performance mode:{}".format(
                low_mhz, high_mhz))
            return [high_mhz, low_mhz]
        else:
            high_mhz = linux_get_cpu_mhz(mode)
            select_mode('ondemand', power_manager)
            time.sleep(15)
            low_mhz = linux_get_cpu_mhz('ondemand')
            log.info("performance mode:{}, ondemand mode:{}".format(
                high_mhz, low_mhz))
            return [high_mhz, low_mhz]
    except:
        log.error(traceback.format_exc())
        error_pic = os.path.join(common_function.get_current_dir(),
                                 r'Test_Report', 'img',
                                 '{}.png'.format(case_name))
        capture_screen(error_pic)
        os.system("wmctrl -c 'Control Panel'")
        return '0'
def step5_res(*args, **kwargs):
    case_name = kwargs.get("case_name")
    report_file = kwargs.get("report_file")
    with open(path, 'r', encoding='utf-8') as f:
        file_info = f.readline()
        print(file_info)
    time.sleep(5)
    time_gap = time.time() - float(file_info)
    log.info('tc power off time is {}'.format(time_gap))
    os.remove(path)
    if time_gap > 5:
        log.info('power off success')
        steps = {
            'step_name':
            "verify screen can be unlocked and shutdown immediately",
            'result': 'Pass',
            'expect': 'success',
            'actual': 'success',
            'note': ''
        }
        common_function.update_cases_result(report_file, case_name, steps)
    else:
        steps = {
            'step_name':
            "verify screen can be unlocked and shutdown immediately",
            'result': 'Fail',
            'expect': 'success',
            'actual': 'fail',
            'note': ''
        }
        common_function.update_cases_result(report_file, case_name, steps)
        reset_settings()
        return False
def template_pic_path(p):
    path = os.path.join(
        common_function.get_current_dir(),
        'Test_Data/td_power_manager/verify_screensaver_diff_image'
        '/{}'.format(p))
    log.info('verify the template picture:{}'.format(path))
    return path
def login_remote(*args, **kwargs):
    case_name = kwargs.get("case_name")
    result_file = kwargs.get("report_file")
    log.info('2.2. Start a remote session with your SH account.')
    SwitchThinProMode(switch_to='user')
    conn = kwargs.get('conn')
    if start_remote('logon', conn=conn):
        steps = {
            'step_name': 'login a remote session (RDP)',
            'result': 'Pass',
            'expect': '',
            'actual': '',
            'note': ''
        }
        common_function.update_cases_result(result_file, case_name, steps)
    else:
        log.info('remote session login fail')
        steps = {
            'step_name': 'login a remote session (RDP)',
            'result': 'Fail',
            'expect': 'login success',
            'actual': 'vdi login fail',
            'note': ''
        }
        common_function.update_cases_result(result_file, case_name, steps)
        reset_all_settings(num=0)
        return False
def reset_all_settings(*args, **kwargs):
    log.info('reset all settings')
    num = kwargs.get('num', 15)
    user_manager = kwargs.get("user_manager")
    user = kwargs.get('user')
    server = kwargs.get('rdp_server')
    conn = kwargs.get('conn')
    if not check_icon('start') and not check_icon('unlock'):
        pyautogui.press('enter')
        unlock_screen(r'sh.dto\!#$%^', 'Shanghai2010')
        time.sleep(5)
        if check_icon('locked'):
            unlock_screen('root', '1')
    if check_icon('unlock'):
        unlock_screen(r'sh.dto\!#$%^', 'Shanghai2010')
        time.sleep(5)
        if check_icon('locked'):
            unlock_screen('root', '1')
    start_remote('', conn=conn)
    reset_key(user_manager, user, server)
    reset_require_pass_domain_users()
    if not leave_domain_with_check():
        common_function.import_profile()
        os.system('reboot')
    else:
        common_function.import_profile()
    time.sleep(num)
def reset_all_settings(lis):
    locked_wake_up()
    time.sleep(2)
    power_m = PowerManagerFactory("ScreenSaver")
    power_m.ScreenSaver.open_power_manager_from_control_panel()
    power_m.ScreenSaver.switch()
    power_m.ScreenSaver.set(
        pms=pms.ScreenSaver.Enable_Screensaver_and_Screen_Lock, radio="on")
    power_m.ScreenSaver.set(
        pms=pms.ScreenSaver.Minutes_before_automatic_Screensaver_activation,
        radio="on",
        text=lis[1])
    power_m.ScreenSaver.apply()
    time.sleep(5)
    power_m.ScreenSaver.close_all_power_manager()
    if lis:
        log.info('reset all settings in the end')
        os.system(
            "mclient --quiet set root/screensaver/enableScreensaver {}".format(
                lis[0]))
        os.system(
            "mclient --quiet set root/screensaver/enableCustomLogo {}".format(
                lis[2]))
        os.system("mclient --quiet set root/screensaver/logoPath {}".format(
            lis[3]))
        os.system("mclient commit")
Пример #7
0
    def run(self):
        """
        run test
        :return:
        """
        try:
            suit = self.set_case_suite()#调用set_case_suite获取test_suite
            print('try')
            print(str(suit))
            if suit is not None:#判断test_suite是否为空
                print('if-suit')
                fp = open(resultPath, 'wb')#打开result/20181108/report.html测试报告文件,如果不存在就创建
                #调用HTMLTestRunner
                runner = HTMLTestRunner.HTMLTestRunner(stream=fp, title='API测试报告', tester='ZhaoJun')
                runner.run(suit)
            else:
                print("Have no case to test.")
        except Exception as ex:
            print(str(ex))
            log.info(str(ex))

        finally:
            print("*********TEST END*********")
            log.info("*********TEST END*********")
            fp.close()
def step2(power_m):
    try:
        set_image_slideshowstretch(power_m)
        power_m.ScreenSaver.apply()
        time.sleep(5)
        lock_screen()
        img21, size21 = open_pic(pic_cut('3', '1'))
        data21 = get_pic_color(img21, get_xy(size21))
        log.info(data21)
        for _ in range(3):
            time.sleep(5)
            img22, size22 = open_pic(pic_cut('3', '2'))
            data22 = get_pic_color(img22, get_xy(size22))
            if data21 != data22:
                break
        else:
            time.sleep(5)
            img22, size22 = open_pic(pic_cut('3', '2'))
            data22 = get_pic_color(img22, get_xy(size22))
        log.info(data22)
        locked_wake_up()
        time.sleep(5)
        return data21, data22
    except:
        log.debug(
            traceback.format_exc(),
            common_function.get_current_dir(
                'Test_Report', 'img', 'different_image_slideshowstretch.png'))
        power_m.ScreenSaver.apply()
        power_m.close_all_power_manager()
        return None
def pic_path(pic_name):
    path = os.path.join(
        common_function.get_current_dir(),
        'Test_Data/td_power_manager/verify_screensaver_diff_image'
        '/source_pic/{}'.format(pic_name))
    log.info('select the source picture:{}'.format(path))
    return path
def verify_two_account(*args, **kwargs):
    case_name = kwargs.get("case_name")
    result_file = kwargs.get("report_file")
    log.info('verify two accounts art listed')
    lock_screen()
    if check_account('with_vdi'):
        steps = {
            'step_name': 'verify two accounts art listed',
            'result': 'Pass',
            'expect': 'correct',
            'actual': 'correct',
            'note': ''
        }
        common_function.update_cases_result(result_file, case_name, steps)
    else:
        error_pic = os.path.join(
            common_function.get_current_dir(), r'Test_Report', 'img',
            'verify_domain_and_rdp_two_account_are_listed.png')
        picture_operator.capture_screen(error_pic)
        steps = {
            'step_name': 'verify two accounts art listed',
            'result': 'Fail',
            'expect': 'correct',
            'actual': 'wrong',
            'note': ''
        }
        common_function.update_cases_result(result_file, case_name, steps)
        reset_all_settings(num=0)
        return False
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 login_domain_user(*args, **kwargs):
    case_name = kwargs.get("case_name")
    result_file = kwargs.get("report_file")
    log.info('2.1. Login with  !#$%^  Shanghai2010')
    time.sleep(10)
    domain_login(user_name='!#$%^', password="******")
    time.sleep(5)
    if check_account('start') or check_account('domain_icon'):
        steps = {
            'step_name': 'login domain account success',
            'result': 'Pass',
            'expect': 'login success',
            'actual': 'success',
            'note': ''
        }
        common_function.update_cases_result(result_file, case_name, steps)
    else:
        error_pic = os.path.join(common_function.get_current_dir(),
                                 r'Test_Report', 'img',
                                 'login_domain_user_result.png')
        picture_operator.capture_screen(error_pic)
        steps = {
            'step_name': 'login domain account success',
            'result': 'Fail',
            'expect': 'login success',
            'actual': 'fail',
            'note': '{}'.format(error_pic)
        }
        common_function.update_cases_result(result_file, case_name, steps)
        reset_all_settings(num=0)
        return False
def add_domain_result(*args, **kwargs):
    log.info('check the result of step join tc domain')
    case_name = kwargs.get("case_name")
    result_file = kwargs.get("report_file")
    if check_icon('domain_login_user') or check_icon('domain_login_pwd'):
        steps = {
            'step_name': 'verify add domain and reboot success',
            'result': 'Pass',
            'expect': 'add domain success',
            'actual': 'success',
            'note': ''
        }
        common_function.update_cases_result(result_file, case_name, steps)
    else:
        error_pic = os.path.join(common_function.get_current_dir(),
                                 r'Test_Report', 'img',
                                 'verify_add_domain_result.png')
        picture_operator.capture_screen(error_pic)
        steps = {
            'step_name': 'verify add domain and reboot success',
            'result': 'Fail',
            'expect': 'add domain success',
            'actual': 'fail',
            'note': '{}'.format(error_pic)
        }
        common_function.update_cases_result(result_file, case_name, steps)
        domain_login(user_name='!#$%^', password="******")
        reset_all_settings(num=0)
        return False
def start(case_name, **kwargs):
    try:
        log.info('Begin to start test {}'.format(case_name))
        user_manager = vdi_connection.MultiUserManger()
        user = user_manager.get_a_available_key()
        rdp_server = user_manager.get_a_available_key('rdp win10')
        conn = vdi_connection.RDPLinux(user=user, rdp_server=rdp_server)
        log.info('user: {}, rdp_server: {}'.format(user, rdp_server))
        report_file = os.path.join(
            common_function.get_current_dir(), r'Test_Report',
            '{}.yaml'.format(common_function.check_ip_yaml()))
        common_function.new_cases_result(report_file, case_name)
        common_function.case_steps_run_control(steps_list,
                                               __name__,
                                               case_name=case_name,
                                               log=log,
                                               report_file=report_file,
                                               user=user,
                                               rdp_server=rdp_server,
                                               conn=conn,
                                               user_manager=user_manager)
    except:
        log.error(traceback.format_exc())
        error_pic = os.path.join(common_function.get_current_dir(),
                                 r'Test_Report', 'img',
                                 '{}.png'.format(case_name))
        picture_operator.capture_screen(error_pic)
        reset_all_settings(num=0)
        return False
def set_image_slideshowstretch(power_m):
    log.info('set the image type to slideshowstretch')
    power_m.ScreenSaver.set(
        pms=pms.ScreenSaver.Enable_Screensaver_and_Screen_Lock, radio="on")
    power_m.ScreenSaver.set(pms=pms.ScreenSaver.Image_Mapping,
                            selected=pms.ScreenSaver.Select.SlideShowStretch)
    power_m.ScreenSaver.set(pms=pms.ScreenSaver.Custom_image,
                            selected=pms.ScreenSaver.Select.Customized_dictory)
Пример #16
0
def select_mode(select, power_manager):
    if select == 'ondemand':
        power_manager.AC.set(pms=pms.AC.CPU_mode, selected=pms.AC.Select.ondemand)
    else:
        power_manager.AC.set(pms=pms.AC.CPU_mode, selected=pms.AC.Select.performance)
    power_manager.AC.apply()
    time.sleep(3)
    log.info('switch cpu mode to {}'.format(select))
def click_icon(lis):
    log.info('check icon and click')
    path = os.path.join(common_function.get_current_dir(), 'Test_Data',
                        'td_power_manager', 'verify_s3_work')
    for i in lis:
        power_icon = picture_operator.wait_element(os.path.join(path, i),
                                                   offset=(20, 10))
        tool.click(power_icon[0][0], power_icon[0][1], 1)
def last_step(*args, **kwargs):
    user_manager = kwargs.get("user_manager")
    case_name = kwargs.get("case_name")
    user = kwargs.get('user')
    server = kwargs.get('rdp_server')
    reset_key(user_manager, user, server)
    common_function.import_profile()
    log.info('test case {} is end'.format(case_name))
def set_image_tile(power_m, path):
    log.info('set the image type to title')
    power_m.ScreenSaver.set(
        pms=pms.ScreenSaver.Enable_Screensaver_and_Screen_Lock, radio="on")
    power_m.ScreenSaver.set(pms=pms.ScreenSaver.Image_Mapping,
                            selected=pms.ScreenSaver.Select.Title)
    power_m.ScreenSaver.set(pms=pms.ScreenSaver.Custom_image,
                            selected=pms.ScreenSaver.Select.Customized_dictory,
                            pic_path=path)
def lock_screen():
    log.info('lock the screen')
    SwitchThinProMode(switch_to='user')
    time.sleep(2)
    pyautogui.hotkey('ctrl', 'alt', 'l')
    time.sleep(2)
    size = common_function.screen_resolution()
    tool.click(int(size[0] / 2), int(size[1] / 2), 1)
    return True
def check_icon(name):
    log.info('check the picture {}'.format(name))
    path = os.path.join(common_function.get_current_dir(), 'Test_Data',
                        'td_power_manager',
                        'verify_screensaver_works_in_system_image_mode',
                        '{}'.format(name))
    if os.path.exists(path):
        if wait_element(path):
            return True
def start_remote(lg, **kwargs):
    conn = kwargs.get('conn')
    if lg == 'logon':
        log.info('Switch to user mode to start remote session')
        return conn.logon("fasdfs")
    else:
        log.info('logoff remote session')
        res = conn.logoff()
        return res
Пример #23
0
def get_cup_mode():
    path = os.path.join(common_function.get_current_dir(), 'Test_Data', 'td_power_manager', 'verify_ac_default_value',
                            'ondemand')
    if wait_element(path):
        cpu_mode = 'ondemand'
    else:
        cpu_mode = 'performance'
    log.info('get cpu mode:{}'.format(cpu_mode))
    return cpu_mode
def lock_screen():
    log.info('lock the screen')
    path = common_function.get_current_dir('Test_Data', 'td_power_manager',
                                           'desktop')
    for _ in range(3):
        pyautogui.hotkey('ctrl', 'alt', 'l')
        time.sleep(2)
        if not wait_element(path):
            break
        time.sleep(2)
def unlock_screen(user, password):
    log.info('Try  {}  {}  to unlock screen'.format(user, password))
    if check_icon('wran_error'):
        pyautogui.press('enter')
        time.sleep(2)
    sw_user('unlock')
    pyautogui.typewrite(user)
    time.sleep(1)
    pyautogui.press("tab")
    time.sleep(1)
    pyautogui.typewrite(password)
    time.sleep(1)
    pyautogui.press("enter")
Пример #26
0
def wait_and_check_screen_saver(t=55):
    log.info("start wait time")
    for i in range(9):
        time.sleep(t)
        if linux_check_locked():
            log.error("current loop times {}".format(i))
            break
    else:
        time.sleep(t + 35)
        flag = linux_check_locked()
        log.info("check screen lock result:{}".format(flag))
        return flag
    return False
def sleep_desktop():
    log.info('sleep by right click desktop')
    tool.right_click(300, 300, 1)
    # try:
    #     click_icon(['power', 'sleep'])
    # except:
    time.sleep(1)
    pyautogui.press("up", interval=0.5)
    pyautogui.press("enter", interval=0.5)
    pyautogui.press("down", interval=0.5)
    pyautogui.press("enter", interval=0.5)
    pyautogui.press("enter", interval=0.5)
    time.sleep(10)
def require_pass_domain_users():
    log.info('Uncheck "Require password for domain users')
    SwitchThinProMode(switch_to='admin')
    power_m = PowerManagerFactory("ScreenSaver")
    power_m.ScreenSaver.open_power_manager_from_control_panel()
    power_m.ScreenSaver.switch()
    power_m.ScreenSaver.set(
        pms=pms.ScreenSaver.Enable_Screensaver_and_Screen_Lock, radio="on")
    power_m.ScreenSaver.set(
        pms=pms.ScreenSaver.Require_password_for_domain_users, radio="off")
    power_m.ScreenSaver.apply()
    time.sleep(3)
    power_m.ScreenSaver.close_all_power_manager()
def step1(*args, **kwargs):
    case_name = kwargs.get("case_name")
    report_file = kwargs.get("report_file")
    SwitchThinProMode(switch_to='admin')
    log.info('set user password: 1')
    set_user_password()
    log.info('enable require password for general users')
    power_m = PowerManagerFactory("ScreenSaver")
    power_m.ScreenSaver.open_power_manager_from_control_panel()
    power_m.ScreenSaver.switch()
    power_m.ScreenSaver.set(
        pms=pms.ScreenSaver.Enable_Screensaver_and_Screen_Lock, radio="on")
    power_m.ScreenSaver.set(
        pms=pms.ScreenSaver.Require_password_for_general_users, radio="on")
    click_icon('ok', count=1)
    power_m.ScreenSaver.apply()
    time.sleep(5)
    power_m.ScreenSaver.close_all_power_manager()
    SwitchThinProMode(switch_to='user')
    log.info('start a web connection')
    web = WebConn([])
    web.open_firefox()
    if click_icon('firefox_title'):
        log.info('web connection success')
    lock_screen()
    pyautogui.press('enter')
    if click_icon('locked_dialog'):
        log.info('screen lock dialog shown')
        steps = {
            'step_name': "verify screen lock dialog shown",
            'result': 'Pass',
            'expect': 'show',
            'actual': 'show',
            'note': ''
        }
        common_function.update_cases_result(report_file, case_name, steps)
    else:
        error_pic = os.path.join(
            common_function.get_current_dir(), r'Test_Report', 'img',
            '{}+step1.png'.format(case_name.replace(' ', '_')))
        capture_screen(error_pic)
        steps = {
            'step_name': "verify screen lock dialog shown",
            'result': 'Fail',
            'expect': 'show',
            'actual': 'not show',
            'note': ''
        }
        common_function.update_cases_result(report_file, case_name, steps)
        reset_settings()
        return False
Пример #30
0
def check_ac_default_value():
    power_manager = PowerManagerFactory("AC")
    power_manager.AC.open_power_manager_from_control_panel()
    power_manager.AC.switch()
    path = os.path.join(common_function.get_current_dir(), 'Test_Data',
                        'td_power_manager', 'verify_ac_default_value',
                        'sleep_time')
    if wait_element(path):
        sleep = '30'
    else:
        sleep = ''
    log.info('get default value on AC sleep after:{}'.format(sleep))
    power_manager.AC.close_all_power_manager()
    return sleep