def soft_assert_bulk_verify_for_in_review_state(page, asmt, soft_assert, is_available): """Soft assert 'Bulk Verify' availability for assessments in 'In Review' status.""" rest_facade.update_object(asmt, status=object_states.READY_FOR_REVIEW) browsers.get_browser().refresh() ui_utils.wait_for_spinner_to_disappear() soft_assert.expect( page.is_bulk_verify_displayed() == is_available, "Bulk Verify should {} be available if assessment is in '{}' status." .format("" if is_available else "not", object_states.READY_FOR_REVIEW))
def soft_assert_verified_state_after_bulk_verify(page, src_obj, soft_assert): """Soft assert that assessments statuses actually have been updated after bulk verify has been completed.""" bulk_verify_all(page) # reload page to see actual assessments state browsers.get_browser().refresh() asmts_from_ui = (webui_service.AssessmentsService() .get_list_objs_from_tree_view(src_obj)) soft_assert.expect( all([asmt.status == object_states.COMPLETED and asmt.verified is True for asmt in asmts_from_ui]), "All assessments should be verified and have 'Completed' state.")
def soft_assert_bulk_complete_for_completed_asmts(soft_assert, asmts, page): """Performs soft assert that 'Bulk complete' option/button is not displayed for several assessments when all of them are in one of the completed states.""" for asmt, status in zip(asmts, object_states.COMPLETED_STATES): rest_facade.update_object(asmt, status=status) browsers.get_browser().refresh() ui_utils.wait_for_spinner_to_disappear() soft_assert.expect( not page.is_bulk_complete_displayed(), "'Bulk complete' for assessment with '{}' status should not be " "available.".format(status))
def soft_assert_bulk_complete_for_opened_asmts(soft_assert, asmts, page, is_displayed=True): """Performs soft assert that 'Bulk complete' option/button is displayed or not for several assessments when at least one of them is in one of the opened states.""" for status in object_states.OPENED_STATES: rest_facade.update_object(asmts[-1], status=status) browsers.get_browser().refresh() ui_utils.wait_for_spinner_to_disappear() soft_assert.expect( page.is_bulk_complete_displayed() == is_displayed, "'Bulk complete' for assessment with '{}' status should {}be " "available.".format(status, "" if is_displayed else "not "))
def test_user_cannot_map_control_via_unified_mapper( self, control, dashboard_controls_tab, selenium): """Tests that user cannot map Control to Scope Objects/Directives via Unified Mapper (existent new scope/directive object)""" dashboard_controls_tab.get_control(control).select_map_to_this_object() map_modal = webui_facade.map_object_via_unified_mapper( selenium=selenium, obj_name=objects.CONTROLS, dest_objs_type=objects.get_singular(plural=objects.PRODUCTS, title=True), return_tree_items=False, open_in_new_frontend=True) browsers.get_browser().windows()[1].use() ui_facade.verify_modal_obj_not_present(modal_obj=map_modal)
def test_user_cannot_map_control_via_unified_mapper(self, control, dashboard_controls_tab, selenium): """Tests that user cannot map Control to Scope Objects/Directives via Unified Mapper (existent new scope/directive object)""" dashboard_controls_tab.get_control(control).select_map_to_this_object() modal = webui_facade.map_object_via_unified_mapper( selenium=selenium, obj_name=objects.CONTROLS, dest_objs_type=objects.get_singular(plural=objects.PRODUCTS, title=True), return_tree_items=False, open_in_new_frontend=True) browsers.get_browser().windows()[1].use() ui_facade.verify_modal_obj_not_present(modal_obj=modal)
def test_review_details_for_disabled_obj(self, control, controls_service): """Check that new browser tab is displayed after clicking Review Details button for objects disabled in GGRC.""" controls_service.open_info_page_of_obj( control).click_ctrl_review_details_btn() old_tab, new_tab = browsers.get_browser().windows() assert old_tab.url == new_tab.url
def test_cannot_map_control_via_um_create_new_obj(self, control, regulation, dashboard_controls_tab, selenium): """Tests that user cannot map control to scope objects/directives via unified mapper (create a new scope/directive object).""" expected_conditions = { "regulation_in_top_tabs": False, "new_tab_url": url.Urls().dashboard_info_tab } actual_conditions = copy.deepcopy(expected_conditions) dashboard_controls_tab.get_control(control).select_map_to_this_object() webui_facade.map_object_via_unified_mapper( selenium=selenium, obj_name=objects.CONTROLS, dest_objs_type=objects.get_singular(plural=objects.REGULATIONS, title=True), obj_to_map=regulation, proceed_in_new_tab=True) _, new_tab = browsers.get_browser().windows() actual_conditions['new_tab_url'] = new_tab.url actual_conditions['regulation_in_top_tabs'] = (objects.get_normal_form( objects.REGULATIONS) in webui_service.ControlsService( selenium).open_info_page_of_obj(control).top_tabs.tab_names) assert expected_conditions == actual_conditions
def __init__(self, driver, locator_or_element): super(Element, self).__init__() self._driver = driver self._browser = browsers.get_browser() self.locator_or_element = locator_or_element self.element = self.get_element() self.text = self.element.text
def verify_modal_obj_not_present_in_all_windows(modal_obj): """Verifies that object is not present in any window.""" assert issubclass(modal_obj.__class__, object_modal.BaseObjectModal), ("Object should be derived " "from BaseObjectModal.") for window in browsers.get_browser().windows(): window.use() verify_modal_obj_not_present(modal_obj)
def test_cannot_unmap_control(self, control, obj, selenium): """Checks that user cannot unmap Control from Scope Objects/Directives and new tab opens.""" webui_service.ControlsService(selenium).open_info_panel_of_mapped_obj( obj, control).three_bbs.select_unmap_in_new_frontend() old_tab, new_tab = browsers.get_browser().windows() expected_url = old_tab.url.replace(url.Widget.CONTROLS, url.Widget.INFO) assert new_tab.url == expected_url
def soft_assert_bulk_verify_for_not_in_review_state(page, asmts, soft_assert): """Soft assert 'Bulk Verify' availability for assessments with different from 'In Review' status.""" statuses = object_states.ASSESSMENT_STATUSES_NOT_READY_FOR_REVIEW for asmt, status in zip(asmts, statuses): if status == object_states.COMPLETED: # normally assessment cannot be in completed state if it has verifiers # GGRC-7802: validation should be added on backend side rest_facade.update_acl([asmt], [], rewrite_acl=True, **roles_rest_facade.get_role_name_and_id( asmt.type, roles.VERIFIERS)) rest_facade.update_object(asmt, status=status) browsers.get_browser().refresh() ui_utils.wait_for_spinner_to_disappear() soft_assert.expect( not page.is_bulk_verify_displayed(), "Bulk Verify should not be available if assessment is in " "'{}' status.".format(status))
def test_cannot_unmap_disabled_obj(self, obj, mapped_obj, selenium): """Check that user cannot unmap Risk/Control from Scope Objects/Directives and new tab opens.""" webui_service.BaseWebUiService( objects.get_plural(obj.type)).open_info_panel_of_mapped_obj( mapped_obj, obj).three_bbs.select_unmap_in_new_frontend() _, new_tab = browsers.get_browser().windows() expected_url = mapped_obj.url + url.Widget.INFO assert new_tab.url == expected_url
def verify_modal_obj_not_present_in_all_windows(modal_obj): """Verifies that object is not present in any window.""" assert issubclass( modal_obj.__class__, object_modal.BaseObjectModal), ("Object should be derived " "from BaseObjectModal.") for window in browsers.get_browser().windows(): window.use() verify_modal_obj_not_present(modal_obj)
def test_user_cannot_add_person_to_custom_role(self, control, selenium): """Tests that user cannot add a person to custom Role.""" service = webui_service.ControlsService(selenium) widget = service.open_info_page_of_obj(control) widget.control_owners.inline_edit.open() assert not widget.control_owners.add_person_text_field.exists, ( "User should not be able to add person to custom Role.") old_tab, new_tab = browsers.get_browser().windows() assert old_tab.url == new_tab.url, ("Urls should be the same. " "New url for redirect to GGRCQ.")
def soft_assert_cannot_add_comment(soft_assert, obj): """Performs soft assert that comment input field is not displayed when 'Add Comment' button is clicked.""" info_page = factory.get_cls_webui_service(objects.get_plural( obj.type))().open_info_page_of_obj(obj) info_page.comments_panel.click_add_button() # wait until new tab contains info page url _, new_tab = browsers.get_browser().windows() test_utils.wait_for(lambda: new_tab.url.endswith(url.Widget.INFO)) soft_assert.expect(not info_page.comments_panel.comment_input.exists, "There should be no input field in comments panel.")
def soft_assert_role_cannot_be_edited(soft_assert, obj, role): """Performs soft assert that click on role's pencil icon doesn't open an input field.""" info_widget = factory.get_cls_webui_service( objects.get_plural(obj.type))().open_info_page_of_obj(obj) role_field_element = getattr(info_widget, role) role_field_element.inline_edit.open() # wait until new tab contains info page url _, new_tab = browsers.get_browser().windows() test_utils.wait_for(lambda: new_tab.url.endswith(url.Widget.INFO)) soft_assert.expect(not role_field_element.add_person_text_field.exists, "There should be no input field.")
def test_user_cannot_update_predefined_field(self, control, selenium): """Tests that user cannot update predefined field.""" expected_conditions = {"predefined_field_updatable": False, "same_url_for_new_tab": True} actual_conditions = copy.deepcopy(expected_conditions) info_widget = webui_service.ControlsService( selenium).open_info_page_of_obj(control) info_widget.assertions.open_inline_edit() actual_conditions[ "predefined_field_updatable"] = info_widget.assertions.input.exists old_tab, new_tab = browsers.get_browser().windows() actual_conditions["same_url_for_new_tab"] = (old_tab.url == new_tab.url) assert expected_conditions == actual_conditions
def soft_assert_no_modals_present(modal_obj, soft_assert): """Performs soft assertion that there is no modal objects in 2 browser tabs.""" assert issubclass(modal_obj.__class__, object_modal.BaseObjectModal), ( "Object should be derived from BaseObjectModal.") tabs = browsers.get_browser().windows() soft_assert.expect( len(tabs) == 2, "Only 2 window tabs should be opened but it is found " "{} tab(s).".format(len(tabs))) for tab_num, tab in enumerate(tabs, start=1): tab.use() soft_assert.expect(not modal_obj.is_present, "There should be no modal windows in browser " "tab number {}.".format(tab_num))
def soft_assert_cannot_view_proposals(info_page, soft_assert): """Performs soft assertion that user cannot view proposals for disabled object.""" info_page.click_change_proposals() soft_assert.expect( info_page.proposals_tab_or_link_name not in info_page.tabs.tab_names, "'Change Proposals' tab should not be displayed.") soft_assert.expect(are_tabs_urls_equal(), "Tabs urls should be equal.") for tab_num, tab in enumerate(browsers.get_browser().windows(), start=1): tab.use() soft_assert.expect( not related_proposals.RelatedProposals().are_proposals_displayed(), "Proposals should not be displayed in browser tab number {}.". format(tab_num))
def soft_assert_cannot_view_version_history(obj, soft_assert, selenium): """Performs soft assertion that user cannot view Version History for disabled object.""" info_page = factory.get_cls_webui_service(objects.get_plural( obj.type))(selenium).open_info_page_of_obj(obj) info_page.click_version_history() soft_assert.expect(are_tabs_urls_equal(), "Tabs urls should be equal.") soft_assert.expect( info_page.version_history_tab_or_link_name not in info_page.tabs.tab_names, "'Version History' tab should not be displayed.") for tab_num, tab in enumerate(browsers.get_browser().windows(), start=1): tab.use() soft_assert.expect( not version_history.VersionHistory().is_version_history_displayed(), "Version history should not be displayed in browser tab number {}.". format(tab_num))
def test_user_cannot_map_control_to_scope_ojbects_via_add_tab( self, control, selenium): """Tests that user cannot map control to scope objects/directives via 'Add Tab' menu.""" service = webui_service.ControlsService(selenium) controls_info_widget = service.open_info_page_of_obj(control) controls_info_widget.click_add_tab_btn() hidden_items = controls_info_widget.get_hidden_items_from_add_tab() for h_item in hidden_items: controls_info_widget.click_add_tab_btn() h_item.click() ui_facade.verify_modal_obj_not_present_in_all_windows( unified_mapper.BaseUnifiedMapperModal()) old_tab, new_tab = browsers.get_browser().windows() assert old_tab.url == new_tab.url, "Urls for tabs should be the same." old_tab.use() new_tab.close()
def test_user_cannot_add_person_to_custom_role(self, control, controls_service): """Tests that user cannot add a person to custom Role.""" expected_conditions = { "add_person_text_field_exists": False, "same_url_for_new_tab": True } actual_conditions = copy.deepcopy(expected_conditions) widget = controls_service.open_info_page_of_obj(control) widget.control_owners.inline_edit.open() actual_conditions["add_person_text_field_exists"] = ( widget.control_owners.add_person_text_field.exists) old_tab, new_tab = browsers.get_browser().windows() actual_conditions["same_url_for_new_tab"] = ( old_tab.url == new_tab.url) assert expected_conditions == actual_conditions
def test_user_cannot_update_custom_attribute(self, gcads_for_control, control, controls_service): """Tests that user cannot update custom attribute.""" expected_conditions = { "same_url_for_new_tab": True, "controls_ca_editable": False } actual_conditions = copy.deepcopy(expected_conditions) actual_conditions["controls_ca_editable"] = ( controls_service.has_gca_inline_edit( control, ca_type=element.AdminWidgetCustomAttributes.RICH_TEXT)) old_tab, new_tab = browsers.get_browser().windows() actual_conditions["same_url_for_new_tab"] = ( old_tab.url == new_tab.url) assert expected_conditions == actual_conditions
def test_user_cannot_map_control_to_scope_ojbects_via_add_tab(self, control, selenium): """Tests that user cannot map control to scope objects/directives via 'Add Tab' menu.""" service = webui_service.ControlsService(selenium) controls_info_widget = service.open_info_page_of_obj(control) controls_info_widget.click_add_tab_btn() hidden_items = controls_info_widget.get_hidden_items_from_add_tab() for h_item in hidden_items: controls_info_widget.click_add_tab_btn() h_item.click() ui_facade.verify_modal_obj_not_present_in_all_windows( object_modal.UnifiedMapperModal()) old_tab, new_tab = browsers.get_browser().windows() assert old_tab.url == new_tab.url, "Urls for tabs should be the same." old_tab.use() new_tab.close()
def test_user_cannot_map_control_to_scope_ojbects_via_add_tab( self, control, soft_assert, selenium): """Tests that user cannot map control to scope objects/directives via 'Add Tab' menu.""" service = webui_service.ControlsService(selenium) controls_info_widget = service.open_info_page_of_obj(control) controls_info_widget.click_add_tab_btn() hidden_items = controls_info_widget.get_hidden_items_from_add_tab() for h_item in hidden_items: controls_info_widget.click_add_tab_btn() h_item.click() soft_assert.expect(webui_facade.are_tabs_urls_equal(), "Tabs urls should be equal.") webui_facade.soft_assert_no_modals_present( unified_mapper.BaseUnifiedMapperModal(), soft_assert) old_tab, new_tab = browsers.get_browser().windows() old_tab.use() new_tab.close() soft_assert.assert_expectations()
def test_cannot_map_control_via_um_create_new_obj(self, control, regulation, dashboard_controls_tab, soft_assert, selenium): """Tests that user cannot map control to scope objects/directives via unified mapper (create a new scope/directive object).""" dashboard_controls_tab.get_control(control).select_map_to_this_object() map_modal = webui_facade.map_object_via_unified_mapper( selenium=selenium, obj_name=objects.CONTROLS, dest_objs_type=objects.get_singular(plural=objects.REGULATIONS, title=True), obj_to_map=regulation, proceed_in_new_tab=True) new_tab = browsers.get_browser().windows()[1] soft_assert.expect(new_tab.url == url.Urls().dashboard_info_tab, "Dashboard info page should be opened in new tab.") soft_assert.expect( not(objects.get_normal_form(objects.REGULATIONS) in webui_service.ControlsService(selenium).open_info_page_of_obj( control).top_tabs.tab_names), "There should be no scope/directive object mapped to Control.") new_tab.use() soft_assert.expect(not map_modal.is_present, "There should be no modal windows in new browser tab.") soft_assert.assert_expectations()
def wait_for_alert(text): """Waits for alert with text `text` to appear.""" browser = browsers.get_browser() browser.element(class_name="alert-info", text=re.compile(text)).wait_until(lambda e: e.present)
def are_tabs_urls_equal(): """Returns whether 2 tab urls are equal.""" old_tab, new_tab = browsers.get_browser().windows() return old_tab.url == new_tab.url
def wait_for_spinner_to_disappear(): """Waits until there are no spinners on the page.""" browser = browsers.get_browser() browser.wait_until(lambda br: len(br.divs(class_name="spinner")) == 0)
def wait_for_alert(text): """Waits for alert with text `text` to appear.""" browser = browsers.get_browser() browser.element( class_name="alert-info", text=re.compile(text)).wait_until( lambda e: e.present)
def is_error_403(): """Returns whether current page is 403 error.""" return browsers.get_browser().h1(visible_text="Forbidden").exists
def is_error_404(): """Returns whether current page is 404 error.""" return browsers.get_browser().body( visible_text=re.compile("not found")).exists
def __init__(self, _driver=None): super(WithBrowser, self).__init__() self._driver = browsers.get_driver() self._browser = browsers.get_browser()