How to use assert_element_present method in SeleniumBase

Best Python code snippet using SeleniumBase

test_login.py

Source:test_login.py Github

copy

Full Screen

...20 self.open(base_url + '/logout')21 # navigate to login page22 self.open(base_url + '/login')23 # verify all form elements present24 self.assert_element_present("h1")25 self.assert_text("Log In", "h1")26 self.assert_element_present("h4#message")27 self.assert_text("Please login", "h4#message")28 self.assert_element_present("input#email")29 self.assert_element_present("input#password")30 self.assert_element_present("input#btn-submit")31 # R1.3 If the user has logged in, redirect to the user profile page.32 @patch('qa327.backend.get_user', return_value=test_user)33 @patch('qa327.backend.login_user', return_value=test_user)34 def test_login_redirect(self, *_):35 # invalidate all sessions36 self.open(base_url + '/logout')37 # navigate to login page38 self.open(base_url + '/login')39 # submit correct credentials40 self.type("#email", test_user.email)41 self.type("#password", test_user.password)42 self.click("input#btn-submit")43 # navigate to login page again44 self.open(base_url + '/login')45 # verify redirect occurred46 self.assert_element_present("h2#welcome-header")47 self.assert_text("Hi", "h2#welcome-header")48 # R1.5 The login form can be submitted as a POST request to the current URL.49 # R1.7a Valid email can login.50 # R1.10 If email/password are correct, redirect to `/`51 @patch('qa327.backend.get_user', return_value=test_user)52 @patch('qa327.backend.login_user', return_value=test_user)53 def test_login_valid_credentials(self, *_):54 # invalidate all sessions55 self.open(base_url + '/logout')56 # navigate to login page57 self.open(base_url + '/login')58 # submit correct credentials59 self.type("#email", test_user.email)60 self.type("#password", test_user.password)61 self.click("input#btn-submit")62 # verify `/` page is displayed63 self.assert_element_present("h2#welcome-header")64 self.assert_text("Hi", "h2#welcome-header")65 # R1.6a Empty email and password does not login.66 def test_login_empty_inputs(self, *_):67 # invalidate all sessions68 self.open(base_url + '/logout')69 # navigate to login page70 self.open(base_url + '/login')71 # submit empty form72 self.click("input#btn-submit")73 # verify all form elements present74 self.assert_element_present("h1")75 self.assert_text("Log In", "h1")76 self.assert_element_present("h4#message")77 self.assert_text("Please login", "h4#message")78 self.assert_element_present("input#email")79 self.assert_element_present("input#password")80 self.assert_element_present("input#btn-submit")81 # R1.6b Empty email does not login.82 def test_login_empty_password(self, *_):83 # invalidate all sessions84 self.open(base_url + '/logout')85 # navigate to login page86 self.open(base_url + '/login')87 # submit incomplete form88 self.type("#password", test_user.password)89 self.click("input#btn-submit")90 # verify all form elements present91 self.assert_element_present("h1")92 self.assert_text("Log In", "h1")93 self.assert_element_present("h4#message")94 self.assert_text("Please login", "h4#message")95 self.assert_element_present("input#email")96 self.assert_element_present("input#password")97 self.assert_element_present("input#btn-submit")98 # R1.6c Empty password does not login.99 def test_login_empty_email(self, *_):100 # invalidate all sessions101 self.open(base_url + '/logout')102 # navigate to login page103 self.open(base_url + '/login')104 # submit incomplete form105 self.type("#email", test_user.email)106 self.click("input#btn-submit")107 # verify all form elements present108 self.assert_element_present("h1")109 self.assert_text("Log In", "h1")110 self.assert_element_present("h4#message")111 self.assert_text("Please login", "h4#message")112 self.assert_element_present("input#email")113 self.assert_element_present("input#password")114 self.assert_element_present("input#btn-submit")115 # R1.7b Invalid email cannot login and error message 'email/password format is incorrect' is displayed.116 def test_login_invalid_email_format(self, *_):117 # invalidate all sessions118 self.open(base_url + '/logout')119 # navigate to login page120 self.open(base_url + '/login')121 # submit correct credentials122 self.type("#email", "test_frontend")123 self.type("#password", test_user.password)124 self.click("input#btn-submit")125 # verify error message126 self.assert_element_present("h4#message")127 self.assert_text("email/password format is incorrect", "h4#message")128 # R1.8a User with password shorter than 6 characters cannot log in129 # and error message 'email/password format is incorrect' is displayed.130 def test_login_invalid_password_less_than_6_characters(self, *_):131 # invalidate all sessions132 self.open(base_url + '/logout')133 # navigate to login page134 self.open(base_url + '/login')135 # submit correct credentials136 self.type("#email", test_user.email)137 self.type("#password", "Pass!")138 self.click("input#btn-submit")139 # verify error message140 self.assert_element_present("h4#message")141 self.assert_text("email/password format is incorrect", "h4#message")142 # R1.8b User with password with no uppercase characters cannot log in143 # and error message 'email/password format is incorrect' is displayed.144 def test_login_invalid_password_no_uppercase(self, *_):145 # invalidate all sessions146 self.open(base_url + '/logout')147 # navigate to login page148 self.open(base_url + '/login')149 # submit correct credentials150 self.type("#email", test_user.email)151 self.type("#password", "password!")152 self.click("input#btn-submit")153 # verify error message154 self.assert_element_present("h4#message")155 self.assert_text("email/password format is incorrect", "h4#message")156 # R1.8c User with password with no lowercase characters cannot log in157 # and error message 'email/password format is incorrect' is displayed.158 def test_login_invalid_password_no_lowercase(self, *_):159 # invalidate all sessions160 self.open(base_url + '/logout')161 # navigate to login page162 self.open(base_url + '/login')163 # submit correct credentials164 self.type("#email", test_user.email)165 self.type("#password", "PASSWORD!")166 self.click("input#btn-submit")167 # verify error message168 self.assert_element_present("h4#message")169 self.assert_text("email/password format is incorrect", "h4#message")170 # R1.8d User with password with no special characters cannot log in171 # and error message 'email/password format is incorrect' is displayed.172 def test_login_invalid_password_no_lowercase(self, *_):173 # invalidate all sessions174 self.open(base_url + '/logout')175 # navigate to login page176 self.open(base_url + '/login')177 # submit correct credentials178 self.type("#email", test_user.email)179 self.type("#password", "Password")180 self.click("input#btn-submit")181 # verify error message182 self.assert_element_present("h4#message")183 self.assert_text("email/password format is incorrect", "h4#message")184 # R1.11a Invalid email redirects to `/login` with error message.185 @patch('qa327.backend.login_user', return_value=None)186 def test_login_invalid_email_credential(self, *_):187 # invalidate all sessions188 self.open(base_url + '/logout')189 # navigate to login page190 self.open(base_url + '/login')191 # submit correct credentials192 self.type("#email", "testing@test.com")193 self.type("#password", test_user.password)194 self.click("input#btn-submit")195 # verify error message196 self.assert_element_present("h4#message")197 self.assert_text("email/password combination incorrect", "h4#message")198 # R1.11b Invalid password redirects to `/login` with error message.199 @patch('qa327.backend.login_user', return_value=None)200 def test_login_invalid_password_credential(self, *_):201 # invalidate all sessions202 self.open(base_url + '/logout')203 # navigate to login page204 self.open(base_url + '/login')205 # submit correct credentials206 self.type("#email", test_user.email)207 self.type("#password", "WrongPassword!")208 self.click("input#btn-submit")209 # verify error message210 self.assert_element_present("h4#message")...

