Commit 7c55932f authored by Guillaume Risbourg's avatar Guillaume Risbourg Committed by Vincent A

[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.
parent 59b764d5
......@@ -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 <http://www.gnu.org/licenses/>.
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 @@ class SogecarteTitulaireBrowser(SeleniumBrowser):
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):
......
......@@ -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 <http://www.gnu.org/licenses/>.
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 @@ class SogecarteEntrepriseBrowser(SeleniumBrowser):
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):
......
......@@ -53,6 +53,9 @@ class LoginPage(SeleniumPage):
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"]')
......
......@@ -33,7 +33,10 @@ from .ent_pages import LoginPage as _LoginPage
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):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment