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_checkbox_basics_with_boolean_field(web_fixture, checkbox_fixture): """CheckboxInput can be used to toggle a single yes/no answer, in which case it renders a single checkbox.""" web_fixture.reahl_server.set_app( web_fixture.new_wsgi_app( child_factory=checkbox_fixture.Form.factory())) browser = web_fixture.driver_browser browser.open('/') checkbox = XPath.input_labelled('Subscribe to newsletter?') assert not browser.is_selected(checkbox) assert browser.is_element_present( XPath.label().with_text('Subscribe to newsletter?')) assert browser.is_element_present( '//div[@class="reahl-checkbox-input reahl-primitiveinput"]/div/input/following-sibling::label' ) assert browser.get_attribute('//label', 'class') == 'custom-control-label' checkbox_classes = browser.get_attribute( '//div/input[@type="checkbox"]/..', 'class').split(' ') assert 'custom-control' in checkbox_classes assert 'custom-checkbox' in checkbox_classes assert browser.get_attribute('//div/input[@type="checkbox"]', 'class') == 'custom-control-input' browser.set_selected(checkbox) browser.click(XPath.button_labelled('Submit')) assert browser.is_selected(checkbox)
def test_example(web_fixture, responsive_example_fixture): fixture = responsive_example_fixture wsgi_application = web_fixture.new_wsgi_app(site_root=ResponsiveUI, enable_js=True) web_fixture.reahl_server.set_app(wsgi_application) browser = fixture.browser browser.open('/') # Reveal sections for new investors assert not browser.is_visible(fixture.investor_information) browser.set_selected(XPath.input_labelled('New')) browser.wait_for_element_visible(fixture.investor_information) browser.wait_for_element_visible(fixture.new_investor_specific_information) # Reveal and complete sections for existing investors browser.set_selected(XPath.input_labelled('Existing')) browser.wait_for_element_visible(fixture.investor_information) browser.wait_for_element_not_visible( fixture.new_investor_specific_information) browser.type(XPath.input_labelled('Existing account number'), '1234') # Reveal sections for Investment allocation details assert not browser.is_visible(fixture.investment_allocation_details) browser.click( XPath.label().with_text('I agree to the terms and conditions')) browser.wait_for_element_visible(fixture.investment_allocation_details) browser.type(XPath.input_labelled('Total amount'), '10000') # Check calculating totals browser.type(fixture.percentage_input_for('Fund A'), '80') browser.wait_for(fixture.percentage_total_is, '80') browser.type(fixture.percentage_input_for('Fund B'), '80') browser.wait_for(fixture.percentage_total_is, '160') # Check DomainException upon submit with incorrect totals browser.click(XPath.button_labelled('Submit')) browser.wait_for_element_visible(fixture.domain_exception_alert) browser.type(fixture.percentage_input_for('Fund B'), '20') browser.wait_for(fixture.percentage_total_is, '100') # Check successful submit browser.click(XPath.button_labelled('Submit')) browser.wait_for_element_not_visible(fixture.domain_exception_alert)
def test_click_checkbox_label_with_boolean_field(web_fixture, checkbox_fixture): """Clickin on the label of a single checkbox, toggles the checkbox itself.""" web_fixture.reahl_server.set_app( web_fixture.new_wsgi_app( child_factory=checkbox_fixture.Form.factory())) browser = web_fixture.driver_browser browser.open('/') checkbox = XPath.input_labelled('Subscribe to newsletter?') assert not browser.is_selected(checkbox) browser.click(XPath.label().with_text('Subscribe to newsletter?')) assert browser.is_selected(checkbox)
def test_async_upload_error(web_fixture, broken_file_upload_input_fixture): """If an error happens during (ajax) upload, the user is notified.""" fixture = broken_file_upload_input_fixture web_fixture.reahl_server.set_app(fixture.new_wsgi_app(enable_js=True)) browser = web_fixture.driver_browser browser.open('/') assert not browser.is_element_present( XPath.label().with_text('an error ocurred, please try again later.')) with expected(Exception): browser.type(XPath.input_labelled('Choose file(s)'), fixture.file_to_upload1.name) assert browser.wait_for_element_present(XPath.span().including_text( 'an error occurred, please try again later.')) assert not browser.is_element_enabled(XPath.button_labelled('Cancel'))
def test_checkbox_basics_with_multichoice_field(web_fixture, checkbox_fixture): """CheckboxInput can also be used to choose many things from a list, in which case it renders many checkboxes.""" choices = [ Choice(1, IntegerField(label='One')), Choice(2, IntegerField(label='Two', writable=Action(lambda: False))), Choice(3, IntegerField(label='Three')), Choice(4, IntegerField(label='Four')), ] checkbox_fixture.field = MultiChoiceField(choices, label='Make your choice', default=[1]) web_fixture.reahl_server.set_app( web_fixture.new_wsgi_app( child_factory=checkbox_fixture.Form.factory())) browser = web_fixture.driver_browser browser.open('/') assert browser.is_element_present( XPath.label().with_text('Make your choice')) assert browser.get_xpath_count( '//div[@class="reahl-checkbox-input reahl-primitiveinput"]/div/input[@class="custom-control-input"]/following-sibling::label[@class="custom-control-label"]' ) == 4 checkbox_one = XPath.input_labelled('One') checkbox_two = XPath.input_labelled('Two') checkbox_three = XPath.input_labelled('Three') checkbox_four = XPath.input_labelled('Four') assert browser.is_selected(checkbox_one) assert not browser.is_selected(checkbox_two) assert not browser.is_element_enabled(checkbox_two) # assert browser.is_visible(checkbox_two) #cannot do this as the way bootsrap renders, the actual html input has opacity=0 assert not browser.is_selected(checkbox_three) assert not browser.is_selected(checkbox_four) browser.set_deselected(checkbox_one) browser.set_selected(checkbox_three) browser.set_selected(checkbox_four) browser.click(XPath.button_labelled('Submit')) assert not browser.is_selected(checkbox_one) assert browser.is_selected(checkbox_three) assert browser.is_selected(checkbox_four)
def upload_button_indicates_focus(self): element = self.web_fixture.driver_browser.find_element( XPath.label().with_text('Choose file(s)')) return 'focus' in element.get_attribute('class')