예제 #1
0
def confirm_username(username):
    ftp = FTP(gc.get_config('ftp_server'))
    ftp.login(gc.get_config('ftp_username'), gc.get_config('ftp_password'))
    ftp.cwd('Automation/Linux/flags')
    i = 180
    while i:
        files = ftp.nlst()
        if 'username.txt' in files:
            file_name = 'RETR ' + 'username.txt'
            file = open('username.txt', 'wb')
            ftp.retrbinary(file_name, file.write)
            file.close()
            file = open('username.txt', 'r')
            for line in file.readlines():
                content = line
                if content == username:
                    print('log on success')
                    ftp.delete('username.txt')
                    file.close()
                    os.remove('username.txt')
                    ftp.quit()
                    return True
                else:
                    ftp.delete('username.txt')
                    ftp.quit()
                    return False
        else:
            time.sleep(1)
            i = i-1
            if i == 0:
                ftp.quit()
                return False
예제 #2
0
 def image_match(image_name, times):
     width, height = pag.size()
     image_path = ''
     if width == 1920:
         cert_pictures = gc.get_config('cert_pictures')['1920x1200']
     elif width == 1366 and height == 768:
         cert_pictures = gc.get_config('cert_pictures')['1366x768']
     else:
         return None
     pictures = cert_pictures[image_name]
     for picture in pictures:
         if width == 1920:
             image_path = './Test_Data/1920x1200/cert/' + picture + '.png'
         if width == 1366 and height == 768:
             image_path = './Test_Data/1366x768/cert/' + picture + '.png'
         if image_path == '':
             return None
         img = cv2.imread(image_path)
         for i in range(times):
             pag.screenshot('screen_shot.png')
             img2 = cv2.imread('screen_shot.png')
             test = cv2.matchTemplate(img, img2, cv2.TM_CCOEFF_NORMED)
             min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(test)
             time.sleep(1)
             if max_val > 0.95:
                 return max_loc
     return None
예제 #3
0
def confirm_result():
    ftp = FTP(gc.get_config('ftp_server'))
    ftp.login(gc.get_config('ftp_username'), gc.get_config('ftp_password'))
    ftp.cwd('Automation/Linux/flags')
    i = 200
    while i:
        files = ftp.nlst()
        if 'test_result.txt' in files:
            file_name = 'RETR ' + 'test_result.txt'
            file = open('test_result.txt', 'wb')
            ftp.retrbinary(file_name, file.write)
            file = open('test_result.txt', 'r')
            for line in file.readlines():
                content = line
                if content.lower() == 'passed':
                    file.close()
                    os.remove('test_result.txt')
                    ftp.delete('test_result.txt')
                    ftp.quit()
                    return 'PASS'
                else:
                    file.close()
                    os.remove('test_result.txt')
                    ftp.delete('test_result.txt')
                    ftp.quit()
                    return content
        else:
            time.sleep(1)
            i = i-1
            if i == 0:
                ftp.quit()
                return False
예제 #4
0
def run(server_name='pcoip_server_name',
        operation='//15.83.240.98/Automation/Linux/scripts/logoff.exe'):
    test_name = 'VMware_win10_pcoip'
    cer = certificate.Cert('ROOTCA')
    find_cert = cer.check_cert()
    if find_cert is False:
        insert = cer.import_cert()
        if insert is False:
            report.fail_report('import cert fail', test_name)
            return False
    print('cert already exist')
    name, password = '******', 'password'
    case = thinpro_view.View(server_name, name, password)
    case.del_connection()
    case.create_connection()
    username = case.edit_connection()
    if username != gc.get_config(name):
        report.fail_report(username, test_name)
        return
    case.start_connection()
    connect = case.log_on_desktop()
    if connect is not True:
        report.fail_report(connect, test_name)
        return
    confirm_result = view_ftp.confirm_username(username)
    if confirm_result is False:
        case.logon_fail()
        report.fail_report('not find username.txt', test_name)
        return
예제 #5
0
def upload_test(operation):
    ftp = FTP(gc.get_config('ftp_server'))
    ftp.login(gc.get_config('ftp_username'), gc.get_config('ftp_password'))
    ftp.cwd('Automation/Linux/flags')
    files = ftp.nlst()
    if 'test_item.txt' in files:
        ftp.delete('test_item.txt')
    file_name = 'STOR ' + 'test_item.txt'
    file = open('test_item.txt', 'w')
    file.write(operation)
    file.close()
    file = open('test_item.txt', 'rb')
    ftp.storbinary(file_name, file)
    file.close()
    ftp.quit()
    os.remove('test_item.txt')
