How to use wait_for_ready_state_complete method in SeleniumBase

Best Python code snippet using SeleniumBase

test_password_reset.py

Source:test_password_reset.py Github

copy

Full Screen

...72 """Password reset scenario73 """74 models.SchoolUser.objects.create_user(**data_test_password_reset.user)75 self.open(settings.LOGIN_URL)76 self.wait_for_ready_state_complete()77 self.click(**self.FORGOT_PASSWORD_BUTTON)78 try:79 self.wait_for_element(**self.RESET_BUTTON)80 self.assertEqual(_('Password reset'), self.get_page_title())81 logging.info('Trying to send e-mail to {} ...'.format(82 data_test_password_reset.user['email']))83 self.send_keys(84 new_value=data_test_password_reset.user['email'],85 **self.EMAIL_FIELD86 )87 self.click(**self.RESET_BUTTON)88 self.wait_for_ready_state_complete()89 self.wait_for_element(**self.EMAIL_SENT_FORM)90 self.assertEqual(_('Password reset sent'), self.get_page_title())91 logging.info('Passed')92 logging.info('Mail count in dummy outbox: {}'.format(93 len(mail.outbox)))94 self.assertEqual(1, len(mail.outbox))95 logging.info('From: {}'.format(mail.outbox[0].from_email))96 self.assertEqual(django_settings.DEFAULT_FROM_EMAIL,97 mail.outbox[0].from_email)98 logging.info('To: {}'.format(mail.outbox[0].to[0]))99 self.assertEqual(data_test_password_reset.user['email'],100 mail.outbox[0].to[0])101 logging.info('Subject: {}'.format(mail.outbox[0].subject))102 self.assertEqual('Schoolmate - password reset confirmation',103 mail.outbox[0].subject)104 logging.info('Body: {}'.format(mail.outbox[0].body))105 email_to = re.search('(?P<email>\S+@\S+\.\S+)',106 mail.outbox[0].body).group('email')107 self.assertEqual(data_test_password_reset.user['email'],108 email_to)109 link = re.search(110 '(?P<link>http.?://\S+/password_reset/\S+/\S+/)',111 mail.outbox[0].body112 ).group('link')113 logging.info('Back to login page')114 self.click(**self.BACK_TO_LOGIN_BUTTON)115 self.wait_for_ready_state_complete()116 self.assertEqual(_('Sign in'), self.get_page_title())117 logging.info('Go to {}'.format(link))118 self.open(link)119 self.wait_for_ready_state_complete()120 self.assertEqual(_('Password reset confirmation'),121 self.get_page_title())122 logging.info('Check empty fields validation...')123 self.click(**self.RESET_CONFIRM_BUTTON)124 msg = self.wait_for_element(125 **self.RESET_NEW_PASSWORD1_FIELD_MSG).text126 self.assertEqual(_('Field can not be empty'), msg)127 msg = self.wait_for_element(128 **self.RESET_NEW_PASSWORD2_FIELD_MSG).text129 self.assertEqual(_('Field can not be empty'), msg)130 logging.info('Done')131 new_password = 'new_password'132 logging.info('Check new password mismatch handling...')133 self.send_keys(new_value=new_password,134 **self.RESET_NEW_PASSWORD1_FIELD)135 self.click(**self.RESET_CONFIRM_BUTTON)136 msg = self.wait_for_element(**self.MESSAGE).text137 self.assertEqual(_('Passwords are not the same'), msg)138 logging.info('Done')139 logging.info('Set up new password: {}'.format(new_password))140 self.send_keys(new_value=new_password,141 **self.RESET_NEW_PASSWORD2_FIELD)142 self.click(**self.RESET_CONFIRM_BUTTON)143 self.wait_for_ready_state_complete()144 self.wait_for_element(**self.PASSWORD_RESET_COMPLETE_FORM)145 self.assertEqual(_('Password reset complete'),146 self.get_page_title())147 logging.info('Done')148 logging.info('Back to login page')149 self.click(**self.BACK_TO_LOGIN_BUTTON)150 self.wait_for_ready_state_complete()151 self.assertEqual(_('Sign in'), self.get_page_title())152 logging.info('Trying old password: {}'.format(153 data_test_password_reset.user['password']))154 self.login(data_test_password_reset.user['username'],155 data_test_password_reset.user['password'], wait=False)156 msg = self.wait_for_element(**self.MESSAGE).text157 self.assertEqual(_('Wrong username/password'), msg)158 logging.info('Passed')159 logging.info('Trying to log in with new password: {}'160 ''.format(new_password))161 self.login(data_test_password_reset.user['username'], new_password)162 logging.info('Password reset procedure test passed')163 except Exception as e:164 logging.error('Error during password reset procedure')165 logging.error(e)166 self.fail(e)167 def test_email_validation_for_password_reset(self):168 """Test e-mail validation for password reset169 """170 self.open(settings.LOGIN_URL)171 self.wait_for_ready_state_complete()172 self.click(**self.FORGOT_PASSWORD_BUTTON)173 try:174 self.wait_for_ready_state_complete()175 self.wait_for_element(**self.RESET_BUTTON)176 self.assertEqual(_('Password reset'), self.get_page_title())177 logging.info('Check empty e-mail field validation...')178 self.click(**self.RESET_BUTTON)179 msg = self.wait_for_element(**self.EMAIL_FIELD_MSG).text180 self.assertEqual(_('E-mail can not be empty'), msg)181 logging.info('Done')182 logging.info('Check with invalid e-mail address...')183 self.send_keys(new_value='email', **self.EMAIL_FIELD)184 self.click(**self.RESET_BUTTON)185 msg = self.wait_for_element(**self.EMAIL_FIELD_MSG).text186 self.assertEqual(_('Must be valid e-mail address'), msg)187 logging.info('Done')188 logging.info('E-mail validation passed')...

