Esempio n. 1
0
 def __init__(self, test_type):
     self.test_type = test_type
     self.dir = Utils.log_dir()
     self.test_log = TestLog(self.dir)
     self.driver = Utils.create_driver(sys.argv[2])
     self.utils = Utils(self.driver, self.test_log)
     print('init')
Esempio n. 2
0
def main():
    print 'in main'
    log_dir = Utils.log_dir()
    equip_view = EquipmentView(IsolatedLoginHandler())
    test_log = TestLog('Equipment View', log_dir)
    equip_view.run_equipment_view(Utils.create_driver(sys.argv[2]), test_log)
    test_log.close()
Esempio n. 3
0
    def run_alarms(self, driver, test_log):
        gui_lib = Utils(driver)

        self.login_manager.login()

        test_log.start('Alarms')
        test_helper = TestHelper(test_log, driver)

        driver.switch_to_default_content()
        gui_lib.click_element('menu_node_status')
        gui_lib.click_element('menu_node_alarms')

        driver.switch_to_frame('frame_content')
        # t = driver.find_element(By.XPATH, "//body/fieldset/legend").text
        # print('test', t)
        buttons = driver.find_elements_by_tag_name('button')
        # try test for visibility on the function below as it finds the buttons
        # before they are onscreen
        # (EC.visibility_of_element_located(
        WebDriverWait(driver, 20).until(EC.presence_of_all_elements_located((By.TAG_NAME, 'button')))


        # check that there are 3 buttons
        test_helper.assert_true(len(buttons) != 3, 'Not all buttons displayed', 'Check that all buttons displayed')

        # test that the buttons have text on them
        for btn in buttons:
            test_helper.assert_true(len(btn.text.strip()) == 0, 'No text on button', 'Check buttons have text')
            print(len(btn.text.strip()))

        # test_log.close()
        self.login_manager.logout()
Esempio n. 4
0
    def run_equipment_view(self, driver, test_log):
        gui_lib = Utils(driver)

        self.login_manager.login()
        test_helper = TestHelper(test_log, driver)
        test_log.start('Equipment View')

        driver.switch_to_default_content()
        prod_description = driver.find_element(By.ID, "top_menu_product_description").text
        # print('prodDescription', prodDescription)
        test_helper.assert_true(len(prod_description) == 0,
                                'Expected Product Name to be > 0 but was ' + str(len(prod_description)),
                                'Ensure Product Name visible')

        driver.switch_to_frame("frame_content")
        time.sleep(5) # added this as I got tired of trying to figure out why it wasn't waiting correctly below
        WebDriverWait(driver, 30).until(
            EC.visibility_of_element_located((By.ID, 'ChassisViewWidget1_container')))

        chassis = gui_lib.find_element_by_id('ChassisViewWidget1_container')
        # driver.execute_script("document.getElementById('ChassisViewWidget1_container').innerHTML=\"\";")
        # WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.ID, chassis)))
        # print('chassis text', chassis.text)
        test_helper.assert_true(len(chassis.text) == 0, 'Expected chassis to be displayed but was not',
                                'Ensure Chassis displayed')

        self.login_manager.logout()
Esempio n. 5
0
    def run_poe(self, driver, test_log):
        self.login_manager.login()

        gui_lib = Utils(driver)
        test_helper = TestHelper(test_log, driver)

        driver.switch_to_default_content()
        gui_lib.click_element('menu_node_system_tree')
        gui_lib.click_element('menu_node_poe_config')

        test_log.start('Power Over Ethernet')

        # gui_lib.find_element_by_id(driver, "PoEConfigWidget1_TW_table1")

        failure_count = 0
        driver.switch_to_frame("frame_content")
        table_element = "PoEConfigWidget1_TW_table"
        WebDriverWait(driver, 30).until(EC.visibility_of_element_located((By.ID, table_element)))
        table = driver.find_element_by_id(table_element)

        headers = table.find_elements_by_tag_name('th')

        test_helper.assert_true(len(headers) == 0, 'Expected Headers, got None', 'Testing Headers')

        # insert error to test. Uncomment when needed
        # driver.execute_script("document.getElementById('PoEConfigWidget1_TW_13_description').innerHTML=\"\";")

        interface = table.find_element_by_id("PoEConfigWidget1_TW_13_description").text

        interface_len = len(interface)
        test_helper.assert_true(len(interface) <= 0, 'Expected Interface length > 0', 'Testing Interfaces')

        time.sleep(2)

        self.login_manager.logout()
Esempio n. 6
0
def get_test_run_info(date):

    total_error_count = 0
    total_test_count = 0

    for run in Utils.get_dirs(os.path.join(logs_dir, date)):
        for ip_in_runs in Utils.get_dirs(os.path.join(logs_dir, date, run)):
            for xml in os.listdir(os.path.join(logs_dir, date, run,
                                               ip_in_runs)):
                if xml.startswith('testresult'):
                    fname = os.path.join(logs_dir, date, run, ip_in_runs, xml)
                    tree = ET.parse(fname)

                    test_count = tree.find('totalTestCount').get(
                        'totalTestCount')
                    error_count = tree.find('errorCount').get('errorCount')

                    total_test_count += int(test_count)
                    total_error_count += int(error_count)

    return {
        'date': date,
        'total_test_count': total_test_count,
        'total_error_count': total_error_count
    }
Esempio n. 7
0
def main():
    print('main')
    log_dir = Utils.log_dir()
    sensors = Sensors(IsolatedLoginHandler())
    test_log = TestLog('Sensors', log_dir)
    sensors.run_sensors(Utils.create_driver(sys.argv[2]), test_log)
    test_log.close()
