Last active
April 26, 2020 18:18
-
-
Save LouisdeBruijn/4e59e6b5c91bf7f74992b45dcccd5397 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from selenium import webdriver | |
| from webdriver_manager.chrome import ChromeDriverManager | |
| from selenium.webdriver.common.keys import Keys | |
| import unittest | |
| class LoginTest(unittest.TestCase): | |
| """User checks whether he can log in on app.""" | |
| def setUp(self): | |
| self.browser = webdriver.Chrome(ChromeDriverManager().install()) | |
| def tearDown(self): | |
| self.browser.quit() | |
| def check_fade_messages(self, msg_text): | |
| """Check whether text is in returned feedback messages.""" | |
| messages = self.browser.find_elements_by_class_name('msg') | |
| self.assertIn(msg_text, [msg.text for msg in messages]) | |
| def test_login(self): | |
| # Max has heard about a cool new online app. | |
| # He goes to login | |
| self.browser.get('http://127.0.0.1:8000/login') | |
| # He notices the page title and header mention site name | |
| self.assertIn('Everything Python', self.browser.title) | |
| form_header = self.browser.find_element_by_tag_name('h2').text | |
| self.assertIn('Login', form_header) | |
| # He finds the username input box | |
| username_inputbox = self.browser.find_element_by_id('user_name') | |
| self.assertEqual( | |
| username_inputbox.get_attribute('placeholder'), | |
| 'username' | |
| ) | |
| # He finds the password input box | |
| password_inputbox = self.browser.find_element_by_id('user_password') | |
| self.assertEqual( | |
| password_inputbox.get_attribute('placeholder'), | |
| 'password' | |
| ) | |
| # He types account information the input boxes | |
| username_inputbox.send_keys('fake_username') | |
| password_inputbox.send_keys('fake_password) | |
| # He submits the form | |
| username_inputbox.send_keys(Keys.ENTER) | |
| # He sees the error message | |
| self.check_fade_messages('Invalid reCAPTCHA. Please try again') | |
| self.fail('Completed login test!') | |
| if __name__ == '__main__': | |
| unittest.main(warnings='ignore') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment