How to use assert_title method in SeleniumBase

Best Python code snippet using SeleniumBase

unit_page_test.py

Source:unit_page_test.py Github

copy

Full Screen

...30 self.driver.find_element_by_id(SEARCH_INPUT_ID).send_keys(unit_id)31 self.driver.find_element_by_id(UNIT_TYPE_INPUT_ID).send_keys(unit_type)32 self.driver.find_element_by_id(PERIOD_INPUT_ID).send_keys(period)33 self.driver.find_element_by_id(SEARCH_BUTTON_ID).click()34 def assert_title(self, title_id, expected_title):35 title = self.driver.find_element_by_id(title_id).text36 self.assertEqual(title, expected_title)37 def assert_dict_values_present_on_page(self, unit_vars):38 """39 Assert that every value in a dictionary is present on the page40 Flattening the dict structure makes things easier than checking for nested dicts41 """42 flattened_vars = flatten(unit_vars)43 for unit_variable in list(flattened_vars.values()):44 self.assertTrue(unit_variable in self.driver.page_source)45 def test_go_direct_to_ent_page(self):46 self.driver.get(f'{SEARCH_URL}/periods/{PERIOD}/types/{ENTERPRISE}/units/{ERN}')47 self.assert_title(UNIT_NAME_ID, enterprise.get('vars').get('name'))48 self.assertEqual(self.driver.find_element_by_id(UNIT_BADGE_ID).text, 'ENTERPRISE')49 self.assertEqual(self.driver.find_element_by_id(UNIT_ID_ID).text, f'ERN {ERN}')50 self.assert_dict_values_present_on_page(enterprise.get('vars'))51 def test_ent_page_contents(self):52 self.search_by_unit_id_type_period(ERN, ENTERPRISE, '201810')53 self.assertEqual(self.driver.current_url, f'{SEARCH_URL}/periods/{PERIOD}/types/{ENTERPRISE}/units/{ERN}')54 self.assert_title(UNIT_NAME_ID, enterprise.get('vars').get('name'))55 self.assertEqual(self.driver.find_element_by_id(UNIT_BADGE_ID).text, 'ENTERPRISE')56 self.assertEqual(self.driver.find_element_by_id(UNIT_ID_ID).text, f'ERN {ERN}')57 self.assert_dict_values_present_on_page(enterprise.get('vars'))58 def test_go_direct_to_leu_page(self):59 self.driver.get(f'{SEARCH_URL}/periods/{PERIOD}/types/{LEGAL_UNIT}/units/{UBRN}')60 self.assert_title(UNIT_NAME_ID, legal_unit.get('vars').get('name'))61 self.assertEqual(self.driver.find_element_by_id(UNIT_BADGE_ID).text, 'LEGAL UNIT')62 self.assertEqual(self.driver.find_element_by_id(UNIT_ID_ID).text, f'UBRN {UBRN}')63 self.assert_dict_values_present_on_page(legal_unit.get('vars'))64 def test_leu_page_contents(self):65 self.search_by_unit_id_type_period(UBRN, LEGAL_UNIT, '201810')66 self.assertEqual(self.driver.current_url, f'{SEARCH_URL}/periods/{PERIOD}/types/{LEGAL_UNIT}/units/{UBRN}')67 self.assert_title(UNIT_NAME_ID, legal_unit.get('vars').get('name'))68 self.assertEqual(self.driver.find_element_by_id(UNIT_BADGE_ID).text, 'LEGAL UNIT')69 self.assertEqual(self.driver.find_element_by_id(UNIT_ID_ID).text, f'UBRN {UBRN}')70 self.assert_dict_values_present_on_page(legal_unit.get('vars'))71 def test_go_direct_to_lou_page(self):72 self.driver.get(f'{SEARCH_URL}/periods/{PERIOD}/types/{LOCAL_UNIT}/units/{LURN}')73 self.assert_title(UNIT_NAME_ID, local_unit.get('vars').get('name'))74 self.assertEqual(self.driver.find_element_by_id(UNIT_BADGE_ID).text, 'LOCAL UNIT')75 self.assertEqual(self.driver.find_element_by_id(UNIT_ID_ID).text, f'LURN {LURN}')76 self.assert_dict_values_present_on_page(local_unit.get('vars'))77 def test_lou_page_contents(self):78 self.search_by_unit_id_type_period(LURN, LOCAL_UNIT, '201810')79 self.assertEqual(self.driver.current_url, f'{SEARCH_URL}/periods/{PERIOD}/types/{LOCAL_UNIT}/units/{LURN}')80 self.assert_title(UNIT_NAME_ID, local_unit.get('vars').get('name'))81 self.assertEqual(self.driver.find_element_by_id(UNIT_BADGE_ID).text, 'LOCAL UNIT')82 self.assertEqual(self.driver.find_element_by_id(UNIT_ID_ID).text, f'LURN {LURN}')83 self.assert_dict_values_present_on_page(local_unit.get('vars'))84 def test_go_direct_to_reu_page(self):85 self.driver.get(f'{SEARCH_URL}/periods/{PERIOD}/types/{REPORTING_UNIT}/units/{RURN}')86 self.assert_title(UNIT_NAME_ID, reporting_unit.get('vars').get('name'))87 self.assertEqual(self.driver.find_element_by_id(UNIT_BADGE_ID).text, 'REPORTING UNIT')88 self.assertEqual(self.driver.find_element_by_id(UNIT_ID_ID).text, f'RURN {RURN}')89 self.assert_dict_values_present_on_page(reporting_unit.get('vars'))90 def test_reu_page_contents(self):91 self.search_by_unit_id_type_period(RURN, REPORTING_UNIT, '201810')92 self.assertEqual(self.driver.current_url, f'{SEARCH_URL}/periods/{PERIOD}/types/{REPORTING_UNIT}/units/{RURN}')93 self.assert_title(UNIT_NAME_ID, reporting_unit.get('vars').get('name'))94 self.assertEqual(self.driver.find_element_by_id(UNIT_BADGE_ID).text, 'REPORTING UNIT')95 self.assertEqual(self.driver.find_element_by_id(UNIT_ID_ID).text, f'RURN {RURN}')96 self.assert_dict_values_present_on_page(reporting_unit.get('vars'))97 def test_go_direct_to_ch_page(self):98 self.driver.get(f'{SEARCH_URL}/periods/{PERIOD}/types/{COMPANY_HOUSE}/units/{CRN}')99 self.assert_title(UNIT_NAME_ID, company_house.get('vars').get('businessName'))100 self.assertEqual(self.driver.find_element_by_id(UNIT_BADGE_ID).text, 'COMPANY HOUSE')101 self.assertEqual(self.driver.find_element_by_id(UNIT_ID_ID).text, f'CRN {CRN}')102 self.assert_dict_values_present_on_page(company_house.get('vars'))103 def test_ch_page_contents(self):104 self.search_by_unit_id_type_period(CRN, COMPANY_HOUSE, '201810')105 self.assertEqual(self.driver.current_url, f'{SEARCH_URL}/periods/{PERIOD}/types/{COMPANY_HOUSE}/units/{CRN}')106 self.assert_title(UNIT_NAME_ID, company_house.get('vars').get('businessName'))107 self.assertEqual(self.driver.find_element_by_id(UNIT_BADGE_ID).text, 'COMPANY HOUSE')108 self.assertEqual(self.driver.find_element_by_id(UNIT_ID_ID).text, f'CRN {CRN}')109 self.assert_dict_values_present_on_page(company_house.get('vars'))110 def test_go_direct_to_vat_page(self):111 self.driver.get(f'{SEARCH_URL}/periods/{PERIOD}/types/{VALUE_ADDED_TAX}/units/{VATREF}')112 self.assert_title(UNIT_NAME_ID, value_added_tax.get('vars').get('businessName'))113 self.assertEqual(self.driver.find_element_by_id(UNIT_BADGE_ID).text, 'VALUE ADDED TAX')114 self.assertEqual(self.driver.find_element_by_id(UNIT_ID_ID).text, f'VATREF {VATREF}')115 self.assert_dict_values_present_on_page(value_added_tax.get('vars'))116 def test_vat_page_contents(self):117 self.search_by_unit_id_type_period(VATREF, VALUE_ADDED_TAX, '201810')118 self.assertEqual(self.driver.current_url, f'{SEARCH_URL}/periods/{PERIOD}/types/{VALUE_ADDED_TAX}/units/{VATREF}')119 self.assert_title(UNIT_NAME_ID, value_added_tax.get('vars').get('businessName'))120 self.assertEqual(self.driver.find_element_by_id(UNIT_BADGE_ID).text, 'VALUE ADDED TAX')121 self.assertEqual(self.driver.find_element_by_id(UNIT_ID_ID).text, f'VATREF {VATREF}')122 self.assert_dict_values_present_on_page(value_added_tax.get('vars'))123 def test_go_direct_to_paye_page(self):124 self.driver.get(f'{SEARCH_URL}/periods/{PERIOD}/types/{PAY_AS_YOU_EARN}/units/{PAYEREF}')125 self.assert_title(UNIT_NAME_ID, pay_as_you_earn.get('vars').get('businessName'))126 self.assertEqual(self.driver.find_element_by_id(UNIT_BADGE_ID).text, 'PAY AS YOU EARN')127 self.assertEqual(self.driver.find_element_by_id(UNIT_ID_ID).text, f'PAYEREF {PAYEREF}')128 self.assert_dict_values_present_on_page(pay_as_you_earn.get('vars'))129 def test_paye_page_contents(self):130 self.search_by_unit_id_type_period(PAYEREF, PAY_AS_YOU_EARN, '201810')131 self.assertEqual(self.driver.current_url, f'{SEARCH_URL}/periods/{PERIOD}/types/{PAY_AS_YOU_EARN}/units/{PAYEREF}')132 self.assert_title(UNIT_NAME_ID, pay_as_you_earn.get('vars').get('businessName'))133 self.assertEqual(self.driver.find_element_by_id(UNIT_BADGE_ID).text, 'PAY AS YOU EARN')134 self.assertEqual(self.driver.find_element_by_id(UNIT_ID_ID).text, f'PAYEREF {PAYEREF}')135 self.assert_dict_values_present_on_page(pay_as_you_earn.get('vars'))136if __name__ == '__main__':...