Esempio n. 8
0
    def __init__(self, test_type):
        self.test_type = test_type
        self.dir = Utils.log_dir()
        self.test_log = TestLog(self.dir)
        self.driver = Utils.create_driver(sys.argv[2])

        self.utils = Utils(self.driver, self.test_log)
        print('init')
Esempio n. 9
0
def main():
    print('main')
    driver = Utils.create_driver(sys.argv[2])
    log_dir = Utils.log_dir()
    alarms = Alarms(IsolatedLoginHandler(driver))
    test_log = TestLog('Alarms', log_dir)
    alarms.run_alarms(driver, test_log)
    test_log.close()
Esempio n. 10
0
def main():
    driver = Utils.create_driver(sys.argv[2])
    log_dir = Utils.log_dir()
    test_log = TestLog(PortManager, log_dir)
    # create instance of class here and then  run method of class 
    port_manager = PortManager(IsolatedLoginHandler(driver))
    port_manager.run_port_manager(driver, test_log)
    test_log.close()
Esempio n. 11
0
def main():
    driver = Utils.create_driver(sys.argv[2])
    log_dir = Utils.log_dir()
    # Utils.delete_existing_logfile(log_dir)
    test_log = TestLog(EventLog, log_dir)
    # create instance of class here and then  run method of class 
    event_log = EventLog(IsolatedLoginHandler(driver))
    event_log.run_event_log(driver, test_log)
    test_log.close()
Esempio n. 12
0
class SmokeTest:
    def __init__(self, driver, test_log, test_helper):
        self.test_log = test_log
        self.driver = driver
        self.gui_lib = Utils(driver, test_log)
        # self.test_helper = TestHelper(self.test_log, self.driver)
        self.test_helper = test_helper

    def create(self, screen_name):

        try:
            self.gui_lib.navigate_to_screen(screen_name)
            self.gui_lib.is_alert_present(self.driver)

            WebDriverWait(self.driver, 45).until(
                EC.visibility_of_element_located((By.ID, "contentInner")))

            content_inner = self.driver.find_element(By.ID, "contentInner")
            error_elements = content_inner.find_elements(
                By.CLASS_NAME, "error")
            name = "/".join(screen_name)

            if not error_elements:
                child_elements = content_inner.find_elements(
                    By.XPATH, "div[starts-with(@class, "
                    "'widget_')]")
                for child in child_elements:

                    try:
                        child.find_element(By.XPATH, "*")
                    except NoSuchElementException as e:
                        self.test_helper.assert_true(
                            True, name + ' page not loaded OK', name)
            else:
                self.test_helper.assert_true(True,
                                             name + ' page not loaded OK',
                                             name)

        except StaleElementReferenceException as e:
            print('StaleElementException', e)
        except Exception as e:
            name = ""
            count = 1

            for s in screen_name:
                if not count == len(screen_name):
                    name += s + '/'
                    count += 1
                else:
                    name += s

            self.test_helper.assert_true(True, name + ' not displayed', name)
            print('Failure *******', e)

        return True
Esempio n. 13
0
def main():
    parser = OptionParser(usage="usage: %prog ipAddress browser")
    # parser.add_option("-c", "--chelp", help="Add arguments for IP Address for radio and target browser")
    (options, args) = parser.parse_args()

    if len(args) != 2:
        parser.error("wrong number of arguments")

    TEST_TYPE = 'smoketest'
    run_all = RunAll(TEST_TYPE)
    run_all.run_all()

    Utils.print_tree(Utils.log_dir(), TEST_TYPE)
Esempio n. 14
0
    def __init__(self, driver, test_helper, test_log):
        self.utils = Utils(driver, None)
        self.driver = driver
        self.login_info = {}
        self.test_helper = test_helper
        self.test_log = test_log

        try:
            with open("login.config") as f:
                content = f.readlines()
                for line in content:
                    parts = line.strip().split(',', 2)
                    print("parts", parts)
                    self.login_info[parts[0]] = (parts[1], parts[2])
        except:
            pass
Esempio n. 15
0
 def __init__(self, log, driver, test_type, utils):
     self.test_type = test_type
     self.log_dir = Utils.log_dir()
     self.driver = driver
     self.log = log
     self.error_count = 0
     self.utils = utils
Esempio n. 16
0
 def __init__(self, log, driver, test_type, utils):
     self.test_type = test_type
     self.log_dir = Utils.log_dir()
     self.driver = driver
     self.log = log
     self.error_count = 0
     self.utils = utils
