From 7c55932f9107b376f4166553a3daca59f1e87985 Mon Sep 17 00:00:00 2001 From: Guillaume Risbourg Date: Fri, 27 Dec 2019 10:32:29 +0100 Subject: [PATCH] [sogecartenet] Fix wrongpass/actionneeded detection + message retrieval The 'titulaire' browser missed a condition to catch wrongpass errors. The 'entreprise' browser now retrieve the error message when raising a wrongpass. --- modules/sogecartenet/browser.py | 14 ++++++++++++-- modules/sogecartenet/ent_browser.py | 19 +++++++++++-------- modules/sogecartenet/ent_pages.py | 3 +++ modules/sogecartenet/pages.py | 5 ++++- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/modules/sogecartenet/browser.py b/modules/sogecartenet/browser.py index 5878b0b7b4..c3934ee130 100644 --- a/modules/sogecartenet/browser.py +++ b/modules/sogecartenet/browser.py @@ -17,10 +17,12 @@ # You should have received a copy of the GNU Lesser General Public License # along with this weboob module. If not, see . +from __future__ import unicode_literals + from datetime import date from weboob.browser import URL, need_login -from weboob.exceptions import BrowserIncorrectPassword +from weboob.exceptions import BrowserIncorrectPassword, ActionNeeded from weboob.browser.selenium import ( SeleniumBrowser, webdriver, AnyCondition, IsHereCondition, VisibleXPath, @@ -61,10 +63,18 @@ def do_login(self): self.wait_until(AnyCondition( IsHereCondition(self.accueil), VisibleXPath('//div[@id="labelQuestion"]'), + VisibleXPath('//div[contains(@class, "Notification-error-message")]'), )) if not self.accueil.is_here(): - raise BrowserIncorrectPassword(self.page.get_error()) + assert self.login.is_here(), 'We landed on an unknown page' + error = self.page.get_error() + if any(( + 'Votre compte a été désactivé' in error, + 'Votre compte est bloqué' in error, + )): + raise ActionNeeded(error) + raise BrowserIncorrectPassword(error) @need_login def iter_accounts(self): diff --git a/modules/sogecartenet/ent_browser.py b/modules/sogecartenet/ent_browser.py index b90c92b90e..77cb555a5e 100644 --- a/modules/sogecartenet/ent_browser.py +++ b/modules/sogecartenet/ent_browser.py @@ -17,10 +17,12 @@ # You should have received a copy of the GNU Lesser General Public License # along with this weboob module. If not, see . +from __future__ import unicode_literals + from datetime import date from weboob.browser import URL, need_login -from weboob.exceptions import BrowserIncorrectPassword +from weboob.exceptions import BrowserIncorrectPassword, ActionNeeded from weboob.tools.capabilities.bank.transactions import sorted_transactions from weboob.browser.selenium import ( SeleniumBrowser, webdriver, AnyCondition, VisibleXPath, IsHereCondition, @@ -65,19 +67,20 @@ def do_login(self): self.page.login(self.username, self.password) - # Error message are displayed with javascript and automatically - # disappear after a few seconds, so it is hard to catch them at - # the right time. self.wait_until(AnyCondition( IsHereCondition(self.accueil), VisibleXPath('//div[contains(@class, "Notification-error-message")]'), )) if not self.accueil.is_here(): - # Message are displayed with javascript and disappear after - # a few seconds, so we might get errors trying to retrieve - # the error message. - raise BrowserIncorrectPassword() + assert self.login.is_here(), 'We landed on an unknown page' + error = self.page.get_error() + if any(( + 'Votre compte a été désactivé' in error, + 'Votre compte est bloqué' in error, + )): + raise ActionNeeded(error) + raise BrowserIncorrectPassword(error) @need_login def iter_accounts(self): diff --git a/modules/sogecartenet/ent_pages.py b/modules/sogecartenet/ent_pages.py index d03d7a18dd..d36afb7b62 100644 --- a/modules/sogecartenet/ent_pages.py +++ b/modules/sogecartenet/ent_pages.py @@ -53,6 +53,9 @@ def login(self, username, password): el.send_keys(Keys.RETURN) + def get_error(self): + return CleanText('//h1[contains(@class, "Notification-caption")]')(self.doc) + class AccueilPage(LoggedPage, SeleniumPage): is_here = VisibleXPath('//div[@id="Menu-responsive"]') diff --git a/modules/sogecartenet/pages.py b/modules/sogecartenet/pages.py index 4b52a1056f..d91b5700d0 100644 --- a/modules/sogecartenet/pages.py +++ b/modules/sogecartenet/pages.py @@ -33,7 +33,10 @@ class LoginPage(_LoginPage): def get_error(self): - return CleanText('//div[@id="labelQuestion"]')(self.doc) + return ( + CleanText('//div[@id="labelQuestion"]')(self.doc) + or CleanText('//h1[contains(@class, "Notification-caption")]')(self.doc) + ) class PreLoginPage(SeleniumPage): -- GitLab