Example #1
0
 def logon(self, profile):
     print('判断是否安装rootca, 如果没装则装到root下面')
     if not self.check_cert('rootca'):
         self.install_ca('.\\test_data\\rootca.cer')
     print('判断autolaunch是否off, 如果为off, 手动启动connection')
     if profile['Autolaunch'] == 'OFF':
         self.utils(profile, 'launch', 'conn')
     time.sleep(profile['Launchdelay'])
     time.sleep(5)
     if not EasyshellLib.getElement('StorePool').Exists():
         print('Storefront桌面池没有启动, 测试FAIL!')
         return False
     if profile['DesktopName']:
         CommonLib.TextControl(
             Name=profile['DesktopName']).GetParentControl().Click()
         wnd = self.wait_element(
             CommonLib.WindowControl(
                 RegexName='{} - .*'.format(profile['DesktopName'])), 30)
         if wnd:
             print('开始上传test_storefont.txt, 等待15秒')
             os.system('echo test_logon>{}'.format(self.local_file))
             ftp = CommonLib.FTPUtils(self.ftp_token['ip'],
                                      self.ftp_token['username'],
                                      self.ftp_token['password'])
             ftp.change_dir(self.log_path)
             ftp.upload_file(self.local_file, self.local_file)
             # -------close license expire dialog for windows7- -----------
             time.sleep(15)
             # ------------------------------------------------------------
             print('开始等待vdi的结果返回,300s')
             status = self.get_test_status(ftp, 300)
             ftp.close()
             if not status:
                 print('获取vdi返回结果超时(300秒)')
                 return False
             if status.upper() == 'PASS':
                 print('logon pass')
                 print('检查session窗口{}是否关系(logoff成功)'.format(
                     profile['DesktopName']))
                 if self.wait_element(
                         CommonLib.WindowControl(
                             RegexName='{} - Desktop Viewer'.format(
                                 profile['DesktopName'])), 180, False):
                     EasyshellLib.getElement('Disconnect').Click()
                 else:
                     print('Logoff 超时!!')
             else:
                 print('测试Fail, 收到VDI的结果没有PASS')
             print('所有Storefont测试结束')
     elif profile['AppName']:
         return True
     else:
         print('No app or desktop need to be launch, logon exit')
         if EasyshellLib.getElement('Disconnect').Exists():
             EasyshellLib.getElement('Disconnect').Click()
         return True
Example #2
0
 def check_logon(self, wait_time):
     ftp = CommonLib.FTPUtils(self.ftp_token['ip'],
                              self.ftp_token['username'],
                              self.ftp_token['password'])
     for i in range(wait_time):
         ftp.upload_file(self.local_file, self.local_file)
     ftp.close()
Example #3
0
 def logoff(self):
     os.system('echo test_logon_pass>{}'.format(self.remote_file))
     ftp = CommonLib.FTPUtils(self.ftp_token['ip'],
                              self.ftp_token['username'],
                              self.ftp_token['password'])
     ftp.change_dir(self.log_path)
     ftp.upload_file(self.remote_file, self.remote_file)
     os.remove(self.remote_file)
     ftp.close()
     os.system('shutdown -l')
Example #4
0
 def get_feedback(self):
     ftp = CommonLib.FTPUtils(self.ftp_token['ip'],
                              self.ftp_token['username'],
                              self.ftp_token['password'])
     if self.remote_file in ftp.get_item_list(self.log_path):
         ftp.download_file(self.remote_file, self.remote_file)
         ftp.close()
         return True
     else:
         ftp.close()
         return False
Example #5
0
 def get_test(self):
     ftp = CommonLib.FTPUtils('15.83.251.201', 'sh\\cheng.balance', 'password.321')
     for log_path in self.log_path_list:
         vdi_item = os.path.basename(log_path)
         self.local_file = 'test_{}.txt'.format(vdi_item)
         self.remote_file = 'test_{}_result.txt'.format(vdi_item)
         ftp.change_dir(log_path)
         if self.local_file in ftp.get_item_list(log_path):
             self.log_path = log_path
             ftp.download_file(self.local_file, self.local_file)
             with open(self.local_file, 'r') as f:
                 _, test_item = f.read().strip().split('_')
             ftp.close()
             return vdi_item, test_item
     if self.log_path == '':
             print('No test needed')
Example #6
0
 def download_test(self):
     self.test_req = self.get_test()
     if not os.path.exists('c:\\scripts'):
         os.mkdir('c:\\scripts')
     if self.test_req:
         print(self.test_req[1].strip())
         if os.path.exists('c:\\scripts\\{}'.format(self.test_req[1].strip())):
             shutil.rmtree('c:\\scripts\\{}'.format(self.test_req[1].strip()))
         ftp = CommonLib.FTPUtils('15.83.251.201', 'sh\\cheng.balance', 'password.321')
         ftp.change_dir(self.tool_path + '/{}'.format(self.test_req[0]))
         print(ftp.get_item_list('.'))
         ftp.download_dir(self.test_req[1].strip(), 'c:\\scripts\\{}'.format(self.test_req[1].strip()))
         ftp.change_dir(self.log_path)
         ftp.delete_file(self.local_file)
         ftp.close()
         return True
     else:
         print('Fail, no test requirement upload to ftp')
         return False