Esempio n. 17
0
    def run_system_information(self, driver, test_log):
        gui_lib = Utils(driver)

        self.login_manager.login()

        usr = "******"
        pw = "admin123"
        timetup = time.localtime()
        iso = time.strftime('%Y-%m-%d %H:%M:%S ', timetup)
        print "=====", iso, "====="

        test_log.start('System Information')
        test_helper = TestHelper(test_log, driver)

        driver.switch_to_default_content()

        gui_lib.click_element('menu_node_system_tree')
        gui_lib.click_element('menu_node_system_info')

        driver.switch_to_frame("frame_content")
        table = driver.find_element_by_id("SystemInformationWidget1_TW_table")
        WebDriverWait(table, 10).until(EC.presence_of_element_located((By.ID, "SystemInformationWidget1_TW_0")))

        headers = table.find_elements_by_tag_name('th')
        test_helper.assert_true(len(headers) == 0, 'Expected Headers, got None', 'Testing Headers')

        # hwVersion = table.find_element_by_id('SystemInformationWidget1_TW_0_1')
        # driver.execute_script("document.getElementById('SystemInformationWidget1_TW_0_1_renderer').innerHTML=\"\";")
        # hwVersionLen = len(hwVersion.text)
        # testHelper.assertTrue(len(hwVersion.text) > 0, 'Expected Headers, got None', 'Testing Headers')

        # assert hwVersionLen > 0, ('Expected length of Hardware Version to be greater than zero but was ', hwVersionLen)

        sw_version = table.find_element_by_id('SystemInformationWidget1_TW_1_1')
        # driver.execute_script("document.getElementById('SystemInformationWidget1_TW_1_1').innerHTML=\"\";")
        test_helper.assert_true(len(sw_version.text) == 0, 'Expected SW Version to be > 0',
                                'Testing SW Version Length')
        # assert swVersionLen > 0, ('Expected length of Software Version to be greater than zero but was ', swVersionLen)

        # firmVersion = table.find_element_by_id('SystemInformationWidget1_TW_2_1')
        # firmVersionLen = len(firmVersion.text)
        # assert firmVersionLen > 0, ('Expected length of Firmware Version to be greater than zero but was ', firmVersionLen)

        time.sleep(2)
        self.login_manager.logout()
Esempio n. 18
0
    def run_port_manager(self, driver, test_log):
        gui_lib = Utils(driver)
        self.login_manager.login()

        test_log.start('Port Manager')
        test_helper = TestHelper(test_log, driver)

        driver.switch_to_default_content()
        gui_lib.click_element('menu_node_ethernet_tree')
        gui_lib.click_element('menu_node_ethernet')

        # WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "menu_node_10")))
        driver.switch_to_frame('frame_content')
        try:
            WebDriverWait(driver, 30).until(
                EC.visibility_of_element_located((By.ID, 'PortSettingsWidget1intSet_TW_table')))
        except TimeoutException:
            test_log.log_info('TimeoutException while waiting for Port Settings table')

        table = driver.find_element_by_id('PortSettingsWidget1intSet_TW_table')
        headers = table.find_elements_by_tag_name('th')
        headers_list = []
        headers_arr = ['', 'Status1', 'Port', 'Enable', 'Description', 'Speed - Duplex', 'Default\nUser Priority',
                       'MAC Address', 'MTU']

        header_ids = ['PortSettingsWidget1intSet_TW_table_header_entity_index',
                      'PortSettingsWidget1intSet_TW_table_header_operational_status',
                      'PortSettingsWidget1intSet_TW_table_header_port',
                      'PortSettingsWidget1intSet_TW_table_header_admin_status',
                      'PortSettingsWidget1intSet_TW_table_header_description',
                      'PortSettingsWidget1intSet_TW_table_header_user_duplex',
                      'PortSettingsWidget1intSet_TW_table_header_priority',
                      'PortSettingsWidget1intSet_TW_table_header_mac',
                      'PortSettingsWidget1intSet_TW_table_header_mtu']

        test = Utils.build_inner_html_array(Utils.build_id_array(table))

        # driver.execute_script(test)
        # these tests only check that headers are displayed. Wont flag if there are any missing,
        # the order incorrect etc. It is only a all or none deal
        for header in headers:
            headers_list.append(header.text)

        # uncomment to remove headers for testing
        # for header in test:
        #     driver.execute_script(header)

        for i in range(len(headers_list)):
            header = headers_list[i]
            header_text_len = len(header)
            test_helper.assert_true(headers[i].text != header,
                                    'Expected ' + header + ' to be > 0 but was ' + str(header_text_len),
                                    'Ensure ' + header + ' visible')

        rows = table.find_elements_by_tag_name('tr')
        test_helper.assert_true(len(rows) <= 0, str(len(rows)) + ' Port Settings rows displayed ',
                                'Ensure Port Settings rows displayed ')

        self.login_manager.logout()
Esempio n. 19
0
def get_test_run_info(date):

    total_error_count = 0
    total_test_count = 0

    for run in Utils.get_dirs(os.path.join(logs_dir, date)):
        for ip_in_runs in Utils.get_dirs(os.path.join(logs_dir, date, run)):
            for xml in os.listdir(os.path.join(logs_dir, date, run, ip_in_runs)):
                if xml.startswith('testresult'):
                    fname = os.path.join(logs_dir, date, run, ip_in_runs, xml)
                    tree = ET.parse(fname)

                    test_count = tree.find('totalTestCount').get('totalTestCount')
                    error_count = tree.find('errorCount').get('errorCount')

                    total_test_count += int(test_count)
                    total_error_count += int(error_count)

    return {'date': date, 'total_test_count': total_test_count, 'total_error_count': total_error_count}
Esempio n. 20
0
    def run_sensors(self, driver, test_log):
        gui_lib = Utils(driver)
        self.login_manager.login()

        test_log.start('Sensors')
        test_helper = TestHelper(test_log, driver)

        driver.switch_to_default_content()
        gui_lib.click_element('menu_node_sensors')

        driver.switch_to_frame('frame_content')

        title = driver.find_element(By.XPATH, "//body/fieldset/legend").text
        test_helper.assert_true(len(title) == 0, 'Expected page title, got None', 'Test page title is displayed')

        table = gui_lib.find_element_by_id('tableWidget1_table')
        # find the table header as a delay
        driver.find_element_by_id('tableWidget1_table_header')

        table_rows = table.find_elements_by_tag_name('tr')
        print('table_rows', table_rows)
        self.login_manager.logout()
