def fxa_login()

in pages/desktop/frontend/login.py [0:0]


    def fxa_login(self, email, password, key):
        self.find_element(*self._email_locator).send_keys(email)
        # sometimes, the login function fails on the 'continue_btn.click()' event with a TimeoutException
        # triggered by the built'in timeout of the 'click()' method;
        # however, the screenshot captured by the html report at test fail time shows that the click occurred
        # since the expected page has been loaded;
        # this seems to be a reoccurring issue in geckodriver as explained in
        # https://github.com/mozilla/geckodriver/issues/1608;
        # here, I'm capturing that TimeoutException and trying to push the script to continue to the next steps.
        try:
            continue_btn = self.wait.until(
                EC.element_to_be_clickable((By.ID, "submit-btn"))
            )
            continue_btn.click()
        except TimeoutException as error:
            print(error.msg)
            pass
        print('The "click continue button" event occurred.')
        self.wait.until(
            EC.element_to_be_clickable(self._password_login),
            message=f"Password input field not displayed; "
            # f"FxA card header was {self.find_element(*self._login_card_header_locator).text}",
        )
        # print(
        #     f'The script should be on the password input screen here. We should see "Sign in" in the header.'
        #     f' The card  header title is "{self.find_element(*self._login_card_header_locator).text}"'
        # )
        self.find_element(*self._password_login).send_keys(password)
        # waits for the password to be filled in
        self.wait.until(
            EC.invisibility_of_element_located((By.CSS_SELECTOR, ".password.empty")),
            message="There was no input added in the password field",
        )
        self.find_element(*self._login_btn_locator).click()
        # logic for 2fa enabled accounts
        if key != "":
            self.wait.until(EC.url_contains("signin_totp_code"))
            self.wait.until(EC.visibility_of_element_located(self._2fa_input_locator))
            time.sleep(30)
            totp = pyotp.TOTP(key)
            self.find_element(*self._2fa_input_locator).send_keys(totp.now())
            self.find_element(*self._confirm_2fa_button_locator).click()
            time.sleep(5)
            for max_retries in range(0, 2):
                if self.is_element_displayed(*self._error_2fa_code_locator):
                    time.sleep(500)
                    totp = pyotp.TOTP(key)
                    self.find_element(*self._2fa_input_locator).clear()
                    self.find_element(*self._2fa_input_locator).send_keys(totp.now())
                    self.find_element(*self._confirm_2fa_button_locator).click()
                else:
                    break

        # wait for transition between FxA page and AMO
        self.wait.until(
            EC.url_contains("addons"),
            message=f"AMO could not be loaded in {self.driver.current_url}. "
            f"Response status code was {requests.head(self.driver.current_url).status_code}",
        )