def test_is_image_visible_by_javascript_svg_no_src(): mock_element = MagicMock() mock_element.tag_name = "svg" mock_element.get_attribute.return_value = None mock_element.is_displayed.return_value = "result of is_displayed" mock_finder = MagicMock() mock_finder.element.return_value = mock_element interrogate = Interrogator(None, mock_finder, None) result = interrogate.is_image_visible_by_javascript(default_page_element) mock_element.is_displayed.assert_called_once() assert_that(result, equal_to("result of is_displayed"), "Element should have been checked with is_displayed")
def test_is_image_visible_by_javascript(): mock_element = MagicMock() mock_element.tag_name = "svg" mock_element.get_attribute.return_value = "test-image" mock_finder = MagicMock() mock_finder.element.return_value = mock_element mock_driver = MagicMock() mock_driver.execute_script.return_value = "result of execute_script" interrogate = Interrogator(mock_driver, mock_finder, None) result = interrogate.is_image_visible_by_javascript(default_page_element) expected_script = "return ((arguments[0].complete)||(arguments[0].naturalWidth !='undefined' && " \ "arguments[0].naturalWidth > 0))" mock_driver.execute_script.assert_called_once_with(expected_script, mock_element) assert_that(result, equal_to("result of execute_script"), "Element should have been checked with JavaScript")