Esempio n. 21
0
    def run_date_time(self, driver, test_log):

        gui_lib = Utils(driver)

        self.login_manager.login()

        test_log.start('Date Time')
        test_helper = TestHelper(test_log, driver)

        failure_count = 0

        driver.switch_to_default_content()
        gui_lib.click_element('menu_node_system_tree')
        gui_lib.click_element('menu_node_date_time')

        # gui_lib.click_element(driver, "menu_node_9")
        driver.switch_to_frame("frame_content")

        table = driver.find_element_by_id("DateTimeWidget1_TW_table")
        WebDriverWait(table, 20).until(
            EC.presence_of_element_located((By.CLASS_NAME, "TableWidget_verticalTableHeading")))

        headers = table.find_elements_by_class_name('TableWidget_verticalTableHeading')

        test_helper.assert_true(len(headers) == 0, 'Expected Headers, got None', 'Testing Headers')

        # driver.execute_script("document.getElementById('DateTimeWidget1_TW_1_1').innerHTML=\"\";")
        mycalendar = table.find_element_by_id('DateTimeWidget1_TW_1_1')
        test_helper.assert_true(len(mycalendar.text) <= 0, 'No DateTimeWidget displayed', 'Testing DateTime widget')

        # driver.execute_script("document.getElementById('DateTimeWidget1_TW_3_1').innerHTML=\"\";")
        time_zone = table.find_element_by_id('DateTimeWidget1_TW_3_1')
        test_helper.assert_true(len(time_zone.text) <= 0, 'Expected TimeZone length > 0', 'Testing Timezone')

        # testLog.end_log2()
        self.login_manager.logout()
Esempio n. 22
0
    def __init__(self, driver, test_helper, test_log):
        self.utils = Utils(driver, None)
        self.driver = driver
        self.login_info = {}
        self.test_helper = test_helper
        self.test_log = test_log

        try:
            with open("login.config") as f:
                content = f.readlines()
                for line in content:
                    parts = line.strip().split(',', 2)
                    print("parts", parts)
                    self.login_info[parts[0]] = (parts[1], parts[2])
        except:
            pass
Esempio n. 23
0
    def do_expand(driver, level):
        expanded = False
        list = []
        root = driver.find_element(By.CLASS_NAME,'menu-tree-root');
        menu_items_by_level = root.find_elements_by_xpath(".//div[@aria-level='" + str(level) + "']")
        # menu_items_by_level = driver.find_elements_by_xpath("//a[@href='undefined']")

        for m in menu_items_by_level:
            if Utils.open_folder(m) < 1:
                list.append(m)
            else:
                expanded = True

        if expanded:
            sub_list = RunAll.do_expand(driver, level + 1)
            for i in sub_list:
                list.append(i)
        return list
class IsolatedLoginHandler(object):
    def __init__(self, driver):
        self.driver = driver
        self.utils = Utils(driver)

    def login(self):
        # self.utils.delete_existing_logfile()
        self.utils.startBrowser(self.driver)
        self.utils.login(self.driver, 'root', 'admin123')

    def logout(self):
        self.driver.switch_to_default_content()
        self.utils.logout(self.driver)
Esempio n. 25
0
class IsolatedLoginHandler(object):
    def __init__(self, driver):
        self.driver = driver
        self.utils = Utils(driver)

    def login(self):
        # self.utils.delete_existing_logfile()
        self.utils.start_browser(self.driver)
        self.utils.login(self.driver, '', '')

    def logout(self):
        self.driver.switch_to_default_content()
        self.utils.logout(self.driver)
Esempio n. 26
0
class LoginHandler(object):
    def __init__(self, driver, test_helper, test_log):
        self.utils = Utils(driver, None)
        self.driver = driver
        self.login_info = {}
        self.test_helper = test_helper
        self.test_log = test_log

        try:
            with open("login.config") as f:
                content = f.readlines()
                for line in content:
                    parts = line.strip().split(',', 2)
                    print("parts", parts)
                    self.login_info[parts[0]] = (parts[1], parts[2])
        except:
            pass

    def login(self):
        print('doing nothing, already logged from start()')

    def logout(self):
        print('normal logout')

    def start(self):

        self.utils.start_browser(self.driver)
        override = self.login_info.get(sys.argv[1])
        print("get override", override, sys.argv[1])
        if override is None:
            self.utils.login(self.driver, 'root', 'admin123', self.test_helper,
                             self.test_log)
        else:
            self.utils.login(self.driver, override[0], override[1],
                             self.test_helper, self.test_log)

    def end(self):
        # self.driver.switch_to_default_content()
        self.utils.logout(self.driver)
Esempio n. 27
0
class LoginHandler(object):
    def __init__(self, driver, test_helper, test_log):
        self.utils = Utils(driver, None)
        self.driver = driver
        self.login_info = {}
        self.test_helper = test_helper
        self.test_log = test_log

        try:
            with open("login.config") as f:
                content = f.readlines()
                for line in content:
                    parts = line.strip().split(',', 2)
                    print("parts", parts)
                    self.login_info[parts[0]] = (parts[1], parts[2])
        except:
            pass


    def login(self):
        print('doing nothing, already logged from start()')

    def logout(self):
        print('normal logout')

    def start(self):

        self.utils.startBrowser(self.driver)
        override = self.login_info.get(sys.argv[1])
        print("get override", override, sys.argv[1])
        if override is None:
            self.utils.login(self.driver, 'root', 'admin123', self.test_helper, self.test_log)
        else:
            self.utils.login(self.driver, override[0], override[1], self.test_helper, self.test_log)

    def end(self):
        # self.driver.switch_to_default_content()
        self.utils.logout(self.driver)
