When testing website login without credentials we're getting a tooltip message that email and password should be entered. I need to make an assertion that the text of the error is relevant when we try to login without any credentials. Unfortunately,I'm not sure how can I do so.
You see, in the LoginPage class there is a variable for error message box: tool_tip = '.error-container'
. And in the test_login_without_credentials
I have added the message
variable. But the error message box has no static error text and it is difficult for me to make right assertions for each case.
For instance, if you have entered no credentials you receive the following message:
<div class="error-container">
<ul>
<li>
<b>Email</b>
: Value is required and can't be empty
</li>
<li>
<b>Password</b>
: Value is required and can't be empty
</li>
</ul>
</div>
Another example when you have entered invalid password:
<div class="error-container">
<ul>
<li>
<b>Email</b>
: '123' is no a valid email address in the basic format local-part@hostname
</li>
<li>
<b>Password</b>
: Value is required and can't be empty
</li>
</ul>
</div>
And one more example when the invalid password is entered:
<div class="error-container">
<ul>
<li>
<b>Log in</b>
: Unknown user or invalid password given
</li>
</ul>
</div>
I'm using the PageObject pattern for testing. Here is the part of the loginPage.py file containing the description of testing without credentials:
class LoginPage(object):
login_page_link = 'Log in'
email_field_locator = 'email'
password_field_locator = 'password'
login_button_locator = 'submit'
tool_tip = '.error-container'
def __init__(self, driver, base_url):
self.driver = driver
self.driver.get(base_url)
def login_without_credentials(self, email = '', password = ''):
self.driver.find_element_by_link_text(self.login_page_link).click()
self.driver.find_element_by_id(self.email_field_locator).clear()
self.driver.find_element_by_id(self.email_field_locator).send_keys(email)
self.driver.find_element_by_id(self.password_field_locator).clear()
self.driver.find_element_by_id(self.password_field_locator).send_keys(password)
self.driver.find_element_by_id(self.login_button_locator).click()
tooltip_message = WebDriverWait(self.driver, 10).until(lambda s: s.find_element_by_css_selector(self.tool_tip).text)
return tooltip_message
And here is the testLogin.py itself:
class TestLoginLogout(object):
@classmethod
def setup_class(cls):
cls.verificationErrors = []
cls.driver = selenium_driver.connect()
cls.driver.implicitly_wait(10)
cls.base_url = selenium_driver.base_url
cls.email = configs.EMAIL
cls.password = configs.PASSWORD
@classmethod
def teardown_class(cls):
cls.driver.quit()
assert cls.verificationErrors == []
def test_login_without_credentials(self):
login_page = LoginPage(self.driver, self.base_url)
message = login_page.login_without_credentials()
if __name__ == '__main__':
pytest.main([__file__, "-s"])