예제 #6
0
 def log_on_desktop(self):
     desktop = gc.get_config(self.server_name)
     window = self.image_match('vm_window', 5)
     if window is None:
         self.log.error('not find vm_window after start connection')
         pag.hotkey('ctrl', 'alt', 'f4')
         return 'not find vm_window after start connection'
     pag.doubleClick(window)
     time.sleep(1)
     if pag.size()[1] != 1200:
         if self.server_name != 'blast_server_name':
             pag.press('down', presses=50)
     max_loc = self.image_match(desktop, 5)
     if max_loc is None:
         pag.hotkey('ctrl', 'alt', 'f4')
         self.log.error('not find %s desktop' % self.server_name)
         return 'not find %s desktop' % self.server_name
     pag.doubleClick(max_loc)
     close = self.image_match('connect_fail', 3)
     if close is not None:
         self.log.error('launch desktop fail,please confirm desktop available')
         pag.hotkey('ctrl', 'alt', 'f4')
         return 'launch desktop fail,please confirm desktop available'
     self.log.info('execute log_on_desktop success')
     return True
예제 #7
0
 def log_on_desktop_spec(self):
     desktop = gc.get_config(self.server_name)
     desktop = desktop[:desktop.rfind('_')]  # Remove the index number of spec_server_name
     window = self.image_match('vm_window', 20)
     pag.doubleClick(window)
     time.sleep(1)
     max_loc = self.image_match(desktop, 6)
     if max_loc is None:
         pag.hotkey('ctrl', 'alt', 'f4')
         self.log.error('not find %s desktop' % self.server_name)
         return 'not find %s desktop' % self.server_name
     pag.doubleClick(max_loc)
     close = self.image_match('connect_fail', 3)
     # If launch desktop is failed for the first time, close the prompt then try again.
     if close is not None:
         # fail_max_loc = self.image_match('connect_fail', 6)
         # if fail_max_loc is None:
         #     pag.hotkey('ctrl', 'alt', 'f4')
         #     self.log.error('Fail prompt not found.')
         #     return 'Fail prompt not found.'
         pag.click(close)  # Close the fail prompt message
         time.sleep(5)
         pag.doubleClick(max_loc)  # Launch the desktop again
         close_second = self.image_match('connect_fail', 3)
         if close_second is not None:
             self.log.error('launch desktop fail, please confirm desktop available')
             pag.hotkey('ctrl', 'alt', 'f4')
             # return 'launch desktop fail, please confirm desktop available'
             return 'desktop_unavailable'
     return True
def run():
    username = get_config.get_config(cert_name)
    cert = certificate.Cert('ROOTCA')
    find_cert = cert.check_cert()
    if find_cert is False:
        insert = cert.import_cert()
        if insert is False:
            report.fail_report('import cert fail', connect_with_cert)
            return False
    print('cert already exist')
    if create_connection() is False:
        return False
    warning = logon(username)
    if warning is not True:
        test_report('select security to be warning:' + warning + '-------')
    edit_connection('allow')
    allow = logon(username)
    if allow is not True:
        test_report('select security to be allow:' + allow + '-------')
    edit_connection('refuse')
    refuse = logon(username)
    if refuse is not True:
        test_report('select security to be refuse:' + refuse + '-------')
    if cert.delete_cert() is False:
        test_report('del cert fail,end refuse test without cert test')
        a = ''
        with open('./Test_Report/%s.txt' % connect_with_cert, 'r') as file:
            for line in file.readlines():
                a += line
        report.fail_report(a, connect_with_cert)
        os.remove('./Test_Report/%s.txt' % connect_with_cert)
        return
    if refuse_connect() is False:
        test_report('not find refuse window after delete cert')
    a = ''
    try:
        with open('./Test_Report/%s.txt' % connect_with_cert, 'r') as file:
            for line in file.readlines():
                a += line
        report.fail_report(a, connect_with_cert)
        os.remove('./Test_Report/%s.txt' % connect_with_cert)
    except:
        report.pass_report(connect_with_cert)
예제 #9
0
 def edit_connection(self):
     lst = [self.server_name, 'view_server', self.username, self.password, 'domain']
     config = []
     for i in range(len(lst)):
         config.append(gc.get_config(lst[i]))
     time.sleep(2)
     max_loc1 = self.image_match('view_icon', 3)
     if max_loc1 is None:
         self.log.error('not find view icon to edit connection')
         return 'not find view icon to edit connection'
     pag.rightClick(max_loc1)
     pag.press('down', presses=2, interval=0.1)
     pag.press('enter')
     time.sleep(4)
     max_loc2 = self.image_match('view_edit', 3)
     if max_loc2 is None:
         self.log.error('not find view connection edit window')
         pag.hotkey('ctrl', 'alt', 'f4')
         return 'not find view connection edit window'
     self.log.info('open view edit window success')
     time.sleep(1)
     pag.click((max_loc2[0]+300, max_loc2[1]+100))
     pag.hotkey('ctrl', 'a')
     pag.typewrite(config[0], interval=0.1)
     pag.press('tab')
     pag.typewrite(config[1], interval=0.1)
     pag.click((max_loc2[0]+300, max_loc2[1]+285))
     for i in range(2, 5):
         pag.press('tab')
         pag.typewrite(config[i], interval=0.1)
     time.sleep(1)
     ok_button = self.image_match('ok', 3)
     if ok_button is None:
         self.log.error('not find ok button in edit window')
         pag.hotkey('ctrl', 'alt', 'f4')
         return 'not find ok button in edit window'
     pag.click(ok_button)
     self.log.info('enable edit connection')
     time.sleep(1)
     return config[2]