Esempio n. 28
0
    def __init__(self, dir, test_type="smoketest"):
        """Class to log errors"""
        self.test_type = test_type
        self.log = None
        self.doc = None
        self.root = ET.Element("tests")
        self.root.append(Comment('Auto Generated in TestLog.py'))
        self.num_tests_run = 0
        self.time = time.localtime()
        self.all_tests_start = time.strftime('%d %B %Y %H:%M:%S', self.time)
        self.url_friendly_start = time.strftime('%d_%B_%Y', self.time)
        self.dir = dir
        self.ipAddress = Utils.format_ip_address(sys.argv[1])

        path = os.path.join(GlobalFuncs.path())

        el = ET.SubElement(self.root, 'allTestsStart')
        el.set('allTestsStart', self.all_tests_start)
        el.set("runNumber", path.split(os.sep)[-1])
        el.set('ipAddress', self.ipAddress)

        self.screenshots = []
Esempio n. 29
0
    def run_system_about(self, driver, test_log):
        gui_lib = Utils(driver)

        self.login_manager.login()
        test_log.start('System About')

        test_helper = TestHelper(test_log, driver)

        driver.switch_to_default_content()
        # WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "menu_node_7_tree")))

        # driver.find_element_by_id("menu_node_7_tree").click()
        # time.sleep(2)
        # WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "menu_node_10")))

        gui_lib.click_element("top_menu_help")
        gui_lib.click_element("help_about")

        original_window_handle = driver.current_window_handle

        driver.switch_to_window(driver.window_handles[1])

        # about = driver.find_element(By.XPATH, "//body/fieldset/legend").text
        # assert about == "About", ("Expected About but got ", about)

        title = 'Aviat Networks Converged Transport Router'
        # webTitle = driver.find_element_by_xpath('//body/div/div/h3').text

        # assert title == webTitle, ('Expected ', title, ' but got ', webTitle)
        #
        # # WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'licenses')))
        # time.sleep(2)

        licenses = gui_lib.find_element('licenses')
        # driver.execute_script("document.getElementById('licenses').innerHTML=\"\";")
        test_helper.assert_true(len(licenses.text) == 0, 'Expected SW Version to be > 0',
                               'Checking Licenses text not empty')

        driver.close()

        driver.switch_to_window(original_window_handle)

        time.sleep(2)
        self.login_manager.logout()
Esempio n. 30
0
    def run_event_log(self, driver, test_log):
        gui_lib = Utils(driver)
        self.login_manager.login()

        test_log.start('EventLog')
        test_helper = TestHelper(test_log, driver)

        driver.switch_to_default_content()
        gui_lib.click_element('menu_node_system_tree')
        gui_lib.click_element('menu_node_status')
        gui_lib.click_element('menu_node_event_log')

        driver.switch_to_frame('frame_content')

        table = driver.find_element_by_id('EventBrowserWidget1_table')
        headers = table.find_elements_by_tag_name('th')

        headers_list = []
        for header in headers:
            print('headers', header.text)
            headers_list.append(header.text)

        for i in range(len(headers)):
            header = headers[i].text
            header_text_len = len(header)
            test_helper.assert_true(header_text_len <= 0,
                                    'Expected ' + header + ' to be > 0 but was ' + str(header_text_len),
                                    'Ensure ' + header + ' visible')

        sleep(10)
        rows = table.find_elements_by_tag_name('tr')

        test_helper.assert_true(len(rows) <= 0, str(len(rows)) + ' Event Log rows displayed ',
                                'Ensure Event Log rows displayed ')

        # test_log.close()
        self.login_manager.logout()
Esempio n. 31
0
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from smoketest.mylib.utils import Utils


def ensure_path_exists(path):
    import errno
    try:
        os.makedirs(path)
    except OSError as exception:
        if exception.errno != errno.EEXIST:
            raise


logs_dir = os.path.join(Utils.log_dir(), 'logs')
sub_path = requests.get('http://localhost:3000/next').content.decode('utf-8')
path_to_dir = os.path.join(os.getcwd(), 'logs', *sub_path.split('/'))
ensure_path_exists(path_to_dir)
# except ConnectionError:
#     print "Need to start webserver. Run ./startup.sh from smoketest dir", os.getcwd()


def signal_handler(sig, frame):
    print('You pressed Ctrl+C!')
    [p.kill() for p in opens]
    sys.exit(0)


signal.signal(signal.SIGINT, signal_handler)
Esempio n. 32
0
def main():
    log_dir = Utils.log_dir()
    system_info = SystemInformation(IsolatedLoginHandler())
    test_log = TestLog('System Information', log_dir)
    system_info.run_system_information(Utils.create_driver(sys.argv[2]), test_log)
    test_log.close()