Full Screen

Full Screen

test_timeline.py

Source:test_timeline.py Github

copy

Full Screen

...15class TweetTest(BaseTestCase):16 @parameterized.expand(normal)17 def test_timeline(self, username):18 self.open_nitter(username)19 self.assert_element_present(Timeline.older)20 self.assert_element_absent(Timeline.newest)21 self.assert_element_absent(Timeline.end)22 self.assert_element_absent(Timeline.none)23 @parameterized.expand(after)24 def test_after(self, username, cursor):25 self.open_nitter(f'{username}?cursor={cursor}')26 self.assert_element_present(Timeline.newest)27 self.assert_element_present(Timeline.older)28 self.assert_element_absent(Timeline.end)29 self.assert_element_absent(Timeline.none)30 @parameterized.expand(no_more)31 def test_no_more(self, username):32 self.open_nitter(username)33 self.assert_text('No more items', Timeline.end)34 self.assert_element_present(Timeline.newest)35 self.assert_element_absent(Timeline.older)36 @parameterized.expand(empty)37 def test_empty(self, username):38 self.open_nitter(username)39 self.assert_text('No items found', Timeline.none)40 self.assert_element_absent(Timeline.newest)41 self.assert_element_absent(Timeline.older)42 self.assert_element_absent(Timeline.end)43 @parameterized.expand(protected)44 def test_protected(self, username):45 self.open_nitter(username)46 self.assert_text('This account\'s tweets are protected.', Timeline.protected)47 self.assert_element_absent(Timeline.newest)48 self.assert_element_absent(Timeline.older)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run SeleniumBase automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful