Example #1
0
class LoginPageObject(PageObject):
    title = Text(By.ID, 'title')
    username = InputText(By.XPATH, '//input[0]')
    password = InputText(By.ID, 'password')
    language = Select(By.ID, 'language')
    login = Button(By.ID, 'login')
    menu = Menu(By.ID, 'menu')
Example #2
0
class LoginPage(BasePageObject):
    """Selenium Page Object Model: LoginPage."""

    # Page Elements
    username = InputText(By.NAME, "sUserName", wait=True)
    password = InputText(By.NAME, "sSysPass", wait=True)
    login_button = Button(By.NAME, "btnOk", wait=True)
    login_error_message = Text(By.ID, "errmsg")

    def login(self, username, passsword):
        """Submit login details to Web Admin login page.

        :param username: The username
        :param password: The password
        """
        self.set_element_value(self.username, username)
        self.set_element_value(self.password, passsword)
        self.login_button.click()

    def login_error(self):
        """Check for presence of login error text.

        :returns: True if error displayed, False otherwise
        """
        if self.login_error_message.is_visible():
            return True
        return False

    def error_message(self):
        """Return error message displayed on login page.

        :returns: Error message string
        """
        if self.login_error_message.is_visible():
            message = self.read_element_value(self.login_error_message)
        else:
            message = "No Error message returned - Login Failed"
        return message
Example #3
0
class FirmwareUpgradePage(BasePageObject):
    """Selenium Page Object Model: FirmwareUpgradePage."""

    # Page Elements
    choose_firmware_button = Button(By.ID, "fw_file")
    firmware_path_form_element = Button(
        By.CSS_SELECTOR, "input[type='file']")  # Might not be needed
    upgrade_button = Button(
        By.XPATH,
        "//input[@name='attach' and @type='button' and @value='Upgrade']")
    preview_button = Button(By.NAME, "btnpreview")
    post_upgrade_restart_button = Button(
        By.XPATH, "//input[@type='button' and @value='Restart']")

    preview_close_button = Button(By.NAME, "btnClose")
    preview_model = Text(By.ID, "smodelName")
    preview_firmware_version = Text(By.ID, "sfwversion")
    preview_modem_version = Text(By.ID, "scurmdmver")
    preview_current_modem_version = Text(By.ID, "snewmdmver")

    def open_page(self):
        """Navigate menus to open Firmware Upgrade page."""
        menu = MenuNavigator(self.driver_wrapper)
        menu.open_sysmain_firmware_upgrade()

    def new_firmware_preview(self, file: Firmware):
        """Preview firmware upgrade information for supplied firmware file.

        :param file: Full file name and path to router firmware
        :eturns Firmware object - Firmware object populated with settings retrieved from previewing the firmware
        """
        if file.filepath is None:
            raise ValueError(
                "Firmware Preview requires a path to the a firmware file")

        self.open_page()

        self.choose_firmware_button.web_element.send_keys(str(file.filepath))
        self.preview_button.click()
        preview_firmware = Firmware(
            filepath=str(file.filepath),
            model=self.read_element_value(self.preview_model),
            firmware_target=self.read_element_value(
                self.preview_firmware_version),
            modem_firmware_current=self.read_element_value(
                self.preview_current_modem_version),
            modem_firmware_target=self.read_element_value(
                self.preview_modem_version),
        )
        self.preview_close_button.click()

        # TODO (#4412): Handle incompatible firmware provided to preview. Raise exception?

        return preview_firmware

    def new_firmware_install(self, file: Firmware):
        """Install firmware using the file specified.

        :param file: Full file name and path to router firmware
        :returns success - True if upgrade successful
        """
        self.open_page()
        self.choose_firmware_button.web_element.send_keys(str(file.filepath))
        self.upgrade_button.click()
        self.driver.switch_to.alert.accept()
        self.post_upgrade_restart_button.click()
        self.driver.switch_to.alert.accept()
        # TODO (#4413): Handle firmware install failures and return false or raise exceptions?
        return True
Example #4
0
class DashboardPage(BasePageObject):
    """Selenium Page Object Model: DashboardPage."""

    # Page Elements
    # Frames
    frame_header = "header"
    frame_main = "main"

    # System Information Table
    model_name = Text(
        By.CSS_SELECTOR,
        "#blksysinfo > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(2)",
    )
    router_name = Text(
        By.CSS_SELECTOR,
        "#blksysinfo > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(3) > td:nth-child(2)",
    )
    fw_version = Text(
        By.CSS_SELECTOR,
        "#blksysinfo > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(4) > td:nth-child(2)",
    )
    dsl_version = Text(
        By.CSS_SELECTOR,
        "#blksysinfo > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(5) > td:nth-child(3)",
    )

    def routerinfo(self):
        """Get the router info via the table on the dashboard or try and use the Javascript variables in the header.

        :returns: RouterInfo object
        """
        router = {
            "router_name": None,
            "firmware": None,
            "model": None,
            "dsl_version": None,
        }
        # try:
        # Initial read via JavaScript Header variables
        self.driver.switch_to.default_content()
        self.driver.switch_to.frame(self.frame_header)
        try:
            router["router_name"] = self.driver.execute_script(
                "return sSysName")
        except Exception:
            pass
        try:
            router["firmware"] = self.driver.execute_script("return sSysVer")
        except Exception:
            pass
        try:
            router["model"] = self.driver.execute_script(
                "return sFwNameLeading")
        except Exception:
            pass
        # except NoSuchElementException:
        #     pass

        # Read the values from the dashboard table and replace initial JavaScript values
        self.driver.switch_to.default_content()
        self.driver.switch_to.frame(self.frame_main)
        # TODO (#4418): Need to replace try/catch around each call with a different approach.
        #       Needs to be potentially implemented over all files.
        if self.model_name.is_visible():
            router["model"] = self.read_element_value(self.model_name)
        if self.router_name.is_visible():
            router["router_name"] = self.read_element_value(self.router_name)
        if self.fw_version.is_visible():
            router["firmware"] = self.read_element_value(self.fw_version)
        if self.dsl_version.is_visible():
            router["dsl_version"] = self.read_element_value(self.dsl_version)

        return RouterInfo(
            model=router["model"],
            router_name=router["router_name"],
            firmware=router["firmware"],
            dsl_version=router["dsl_version"],
        )