Esempio n. 33
0
class RunAll():
    def __init__(self, test_type):
        self.dir = Utils.log_dir()
        self.test_log = TestLog(self.dir, test_type)
        self.driver = Utils.create_driver(sys.argv[2])
        self.utils = Utils(self.driver, self.test_log)
        self.test_type = test_type
        print('init')

    def run_all(self):
        self.utils.delete_existing_dir()

        login_handler = LoginHandler(self.driver)
        login_handler.start()

        self.write_config_test(self.driver)

        # test_log = TestLog(self.dir)
        # test_helper = TestHelper(self.test_log, self.driver)

        login_handler.end()
        # self.test_log.close()

    def write_config_test(self, driver):
        # test_log = TestLog(self.dir)
        test_helper = TestHelper(self.test_log, driver, self.test_type)

        self.utils.navigate_to_screen("System Configuration/System Information")
        driver.switch_to_default_content()

        # driver.switch_to_frame("frame_content")
        time.sleep(5)
        WebDriverWait(driver, 20).until(
            EC.visibility_of_element_located((By.ID, "SystemInformationWidget1_TW_3_1_renderer")))

        node_name = driver.find_element_by_id("SystemInformationWidget1_TW_3_1_renderer_input")
        contact = driver.find_element_by_id("SystemInformationWidget1_TW_5_1_renderer_input")
        location = driver.find_element_by_id("SystemInformationWidget1_TW_6_1_renderer_input")

        node_name.clear()
        contact.clear()
        location.clear()

        node_name.send_keys(self.random_letters(10))
        contact.send_keys(self.random_letters(30))
        location.send_keys(self.random_letters(30))

        initial_node_name = node_name.get_attribute("value")
        initial_contact = contact.get_attribute("value")
        initial_location = location.get_attribute("value")

        apply_btn = driver.find_element_by_class_name("apply")
        apply_btn.is_enabled()
        apply_btn.click()

        # self.utils.navigate_to_screen("System Configuration/System Information")
        print('about to press refresh')
        ActionChains(driver).key_down(Keys.F5).perform()
        print('refresh pressed after this point')

        WebDriverWait(driver, 30).until(
            EC.visibility_of_element_located((By.ID, "SystemInformationWidget1_TW_3_1_renderer")))

        updated_node_name = driver.find_element_by_id("SystemInformationWidget1_TW_3_1_renderer_input").get_attribute(
            "value")
        updated_contact = driver.find_element_by_id("SystemInformationWidget1_TW_5_1_renderer_input").get_attribute(
            "value")
        updated_location = driver.find_element_by_id("SystemInformationWidget1_TW_6_1_renderer_input").get_attribute(
            "value")

        print(initial_node_name, updated_node_name)
        print(initial_contact, updated_contact)
        print(initial_location, updated_location)

        v1 = self.compare_vals(initial_node_name, updated_node_name)
        v2 = self.compare_vals(initial_contact, updated_contact)
        v3 = self.compare_vals(initial_location, updated_location)

        # test_helper.assert_true(initial_node_name != updated_node_name,
        #                         'Expected ' + initial_node_name + ' but was ' + updated_node_name,
        #                         'Ensure Node name is persisted')
        test_helper.assert_true(False,
                                'Expected this but was that',
                                'Ensure Node name is persisted')
        print(v1, v2, v3)
        self.test_log.close()


    def compare_vals(self, initial_node_name, updated_node_name):
        return initial_node_name == updated_node_name


    import string


    def random_letters(self, size=6, chars=string.ascii_letters + string.digits):
        import random

        return ''.join(random.choice(chars) for _ in range(size))