Example #7
0
 def utils(self, profile='', op='exist', item='normal'):
     """
     :param profile:  test profile, [test1,test2,,standardApp...]
     :param op: test option [exist | notexist | shown | edit | delete |launch |default]
     :param item: specific for connection, if item=connection, connection button element=textcontrol.getparent,
             else element=textcontrol.getparent.getparent
     :return: Bool
     """
     name = profile["Name"]
     if op.upper() == 'NOTEXIST':
         if CommonLib.TextControl(Name=name).Exists(0, 0):
             self.Logfile('Check {}-{} Not Exist Fail'.format(
                 profile, name))
             self.capture(
                 profile,
                 'Check {}-{} Not Exist Fail'.format(profile, name))
             return False
         else:
             self.Logfile('Check {}-{} Not Exist PASS'.format(
                 profile, name))
             return True
     if CommonLib.TextControl(Name=name).Exists(0, 0):
         txt = CommonLib.TextControl(Name=name)
     else:
         print("{}-{} Not Exist".format(profile, name))
         return False
     if 'CONN' in item.upper():
         appControl = txt.GetParentControl()
     else:
         appControl = txt.GetParentControl().GetParentControl()
     launch = txt  # type=txtcontrol
     if appControl.ButtonControl(AutomationId='editButton').Exists(1, 1):
         edit = appControl.ButtonControl(AutomationId='editButton')
     else:
         edit = appControl.ButtonControl(AutomationId='EditButton')
     if appControl.ButtonControl(AutomationId='deleteButton').Exists(1, 1):
         delete = appControl.ButtonControl(AutomationId='deleteButton')
     else:
         delete = appControl.ButtonControl(AutomationId='DeleteButton')
     if op.upper() == 'LAUNCH':
         launch.Click()
         return True
     elif op.upper() == 'EDIT':
         edit.Click()
         return True
     elif op.upper() == 'SHOWN':
         if txt.IsOffScreen:
             return False
         else:
             return True
     elif op.upper() == 'DEFAULT':
         print('home')
         appControl.ButtonControl(AutoamtionId='homeButton').Click()
     elif op.upper() == 'DELETE':
         try:
             delete.Click()
             EasyshellLib.getElement('DeleteYes').Click()
             EasyshellLib.getElement('APPLY').Click()
             return True
         except:
             self.Logfile("[FAIL]:App {} Delete\nErrors:\n{}\n".format(
                 name, traceback.format_exc()))
             self.capture(
                 profile, "[FAIL]:App {} Delete\nErrors:\n{}\n".format(
                     name, traceback.format_exc()))
             return False
     else:
         return True
Example #8
0
    def logon(self, profile):
        print('判断是否安装rootca, 如果没装则装到root下面')
        if not self.check_cert('rootca'):
            self.install_ca('.\\test_data\\rootca.cer')
        print('判断autolaunch是否off, 如果为off, 手动启动connection')
        if profile['Autolaunch'] == 'OFF':
            self.utils(profile, 'launch', 'conn')
        time.sleep(profile['Launchdelay'])
        print('检查桌面池...')
        if not self.wait_element(CommonLib.PaneControl(AutomationId='793')):
            print('桌面池没有出现, 测试Fail')
            return False
        time.sleep(3)
        # launch desktop or app
        if profile['AppName']:
            CommonLib.WindowControl(Name='VMware Horizon Client').Click()
            # must add above click, or else will below focus fail
            app_name = CommonLib.PaneControl(Name=profile['AppName'])
            app_name.SetFocus()
            app_name.DoubleClick()
            wait_time = 30000
            current_cycle = 0
            while 1:
                if current_cycle > wait_time:
                    break
                """
                Code here to check app windows show up
                """
        elif profile['DesktopName']:
            print('让需要启动的桌面图标{}显示出来'.format(profile['DesktopName']))
            CommonLib.WindowControl(Name='VMware Horizon Client').Click()
            # must add above click, or else will below focus fail
            desktop_name = CommonLib.PaneControl(Name=profile['DesktopName'])
            desktop_name.SetFocus()
            desktop_name.DoubleClick()
            print('检查VMWare Session窗口{}是否出现'.format(profile['DesktopName']))
            if self.wait_element(
                    CommonLib.WindowControl(Name=profile['DesktopName']), 30):
                print('开始上传test_vmware.txt, 等待15秒')
                os.system('echo test_logon>{}'.format(self.local_file))
                ftp = CommonLib.FTPUtils(self.ftp_token['ip'],
                                         self.ftp_token['username'],
                                         self.ftp_token['password'])
                ftp.change_dir(self.log_path)
                ftp.upload_file(self.local_file, self.local_file)
                # -------close license expire dialog for windows7- -----------
                time.sleep(15)
                print('开始点击license对话框')
                x, y = self.get_resolution()
                CommonLib.Click(int(x / 2), int(y / 3))
                CommonLib.SendKey(CommonLib.Keys.VK_ESCAPE)
                # ------------------------------------------------------------
                print('开始等待vdi的结果返回,300s')
                status = self.get_test_status(ftp, 300)
                ftp.close()
                if not status:
                    print('获取vdi返回结果超时(300秒)')
                    return False
                print('finished wait get test status', status)
                if status.upper() == 'PASS':
                    print('logon pass')
                    print('检查session窗口{}是否关系(logoff成功)'.format(
                        profile['DesktopName']))
                    if self.wait_element(
                            CommonLib.WindowControl(
                                Name=profile['DesktopName']), 180, False):
                        EasyshellLib.getElement('VMwarePool').Close()
                    else:
                        print('Logoff 超时!!')
                else:
                    print('测试Fail, 收到VDI的结果没有PASS')
                print('所有VMWare测试结束')

        else:
            print('do not need to launch session or app')
            return