Full Screen

Full Screen

test_baidu_keywords_search.py

Source:test_baidu_keywords_search.py Github

copy

Full Screen

1"""2@Name: test_baidu_keywords_search3@Version: 4@Project: PyCharm Community Edition5@Author: liujinjia6@Data: 2017/12/27"""8import lib9from config import Config10import unittest11from BeautifulReport import BeautifulReport12# 原子化层级, WebdDiverClient, Config13# 业务封装层级, page object , Business, 封装了多个业务方法14# 测试方法层级, 他只调用业务层级的逻辑关系, 除非业务逻辑和顺序发生变化, 否则不做修改15class BaiDuTestCases(unittest.TestCase):16 @classmethod17 def setUpClass(cls):18 cls.config = Config.enum.get('baidu')19 20 def setUp(self):21 self.lib = lib.BusinessApi(self.config)22 self.driver = self.lib.driver23 24 def tearDown(self):25 self.driver.quit()26 27 def test_config_enum_is_ok(self):28 """[百度][Config] 验证百度config文件是否正确"""29 print('test start with test_config_enum_is_ok')30 self.assertIsNotNone(self.lib.config)31 self.assertIsNotNone(self.lib.keywords)32 self.assertIsNotNone(self.lib.url)33 self.assertIsNotNone(self.lib.assert_title)34 print('断言所有配置文件不为None')35 def test_baidu_search_is_ok(self):36 """[百度][TEST] 在百度首页输入搜索关键字,确认返回结果正确"""37 print('在百度搜索中输入{}关键字进行查询并跳转到查询结果页面')38 self.lib.baidu_search(self.lib.url, self.lib.keywords)39 print('断言测试结果 {} 不为None'.format(self.lib.parse(self.lib.assert_title)))40 # self.go_to_some_path_and_click_elments(xxxx)41 self.assertIsNotNone(self.lib.parse(self.lib.assert_title))42 self.assertEqual(self.lib.parse(self.lib.assert_title)[0], '{}_百度搜索'.format(self.lib.keywords))43 44 @BeautifulReport.add_test_img('test')45 def test_baidu_tieba(self):46 """[百度][TEST] 测试搜索后,跳转到贴吧中的title与预期结果一致"""47 print('在百度搜索中输入{}关键字进行查询并跳转到查询结果页面'.format(self.lib.keywords))48 self.lib.baidu_search(self.lib.url, self.lib.keywords)49 print('跳转到结果页面中的贴吧页面')50 # self.lib.driver.get_screenshot_as_file('img/test.png')51 print('将当前页面进行图片存储')52 self.lib.click(self.lib.tieba_button)53 print('断言页面中的内容与我们的预期结果一致')...

