From af797ac915cd17b4ac78bbfcd19c2dac22d8098a Mon Sep 17 00:00:00 2001 From: Natalya Mastyaeva <71374230+Nat754@users.noreply.github.com> Date: Sun, 12 Jan 2025 22:29:09 +0400 Subject: [PATCH] refactor: get_link_change_password_by_email --- pages/profile_page.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/pages/profile_page.py b/pages/profile_page.py index 48865acd45..b848aa9c99 100644 --- a/pages/profile_page.py +++ b/pages/profile_page.py @@ -1,5 +1,4 @@ import imaplib -import time from random import choice import allure import os @@ -20,21 +19,22 @@ class ProfilePage(BasePage): @staticmethod def get_link_change_password_by_email(): with allure.step('Get a link to change the password by email'): - mail = imaplib.IMAP4_SSL('imap.mail.ru') - mail.login(os.environ["CHANGE_PASSWORD_EMAIL"], os.environ["PASSWORD_EMAIL"]) - mail.select('INBOX') - result, data_id = mail.search(None, 'ALL') + data_id = [b''] + while data_id == [b'']: + mail = imaplib.IMAP4_SSL('imap.mail.ru') + mail.login(os.environ["CHANGE_PASSWORD_EMAIL"], os.environ["PASSWORD_EMAIL"]) + mail.select('INBOX') + result, data_id = mail.search(None, 'UNSEEN') message_ids = data_id[0].split() result, data_id = mail.fetch(message_ids[-1], '(RFC822)') - raw_email = str(data_id[0][1]) mail.logout() - first = raw_email.find(os.environ["PASSWORD_LINK"]) - link = raw_email[first:first + 186] + msg = str(data_id[0][1]) + first = msg.find(os.environ["PASSWORD_LINK"]) + link = msg[first:first + 186] return link @allure.step("Authorise user") def authorise_user(self): - self.timeout = 2 self.element_is_visible(LoginPageLocators.INPUT_LOGIN).send_keys(os.environ["CHANGE_PASSWORD_EMAIL"]) self.element_is_visible(LoginPageLocators.INPUT_PASSWORD).send_keys(os.environ["CHANGE_PASSWORD"]) self.element_is_present_and_clickable(LoginPageLocators.SIGN_IN_BUTTON).click() @@ -67,7 +67,6 @@ def field_recovery_email(self): @allure.step("Click the button 'Send recovery email'") def click_send_recovery_email_link(self): self.element_is_present_and_clickable(ProfilePageLocators.SEND_EMAIL).click() - time.sleep(5) @allure.step("Enter the data in the email field") def enter_new_password_field(self):