예제 #10
0
 def edit_connection_spec2(self):
     lst = [self.server_name, 'view_server', 'spec_username2', 'domain']
     config = []
     for i in range(len(lst)):
         config.append(gc.get_config(lst[i]))
     max_loc1 = self.image_match('view_icon', 3)
     if max_loc1 is None:
         self.log.error('not find view icon to edit connection')
         return 'not find view icon to edit connection'
     pag.rightClick(max_loc1)
     pag.press('down', presses=2, interval=0.1)
     pag.press('enter')
     max_loc2 = self.image_match('view_edit', 10)
     if max_loc2 is None:
         self.log.error('not find view connection edit window')
         pag.hotkey('ctrl', 'alt', 'f4')
         return 'not find view connection edit window'
     time.sleep(1)
     pag.click((max_loc2[0] + 300, max_loc2[1] + 100))
     pag.hotkey('ctrl', 'a')
     pag.typewrite(config[0], interval=0.1)  # Input spec_server_name
     pag.press('tab')
     pag.typewrite(config[1], interval=0.1)  # Input view_server
     pag.click((max_loc2[0] + 300, max_loc2[1] + 285))  # Click the radio button before using predefined user name\
     # and password
     pag.press('tab')
     pag.typewrite(config[2], interval=0.1)  # Input spec_username2
     pag.press('tab')
     # Input spec password for spec user 2
     pag.typewrite('+=_,-?', interval=0.1)
     pag.hotkey('shift', ',')  # Input '<'
     pag.typewrite('>~', interval=0.1)
     pag.press('tab')
     pag.typewrite(config[3], interval=0.1)  # Input domain
     time.sleep(1)
     pag.click(self.image_match('ok', 3))
     time.sleep(1)
     return config[2]
예제 #11
0
def run(server_name='blast_server_name'):
    file_name = 'VMware_win10_USB_key_USBR_blast'
    local_usb = check_usb()
    if local_usb is not True:
        report.fail_report(local_usb, file_name)
        return False
    operation = '//15.83.240.98/Automation/Linux/scripts/usbkey_redirection.exe'
    cer = certificate.Cert('ROOTCA')
    find_cert = cer.check_cert()
    if find_cert is False:
        insert = cer.import_cert()
        if insert is False:
            report.fail_report('import cert fail', file_name)
            return False
        blast_usbr_log.info('import cert success for %s' % file_name)
    name, password = '******', 'password'
    case = thinpro_view.View(server_name, name, password)
    case.del_connection()
    case.create_connection()
    username = case.edit_connection()
    if username != gc.get_config(name):
        report.fail_report(username, file_name)
        return False
    enable_usbr = edit_connection(case)
    if enable_usbr is not True:
        report.fail_report(enable_usbr, file_name)
        return False
    case.start_connection()
    connect = case.log_on_desktop()
    if connect is not True:
        report.fail_report(connect, file_name)
        return False
    confirm_result = view_ftp.confirm_username(username)
    if confirm_result is False:
        case.logon_fail()
        report.fail_report('not confirm username', file_name)
        return False
        if case.check_logoff() is True:
            return True
        else:
            return 'VDI test success,logoff fail'
    else:
        if case.check_logoff() is True:
            return 'VDI test fail:%s' % result
        else:
            return 'VDI test fail:%s,and logoff fail' % result


def create_connection():
    case.del_connection()
    case.create_connection()
    username = case.edit_connection()
    if username != get_config.get_config(cert_name):
        report.fail_report(username, connect_with_cert)
        return False


def edit_connection(policy):
    max_loc = case.image_match('view_icon', 3)
    pag.rightClick(max_loc)
    pag.press('down', presses=2, interval=0.1)
    pag.press('enter')
    time.sleep(5)
    max_loc = case.image_match('Security', 3)
    pag.click(max_loc)
    time.sleep(1)
    pag.press('tab', presses=9, interval=0.1)
    pag.press('space')
예제 #13
0
from Test_Script import thinpro_view
from Test_Script import view_ftp
from Test_Script import common_function as report
from Test_Script import view_common_functions
from Test_Script import common_connection
import time
import os
from Test_Script import get_config


log_for_vmware_spec = report.logger()  # Create instance of log


def run_single(server_name, operation, name, password):
    case = thinpro_view.ViewSpec(server_name, name, password)
    name_in_config = get_config.get_config(name)
    common_connection.clear_connections("view")
    # case.del_vmware_in_task_bar()  # Delete vmware in task bar if exists
    # case.del_connection()
    # If vmware view exists in task bar, kill the process of vmware.
    max_loc = case.image_match('vmware_in_task_bar', 1)
    if max_loc is not None:
        os.popen('pkill vmware')
        vm_process = os.popen("ps -A | grep vmware").readlines()
        if len(vm_process) == 0:
            log_for_vmware_spec.info("Kill process for vmware successfully.")
    case.create_connection()
    if name == 'spec_username2':
        username = case.edit_connection_spec2()
    else:
        username = case.edit_connection()