Full Screen

Full Screen

switch_to_window.py

Source:switch_to_window.py Github

copy

Full Screen

...8sst.actions.go_to('/')9sst.actions.click_link('popup_link')10# switch to new window/tab11sst.actions.switch_to_window(index_or_name='_NEW_WINDOW')12sst.actions.assert_title('Popup Window')13# switch back to default/main window/tab14sst.actions.switch_to_window()15sst.actions.assert_title('The Page Title')16# switch to new window/tab17sst.actions.switch_to_window('_NEW_WINDOW')18sst.actions.assert_title('Popup Window')19# verify we can access content in new window20elem = sst.actions.get_element(tag='p', id='popup_id', text='Popup text here')21sst.actions.assert_text(elem, 'Popup text here')22# switch back to default/main window/tab23sst.actions.switch_to_window(index_or_name='')24sst.actions.assert_title('The Page Title')25# switch to new window/tab using index26sst.actions.switch_to_window(index_or_name=1)27sst.actions.assert_title('Popup Window')28# switch back to default/main window using index29sst.actions.switch_to_window(0)30sst.actions.assert_title('The Page Title')31# fails when the window name does not exist32sst.actions.fails(sst.actions.switch_to_window, index_or_name='not_a_window')33# fails when the window name does not exist34sst.actions.fails(sst.actions.switch_to_window, 'not_a_window')35# fails when the window index does not exist36sst.actions.fails(sst.actions.switch_to_window, index_or_name=99)37# fails when the window index does not exist38sst.actions.fails(sst.actions.switch_to_window, 99)39# verify we are still back on main window...

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