def test_add_collaborator(web_fixture, access_domain_fixture, access_ui_fixture): """A user may add other users as collaborators to his address book, specifying the privileges in the process.""" browser = access_ui_fixture.browser address_book = access_domain_fixture.address_book account = access_domain_fixture.account other_address_book = access_domain_fixture.other_address_book other_account = access_domain_fixture.other_account web_fixture.log_in(browser=browser, system_account=account) browser.open('/') assert address_book not in AddressBook.address_books_visible_to( other_account) assert not address_book.can_be_edited_by(other_account) assert not address_book.can_be_added_to_by(other_account) browser.click(XPath.link().with_text('Address book of [email protected]')) browser.click(XPath.link().with_text('Add collaborator')) browser.select(XPath.select_labelled('Choose collaborator'), '*****@*****.**') browser.click(XPath.input_labelled('May add new addresses')) browser.click(XPath.input_labelled('May edit existing addresses')) browser.click(XPath.button_labelled('Share')) assert access_ui_fixture.is_on_address_book_page_of('*****@*****.**') assert address_book in AddressBook.address_books_visible_to(other_account) assert address_book.can_be_edited_by(other_account) assert address_book.can_be_added_to_by(other_account)
def test_navigating_the_page_numbers(web_fixture, page_menu_fixture): """One can navigate the range of page links displayed by the PageMenu using the special links.""" fixture = page_menu_fixture fixture.number_of_pages = 30 fixture.max_page_links = 5 web_fixture.reahl_server.set_app(page_menu_fixture.wsgi_app) browser = web_fixture.driver_browser browser.open('/') # Case: next link browser.click(XPath.link().with_text_starting('»')) assert browser.wait_for(fixture.page_range_links_match, 'p6,p7,p8,p9,p10') browser.click(XPath.link().with_text_starting('»')) assert browser.wait_for(fixture.page_range_links_match, 'p11,p12,p13,p14,p15') # Case: prev link browser.click(XPath.link().with_text_starting('«')) assert browser.wait_for(fixture.page_range_links_match, 'p6,p7,p8,p9,p10') # Case: last link browser.click(XPath.link().with_text_starting('→')) assert browser.wait_for(fixture.page_range_links_match, 'p26,p27,p28,p29,p30') # Case: first link browser.click(XPath.link().with_text_starting('←')) assert browser.wait_for(fixture.page_range_links_match, 'p1,p2,p3,p4,p5')
def test_detour_is_non_reentrant(web_fixture): """Once detoured to a View marked as the start of a Detour, a Bookmark to that View itself will not re-enter the detour. """ class MainUI(UserInterface): def assemble(self): self.define_page(HTML5Page).use_layout(BasicPageLayout()) step1 = self.define_view('/firstStepOfDetour', title='Step 1', detour=True) step1.set_slot('main', A.factory_from_bookmark(step1.as_bookmark(self))) home = self.define_view('/initial', title='View a') home.set_slot('main', A.factory_from_bookmark(step1.as_bookmark(self))) wsgi_app = web_fixture.new_wsgi_app(site_root=MainUI) browser = Browser(wsgi_app) def locationIsSetToReturnTo(url_path): return urllib.parse.parse_qs(browser.current_url.query)['returnTo'] == [url_path] browser.open('/initial') browser.click(XPath.link().with_text('Step 1')) assert browser.current_url.path == '/firstStepOfDetour' assert locationIsSetToReturnTo('http://localhost/initial') browser.click(XPath.link().with_text('Step 1')) assert browser.current_url.path == '/firstStepOfDetour' assert locationIsSetToReturnTo('http://localhost/initial')
def test_edit_and_add_own(web_fixture, access_domain_fixture, access_ui_fixture): """The owner of an AddressBook can add and edit Addresses to the owned AddressBook.""" browser = access_ui_fixture.browser fixture = access_domain_fixture account = fixture.account address_book = fixture.address_book web_fixture.log_in(browser=browser, system_account=account) browser.open('/') browser.click(XPath.link().with_text('Address book of [email protected]')) # add browser.click(XPath.link().with_text('Add address')) browser.type(XPath.input_labelled('Name'), 'Someone') browser.type(XPath.input_labelled('Email'), '*****@*****.**') browser.click(XPath.button_labelled('Save')) assert browser.is_element_present( XPath.paragraph().including_text('Someone: [email protected]')) # edit browser.click(XPath.button_labelled('Edit')) browser.type(XPath.input_labelled('Name'), 'Else') browser.type(XPath.input_labelled('Email'), '*****@*****.**') browser.click(XPath.button_labelled('Update')) assert browser.is_element_present( XPath.paragraph().including_text('Else: [email protected]'))
def test_clicking_on_different_tabs_switch(web_fixture, panel_switch_fixture, tabbed_panel_ajax_fixture): """Clicking on tabs change the contents that are displayed as well as the active tab.""" if not panel_switch_fixture.enable_js: panel_switch_fixture.ensure_disabled_js_files_not_cached() wsgi_app = tabbed_panel_ajax_fixture.new_wsgi_app( enable_js=panel_switch_fixture.enable_js) web_fixture.reahl_server.set_app(wsgi_app) browser = web_fixture.driver_browser browser.open('/') # Clicking on 3 (a normal tab), changes the current tab assert browser.wait_for_not(tabbed_panel_ajax_fixture.tab_is_active, 'tab 3 name') assert browser.wait_for_not(tabbed_panel_ajax_fixture.tab_contents_equals, '<p>tab 3 content</p>') browser.click(XPath.link().with_text('tab 3 name')) assert browser.wait_for(tabbed_panel_ajax_fixture.tab_is_active, 'tab 3 name') assert browser.wait_for(tabbed_panel_ajax_fixture.tab_contents_equals, '<p>tab 3 content</p>') browser.click(XPath.link().with_text('tab 4 name')) assert browser.wait_for_not(tabbed_panel_ajax_fixture.tab_is_active, 'tab 3 name') assert browser.wait_for(tabbed_panel_ajax_fixture.tab_is_active, 'tab 4 name') assert browser.wait_for(tabbed_panel_ajax_fixture.tab_contents_equals, '<p>tab 4 content</p>')
def test_see_other(web_fixture, access_domain_fixture, access_ui_fixture): """If allowed, an account may see another account's AddressBook, and could edit or add Addresses, depending on the allowed rights.""" browser = access_ui_fixture.browser account = access_domain_fixture.account address_book = access_domain_fixture.address_book other_address_book = access_domain_fixture.other_address_book other_address_book.allow(account) Address(address_book=other_address_book, email_address='*****@*****.**', name='Friend').save() web_fixture.log_in(browser=browser, system_account=account) browser.open('/') browser.click(XPath.link().with_text('Address book of [email protected]')) assert browser.is_element_present( XPath.paragraph().including_text('Friend: [email protected]')) # Case: can only see assert not browser.is_element_enabled( XPath.link().with_text('Add address')) assert not browser.is_element_enabled(XPath.button_labelled('Edit')) # Case: can edit only other_address_book.allow(account, can_edit_addresses=True, can_add_addresses=False) browser.refresh() assert not browser.is_element_enabled( XPath.link().with_text('Add address')) assert browser.is_element_enabled(XPath.button_labelled('Edit')) # Case: can add, and therefor also edit other_address_book.allow(account, can_add_addresses=True) browser.refresh() assert browser.is_element_enabled(XPath.link().with_text('Add address')) assert browser.is_element_enabled(XPath.button_labelled('Edit')) browser.click(XPath.button_labelled('Edit')) browser.type(XPath.input_labelled('Name'), 'Else') browser.type(XPath.input_labelled('Email'), '*****@*****.**') browser.click(XPath.button_labelled('Update')) assert browser.is_element_present( XPath.paragraph().including_text('Else: [email protected]'))
def test_widgets(web_fixture, carousel_panel_scenario): fixture = carousel_panel_scenario fixture.start_example_app() web_fixture.driver_browser.open('/') assert web_fixture.driver_browser.wait_for(fixture.carousel_caption_equals, 'a paragraph with text') web_fixture.driver_browser.click(XPath.link().with_text('Next')) assert web_fixture.driver_browser.wait_for(fixture.carousel_caption_equals, 'a different paragraph')
def test_customising_dialog_buttons(web_fixture, popup_a_fixture): """The buttons of the dialog can be customised.""" class PopupTestPanel(Div): def __init__(self, view): super().__init__(view) popup_a = self.add_child( PopupA(view, view.as_bookmark(), '#contents')) popup_a.add_js_button('Butt1') popup_a.add_js_button('Butt2') popup_contents = self.add_child( P(view, text='this is the content of the popup')) popup_contents.set_id('contents') wsgi_app = web_fixture.new_wsgi_app(enable_js=True, child_factory=PopupTestPanel.factory()) web_fixture.reahl_server.set_app(wsgi_app) browser = web_fixture.driver_browser button1_xpath = XPath.button_labelled('Butt1') button2_xpath = XPath.button_labelled('Butt2') browser.open('/') browser.click(XPath.link().with_text('Home page')) browser.wait_for(popup_a_fixture.is_popped_up) assert browser.is_element_present(button1_xpath) assert browser.is_element_present(button2_xpath)
def test_default_behaviour(web_fixture, popup_a_fixture): """If you click on the A, a popupwindow opens with its contents the specified element on the target page.""" class PopupTestPanel(Div): def __init__(self, view): super().__init__(view) self.add_child(PopupA(view, view.as_bookmark(), '#contents')) popup_contents = self.add_child( P(view, text='this is the content of the popup')) popup_contents.set_id('contents') wsgi_app = web_fixture.new_wsgi_app(enable_js=True, child_factory=PopupTestPanel.factory()) web_fixture.reahl_server.set_app(wsgi_app) browser = web_fixture.driver_browser browser.open('/') # The A is rendered correctly assert browser.is_element_present( "//a[@title='Home page' and text()='Home page' and @href='/']") # subsequent behaviour browser.click(XPath.link().with_text('Home page')) browser.wait_for(popup_a_fixture.is_popped_up) #check some bootstrap attributes dialog_xpath = "//div[@class='modal fade show' and @tabindex='-1']/div[@class='modal-dialog']/div[@class='modal-content']" assert browser.is_element_present(dialog_xpath) browser.click(XPath.button_labelled('Close')) browser.wait_for_not(popup_a_fixture.is_popped_up)
def test_centering_dialog_vertically(web_fixture, popup_a_fixture): """The dialog can be centered vertically.""" class PopupTestPanel(Div): def __init__(self, view): super().__init__(view) self.add_child( PopupA(view, view.as_bookmark(), '#contents', center_vertically=True)) popup_contents = self.add_child( P(view, text='this is the content of the popup')) popup_contents.set_id('contents') wsgi_app = web_fixture.new_wsgi_app(enable_js=True, child_factory=PopupTestPanel.factory()) web_fixture.reahl_server.set_app(wsgi_app) browser = web_fixture.driver_browser browser.open('/') browser.click(XPath.link().with_text('Home page')) browser.wait_for(popup_a_fixture.is_popped_up) dialog_xpath = "//div[@class='modal fade show' and @tabindex='-1']/div[@class='modal-dialog modal-dialog-centered']/div[@class='modal-content']" assert browser.is_element_present(dialog_xpath)
def test_workings_of_check_checkbox_button(web_fixture, popup_a_fixture): """A CheckCheckBoxButton checks the checkbox on the original page when clicked.""" class PopupTestPanel(Div): @exposed def fields(self, fields): fields.field = BooleanField(label='a checkbox') def __init__(self, view): super().__init__(view) popup_a = self.add_child( PopupA(view, view.as_bookmark(), '#contents')) popup_contents = self.add_child( P(view, text='this is the content of the popup')) popup_contents.set_id('contents') form = self.add_child(Form(view, 'aform')).use_layout(FormLayout()) checkbox = form.layout.add_input( CheckboxInput(form, self.fields.field)) popup_a.add_js_button('Checkit', CheckCheckboxScript(checkbox)) wsgi_app = web_fixture.new_wsgi_app(enable_js=True, child_factory=PopupTestPanel.factory()) web_fixture.reahl_server.set_app(wsgi_app) browser = web_fixture.driver_browser browser.open('/') browser.click(XPath.link().with_text('Home page')) browser.wait_for(popup_a_fixture.is_popped_up) browser.click(XPath.button_labelled('Checkit')) browser.wait_for_not(popup_a_fixture.is_popped_up) assert browser.is_selected(XPath.input_labelled('a checkbox'))
def test_active_state_on_multiple_menus(web_fixture, page_menu_fixture): """If there's more than one PageMenu on the page, the active page is switched for both of them""" fixture = page_menu_fixture class MainWidget(Div): def __init__(self, view): super().__init__(view) page_index = fixture.PageIndexStub(fixture.max_page_links, fixture.number_of_pages) page_container = self.add_child( fixture.PageContainer(self.view, page_index)) self.add_child( PageMenu(self.view, 'page_menu_widget', page_index, page_container)) self.add_child( PageMenu(self.view, 'page_menu_widget2', page_index, page_container)) fixture.MainWidget = MainWidget web_fixture.reahl_server.set_app(fixture.wsgi_app) browser = web_fixture.driver_browser browser.open('/') assert not fixture.is_marked_active('p2', nth=1) assert not fixture.is_marked_active('p2', nth=2) browser.click(XPath.link().with_text('p2')) browser.wait_for(fixture.is_marked_active, 'p2', 1) browser.wait_for(fixture.is_marked_active, 'p2', 2)
def test_contents_when_navigating_the_page_numbers(web_fixture, page_menu_fixture): """When navigating the range of page links, the currently displayed contents stay unchanged.""" page_menu_fixture.number_of_pages = 30 page_menu_fixture.max_page_links = 5 web_fixture.reahl_server.set_app(page_menu_fixture.wsgi_app) browser = web_fixture.driver_browser browser.open('/') browser.click(XPath.link().with_text('p2')) browser.wait_for(page_menu_fixture.container_contents_is, 'contents of page 2') browser.click(XPath.link().with_text_starting('»')) browser.wait_for(page_menu_fixture.container_contents_is, 'contents of page 2')
def test_logging_in(web_fixture, session_scope_fixture): """A user can log in by going to the Log in page. The name of the currently logged in user is displayed on the home page.""" browser = Browser(web_fixture.new_wsgi_app(site_root=SessionScopeUI)) user = session_scope_fixture.user browser.open('/') browser.click(XPath.link().with_text('Log in')) browser.type(XPath.input_labelled('Email'), '*****@*****.**') browser.type(XPath.input_labelled('Password'), 'topsecret') browser.click(XPath.button_labelled('Log in')) browser.click(XPath.link().with_text('Home')) assert browser.is_element_present( XPath.paragraph().including_text('Welcome John Doe'))
def test_logging_in(web_fixture, login_fixture): """A user can log in by going to the Log in page. The name of the currently logged in user is displayed on the home page.""" browser = login_fixture.browser login_fixture.new_account() browser.open('/') browser.click(XPath.link().with_text('Log in')) browser.type(XPath.input_labelled('Email'), '*****@*****.**') browser.type(XPath.input_labelled('Password'), 'topsecret') browser.click(XPath.button_labelled('Log in')) browser.click(XPath.link().with_text('Home')) assert browser.is_element_present( XPath.paragraph().including_text('Welcome [email protected]'))
def test_button_layouts_on_anchors(web_fixture): """A ButtonLayout can also be used to make an A (anchor) look like a button.""" anchor = A(web_fixture.view, href=Url('/an/href'), description='link text').use_layout(ButtonLayout()) tester = WidgetTester(anchor) [rendered_anchor] = tester.xpath(XPath.link().with_text('link text')) assert rendered_anchor.attrib['class'] == 'btn btn-secondary' assert 'aria-disabled' not in rendered_anchor.attrib assert 'tabindex' not in rendered_anchor.attrib anchor = A(web_fixture.view, href=Url('/an/href'), description='link text', write_check=lambda: False).use_layout(ButtonLayout()) tester = WidgetTester(anchor) [rendered_anchor] = tester.xpath(XPath.link().with_text('link text')) assert rendered_anchor.attrib['class'] == 'btn btn-secondary disabled' assert rendered_anchor.attrib['aria-disabled'] == 'true' assert rendered_anchor.attrib['tabindex'] == '-1'
def test_email_retained(web_fixture, session_scope_fixture): """The email address used when last logged in is always pre-populated on the Log in page.""" browser = Browser(web_fixture.new_wsgi_app(site_root=SessionScopeUI)) user = session_scope_fixture.user browser.open('/') browser.click(XPath.link().with_text('Log in')) browser.type(XPath.input_labelled('Email'), '*****@*****.**') browser.type(XPath.input_labelled('Password'), 'topsecret') browser.click(XPath.button_labelled('Log in')) # Go away from the page, then back browser.click(XPath.link().with_text('Home')) browser.click(XPath.link().with_text('Log in')) # .. then the email is still pre-populated typed_value = browser.get_value(XPath.input_labelled('Email')) assert typed_value == '*****@*****.**'
def test_clicking_on_sub_tab_switches(web_fixture, panel_switch_fixture, tabbed_panel_ajax_fixture): """Clicking on a sub tab also changes the contents that are displayed as well as the active tab.""" if not panel_switch_fixture.enable_js: panel_switch_fixture.ensure_disabled_js_files_not_cached() wsgi_app = tabbed_panel_ajax_fixture.new_wsgi_app( enable_js=panel_switch_fixture.enable_js) web_fixture.reahl_server.set_app(wsgi_app) browser = web_fixture.driver_browser browser.open('/') browser.click(XPath.link().with_text('tab 3 name')) assert browser.wait_for(tabbed_panel_ajax_fixture.tab_is_active, 'tab 3 name') assert browser.wait_for(tabbed_panel_ajax_fixture.tab_contents_equals, '<p>tab 3 content</p>') assert browser.wait_for_not(tabbed_panel_ajax_fixture.tab_is_active, 'tab 2 name') assert browser.wait_for_not(tabbed_panel_ajax_fixture.tab_contents_equals, '<p>tab 1/2 content</p>') browser.click(XPath.link().with_text('multitab name')) browser.click(XPath.link().with_text('tab 2 name')) # - active status removed from previous assert browser.wait_for_not(tabbed_panel_ajax_fixture.tab_is_active, 'tab 3 name') # - new status and contents set assert browser.wait_for(tabbed_panel_ajax_fixture.tab_is_active, 'tab 2 name') assert browser.wait_for(tabbed_panel_ajax_fixture.tab_contents_equals, '<p>tab 1/2 content</p>') # Clicking away from the multitab sub-tab removes its active status browser.click(XPath.link().with_text('tab 3 name')) # tab2 is not active anymore assert browser.wait_for_not(tabbed_panel_ajax_fixture.tab_is_active, 'tab 2 name')
def test_i18n(web_fixture, i18n_scenario): fixture = i18n_scenario fixture.start_example_app() web_fixture.driver_browser.open('/some_page') assert fixture.get_text_in_p() == 'This is a translated message. The current URL is "/some_page".' assert web_fixture.driver_browser.title == 'Translated example' web_fixture.driver_browser.capture_cropped_screenshot(fixture.new_screenshot_path('i18n1.png')) web_fixture.driver_browser.click(XPath.link().with_text('Afrikaans')) assert fixture.get_text_in_p() == 'Hierdie is \'n vertaalde boodskap. Die huidige URL is "/af/some_page".' assert web_fixture.driver_browser.title == 'Vertaalde voorbeeld' web_fixture.driver_browser.capture_cropped_screenshot(fixture.new_screenshot_path('i18n2.png'))
def test_parameterised1(web_fixture, parameterised1_scenario): browser = Browser(parameterised1_scenario.wsgi_app) browser.open('/') browser.click(XPath.link().with_text('Add')) browser.type(XPath.input_labelled('Name'), 'John') browser.type(XPath.input_labelled('Email'), '*****@*****.**') browser.click(XPath.button_labelled('Save')) assert browser.current_url.path == '/' browser.click(XPath.link().with_text('edit')) john = Session.query(parameterised1.Address).one() assert browser.current_url.path == '/edit/%s' % john.id browser.type(XPath.input_labelled('Name'), 'Johnny') browser.type(XPath.input_labelled('Email'), '*****@*****.**') browser.click(XPath.button_labelled('Update')) assert browser.current_url.path == '/' assert browser.is_element_present(XPath.paragraph().including_text('Johnny: [email protected]'))
def test_translations(web_fixture, translation_example_fixture): """The user can choose between languages. The text for which translations exist change accordingly.""" browser = translation_example_fixture.browser browser.open('/') assert browser.is_element_present(XPath.heading(1).with_text("Addresses")) assert browser.is_element_present(XPath.label().with_text("Name")) #go to the the translated page browser.click(XPath.link().with_text('Afrikaans')) assert browser.is_element_present(XPath.heading(1).with_text("Adresse")) assert browser.is_element_present(XPath.label().with_text("Naam"))
def test_selecting_a_page(web_fixture, page_menu_fixture): """Clicking the link of a page results in the contents of the PageContainer being refreshed.""" web_fixture.reahl_server.set_app(page_menu_fixture.wsgi_app) browser = web_fixture.driver_browser browser.open('/') browser.wait_for(page_menu_fixture.container_contents_is, 'contents of page 1') browser.click(XPath.link().with_text('p2')) browser.wait_for(page_menu_fixture.container_contents_is, 'contents of page 2')
def test_logging_in(web_fixture, access_domain_fixture, access_ui_fixture): """A user first sees only a login screen on the home page; after logging in, all the address books visible to the user appear.""" browser = access_ui_fixture.browser account = access_domain_fixture.account address_book = access_domain_fixture.address_book other_address_book = access_domain_fixture.other_address_book other_address_book.allow(account) browser.open('/') browser.type(XPath.input_labelled('Email'), '*****@*****.**') browser.type(XPath.input_labelled('Password'), access_domain_fixture.password) browser.click(XPath.button_labelled('Log in')) assert browser.is_element_present( XPath.link().with_text('Address book of [email protected]')) assert browser.is_element_present( XPath.link().with_text('Address book of [email protected]'))
def test_clicking_on_multi_tab(web_fixture, panel_switch_fixture, tabbed_panel_ajax_fixture): """Clicking on a multitab just opens and closes its dropdown without affecting the current open tab.""" if not panel_switch_fixture.enable_js: panel_switch_fixture.ensure_disabled_js_files_not_cached() wsgi_app = tabbed_panel_ajax_fixture.new_wsgi_app( enable_js=panel_switch_fixture.enable_js) web_fixture.reahl_server.set_app(wsgi_app) browser = web_fixture.driver_browser browser.open('/') # Make tab 3 the active one browser.click(XPath.link().with_text('tab 3 name')) assert browser.wait_for(tabbed_panel_ajax_fixture.tab_is_active, 'tab 3 name') assert browser.wait_for(tabbed_panel_ajax_fixture.tab_contents_equals, '<p>tab 3 content</p>') # Clicking on the multitab toggles the dropdown assert browser.wait_for_element_not_visible( XPath.link().with_text('tab 2 name')) browser.click(XPath.link().with_text('multitab name')) assert browser.wait_for_element_visible( XPath.link().with_text('tab 2 name')) # - current active tab not changed assert browser.wait_for(tabbed_panel_ajax_fixture.tab_is_active, 'tab 3 name') assert browser.wait_for(tabbed_panel_ajax_fixture.tab_contents_equals, '<p>tab 3 content</p>') # Clicking on the multitab toggles the dropdown again browser.click(XPath.link().with_text('multitab name')) # - current active tab not changed assert browser.wait_for(tabbed_panel_ajax_fixture.tab_is_active, 'tab 3 name') assert browser.wait_for(tabbed_panel_ajax_fixture.tab_contents_equals, '<p>tab 3 content</p>')
def test_active_state_of_page_links(web_fixture, page_menu_fixture): """When choosing a page, the new page link is marked as active, without a server round-trip.""" fixture = page_menu_fixture fixture.number_of_pages = 30 fixture.max_page_links = 5 web_fixture.reahl_server.set_app(fixture.wsgi_app) web_fixture.driver_browser.open('/') with web_fixture.driver_browser.no_load_expected_for('.pagination>*'): assert not fixture.is_marked_active('p2') web_fixture.driver_browser.click(XPath.link().with_text('p2')) web_fixture.driver_browser.wait_for(fixture.is_marked_active, 'p2')
def test_sorting(web_fixture, data_table_fixture): """By clicking on special links in the column header, the table is sorted according to that column - ascending or descending.""" web_fixture.reahl_server.set_app(data_table_fixture.wsgi_app) browser = web_fixture.driver_browser browser.open('/') #----- by default, not sorted assert not data_table_fixture.is_column_sorted(1, 'ascending') assert not data_table_fixture.is_column_sorted(1, 'descending') assert not data_table_fixture.is_column_sorted(2, 'ascending') assert not data_table_fixture.is_column_sorted(2, 'descending') #----- first click on column sorts ascending browser.click(data_table_fixture.xpath_for_sort_link_for_column(1)) assert data_table_fixture.is_column_sorted(1, 'ascending') assert data_table_fixture.get_table_row(1) == ['1', 'T'] assert data_table_fixture.get_table_row(2) == ['2', 'H'] assert data_table_fixture.get_table_row(3) == ['3', 'E'] #----- sort ascending on alpha, the second column assert data_table_fixture.is_column_sorted(2, None) browser.click(data_table_fixture.xpath_for_sort_link_for_column(2)) assert data_table_fixture.is_column_sorted(2, 'ascending') assert data_table_fixture.is_column_sorted(1, None) assert data_table_fixture.get_table_row(1) == ['22', 'A'] assert data_table_fixture.get_table_row(2) == ['9', 'B'] assert data_table_fixture.get_table_row(3) == ['7', 'C'] #----- sort descending on alpha, the second column browser.click(data_table_fixture.xpath_for_sort_link_for_column(2)) assert data_table_fixture.is_column_sorted(2, 'descending') assert data_table_fixture.get_table_row(1) == ['23', 'Z'] assert data_table_fixture.get_table_row(2) == ['24', 'Y'] assert data_table_fixture.get_table_row(3) == ['15', 'X'] #----- sort order stays changed when paging browser.click(XPath.link().with_text('4')) assert data_table_fixture.get_table_row(1) == ['4', 'Q'] assert data_table_fixture.get_table_row(2) == ['18', 'P'] assert data_table_fixture.get_table_row(3) == ['11', 'O'] #----- contents of the page you are on changes according to a new sort order browser.click(data_table_fixture.xpath_for_sort_link_for_column(1)) assert data_table_fixture.get_table_row(1) == ['10', 'R'] assert data_table_fixture.get_table_row(2) == ['11', 'O'] assert data_table_fixture.get_table_row(3) == ['12', 'W']
def test_button_layouts_on_disabled_anchors(web_fixture): """Disabled A's are marked with a class so Bootstrap can style them appropriately.""" def can_write(): return False anchor = A(web_fixture.view, href=Url('/an/href'), description='link text', write_check=can_write) anchor.use_layout(ButtonLayout()) tester = WidgetTester(anchor) [rendered_anchor] = tester.xpath(XPath.link().with_text('link text')) assert rendered_anchor.attrib['class'] == 'btn btn-secondary disabled'
def test_register_help_duplicate(web_fixture, party_account_fixture, accounts_web_fixture): fixture = accounts_web_fixture fixture.browser.open('/a_ui/registerHelp') fixture.browser.type(XPath.input_labelled('Email'), party_account_fixture.system_account.email) fixture.browser.click(XPath.button_labelled('Investigate')) assert fixture.browser.current_url.path == '/a_ui/registerHelp/duplicate' fixture.browser.click( XPath.link().including_text('password reset procedure')) assert fixture.browser.current_url.path == '/a_ui/resetPassword'
def test_language_menu(web_fixture): """A Nav can also be constructed to let a user choose to view the same page in another of the supported languages.""" class PanelWithMenu(Div): def __init__(self, view): super().__init__(view) self.add_child(Menu(view).with_languages()) self.add_child(P(view, text=_('This is an English sentence.'))) wsgi_app = web_fixture.new_wsgi_app(child_factory=PanelWithMenu.factory()) browser = Browser(wsgi_app) browser.open('/') assert browser.is_element_present(XPath.paragraph().including_text('This is an English sentence.')) browser.click(XPath.link().with_text('Afrikaans')) assert browser.is_element_present(XPath.paragraph().including_text('Hierdie is \'n sin in Afrikaans.')) browser.click(XPath.link().with_text('English (United Kingdom)')) assert browser.is_element_present(XPath.paragraph().including_text('This is an English sentence.'))
def test_widgets_using_factories(web_fixture, tabbed_panel_scenario): fixture = tabbed_panel_scenario fixture.start_example_app() web_fixture.driver_browser.open('/') web_fixture.driver_browser.set_window_size('xs') assert web_fixture.driver_browser.wait_for(fixture.tab_is_active, 'Tab 1') assert web_fixture.driver_browser.wait_for(fixture.tab_contents_equals, 'A paragraph to give content to the first tab.') web_fixture.driver_browser.capture_cropped_screenshot(fixture.new_screenshot_path('tabbedpanel1.png')) web_fixture.driver_browser.click(XPath.link().with_text('Tab 2')) assert web_fixture.driver_browser.wait_for(fixture.tab_is_active, 'Tab 2') assert web_fixture.driver_browser.wait_for(fixture.tab_contents_equals, 'And another ... to give content to the second tab.') web_fixture.driver_browser.capture_cropped_screenshot(fixture.new_screenshot_path('tabbedpanel2.png'))