Example #9
0
 def logon(self, profile):
     if profile['Autolaunch'] == 'OFF' or not profile['Autolaunch']:
         self.utils(profile, 'launch', 'conn')
         # check connection not launch directly when launchdelay 30
     time.sleep(profile['Launchdelay'])
     time.sleep(2)
     if self.wait_element(
             EasyshellLib.getElement(
                 'Connect',
                 searchFromControl=EasyshellLib.getElement(
                     'RDP_WARNNING'))):
         EasyshellLib.getElement('Connect',
                                 searchFromControl=EasyshellLib.getElement(
                                     'RDP_WARNNING')).Click()
     else:
         print(
             '-----------Manual Launch fail, connection not launch------------------------'
         )
         return False
     # loop 3 times to wait for warning dialog pops up
     time.sleep(2)
     print('等待密码输入框, 密码: ' + profile['Password'])
     if self.wait_element(EasyshellLib.getElement('RDPPassword')):
         EasyshellLib.getElement('RDPPassword').SetValue(
             profile['Password'])
         EasyshellLib.getElement('ButtonOK').Click()
     # loop 3 times wait for certificate dialog pops up
     time.sleep(2)
     print('等待证书提示框')
     if self.wait_element(EasyshellLib.getElement('ViewCertificate')):
         EasyshellLib.getElement('ButtonYES').Click()
     # loop 60 cycles to wait for RDP session
     time.sleep(2)
     print('等待session窗口')
     if self.wait_element(EasyshellLib.getElement('RDPSessionWindow'), 60):
         print('session窗口出现, 上传测试item')
         # send test logon to remote session
         os.system('echo test_logon>{}'.format(self.local_file))
         ftp = CommonLib.FTPUtils(self.ftp_token['ip'],
                                  self.ftp_token['username'],
                                  self.ftp_token['password'])
         ftp.change_dir(self.log_path)
         ftp.upload_file(self.local_file, self.local_file)
         if self.remote_file in ftp.get_item_list('.'):
             ftp.delete_file(self.remote_file)
         print('等待vdi返回结果 300秒')
         status = self.get_test_status(ftp, 600)
         ftp.close()
         if not status:
             print('获取vdi返回结果超时(300秒)')
             return False
         print('finished wait get test status', status)
         if status.upper() == 'PASS':
             print('logon pass')
         else:
             print('测试Fail, 收到VDI的结果没有PASS')
             return False
         time.sleep(10)
         # check if connection will reconnected with persistent
         if profile['Persistent'] == 'ON':
             time.sleep(profile['Launchdelay'])
             if self.wait_element(
                     EasyshellLib.getElement(
                         'Connect',
                         searchFromControl=EasyshellLib.getElement(
                             'RDP_WARNNING'))):
                 print('-------------perisitent ON PASS ------------------')
             else:
                 print('-------------perisitent ON Fail ------------------')
                 return False
         else:
             time.sleep(profile['Launchdelay'])
             if self.wait_element(EasyshellLib.getElement(
                     'Connect',
                     searchFromControl=EasyshellLib.getElement(
                         'RDP_WARNNING')),
                                  cycles=3):
                 print(
                     '-------------perisitent OFF Fail ------------------')
             else:
                 print(
                     '-------------perisitent OFF PASS ------------------')
                 return False
     else:
         print('logon fail')
         return False