Esempio n. 34
0
class SmokeTest:
    def __init__(self, driver, test_log, test_helper):
        self.test_log = test_log
        self.driver = driver
        self.gui_lib = Utils(driver, test_log)
        # self.test_helper = TestHelper(self.test_log, self.driver)
        self.test_helper = test_helper

    # def __navigate_to_screen(self, screen_name):
    #     breadcrumbs = screen_name.split('/')
    #     self.__navigate_to_location(breadcrumbs)
    #     self.driver.switch_to_frame('frame_content')
    #     self.test_log.start(breadcrumbs[-1])

    def create_equipment_test(self, screen_name):
        self.gui_lib.navigate_to_screen(screen_name)

        # self.driver.switch_to_frame("frame_content")
        time.sleep(5)  # added this as I got tired of trying to figure out why it wasn't waiting correctly below
        WebDriverWait(self.driver, 50).until(
            EC.visibility_of_element_located((By.ID, 'ChassisViewWidget1_container')))

        elem = self.driver.find_element_by_xpath("//canvas")

        chassis = self.driver.find_element_by_id('ChassisViewWidget1_container')

        # driver.execute_script("document.getElementById('ChassisViewWidget1_container').innerHTML=\"\";")
        # WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.ID, chassis)))

        self.test_helper.assert_true(len(chassis.text) == 0, 'Expected chassis to be displayed but was not',
                                     'Ensure Chassis displayed')

    def create_button_test(self, screen_name, buttons, finder):
        self.gui_lib.navigate_to_screen(screen_name)

        # time.sleep(5)
        # self.driver.execute_script(
        #     "document.getElementsByClassName('alarms_resetChangeIndicators')[0].style.display=\"none\";")
        # self.driver.execute_script(
        #     "document.getElementsByClassName('alarms_resetChangeIndicators')[0].innerHTML=\"\";")

        for button in buttons:
            try:
                button_el = WebDriverWait(self.driver, 30).until(finder.find_buttons(button))
                button_text = button_el.text
                self.test_helper.assert_true(len(button_text) == 0,
                                             'Expected ' + button_text + ' to be > 0, but was ' + str(
                                                 len(button_text)),
                                             'Ensure ' + button_text + ' is displayed.')
            except TimeoutException:
                self.test_helper.assert_true(True,
                                             'Expected ' + button + ' but TimeoutException occurred.',
                                             'Ensure ' + button + ' is displayed.')
                break

    def create2(self, screen_name, items_to_test, finder, just_headers=False):
        self.gui_lib.navigate_to_screen(screen_name)

        # time.sleep(5)
        # self.driver.execute_script("document.getElementById('tableWidget1_3_mapping').innerHTML=\"\";")

        values = []

        for item in items_to_test:
            try:
                label_name = WebDriverWait(self.driver, 30).until(finder.find_label(item))

                if not just_headers:
                    vals = finder.find_values(label_name)
                    values.append(vals)
                else:
                    label = label_name.find_element_by_class_name('syslog_heading')
                    self.test_helper.assert_true(len(label.text) == 0,
                                                 'Expected ' + label.text + ' to be > 0, but was ' + str(
                                                     len(label.text)),
                                                 'Ensure ' + label.text + ' is displayed.')
            except TimeoutException:
                self.test_helper.assert_true(True,
                                             'Expected ' + item + ' but TimeoutException occurred.',
                                             'Ensure ' + item + ' is displayed.')
                break

        for idx, row in enumerate(values):
            name = items_to_test[idx]
            self.test_helper.assert_true(len(name) == 0, 'Expected ' + name + ' to be > 0 but was ' + str(
                len(name)), 'Ensure ' + name + ' visible.')
            for td in row:
                self.test_helper.assert_true(len(td) == 0,
                                             'Expected ' + td + ' to be > 0 but was ' + str(
                                                 len(td)),
                                             'Ensure ' + name + ' data visible.')

    def fix_screen_name(self, name):
        name.split('/')

    def create(self, screen_name):

        try:
            self.gui_lib.navigate_to_screen(screen_name)
            self.gui_lib.is_alert_present(self.driver)

            time.sleep(3)
            # self.driver.execute_script("document.getElementById('tableWidget1_3_mapping').innerHTML=\"\";")

            # WebDriverWait(self.driver, 30).until(EC.invisibility_of_element_located((By.ID, "page_loader_container")))
            WebDriverWait(self.driver, 45).until(EC.invisibility_of_element_located((By.CLASS_NAME, "loading_tag")))

            warning_elements = self.driver.find_elements_by_class_name('warning')

            # attr = warning_elements.get_attribute('class')
            # print('warning_elements classname', screen_name, attr, warning_elements[0].text)

            # if attr == 'warning':
            #     display_prop = warning_elements.value_of_css_property('display')
            #     print('display_prop', screen_name, display_prop)

            for el in warning_elements:
                display_prop = el.value_of_css_property('display')

                page_name = screen_name.split('/').pop().replace(' ', '_')

                if display_prop == u'block':
                    self.test_helper.assert_true(True,
                                                 page_name + ' page not loaded OK',
                                                 page_name)
                else:
                    self.test_helper.assert_true(False,
                                                 'Ensure page is displayed.',
                                                 page_name + ' page loaded OK')

        except StaleElementReferenceException as e:
            print('StaleElementException', e)

        return True
Esempio n. 35
0
 def __init__(self, driver, test_log, test_helper):
     self.test_log = test_log
     self.driver = driver
     self.gui_lib = Utils(driver, test_log)
     # self.test_helper = TestHelper(self.test_log, self.driver)
     self.test_helper = test_helper
Esempio n. 36
0
class RunAll:
    def __init__(self, test_type):
        self.test_type = test_type
        self.dir = Utils.log_dir()
        self.test_log = TestLog(self.dir)
        self.driver = Utils.create_driver(sys.argv[2])

        self.utils = Utils(self.driver, self.test_log)
        print('init')

    def run_all(self):
        self.run_smoke_test()

    @staticmethod
    def do_expand(driver, level):
        expanded = False
        list = []
        root = driver.find_element(By.CLASS_NAME,'menu-tree-root');
        menu_items_by_level = root.find_elements_by_xpath(".//div[@aria-level='" + str(level) + "']")
        # menu_items_by_level = driver.find_elements_by_xpath("//a[@href='undefined']")

        for m in menu_items_by_level:
            if Utils.open_folder(m) < 1:
                list.append(m)
            else:
                expanded = True

        if expanded:
            sub_list = RunAll.do_expand(driver, level + 1)
            for i in sub_list:
                list.append(i)
        return list

    @staticmethod
    def make_path(el):
        res = []
        cur = el
        count = 0

# todo fix population of menus. Not all are getting into list
        try:
            while cur:

                if cur.get_attribute('class') == "menu-tree-item":
                    try:
                        res.insert(0, cur.find_element(By.XPATH, "div[@class='menu-tree-row' or @class='menu-tree-row "
                                                                 "selected']").text)
                        count += 1
                    except:
                        print("not found", cur)

                cur = cur.find_element(By.XPATH, "..")
        except NoSuchElementException:
            return res

    @staticmethod
    def get_screens(driver):
        items_list = RunAll.do_expand(driver, 1)
        result = []

        for item in items_list:
            path = RunAll.make_path(item)
            result.append(path)

        return result

    def run_smoke_test(self):
        # driver = Utils.create_driver(sys.argv[2])
        # utils = Utils(driver, self.test_log)
        self.utils.delete_existing_dir()

        # self.test_log.start('login')
        test_helper = TestHelper(self.test_log, self.driver, self.test_type, self.utils)
        login_handler = LoginHandler(self.driver, test_helper, self.test_log)
        login_handler.start()

        # test_log = TestLog(self.dir)

        smoke_test = SmokeTest(self.driver, self.test_log, test_helper)
        try:
            side_menu = WebDriverWait(self.driver, 35).until(
                EC.presence_of_element_located((By.CLASS_NAME, "menu-tree-item")))
        except e:
            test_helper.assert_false(True, "unable to find side menu", "side_menu")
            login_handler.end()
            self.test_log.close()
            raise e

        # if you want to run individual tests follow format below
        # smoke_test.create(["Status", "Alarms"])
        # smoke_test.create(["Status", "System Log"])
        # smoke_test.create(["Status", "Equipment"])
        # smoke_test.create(["System Configuration", "Management IP"])
        # smoke_test.create(["Admin", "Advanced"])
        # smoke_test.create(["System Configuration", "SNMP"])
        # smoke_test.create(["System Configuration", "DNS"])
        # smoke_test.create(["Admin", "User Management", "Local"])
        # smoke_test.create(["Switching and Routing", "Interfaces"])
        # smoke_test.create(["Switching and Routing", "RMON", "Quarter Hour"])