Full Screen

Full Screen

web_asserts.py

Source:web_asserts.py Github

copy

Full Screen

...9 """10 Методы проверок текста11 """12 def assert_text_on_page(self, text: str, locator: Locator = Locator(css="html"), timeout=None):13 self.wait_for_ready_state_complete()14 try:15 self.wait_text_visible(text, locator, timeout)16 except WebDriverException as e:17 message = f"Ожидаемый текст '{text}' в локаторе '{locator.value}' не появился по {e}"18 raise AssertionError(message)19 def assert_text_present_on_page(self, text: str, sleep_second: int = None):20 self.wait_for_ready_state_complete()21 if sleep_second:22 time.sleep(sleep_second)23 body_text = self.browser.wd.find_element_by_tag_name('body').text24 try:25 assert text in body_text26 except AssertionError:27 raise AssertionError(f"Текст '{text}' не найден на странице")28 def assert_text_not_on_page(self, text: str, locator: Locator = Locator(css="html")):29 element = self.find(locator)30 assert text not in element.text, \31 f"Текст '{text}' элемента '{locator}' все еще содержится в элементе либо не соответствует ему"32 def assert_text_in_element(self, text: str, locator: Locator):33 element_text = self.find(locator).text34 assert text in element_text, \35 f"Найденный текст '{element_text}' элемента '{locator}' не соответствует искомому '{text}'"36 def assert_text_not_in_element(self, text: str, locator: Locator):37 element_text = self.find(locator).text38 assert text not in element_text, \39 f"Найденный текст '{element_text}' элемента '{locator}' соответствует искомому '{text}'"40 def assert_element_value(self, expected_value: str, locator: Locator):41 element_value = self.get_element_value(locator)42 assert expected_value in element_value, \43 f"Найденное значение элемента '{element_value}' не соответствует искомому '{expected_value}'"44 def assert_element_attribute(self, locator: Locator, expected_value: str, attribute: str):45 element = self.find(locator=locator)46 element_value = element.get_attribute(attribute)47 assert expected_value in element_value, \48 f"Найденное значение элемента '{element_value}' не соответствует искомому '{expected_value}'"49 """50 Методы проверок элементов51 """52 def assert_element_present(self, locator: Locator, timeout=None):53 self.wait_for_ready_state_complete()54 for x in range(3):55 try:56 element = self.wait_present(locator, timeout)57 if element:58 return True59 except WebDriverException:60 self.browser.wd.refresh()61 raise NoSuchElementException(f"Элемент '{locator}' не найден на странице")62 def assert_element_visible(self, locator: Locator, timeout=None):63 self.wait_for_ready_state_complete()64 for x in range(3):65 try:66 element = self.wait_visible(locator, timeout)67 if element:68 return True69 except WebDriverException:70 self.browser.wd.refresh()71 raise ElementNotVisibleException(f"Элемент '{locator}' не отображается на странице")72 """73 Методы проверок ссылок74 """75 def assert_url_contains(self, expected_part: str):76 self.wait_for_ready_state_complete()77 assert expected_part in self.browser.wd.current_url78 def assert_url_not_contains(self, expected_part: str):79 self.wait_for_ready_state_complete()80 assert expected_part not in self.browser.wd.current_url81 def assert_tittle_contains(self, expected_title: str):82 self.wait_for_ready_state_complete()83 assert expected_title in self.browser.wd.title, \84 f"Текущий заголовок '{self.browser.wd.title}' не соответствует ожидаемому '{expected_title}'"85 def assert_tittle_not_contains(self, expected_title: str):86 assert expected_title not in self.browser.wd.title, \...

Full Screen

Full Screen

my.py

Source:my.py Github

copy

Full Screen

...9 number = number - 110 if number < 0:11 number = 012 element = elements[number]13 self.wait_for_ready_state_complete()14 try:15 self.__scroll_to_element(element)16 element.click()17 except (StaleElementReferenceException, ENI_Exception):18 self.wait_for_ready_state_complete()19 time.sleep(0.05)20 self.__scroll_to_element(element)...

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