def test_get_attribute_no_element_found(): mock_finder = MagicMock() mock_finder.elements.return_value = [] interrogate = Interrogator(None, mock_finder, None) result = interrogate.get_attribute(default_page_element, "test_attr") assert_that(result, equal_to(""), "No elements should have been found")
def test_is_image_visible_by_checking_src_no_src_url(): interrogate = Interrogator(None, None, None) mock_get_attribute = MagicMock(return_value=None) interrogate.get_attribute = mock_get_attribute result = interrogate.is_image_visible_by_checking_src(default_page_element) mock_get_attribute.assert_called_once_with(default_page_element, "src") assert_that( result, equal_to(True), "The image should be considered visible if it has no source URL")
def test_get_attribute(): mock_element = MagicMock() mock_element.get_attribute.return_value = "test_attr_val" mock_finder = MagicMock() mock_finder.elements.return_value = [mock_element] interrogate = Interrogator(None, mock_finder, None) result = interrogate.get_attribute(default_page_element, "test_attr") assert_that(result, equal_to("test_attr_val"), "Element attribute not returned correctly")
def test_is_image_visible_by_checking_src_success(): mock_driver = MagicMock() mock_driver.execute_script.return_value = "test/url" interrogate = Interrogator(mock_driver, None, None) mock_get_attribute = MagicMock(return_value="/source") interrogate.get_attribute = mock_get_attribute mock_response = MagicMock() mock_response.status_code = 200 mock_get = MagicMock(return_value=mock_response) requests.get = mock_get result = interrogate.is_image_visible_by_checking_src(default_page_element) mock_get_attribute.assert_called_once_with(default_page_element, "src") mock_get.assert_called_once_with("test/url/source") mock_driver.execute_script.assert_called_once_with( "return window.location.origin") assert_that(result, equal_to(True), "The image should have been found")