From fdf714bd29bd4b8def714cb439abc77676c59be0 Mon Sep 17 00:00:00 2001 From: thibault douge Date: Thu, 17 Sep 2020 16:16:05 +0200 Subject: [PATCH] [amazon] refactor the AppValidation with a specific url and global xpaths --- modules/amazon/browser.py | 17 +++++++++-------- modules/amazon/pages.py | 24 +++++++++++------------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/modules/amazon/browser.py b/modules/amazon/browser.py index eff14d0805..699fe897cb 100644 --- a/modules/amazon/browser.py +++ b/modules/amazon/browser.py @@ -33,7 +33,7 @@ from .pages import ( LoginPage, SubscriptionsPage, DocumentsPage, DownloadDocumentPage, HomePage, - PanelPage, SecurityPage, LanguagePage, HistoryPage, PasswordExpired, + PanelPage, SecurityPage, LanguagePage, HistoryPage, PasswordExpired, ApprovalPage, ) @@ -64,6 +64,7 @@ class AmazonBrowser(LoginBrowser, StatesMixin): DocumentsPage, ) download_doc = URL(r'/gp/shared-cs/ajax/invoice/invoice.html', DownloadDocumentPage) + approval_page = URL(r'/ap/cvf/approval', ApprovalPage) security = URL( r'/ap/dcq', r'/ap/cvf/', @@ -110,10 +111,6 @@ def handle_security(self): # many captcha, reset value self.config['captcha_response'] = Value(value=None) else: - msg_validation = self.page.get_msg_app_validation() - if 'approve the notification' in msg_validation: - raise AppValidation(msg_validation) - otp_type = self.page.get_otp_type() if otp_type == '/ap/signin': # this otp will be always present until user deactivate it @@ -151,7 +148,7 @@ def check_app_validation(self): while time.time() < timeout: link = self.page.get_link_app_validation() self.location(link) - if self.security.is_here(): + if self.approval_page.is_here(): time.sleep(2) else: return @@ -170,6 +167,9 @@ def do_login(self): # Means security was passed, we're logged return + if self.config['resume'].get(): + self.check_app_validation() + if self.security.is_here(): self.handle_security() @@ -209,8 +209,9 @@ def do_login(self): self.page.login(self.username, self.password) - if self.config['resume'].get(): - self.check_app_validation() + if self.approval_page.is_here(): + msg_validation = self.page.get_msg_app_validation() + raise AppValidation(msg_validation) if self.password_expired.is_here(): raise BrowserPasswordExpired(self.page.get_message()) diff --git a/modules/amazon/pages.py b/modules/amazon/pages.py index 6d5d38ab88..e06bd62db5 100644 --- a/modules/amazon/pages.py +++ b/modules/amazon/pages.py @@ -58,19 +58,6 @@ def get_otp_type(self): assert url in ('verify', '/ap/signin'), url return url - def get_msg_app_validation(self): - msg = CleanText('//span[has-class("transaction-approval-word-break")]') - email = CleanText('//div[contains(text(), "Email")]/following-sibling::div') - mobile_number = CleanText('//div[contains(text(), "Mobile number")]/following-sibling::div') - if mobile_number: - msg = Format('%s: %s', msg, mobile_number)(self.doc) - elif email: - msg = Format('%s: %s', msg, email)(self.doc) - return msg - - def get_link_app_validation(self): - return Link('//a[contains(text(), "Click here to refresh the page")]')(self.doc) - def get_otp_message(self): return CleanText('//div[@class="a-box-inner"]/p')(self.doc) @@ -107,6 +94,17 @@ def has_form_verify(self): return True +class ApprovalPage(HTMLPage, LoggedPage): + def get_msg_app_validation(self): + msg = CleanText('//span[has-class("transaction-approval-word-break")]') + sending_address = CleanText('//div[@class="a-row"][1]') + msg = Format('%s %s', msg, sending_address) + return msg(self.doc) + + def get_link_app_validation(self): + return Link('//a[contains(text(), "Click here to refresh the page")]')(self.doc) + + class LanguagePage(HTMLPage): pass -- GitLab