#        smoke_test.create(["Switching and Routing", "Quality of Service", "Policies"])

        # OR
        
        # if you want to run over all the screens, remove the empty array and uncomment rest
        tests = RunAll.get_screens(self.driver)
#        tests = []
        
        for test in tests:
            try:
                if not smoke_test.create(test):
                    return False
            except Exception as ex:
                # error_file.write("Failed running: " + test + ex + '\r\n')
                print("Failed running ", test, ex)

        login_handler.end()
        self.test_log.close()
 def __init__(self, driver):
     self.driver = driver
     self.utils = Utils(driver)
Esempio n. 38
0
def main():
    log_dir = Utils.log_dir()
    about = SystemAbout(IsolatedLoginHandler())
    test_log = TestLog('System About', log_dir)
    about.run_system_about(Utils.create_driver(sys.argv[2]), test_log)
    test_log.close()
Esempio n. 39
0
def main():
    log_dir = Utils.log_dir()
    poe = PowerOverEthernet(IsolatedLoginHandler())
    test_log = TestLog('Power Over Ethernet', log_dir)
    poe.run_poe(Utils.create_driver(sys.argv[2]), test_log)
    test_log.close()
Esempio n. 40
0
 def __init__(self, driver):
     self.driver = driver
     self.utils = Utils(driver)
Esempio n. 41
0
 def __init__(self, driver, test_log, test_helper):
     self.test_log = test_log
     self.driver = driver
     self.gui_lib = Utils(driver, test_log)
     # self.test_helper = TestHelper(self.test_log, self.driver)
     self.test_helper = test_helper
Esempio n. 42
0
def main():
    log_dir = Utils.log_dir()
    date_time = DateTime(IsolatedLoginHandler())
    test_log = TestLog('Date Time', log_dir)
    date_time.run_date_time(Utils.create_driver(sys.argv[2]), test_log)
    test_log.close()
Esempio n. 43
0
class RunAll():
    def __init__(self, test_type):
        self.test_type = test_type
        self.dir = Utils.log_dir()
        self.test_log = TestLog(self.dir)
        self.driver = Utils.create_driver(sys.argv[2])
        self.utils = Utils(self.driver, self.test_log)
        print('init')

    def run_all(self):

        self.run_smoke_test()
        # active_sw_version = Utils.get_active_sw_version()
        # latest_swpack = Utils.get_latest_sw_pack_version()
        #
        # # dummies for tests
        # active_sw_version = '3.6.1(41.5629)' #'master.12.1919'
        # latest_swpack = active_sw_version  # 'master.12.1919'
        #
        # swpack = determine_latest_swpack(reformat_for_compare(active_sw_version), reformat_for_compare(latest_swpack))
        # get_latest = must_download_latest(reformat_for_compare(active_sw_version), reformat_for_compare(latest_swpack))
        #
        # if get_latest:
        #     print ('Get latest sw pack...')
        #     Utils.upload_latest(self.run_smoke_test)
        # else:
        #     print ('Using latest, don\'t need to upload latest... ')
        #     self.run_smoke_test()
        #     # self.write_config_test(self.driver)

    @staticmethod
    def get_num_screens(driver):
        num_screens = 0
        side_menu_folders = driver.find_elements_by_xpath("//div[@class='side_menu_tree']")
        for folder in side_menu_folders:
            id_attr = folder.get_attribute('id')
            root_folder = driver.find_element_by_id(id_attr)
            root_folder.click()
            individual_pages = root_folder.find_elements_by_tag_name('a')
            for page in individual_pages:
                WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.LINK_TEXT, page.text)))
                if page.text != '':
                    num_screens += 1
                    # print('page', page.text, num_screens)
        return num_screens

    def run_smoke_test(self):
        print('Gonna run the smoketests...')
        # driver = Utils.create_driver(sys.argv[2])
        # utils = Utils(driver, self.test_log)
        self.utils.delete_existing_dir()

        login_handler = LoginHandler(self.driver)
        login_handler.start()

        test_log = TestLog(self.dir)
        test_helper = TestHelper(test_log, self.driver, self.test_type)

        # Uncomment this to get coverage graph
        # test_log.add_num_screens(RunAll.get_num_screens(self.driver))
        # WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.ID, 'menu_node_equipment')))
        # self.driver.find_element_by_id('menu_node_equipment').click()

        smoke_test = SmokeTest(self.driver, test_log, test_helper)
        run_smoke_tests(smoke_test)

        login_handler.end()
        test_log.close()