From 0bf41309e937499967b58d81f208c0666846121f Mon Sep 17 00:00:00 2001 From: Joshua Fehler Date: Mon, 3 Jun 2024 08:22:34 -0400 Subject: [PATCH 1/2] tests: Replace unittest with pytest --- tests/base.py | 77 +++++++++---------- tests/click_elements.py | 6 +- tests/element.py | 31 +++----- tests/element_does_not_exist.py | 26 ++++--- tests/find_elements.py | 118 ++++++++++++++--------------- tests/form_elements.py | 129 +++++++++++++------------------- tests/is_element_present.py | 95 +++++++++-------------- tests/is_text_present.py | 16 ++-- tests/status_code.py | 8 +- tests/test_djangoclient.py | 48 ++++++------ tests/test_flaskclient.py | 61 ++++++++------- tests/test_request_handler.py | 4 +- tests/test_webdriver_remote.py | 20 ++--- tests/test_zopetestbrowser.py | 40 +++++----- tests/type.py | 20 ++--- 15 files changed, 318 insertions(+), 381 deletions(-) diff --git a/tests/base.py b/tests/base.py index 17be49de7..ce7c872d7 100644 --- a/tests/base.py +++ b/tests/base.py @@ -56,14 +56,14 @@ def get_new_browser(self): def test_can_open_page(self): """should be able to visit, get title and quit""" self.browser.visit(EXAMPLE_APP) - self.assertEqual("Example Title", self.browser.title) + assert "Example Title" == self.browser.title def test_can_back_on_history(self): """should be able to back on history""" self.browser.visit(EXAMPLE_APP) self.browser.visit(f"{EXAMPLE_APP}iframe") self.browser.back() - self.assertEqual(EXAMPLE_APP, self.browser.url) + assert EXAMPLE_APP == self.browser.url def test_can_forward_on_history(self): """User can forward history""" @@ -83,41 +83,41 @@ def test_can_forward_on_history(self): def test_should_have_html(self): self.browser.visit(EXAMPLE_APP) html = self.browser.html - self.assertIn("Example Title", html) - self.assertIn('

Example Header

', html) + assert "Example Title" in html + assert '

Example Header

' in html def test_should_reload_a_page(self): self.browser.visit(EXAMPLE_APP) self.browser.reload() - self.assertEqual("Example Title", self.browser.title) + assert "Example Title" == self.browser.title def test_should_have_url(self): "should have access to the url" - self.assertEqual(EXAMPLE_APP, self.browser.url) + assert EXAMPLE_APP == self.browser.url def test_accessing_attributes_of_links(self): "should allow link's attributes retrieval" foo = self.browser.links.find_by_text("FOO") - self.assertEqual("http://localhost:5000/foo", foo["href"]) + assert "http://localhost:5000/foo" == foo["href"] def test_accessing_attributes_of_inputs(self): "should allow input's attributes retrieval" button = self.browser.find_by_css('input[name="send"]') - self.assertEqual("send", button["name"]) + assert "send" == button["name"] def test_accessing_attributes_of_simple_elements(self): "should allow simple element's attributes retrieval" header = self.browser.find_by_css("h1") - self.assertEqual("firstheader", header["id"]) + assert "firstheader" == header["id"] def test_links_should_have_value_attribute(self): foo = self.browser.links.find_by_href("http://localhost:5000/foo") - self.assertEqual("FOO", foo.value) + assert "FOO" == foo.value def test_should_receive_browser_on_parent(self): 'element should contains the browser on "parent" attribute' element = self.browser.find_by_id("firstheader") - self.assertEqual(self.browser, element.parent) + assert self.browser == element.parent def test_redirection(self): """ @@ -125,8 +125,8 @@ def test_redirection(self): browser.url should be updated """ self.browser.visit(f"{EXAMPLE_APP}redirected") - self.assertIn("I just been redirected to this location.", self.browser.html) - self.assertIn("redirect-location?come=get&some=true", self.browser.url) + assert "I just been redirected to this location." in self.browser.html + assert "redirect-location?come=get&some=true" in self.browser.url class WebDriverTests( @@ -135,14 +135,14 @@ class WebDriverTests( IsElementPresentTest, ): def test_status_code(self): - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.status_code def test_can_open_page_in_new_tab(self): """should be able to visit url in a new tab""" self.browser.windows.current.new_tab(EXAMPLE_APP) self.browser.windows[1].is_current = True - self.assertEqual(EXAMPLE_APP, self.browser.url) + assert EXAMPLE_APP == self.browser.url assert 2 == len(self.browser.windows) self.browser.windows[0].is_current = True @@ -151,40 +151,37 @@ def test_can_open_page_in_new_tab(self): def test_can_execute_javascript(self): "should be able to execute javascript" self.browser.execute_script("$('body').empty()") - self.assertEqual("", self.browser.find_by_tag("body").value) + assert "" == self.browser.find_by_tag("body").value def test_can_evaluate_script(self): "should evaluate script" - self.assertEqual(8, self.browser.evaluate_script("4+4")) + assert 8 == self.browser.evaluate_script("4+4") def test_can_see_the_text_for_an_element(self): "should provide text for an element" - self.assertEqual(self.browser.find_by_id("simple_text").text, "my test text") + assert self.browser.find_by_id("simple_text").text == "my test text" def test_the_text_for_an_element_strips_html_tags(self): "should show that the text attribute strips html" - self.assertEqual( - self.browser.find_by_id("text_with_html").text, - "another bit of text", - ) + assert self.browser.find_by_id("text_with_html").text == "another bit of text" def test_can_verify_if_a_element_is_visible(self): "should provide verify if element is visible" - self.assertTrue(self.browser.find_by_id("visible").visible) + assert self.browser.find_by_id("visible").visible def test_can_verify_if_a_element_is_invisible(self): "should provide verify if element is invisible" - self.assertFalse(self.browser.find_by_id("invisible").visible) + assert not self.browser.find_by_id("invisible").visible def test_default_wait_time(self): "should driver default wait time 2" - self.assertEqual(2, self.browser.wait_time) + assert 2 == self.browser.wait_time def test_access_alerts_and_accept_them(self): self.browser.visit(EXAMPLE_APP + "alert") self.browser.find_by_tag("h1").click() alert = self.browser.get_alert() - self.assertEqual("This is an alert example.", alert.text) + assert "This is an alert example." == alert.text alert.accept() def test_access_prompts_and_be_able_to_fill_then(self): @@ -192,7 +189,7 @@ def test_access_prompts_and_be_able_to_fill_then(self): self.browser.find_by_tag("h2").click() alert = self.browser.get_alert() - self.assertEqual("What is your name?", alert.text) + assert "What is your name?" == alert.text alert.fill_with("Splinter") alert.accept() @@ -200,7 +197,7 @@ def test_access_prompts_and_be_able_to_fill_then(self): time.sleep(2.5) response = self.browser.get_alert() - self.assertEqual("Splinter", response.text) + assert "Splinter" == response.text response.accept() def test_access_confirm_and_accept_and_dismiss_them(self): @@ -209,26 +206,26 @@ def test_access_confirm_and_accept_and_dismiss_them(self): self.browser.find_by_tag("h3").click() alert = self.browser.get_alert() - self.assertEqual("Should I continue?", alert.text) + assert "Should I continue?" == alert.text alert.accept() # Wait for alert time.sleep(2.5) alert = self.browser.get_alert() - self.assertEqual("You say I should", alert.text) + assert "You say I should" == alert.text alert.accept() self.browser.find_by_tag("h3").click() alert = self.browser.get_alert() - self.assertEqual("Should I continue?", alert.text) + assert "Should I continue?" == alert.text alert.dismiss() # Wait for alert time.sleep(2.5) alert = self.browser.get_alert() - self.assertEqual("You say I should not", alert.text) + assert "You say I should not" == alert.text alert.accept() def test_access_confirm_and_accept_and_dismiss_them_using_with(self): @@ -236,26 +233,26 @@ def test_access_confirm_and_accept_and_dismiss_them_using_with(self): self.browser.find_by_tag("h3").click() with self.browser.get_alert() as alert: - self.assertEqual("Should I continue?", alert.text) + assert "Should I continue?" == alert.text alert.accept() # Wait for alert time.sleep(2.5) with self.browser.get_alert() as alert: - self.assertEqual("You say I should", alert.text) + assert "You say I should" == alert.text alert.accept() self.browser.find_by_tag("h3").click() with self.browser.get_alert() as alert: - self.assertEqual("Should I continue?", alert.text) + assert "Should I continue?" == alert.text alert.dismiss() # Wait for alert time.sleep(2.5) with self.browser.get_alert() as alert: - self.assertEqual("You say I should not", alert.text) + assert "You say I should not" == alert.text alert.accept() def test_access_alerts_using_with(self): @@ -263,19 +260,19 @@ def test_access_alerts_using_with(self): self.browser.visit(EXAMPLE_APP + "alert") self.browser.find_by_tag("h1").click() with self.browser.get_alert() as alert: - self.assertEqual("This is an alert example.", alert.text) + assert "This is an alert example." == alert.text alert.accept() def test_get_alert_return_none_if_no_alerts(self): "should return None if no alerts available" alert = self.browser.get_alert() - self.assertEqual(None, alert) + assert alert is None def test_can_select_a_option_via_element_text(self): "should provide a way to select a option via element" - self.assertFalse(self.browser.find_option_by_value("rj").selected) + assert not self.browser.find_option_by_value("rj").selected self.browser.find_by_name("uf").select_by_text("Rio de Janeiro") - self.assertTrue(self.browser.find_option_by_value("rj").selected) + assert self.browser.find_option_by_value("rj").selected def test_should_be_able_to_change_user_agent(self): driver_name = self.browser.driver_name.lower() diff --git a/tests/click_elements.py b/tests/click_elements.py index 7365c6e05..fec446f57 100644 --- a/tests/click_elements.py +++ b/tests/click_elements.py @@ -6,12 +6,12 @@ class ClickElementsTest: def test_click_links(self): self.browser.links.find_by_text("FOO").click() - self.assertIn("BAR!", self.browser.html) + assert "BAR!" in self.browser.html def test_click_element_by_css_selector(self): self.browser.find_by_css('a[href="http://localhost:5000/foo"]').click() - self.assertIn("BAR!", self.browser.html) + assert "BAR!" in self.browser.html def test_click_input_by_css_selector(self): self.browser.find_by_css('input[name="send"]').click() - self.assertIn("My name is: Master Splinter", self.browser.html) + assert "My name is: Master Splinter" in self.browser.html diff --git a/tests/element.py b/tests/element.py index 78be1d573..978c8087f 100644 --- a/tests/element.py +++ b/tests/element.py @@ -5,40 +5,27 @@ class ElementTest: def test_element_has_class_when_element_has_the_class_as_first_class(self): - self.assertTrue( - self.browser.find_by_css(".has-class-first").has_class("has-class-first"), - ) + assert self.browser.find_by_css(".has-class-first").has_class("has-class-first") def test_element_has_class_when_element_has_the_class_as_middle_class(self): - self.assertTrue( - self.browser.find_by_css(".has-class-middle").has_class("has-class-middle"), - ) + assert self.browser.find_by_css(".has-class-middle").has_class("has-class-middle") def test_element_has_class_when_element_has_the_class_as_end_class(self): - self.assertTrue( - self.browser.find_by_css(".has-class-end").has_class("has-class-end"), - ) + assert self.browser.find_by_css(".has-class-end").has_class("has-class-end") def test_element_has_class_when_element_doesnt_have_the_class(self): - self.assertFalse( - self.browser.find_by_css(".has-class-first").has_class("has-class"), - ) + assert not self.browser.find_by_css(".has-class-first").has_class("has-class") def test_element_outer_html(self): - self.assertEqual( - self.browser.find_by_id("html-property").outer_html, + assert self.browser.find_by_id("html-property").outer_html == ( '
' - 'inner
inner text
html test
', + 'inner
inner text
html test' ) def test_element_html_with_breakline(self): - self.assertEqual( - self.browser.find_by_id("html-property-with-breakline").html, - "\\n some text here\\n", - ) + assert self.browser.find_by_id("html-property-with-breakline").html == "\\n some text here\\n" def test_element_html(self): - self.assertEqual( - self.browser.find_by_id("html-property").html, - 'inner
inner text
html test', + assert ( + self.browser.find_by_id("html-property").html == 'inner
inner text
html test' ) diff --git a/tests/element_does_not_exist.py b/tests/element_does_not_exist.py index e28704225..14ab80a55 100644 --- a/tests/element_does_not_exist.py +++ b/tests/element_does_not_exist.py @@ -1,52 +1,54 @@ # Copyright 2012 splinter authors. All rights reserved. # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. +import pytest + from splinter.exceptions import ElementDoesNotExist class ElementDoestNotExistTest: def test_element_query_should_raises_when_element_first_doest_exists(self): - with self.assertRaises(ElementDoesNotExist): + with pytest.raises(ElementDoesNotExist): self.browser.find_by_css(".element-that-dont-exists").first def test_element_list_raises_when_element_last_does_not_exists(self): - with self.assertRaises(ElementDoesNotExist): + with pytest.raises(ElementDoesNotExist): self.browser.find_by_css(".element-that-dont-exists").last def test_element_list_raises_when_element_does_not_exists(self): - with self.assertRaises(ElementDoesNotExist): + with pytest.raises(ElementDoesNotExist): self.browser.find_by_css(".element-that-dont-exists")[2] def test_element_list_raises_with_unicode_query(self): - with self.assertRaises(ElementDoesNotExist): + with pytest.raises(ElementDoesNotExist): self.browser.find_by_css(".element[title=título]").last def test_element_list_contains_right_information_and_raises_right_exception(self): "element list contains right information about query and raises nice exception message" - with self.assertRaises(ElementDoesNotExist) as cm: + with pytest.raises(ElementDoesNotExist) as cm: element_list = self.browser.find_by_css(".element-that-dont-exists") - self.assertEqual("css", element_list.find_by) - self.assertEqual(".element-that-dont-exists", element_list.query) + assert "css" == element_list.find_by + assert ".element-that-dont-exists" == element_list.query element_list.first expected_message = 'No elements were found with css ".element-that-dont-exists"' e = cm.exception - self.assertEqual(expected_message, e.args[0]) + assert expected_message == e.args[0] def test_element_list_raises_when_element_first_doesnt_exists_in_element_context( self, ): "element list raises exception with right information in element context" - with self.assertRaises(ElementDoesNotExist) as cm: + with pytest.raises(ElementDoesNotExist) as cm: element_list = self.browser.find_by_css("#inside").find_by_css( ".inner-element-that-dont-exists", ) - self.assertEqual("css", element_list.find_by) - self.assertEqual(".inner-element-that-dont-exists", element_list.query) + assert "css" == element_list.find_by + assert ".inner-element-that-dont-exists" == element_list.query element_list.first expected_message = 'No elements were found with css ".inner-element-that-dont-exists"' e = cm.exception - self.assertEqual(expected_message, e.args[0]) + assert expected_message == e.args[0] diff --git a/tests/find_elements.py b/tests/find_elements.py index 9b79dc2bb..892dfe3ce 100644 --- a/tests/find_elements.py +++ b/tests/find_elements.py @@ -8,77 +8,77 @@ class FindElementsTest: def test_finding_by_css(self): value = self.browser.find_by_css("h1").value - self.assertEqual("Example Header", value) + assert "Example Header" == value def test_finding_by_xpath(self): value = self.browser.find_by_xpath("//h1").value - self.assertEqual("Example Header", value) + assert "Example Header" == value def test_finding_by_tag(self): value = self.browser.find_by_tag("h1").value - self.assertEqual("Example Header", value) + assert "Example Header" == value def test_finding_by_value(self): value = self.browser.find_by_value("M").value element = self.browser.find_by_id("gender-m") - self.assertEqual(element.value, value) + assert element.value == value def test_finding_by_value_in_btn_elements(self): value = self.browser.find_by_value("some value").value btn = self.browser.find_by_id("button-value") - self.assertEqual(btn.value, value) + assert btn.value == value def test_finding_by_text(self): element = self.browser.find_by_text("Complex") - self.assertEqual(element.value, "Complex") + assert element.value == "Complex" def test_finding_by_text_with_quotation_marks(self): element = self.browser.find_by_text('Quotation " marks') - self.assertEqual(element.value, 'Quotation " marks') + assert element.value == 'Quotation " marks' def test_finding_by_id(self): value = self.browser.find_by_id("firstheader").value - self.assertEqual("Example Header", value) + assert "Example Header" == value def test_finding_by_name(self): value = self.browser.find_by_name("query").value - self.assertEqual("default value", value) + assert "default value" == value def test_finding_all_elements_by_css(self): value = self.browser.find_by_css("h1")[0].value - self.assertEqual("Example Header", value) + assert "Example Header" == value def test_finding_all_elements_by_xpath(self): value = self.browser.find_by_xpath("//h1")[0].value - self.assertEqual("Example Header", value) + assert "Example Header" == value def test_finding_all_elements_by_tag(self): value = self.browser.find_by_tag("h1")[0].value - self.assertEqual("Example Header", value) + assert "Example Header" == value def test_finding_all_elements_by_id(self): value = self.browser.find_by_id("firstheader").value - self.assertEqual("Example Header", value) + assert "Example Header" == value def test_finding_all_elements_by_name(self): value = self.browser.find_by_name("query").value - self.assertEqual("default value", value) + assert "default value" == value def test_finding_all_links_by_text(self): link = self.browser.links.find_by_text("Link for Example.com")[0] - self.assertEqual("http://example.com/", link["href"]) + assert "http://example.com/" == link["href"] def test_finding_all_links_by_href(self): link = self.browser.links.find_by_href("http://example.com/")[0] - self.assertEqual("http://example.com/", link["href"]) + assert "http://example.com/" == link["href"] def test_finding_all_links_by_partial_href(self): link = self.browser.links.find_by_partial_href("example.c")[0] - self.assertEqual("http://example.com/", link["href"]) + assert "http://example.com/" == link["href"] def test_finding_all_links_by_partial_text(self): link = self.browser.links.find_by_partial_text("FOO")[0] - self.assertEqual("http://localhost:5000/foo", link["href"]) + assert "http://localhost:5000/foo" == link["href"] def test_find_links_by_partial_text_nested_elements(self): """ @@ -104,139 +104,139 @@ def test_find_links_by_partial_text_nested_elements(self): def test_finding_last_element_by_css(self): value = self.browser.find_by_css("h1").last.value - self.assertEqual("Example Last Header", value) + assert "Example Last Header" == value def test_finding_last_element_by_xpath(self): value = self.browser.find_by_xpath("//h1").last.value - self.assertEqual("Example Last Header", value) + assert "Example Last Header" == value def test_finding_last_element_by_tag(self): value = self.browser.find_by_tag("h1").last.value - self.assertEqual("Example Last Header", value) + assert "Example Last Header" == value def test_finding_last_element_by_id(self): value = self.browser.find_by_id("firstheader").last.value - self.assertEqual("Example Header", value) + assert "Example Header" == value def test_last_element_is_same_than_first_element_in_find_by_id(self): # a html page have contain one element by id first = self.browser.find_by_id("firstheader").value last = self.browser.find_by_id("firstheader").last.value - self.assertEqual(first, last) + assert first == last def test_finding_last_element_by_name(self): value = self.browser.find_by_name("input1").last.value - self.assertEqual("default last value", value) + assert "default last value" == value def test_finding_last_link_by_text(self): link = self.browser.links.find_by_text("Link for Example.com").last - self.assertEqual("http://example.com/last", link["href"]) + assert "http://example.com/last" == link["href"] def test_finding_last_link_by_href(self): link = self.browser.links.find_by_href("http://example.com/").last - self.assertEqual("Link for last Example.com", link.text) + assert "Link for last Example.com" == link.text def test_finding_link_by_partial_href(self): link = self.browser.links.find_by_partial_href("example.c").last - self.assertEqual("Link for last Example.com", link.text) + assert "Link for last Example.com" == link.text def test_finding_last_link_by_partial_text(self): link = self.browser.links.find_by_partial_text("FOO").last - self.assertEqual("A wordier (and last) link to FOO", link.text) + assert "A wordier (and last) link to FOO" == link.text def test_finding_element_by_css_using_slice(self): value = self.browser.find_by_css("h1")[-1].value - self.assertEqual("Example Last Header", value) + assert "Example Last Header" == value def test_finding_element_by_xpath_using_slice(self): value = self.browser.find_by_xpath("//h1")[-1].value - self.assertEqual("Example Last Header", value) + assert "Example Last Header" == value def test_finding_element_by_tag_using_slice(self): value = self.browser.find_by_tag("h1")[-1].value - self.assertEqual("Example Last Header", value) + assert "Example Last Header" == value def test_finding_element_by_id_using_slice(self): value = self.browser.find_by_id("firstheader")[-1].value - self.assertEqual("Example Header", value) + assert "Example Header" == value def test_all_elements_is_same_than_first_element_in_find_by_id(self): # a html page have contain one element by id first = self.browser.find_by_id("firstheader").value some = self.browser.find_by_id("firstheader")[-1].value - self.assertEqual(first, some) + assert first == some def test_finding_element_by_name_using_slice(self): value = self.browser.find_by_name("input1")[-1].value - self.assertEqual("default last value", value) + assert "default last value" == value def test_finding_link_by_text_using_slice(self): link = self.browser.links.find_by_text("Link for Example.com")[-1] - self.assertEqual("http://example.com/last", link["href"]) + assert "http://example.com/last" == link["href"] def test_finding_link_by_href_using_slice(self): "should find link by href using slice" link = self.browser.links.find_by_href("http://example.com/")[-1] - self.assertEqual("Link for last Example.com", link.text) + assert "Link for last Example.com" == link.text def test_finding_links_by_text(self): "should find links by text" link = self.browser.links.find_by_text("Link for Example.com") - self.assertEqual("http://example.com/", link["href"]) + assert "http://example.com/" == link["href"] def test_finding_links_by_href(self): "should find links by href" link = self.browser.links.find_by_href("http://example.com/") - self.assertEqual("http://example.com/", link["href"]) + assert "http://example.com/" == link["href"] def test_find_by_css_in_element_context(self): "should find elements by css in element context and should return splinter driver element" elements = self.browser.find_by_css("#inside") decendent = elements[0].find_by_css("h2") - self.assertEqual(decendent.text.strip(), "inside") - self.assertIsInstance(decendent, ElementList) - self.assertIsInstance(decendent[0], ElementAPI) + assert decendent.text.strip() == "inside" + assert isinstance(decendent, ElementList) + assert isinstance(decendent[0], ElementAPI) def test_find_by_xpath_in_element_context(self): "should find elements by xpath in element context" elements = self.browser.find_by_css("#inside") decendent = elements[0].find_by_xpath("//h2") - self.assertEqual(decendent.text.strip(), "inside") - self.assertIsInstance(decendent, ElementList) - self.assertIsInstance(decendent.first, ElementAPI) + assert decendent.text.strip() == "inside" + assert isinstance(decendent, ElementList) + assert isinstance(decendent.first, ElementAPI) def test_find_by_name_in_element_context(self): elements = self.browser.find_by_css("#inside") decendent = elements[0].find_by_name("crazy-upload") - self.assertEqual(len(decendent), 1) - self.assertIsInstance(decendent, ElementList) - self.assertIsInstance(decendent.first, ElementAPI) + assert len(decendent) == 1 + assert isinstance(decendent, ElementList) + assert isinstance(decendent.first, ElementAPI) def test_find_by_tag_in_element_context(self): elements = self.browser.find_by_css("#inside") decendent = elements[0].find_by_tag("input") - self.assertEqual(len(decendent), 1) - self.assertIsInstance(decendent, ElementList) - self.assertIsInstance(decendent.first, ElementAPI) + assert len(decendent) == 1 + assert isinstance(decendent, ElementList) + assert isinstance(decendent.first, ElementAPI) def test_find_by_id_in_element_context(self): elements = self.browser.find_by_css("#inside") decendent = elements[0].find_by_id("visible") - self.assertEqual(len(decendent), 1) - self.assertIsInstance(decendent, ElementList) - self.assertIsInstance(decendent.first, ElementAPI) + assert len(decendent) == 1 + assert isinstance(decendent, ElementList) + assert isinstance(decendent.first, ElementAPI) def test_find_by_value_in_element_context(self): elements = self.browser.find_by_css("#inside") decendent = elements[0].find_by_value("crazy diamond") - self.assertEqual(len(decendent), 1) - self.assertIsInstance(decendent, ElementList) - self.assertIsInstance(decendent.first, ElementAPI) + assert len(decendent) == 1 + assert isinstance(decendent, ElementList) + assert isinstance(decendent.first, ElementAPI) def test_finding_by_text_in_element_context(self): inside = self.browser.find_by_id("inside") element = inside.find_by_text("Complex") - self.assertEqual(len(element), 1) - self.assertEqual(element["class"], "inside") - self.assertEqual(element.value, "Complex") + assert len(element) == 1 + assert element["class"] == "inside" + assert element.value == "Complex" diff --git a/tests/form_elements.py b/tests/form_elements.py index 6df3630bb..63da41711 100644 --- a/tests/form_elements.py +++ b/tests/form_elements.py @@ -34,178 +34,157 @@ class FormElementsTest: def test_fill(self): self.browser.fill("query", "LT-CS-01/2018") value = self.browser.find_by_name("query").value - self.assertEqual("LT-CS-01/2018", value) + assert "LT-CS-01/2018" == value def test_fill_element(self): self.browser.find_by_name("q").fill("new query") time.sleep(1) value = self.browser.find_by_name("q").value - self.assertEqual("new query", value) + assert "new query" == value @skip_if_zope def test_clicking_submit_input_doesnt_post_input_value_if_name_not_present(self): self.browser.find_by_css("input.submit-input-no-name").click() - self.assertEqual( - self.browser.find_by_xpath("/descendant-or-self::*").text.strip(), - "", - ) + assert self.browser.find_by_xpath("/descendant-or-self::*").text.strip() == "" @skip_if_zope def test_clicking_submit_input_posts_empty_value_if_value_not_present(self): self.browser.find_by_css('input[name="submit-input-no-value"]').click() body_text = self.browser.find_by_xpath("/descendant-or-self::*").text.strip() - self.assertTrue( - re.match(r"^submit-input-no-value:(?:| Submit| Submit Query)$", body_text), - repr(body_text), - ) + assert re.match(r"^submit-input-no-value:(?:| Submit| Submit Query)$", body_text), repr(body_text) @skip_if_zope def test_clicking_submit_input_doesnt_post_input_value_if_empty(self): self.browser.find_by_css("input.submit-input-empty").click() - self.assertEqual( - self.browser.find_by_xpath("/descendant-or-self::*").text.strip(), - "", - ) + assert self.browser.find_by_xpath("/descendant-or-self::*").text.strip() == "" def test_clicking_submit_input_posts_input_value_if_value_present(self): self.browser.find_by_css('input[name="submit-input"]').click() - self.assertEqual( - self.browser.find_by_xpath("/descendant-or-self::*").text, - "submit-input: submit-input-value", - ) + assert self.browser.find_by_xpath("/descendant-or-self::*").text == "submit-input: submit-input-value" @skip_if_zope def test_clicking_submit_button_doesnt_post_button_value_if_name_not_present(self): self.browser.find_by_css("button.submit-button-no-name").click() - self.assertEqual(self.browser.find_by_xpath("/descendant-or-self::*").text, "") + assert self.browser.find_by_xpath("/descendant-or-self::*").text == "" @skip_if_zope def test_clicking_submit_button_posts_empty_value_if_value_not_present(self): self.browser.find_by_css('button[name="submit-button-no-value"]').click() - self.assertEqual( - self.browser.find_by_xpath("/descendant-or-self::*").text.strip(), - "submit-button-no-value:", - ) + assert self.browser.find_by_xpath("/descendant-or-self::*").text.strip() == "submit-button-no-value:" @skip_if_zope def test_clicking_submit_button_doesnt_post_button_value_if_empty(self): self.browser.find_by_css("button.submit-button-empty").click() - self.assertEqual( - self.browser.find_by_xpath("/descendant-or-self::*").text.strip(), - "", - ) + assert self.browser.find_by_xpath("/descendant-or-self::*").text.strip() == "" @skip_if_zope def test_clicking_submit_button_posts_button_value_if_value_present(self): self.browser.find_by_css('button[name="submit-button"]').click() - self.assertEqual( - self.browser.find_by_xpath("/descendant-or-self::*").text, - "submit-button: submit-button-value", - ) + assert self.browser.find_by_xpath("/descendant-or-self::*").text == "submit-button: submit-button-value" def test_submiting_a_form_and_verifying_page_content(self): self.browser.fill("query", "my name") self.browser.find_by_name("send").click() - self.assertIn("My name is: Master Splinter", self.browser.html) + assert "My name is: Master Splinter" in self.browser.html def test_can_choose_a_radio_button(self): "should provide a way to choose a radio button" - self.assertFalse(self.browser.find_by_id("gender-m").checked) + assert not self.browser.find_by_id("gender-m").checked self.browser.choose("gender", "M") - self.assertTrue(self.browser.find_by_id("gender-m").checked) + assert self.browser.find_by_id("gender-m").checked def test_can_find_textarea_by_tag(self): "should provide a way to find a textarea by tag_name" tag = self.browser.find_by_tag("textarea").first - self.assertEqual("", tag.value) + assert "" == tag.value def test_can_find_input_without_type(self): "should recognize an input element that doesn't have a `type` attribute" tag = self.browser.find_by_css('[name="typeless"]').first - self.assertEqual("default value", tag.value) + assert "default value" == tag.value def test_can_find_button(self): "should recognize a button" tag = self.browser.find_by_css(".just-a-button").first - self.assertTrue(hasattr(tag, "click")) + assert hasattr(tag, "click") def test_can_find_option_by_value(self): "should provide a way to find select option by value" - self.assertEqual("Rio de Janeiro", self.browser.find_option_by_value("rj").text) + assert "Rio de Janeiro" == self.browser.find_option_by_value("rj").text def test_can_get_value_attribute_for_a_option(self): "should option have a value attribute" - self.assertEqual("rj", self.browser.find_option_by_value("rj")["value"]) + assert "rj" == self.browser.find_option_by_value("rj")["value"] def test_can_find_option_by_text(self): "should provide a way to find select option by text" - self.assertEqual("rj", self.browser.find_option_by_text("Rio de Janeiro").value) + assert "rj" == self.browser.find_option_by_text("Rio de Janeiro").value def test_can_select_a_option(self): "should provide a way to select a option" - self.assertFalse(self.browser.find_option_by_value("rj").selected) + assert not self.browser.find_option_by_value("rj").selected self.browser.select("uf", "rj") - self.assertTrue(self.browser.find_option_by_value("rj").selected) + assert self.browser.find_option_by_value("rj").selected def test_can_select_an_option_in_an_optgroup(self): "should provide a way to select an option that is in an optgroup" - self.assertEqual(self.browser.find_by_name("food").value, "apples") + assert self.browser.find_by_name("food").value == "apples" self.browser.select("food", "grapes") - self.assertEqual(self.browser.find_by_name("food").value, "grapes") + assert self.browser.find_by_name("food").value == "grapes" def test_can_select_a_option_via_element(self): "should provide a way to select a option via element" - self.assertFalse(self.browser.find_option_by_value("rj").selected) + assert not self.browser.find_option_by_value("rj").selected self.browser.find_by_name("uf").select("rj") - self.assertTrue(self.browser.find_option_by_value("rj").selected) + assert self.browser.find_option_by_value("rj").selected def test_can_check_a_checkbox(self): "should provide a way to check a radio checkbox" - self.assertFalse(self.browser.find_by_name("some-check").checked) + assert not self.browser.find_by_name("some-check").checked self.browser.check("some-check") - self.assertTrue(self.browser.find_by_name("some-check").checked) + assert self.browser.find_by_name("some-check").checked def test_check_keeps_checked_if_called_multiple_times(self): "should keep a checkbox checked if check() is called multiple times" - self.assertFalse(self.browser.find_by_name("some-check").checked) + assert not self.browser.find_by_name("some-check").checked self.browser.check("some-check") self.browser.check("some-check") - self.assertTrue(self.browser.find_by_name("some-check").checked) + assert self.browser.find_by_name("some-check").checked def test_can_uncheck_a_checkbox(self): "should provide a way to uncheck a radio checkbox" - self.assertTrue(self.browser.find_by_name("checked-checkbox").checked) + assert self.browser.find_by_name("checked-checkbox").checked self.browser.uncheck("checked-checkbox") - self.assertFalse(self.browser.find_by_name("checked-checkbox").checked) + assert not self.browser.find_by_name("checked-checkbox").checked def test_uncheck_should_keep_unchecked_if_called_multiple_times(self): "should keep a checkbox unchecked if uncheck() is called multiple times" - self.assertTrue(self.browser.find_by_name("checked-checkbox").checked) + assert self.browser.find_by_name("checked-checkbox").checked self.browser.uncheck("checked-checkbox") self.browser.uncheck("checked-checkbox") - self.assertFalse(self.browser.find_by_name("checked-checkbox").checked) + assert not self.browser.find_by_name("checked-checkbox").checked def test_can_fill_text_field_in_form(self): "should provide a away to change field value" self.browser.fill_form({"query": "new query"}) value = self.browser.find_by_name("query").value - self.assertEqual("new query", value) + assert "new query" == value def test_can_fill_password_field_in_form(self): "should provide a way to change password value" new_password = "new password" self.browser.fill_form({"password": new_password}) value = self.browser.find_by_name("password").value - self.assertEqual(new_password, value) + assert new_password == value def test_can_fill_more_than_one_field_in_form(self): "should provide a away to change field value" self.browser.fill("query", "my name") - self.assertFalse(self.browser.find_by_id("gender-m").checked) - self.assertFalse(self.browser.find_option_by_value("rj").selected) - self.assertFalse(self.browser.find_by_name("some-check").checked) - self.assertTrue(self.browser.find_by_name("checked-checkbox").checked) + assert not self.browser.find_by_id("gender-m").checked + assert not self.browser.find_option_by_value("rj").selected + assert not self.browser.find_by_name("some-check").checked + assert self.browser.find_by_name("checked-checkbox").checked self.browser.fill_form( { "query": "another new query", @@ -217,27 +196,27 @@ def test_can_fill_more_than_one_field_in_form(self): }, ) query_value = self.browser.find_by_name("query").value - self.assertEqual("another new query", query_value) + assert "another new query" == query_value desc_value = self.browser.find_by_name("description").value - self.assertEqual("Just another description value in the textarea", desc_value) - self.assertTrue(self.browser.find_by_id("gender-m").checked) - self.assertTrue(self.browser.find_option_by_value("rj").selected) - self.assertTrue(self.browser.find_by_name("some-check").checked) - self.assertFalse(self.browser.find_by_name("checked-checkbox").checked) + assert "Just another description value in the textarea" == desc_value + assert self.browser.find_by_id("gender-m").checked + assert self.browser.find_option_by_value("rj").selected + assert self.browser.find_by_name("some-check").checked + assert not self.browser.find_by_name("checked-checkbox").checked def test_can_fill_tel_text_field(self): "should provide a way to change a tel field value" new_telephone = "555-0042" self.browser.fill_form({"telephone": new_telephone}) value = self.browser.find_by_name("telephone").value - self.assertEqual(new_telephone, value) + assert new_telephone == value def test_can_fill_unknown_text_field(self): "should provide a way to change a unknown text field type that isn't specifically defined" new_search_keyword = "foobar" self.browser.fill_form({"search_keyword": new_search_keyword}) value = self.browser.find_by_name("search_keyword").value - self.assertEqual(new_search_keyword, value) + assert new_search_keyword == value def test_can_fill_form_by_id(self): "should be able to fill a form by its id" @@ -246,7 +225,7 @@ def test_can_fill_form_by_id(self): form_id="login", ) value = self.browser.find_by_name("firstname").value - self.assertEqual("John", value) + assert "John" == value def test_fill_form_missing_values(self): """Missing values should raise an error.""" @@ -269,29 +248,29 @@ def test_fill_form_missing_values_ignore_missing(self): def test_can_clear_text_field_content(self): self.browser.fill("query", "random query") value = self.browser.find_by_name("query").value - self.assertEqual("random query", value) + assert "random query" == value self.browser.find_by_name("query").clear() value = self.browser.find_by_name("query").value - self.assertFalse(value) + assert not value def test_can_clear_password_field_content(self): self.browser.fill("password", "1nF4m310") value = self.browser.find_by_name("password").value - self.assertEqual("1nF4m310", value) + assert "1nF4m310" == value self.browser.find_by_name("password").clear() value = self.browser.find_by_name("password").value - self.assertFalse(value) + assert not value def test_can_clear_tel_field_content(self): self.browser.fill("telephone", "5553743980") value = self.browser.find_by_name("telephone").value - self.assertEqual("5553743980", value) + assert "5553743980" == value self.browser.find_by_name("telephone").clear() value = self.browser.find_by_name("telephone").value - self.assertFalse(value) + assert not value @skip_if_django def test_can_clear_textarea_content(self): diff --git a/tests/is_element_present.py b/tests/is_element_present.py index 15a8032f9..c20fd59cb 100644 --- a/tests/is_element_present.py +++ b/tests/is_element_present.py @@ -7,46 +7,42 @@ class IsElementPresentTest: def test_is_element_present_by_css(self): "should is element present by css verify if element is present" self.browser.find_by_css(".add-async-element").click() - self.assertTrue(self.browser.is_element_present_by_css(".async-element")) + assert self.browser.is_element_present_by_css(".async-element") def test_is_element_present_by_css_using_a_custom_wait_time(self): "should is element present by css verify if element is present using a custom wait time" self.browser.find_by_css(".add-async-element").click() - self.assertTrue( - self.browser.is_element_present_by_css(".async-element2", wait_time=12), - ) + assert self.browser.is_element_present_by_css(".async-element2", wait_time=12) def test_is_element_present_by_css_returns_false_if_element_is_not_present(self): "should is element present by css returns False if element is not present" - self.assertFalse(self.browser.is_element_present_by_css(".async-elementzz")) + assert not self.browser.is_element_present_by_css(".async-elementzz") def test_is_element_not_present_by_css(self): "should is element not present by css verify if element is not present" - self.assertTrue(self.browser.is_element_not_present_by_css(".async-element")) + assert self.browser.is_element_not_present_by_css(".async-element") def test_is_element_not_present_by_css_returns_false_if_element_is_present(self): "should is element not present by css returns False if element is present" - self.assertFalse(self.browser.is_element_not_present_by_css("h1")) + assert not self.browser.is_element_not_present_by_css("h1") def test_is_element_not_present_by_css_using_a_custom_wait_time(self): "should is element not present by css verify if element is not present using a custom wait time" - self.assertTrue( - self.browser.is_element_not_present_by_css(".async-element", wait_time=12), - ) + assert self.browser.is_element_not_present_by_css(".async-element", wait_time=12) def test_is_element_present_by_xpath(self): "should is element present by xpath verify if element is present" self.browser.find_by_css(".add-async-element").click() - self.assertTrue(self.browser.is_element_present_by_xpath("//h4")) + assert self.browser.is_element_present_by_xpath("//h4") def test_is_element_present_by_xpath_using_a_custom_wait_time(self): "should is element present by xpath verify if element is present using a custom wait time" self.browser.find_by_css(".add-async-element").click() - self.assertTrue(self.browser.is_element_present_by_xpath("//h5", wait_time=12)) + assert self.browser.is_element_present_by_xpath("//h5", wait_time=12) def test_is_element_present_by_xpath_returns_false_if_element_is_not_present(self): "should is element present by xpath returns false if element is not present" - self.assertTrue(self.browser.is_element_not_present_by_xpath("//h4")) + assert self.browser.is_element_not_present_by_xpath("//h4") def test_is_element_not_present_by_xpath_returns_false_if_element_is_present(self): """should is_element_not_present_by_xpath returns False if element is present""" @@ -56,31 +52,29 @@ def test_is_element_not_present_by_xpath_returns_false_if_element_is_present(sel def test_is_element_not_present_by_xpath_using_a_custom_wait_time(self): "should is element not present by xpath verify if element is not present using a custom wait time" - self.assertTrue( - self.browser.is_element_not_present_by_xpath("//h4", wait_time=12), - ) + assert self.browser.is_element_not_present_by_xpath("//h4", wait_time=12) def test_is_element_present_by_tag(self): "should is element present by tag verify if element is present" self.browser.find_by_css(".add-async-element").click() - self.assertTrue(self.browser.is_element_present_by_tag("h4")) + assert self.browser.is_element_present_by_tag("h4") def test_is_element_present_by_tag_using_a_custom_wait_time(self): "should is element present by tag verify if element is present using a custom wait time" self.browser.find_by_css(".add-async-element").click() - self.assertTrue(self.browser.is_element_present_by_tag("h4", wait_time=12)) + assert self.browser.is_element_present_by_tag("h4", wait_time=12) def test_is_element_present_by_tag_returns_false_if_element_is_not_present(self): "should is element present by tag returns false if element is not present" - self.assertFalse(self.browser.is_element_present_by_tag("h4")) + assert not self.browser.is_element_present_by_tag("h4") def test_is_element_not_present_by_tag(self): "should is element not present by tag verify if element is not present" - self.assertTrue(self.browser.is_element_not_present_by_tag("h4")) + assert self.browser.is_element_not_present_by_tag("h4") def test_is_element_not_present_by_tag_using_a_custom_wait_time(self): "should is element not present by tag verify if element is not present using a custom wait time" - self.assertTrue(self.browser.is_element_not_present_by_tag("h4", wait_time=12)) + assert self.browser.is_element_not_present_by_tag("h4", wait_time=12) def test_is_element_not_present_by_tag_returns_false_if_element_is_present(self): """should is_element_not_present_by_tag returns False if element is present""" @@ -90,57 +84,48 @@ def test_is_element_not_present_by_tag_returns_false_if_element_is_present(self) def test_is_element_present_by_text(self): "should is element present by text verify if element is present" - self.assertTrue(self.browser.is_element_present_by_text("Complex")) + assert self.browser.is_element_present_by_text("Complex") def test_is_element_present_by_text_returns_false_if_element_is_not_present(self): "should is element present by text verify if element is present" - self.assertFalse(self.browser.is_element_present_by_text("Not present")) + assert not self.browser.is_element_present_by_text("Not present") def test_is_element_not_present_by_text(self): "should is element not present by text verify if element is not present" - self.assertTrue(self.browser.is_element_not_present_by_text("Not present")) + assert self.browser.is_element_not_present_by_text("Not present") def test_is_element_not_present_by_text_returns_false_if_element_is_present(self): "should is element not present by text returns False if element is present" - self.assertFalse(self.browser.is_element_not_present_by_text("Complex")) + assert not self.browser.is_element_not_present_by_text("Complex") def test_is_element_present_by_value(self): "should is element present by value verify if element is present" self.browser.find_by_css(".add-async-element").click() - self.assertTrue(self.browser.is_element_present_by_value("async-header-value")) + assert self.browser.is_element_present_by_value("async-header-value") def test_is_element_present_by_value_using_a_custom_wait_time(self): "should is element present by value verify if element is present using a custom wait time" self.browser.find_by_css(".add-async-element").click() - self.assertTrue( - self.browser.is_element_present_by_value( - "async-header-value", - wait_time=12, - ), - ) + assert self.browser.is_element_present_by_value("async-header-value", wait_time=12) def test_is_element_present_by_value_returns_false_if_element_is_not_present(self): "should is element present by value returns False if element is not present" - self.assertFalse(self.browser.is_element_present_by_value("async-header-value")) + assert not self.browser.is_element_present_by_value("async-header-value") def test_is_element_not_present_by_value(self): "should is element not present by value verify if element is not present" - self.assertTrue( - self.browser.is_element_not_present_by_value("async-header-value"), - ) + assert self.browser.is_element_not_present_by_value("async-header-value") def test_is_element_not_present_by_value_using_a_custom_wait_time(self): "should is element not present by value verify if element is not present using a custom wait time" - self.assertTrue( - self.browser.is_element_not_present_by_value( - "async-header-value", - wait_time=12, - ), + assert self.browser.is_element_not_present_by_value( + "async-header-value", + wait_time=12, ) def test_is_element_not_present_by_value_returns_false_if_element_is_present(self): "should is element not present by value returns False if element is present" - self.assertFalse(self.browser.is_element_not_present_by_value("default value")) + assert not self.browser.is_element_not_present_by_value("default value") def test_is_element_present_by_id(self): "should is element present by id verify if element is present" @@ -151,23 +136,19 @@ def test_is_element_present_by_id(self): def test_is_element_present_by_id_using_a_custom_wait_time(self): "should is element present by id verify if element is present using a custom wait time" self.browser.find_by_css(".add-async-element").click() - self.assertTrue( - self.browser.is_element_present_by_id("async-header", wait_time=12), - ) + assert self.browser.is_element_present_by_id("async-header", wait_time=12) def test_is_element_present_by_id_returns_false_if_element_is_not_present(self): "should is element present by id returns False if element is not present" - self.assertFalse(self.browser.is_element_present_by_id("async-header")) + assert not self.browser.is_element_present_by_id("async-header") def test_is_element_not_present_by_id(self): "should is element not present by id verify if element is not present" - self.assertTrue(self.browser.is_element_not_present_by_id("async-header")) + assert self.browser.is_element_not_present_by_id("async-header") def test_is_element_not_present_by_id_using_a_custom_wait_time(self): "should is element not present by id verify if element is not present using a custom wait time" - self.assertTrue( - self.browser.is_element_not_present_by_id("async-header", wait_time=12), - ) + assert self.browser.is_element_not_present_by_id("async-header", wait_time=12) def test_is_element_not_present_by_id_returns_false_if_element_is_present(self): """should is_element_not_present_by_id returns False if element is present""" @@ -178,28 +159,24 @@ def test_is_element_not_present_by_id_returns_false_if_element_is_present(self): def test_is_element_present_by_name(self): "should is element present by name verify if element is present" self.browser.find_by_css(".add-async-element").click() - self.assertTrue(self.browser.is_element_present_by_name("async-input")) + assert self.browser.is_element_present_by_name("async-input") def test_is_element_present_by_name_using_a_custom_wait_time(self): "should is element present by name verify if element is present using a custom wait time" self.browser.find_by_css(".add-async-element").click() - self.assertTrue( - self.browser.is_element_present_by_name("async-input", wait_time=12), - ) + assert self.browser.is_element_present_by_name("async-input", wait_time=12) def test_is_element_present_by_name_returns_false_if_element_is_not_present(self): "should is element present by name returns false if element is not present" - self.assertFalse(self.browser.is_element_present_by_name("async-input")) + assert not self.browser.is_element_present_by_name("async-input") def test_is_element_not_present_by_name(self): "should is element not present by name verify if element is not present" - self.assertTrue(self.browser.is_element_not_present_by_name("async-input")) + assert self.browser.is_element_not_present_by_name("async-input") def test_is_element_not_present_by_name_using_a_custom_wait_time(self): "should is element not present by name verify if element is not present using a custom wait time" - self.assertTrue( - self.browser.is_element_not_present_by_name("async-input", wait_time=12), - ) + assert self.browser.is_element_not_present_by_name("async-input", wait_time=12) def test_is_element_not_present_by_name_returns_false_if_element_is_present(self): """should is_element_not_present_by_name returns False if element is present""" diff --git a/tests/is_text_present.py b/tests/is_text_present.py index 6042f9356..065ae8b80 100644 --- a/tests/is_text_present.py +++ b/tests/is_text_present.py @@ -7,36 +7,36 @@ class IsTextPresentTest: def test_is_text_present(self): "should verify if text is present" - self.assertTrue(self.browser.is_text_present("Example Header")) + assert self.browser.is_text_present("Example Header") def test_is_text_present_and_should_return_false(self): "should verify if text is present and return false" - self.assertFalse(self.browser.is_text_present("Text that not exist")) + assert not self.browser.is_text_present("Text that not exist") def test_is_text_present_and_should_wait_time(self): "should verify if text is present and wait for five seconds" self.browser.links.find_by_text("FOO").click() - self.assertTrue(self.browser.is_text_present("BAR!", wait_time=20)) + assert self.browser.is_text_present("BAR!", wait_time=20) def test_is_text_not_present(self): "should verify if text is not present" - self.assertTrue(self.browser.is_text_not_present("Text that not exist")) + assert self.browser.is_text_not_present("Text that not exist") def test_is_text_not_present_and_should_return_false(self): "should verify if text is not present and return false" - self.assertFalse(self.browser.is_text_not_present("Example Header")) + assert not self.browser.is_text_not_present("Example Header") def test_is_text_not_present_and_should_wait_time(self): "should verify if text is not present and wait for five seconds" self.browser.links.find_by_text("FOO").click() - self.assertTrue(self.browser.is_text_not_present("another text", wait_time=20)) + assert self.browser.is_text_not_present("another text", wait_time=20) def test_is_text_present_no_body(self): "should work properly (return false) even if there's no body" self.browser.visit(EXAMPLE_APP + "no-body") - self.assertFalse(self.browser.is_text_present("No such text")) + assert not self.browser.is_text_present("No such text") def test_is_text_not_present_no_body(self): "returns true if there's no body" self.browser.visit(EXAMPLE_APP + "no-body") - self.assertTrue(self.browser.is_text_not_present("No such text")) + assert self.browser.is_text_not_present("No such text") diff --git a/tests/status_code.py b/tests/status_code.py index 3acc9545a..814835253 100644 --- a/tests/status_code.py +++ b/tests/status_code.py @@ -7,10 +7,10 @@ class StatusCodeTest: def test_should_visit_index_of_example_app_and_get_200_status_code(self): self.browser.visit(EXAMPLE_APP) - self.assertEqual(200, self.browser.status_code) - self.assertEqual("200 - OK", str(self.browser.status_code)) + assert 200 == self.browser.status_code + assert "200 - OK" == str(self.browser.status_code) def test_should_visit_error_of_example_app_and_not_get_200_status_code(self): self.browser.visit(EXAMPLE_APP + "error.html") - self.assertNotEqual(200, self.browser.status_code) - self.assertEqual("404 - Not Found", str(self.browser.status_code)) + assert 200 != self.browser.status_code + assert "404 - Not Found" == str(self.browser.status_code) diff --git a/tests/test_djangoclient.py b/tests/test_djangoclient.py index dad8e691d..a0ee72756 100644 --- a/tests/test_djangoclient.py +++ b/tests/test_djangoclient.py @@ -34,7 +34,7 @@ def visit_example_app(self): def test_should_support_with_statement(self): with Browser("django") as internet: - self.assertIsNotNone(internet) + assert internet is not None def test_attach_file(self): "should provide a way to change file field value" @@ -46,47 +46,48 @@ def test_attach_file(self): self.browser.find_by_name("upload").click() html = self.browser.html - self.assertIn("text/plain", html) - self.assertIn(open(file_path).read(), html) + assert "text/plain" in html + with open(file_path) as f: + assert f.read() in html def test_forward_to_none_page(self): "should not fail when trying to forward to none" browser = Browser("django") browser.visit(EXAMPLE_APP) browser.forward() - self.assertEqual(EXAMPLE_APP, browser.url) + assert EXAMPLE_APP == browser.url browser.quit() def test_can_clear_password_field_content(self): "django should not be able to clear" - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.find_by_name("password").first.clear() def test_can_clear_tel_field_content(self): "django should not be able to clear" - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.find_by_name("telephone").first.clear() def test_can_clear_text_field_content(self): "django should not be able to clear" - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.find_by_name("query").first.clear() def test_cant_switch_to_frame(self): "django driver should not be able to switch to frames" - with self.assertRaises(NotImplementedError) as cm: + with pytest.raises(NotImplementedError) as cm: self.browser.get_iframe("frame_123") self.fail() e = cm.exception - self.assertEqual("django doesn't support frames.", e.args[0]) + assert "django doesn't support frames." == e.args[0] def test_simple_type(self): """ django won't support type method because it doesn't interact with JavaScript """ - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.type("query", "with type method") def test_simple_type_on_element(self): @@ -94,7 +95,7 @@ def test_simple_type_on_element(self): django won't support type method because it doesn't interact with JavaScript """ - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.find_by_name("query").type("with type method") def test_slowly_typing(self): @@ -102,7 +103,7 @@ def test_slowly_typing(self): django won't support type method because it doesn't interact with JavaScript """ - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.type("query", "with type method", slowly=True) def test_slowly_typing_on_element(self): @@ -110,27 +111,25 @@ def test_slowly_typing_on_element(self): django won't support type method on element because it doesn't interac with JavaScript """ - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): query = self.browser.find_by_name("query") query.type("with type method", slowly=True) def test_cant_mouseover(self): "django should not be able to put the mouse over the element" - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.find_by_css("#visible").mouse_over() def test_cant_mouseout(self): "django should not be able to mouse out of an element" - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.find_by_css("#visible").mouse_out() def test_links_with_nested_tags_xpath(self): links = self.browser.find_by_xpath('//a/span[text()="first bar"]/..') - self.assertEqual( - len(links), - 1, - 'Found not exactly one link with a span with text "BAR ONE". %s' % [item.outer_html for item in links], - ) + assert len(links) == 1, 'Found more than one link with a span with text "BAR ONE". %s' % [ + item.outer_html for item in links + ] def test_finding_all_links_by_non_ascii_text(self): "should find links by non ascii text" @@ -142,7 +141,7 @@ def test_finding_all_links_by_non_ascii_text(self): } for key, text in non_ascii_encodings.items(): link = self.browser.links.find_by_text(text) - self.assertEqual(key, link["id"]) + assert key == link["id"] def test_cookies_extra_parameters(self): """Cookie can be created with extra parameters.""" @@ -163,10 +162,9 @@ def setUpClass(cls): def test_create_a_phantomjs_with_custom_headers(self): self.browser.visit(EXAMPLE_APP + "headers") - self.assertTrue( - self.browser.is_text_present("X-Splinter-Customheaders-1: Hello"), - ) - self.assertTrue(self.browser.is_text_present("X-Splinter-Customheaders-2: Bye")) + assert self.browser.is_text_present("X-Splinter-Customheaders-1: Hello") + + assert self.browser.is_text_present("X-Splinter-Customheaders-2: Bye") @classmethod def tearDownClass(cls): diff --git a/tests/test_flaskclient.py b/tests/test_flaskclient.py index b999e09b7..db23dd375 100644 --- a/tests/test_flaskclient.py +++ b/tests/test_flaskclient.py @@ -5,6 +5,8 @@ import time import unittest +import pytest + from .base import BaseBrowserTests from .fake_webapp import app from .fake_webapp import EXAMPLE_APP @@ -25,7 +27,7 @@ def tearDownClass(cls): def test_should_support_with_statement(self): with Browser("flask", app=app) as internet: - self.assertIsNotNone(internet) + assert internet is not None def test_attach_file(self): "should provide a way to change file field value" @@ -37,69 +39,70 @@ def test_attach_file(self): self.browser.find_by_name("upload").click() html = self.browser.html - self.assertIn("text/plain", html) - self.assertIn(open(file_path).read(), html) + assert "text/plain" in html + with open(file_path) as f: + assert f.read() in html def test_serialize_select_mutiple(self): "should serialize a select with multiple values into a list" self.browser.select("pets", ["cat", "dog"]) form = self.browser.find_by_name("send")._get_parent_form() data = self.browser.serialize(form) - self.assertListEqual(data["pets"], ["cat", "dog"]) + assert data["pets"] == ["cat", "dog"] def test_forward_to_none_page(self): "should not fail when trying to forward to none" browser = Browser("flask", app=app) browser.visit(EXAMPLE_APP) browser.forward() - self.assertEqual(EXAMPLE_APP, browser.url) + assert EXAMPLE_APP == browser.url browser.quit() def test_can_clear_password_field_content(self): "flask should not be able to clear" - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.find_by_name("password").first.clear() def test_can_clear_tel_field_content(self): "flask should not be able to clear" - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.find_by_name("telephone").first.clear() def test_can_clear_text_field_content(self): "flask should not be able to clear" - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.find_by_name("query").first.clear() def test_can_clear_textarea_content(self): "flask should not be able to clear" - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.find_by_name("description").first.clear() def test_can_clear_search_content(self): "flask should not be able to clear" - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.find_by_name("search_keyword").first.clear() def test_can_clear_url_content(self): "flask should not be able to clear" - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.find_by_name("url_input").first.clear() def test_cant_switch_to_frame(self): "flask should not be able to switch to frames" - with self.assertRaises(NotImplementedError) as cm: + with pytest.raises(NotImplementedError) as cm: self.browser.get_iframe("frame_123") self.fail() e = cm.exception - self.assertEqual("flask doesn't support frames.", e.args[0]) + assert "flask doesn't support frames." == e.args[0] def test_simple_type(self): """ flask won't support type method because it doesn't interact with JavaScript """ - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.type("query", "with type method") def test_simple_type_on_element(self): @@ -107,7 +110,7 @@ def test_simple_type_on_element(self): flask won't support type method because it doesn't interact with JavaScript """ - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.find_by_name("query").type("with type method") def test_slowly_typing(self): @@ -115,7 +118,7 @@ def test_slowly_typing(self): flask won't support type method because it doesn't interact with JavaScript """ - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.type("query", "with type method", slowly=True) def test_slowly_typing_on_element(self): @@ -123,27 +126,25 @@ def test_slowly_typing_on_element(self): flask won't support type method on element because it doesn't interac with JavaScript """ - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): query = self.browser.find_by_name("query") query.type("with type method", slowly=True) def test_cant_mouseover(self): "flask should not be able to put the mouse over the element" - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.find_by_css("#visible").mouse_over() def test_cant_mouseout(self): "flask should not be able to mouse out of an element" - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.find_by_css("#visible").mouse_out() def test_links_with_nested_tags_xpath(self): links = self.browser.find_by_xpath('//a/span[text()="first bar"]/..') - self.assertEqual( - len(links), - 1, - 'Found not exactly one link with a span with text "BAR ONE". %s' % [item.outer_html for item in links], - ) + assert len(links) == 1, 'Found more than one link with a span with text "BAR ONE". %s' % [ + item.outer_html for item in links + ] def test_finding_all_links_by_non_ascii_text(self): "should find links by non ascii text" @@ -155,7 +156,7 @@ def test_finding_all_links_by_non_ascii_text(self): } for key, text in non_ascii_encodings.items(): link = self.browser.links.find_by_text(text) - self.assertEqual(key, link["id"]) + assert key == link["id"] def test_redirection_on_post(self): """ @@ -163,8 +164,8 @@ def test_redirection_on_post(self): browser should be redirected to GET /redirected-location?come=get&some=true """ self.browser.find_by_name("redirect").click() - self.assertIn("I just been redirected to this location", self.browser.html) - self.assertIn("redirect-location?come=get&some=true", self.browser.url) + assert "I just been redirected to this location" in self.browser.html + assert "redirect-location?come=get&some=true" in self.browser.url def test_cookies_extra_parameters(self): """Cookie can be created with extra parameters.""" @@ -185,10 +186,8 @@ def setUpClass(cls): def test_create_a_flask_client_with_custom_headers(self): self.browser.visit(EXAMPLE_APP + "headers") - self.assertTrue( - self.browser.is_text_present("X-Splinter-Customheaders-1: Hello"), - ) - self.assertTrue(self.browser.is_text_present("X-Splinter-Customheaders-2: Bye")) + assert self.browser.is_text_present("X-Splinter-Customheaders-1: Hello") + assert self.browser.is_text_present("X-Splinter-Customheaders-2: Bye") @classmethod def tearDownClass(cls): diff --git a/tests/test_request_handler.py b/tests/test_request_handler.py index 2212ed783..0b06524c6 100644 --- a/tests/test_request_handler.py +++ b/tests/test_request_handler.py @@ -11,7 +11,7 @@ def setUp(self): self.status_code = StatusCode(200, "OK") def test_should_receive_an_url_and_get_a_success_response(self): - self.assertTrue(self.status_code.is_success()) + assert self.status_code.is_success() def test_should_compare_app_index_with_404_and_get_false(self): - self.assertNotEqual(self.status_code, 404) + assert self.status_code != 404 diff --git a/tests/test_webdriver_remote.py b/tests/test_webdriver_remote.py index b2640c1cc..4b0f9beba 100644 --- a/tests/test_webdriver_remote.py +++ b/tests/test_webdriver_remote.py @@ -132,10 +132,10 @@ def test_create_and_use_contains(self): def test_can_fill_more_than_one_field_in_form(self): "should provide a away to change field value" self.browser.fill("query", "my name") - self.assertFalse(self.browser.find_by_id("gender-m").checked) - self.assertFalse(self.browser.find_option_by_value("rj").selected) - self.assertFalse(self.browser.find_by_name("some-check").checked) - self.assertTrue(self.browser.find_by_name("checked-checkbox").checked) + assert not self.browser.find_by_id("gender-m").checked + assert not self.browser.find_option_by_value("rj").selected + assert not self.browser.find_by_name("some-check").checked + assert self.browser.find_by_name("checked-checkbox").checked # Select of dropdown doesn't work for Safari 17 (remote). Safari as OS user works well # for some reason select doesn't work for Safari self.browser.fill_form( @@ -149,13 +149,13 @@ def test_can_fill_more_than_one_field_in_form(self): }, ) query_value = self.browser.find_by_name("query").value - self.assertEqual("another new query", query_value) + assert "another new query" == query_value desc_value = self.browser.find_by_name("description").value - self.assertEqual("Just another description value in the textarea", desc_value) - self.assertTrue(self.browser.find_by_id("gender-m").checked) - # self.assertTrue(self.browser.find_option_by_value("rj").selected) - self.assertTrue(self.browser.find_by_name("some-check").checked) - self.assertFalse(self.browser.find_by_name("checked-checkbox").checked) + assert "Just another description value in the textarea" == desc_value + assert self.browser.find_by_id("gender-m").checked + # assert self.browser.find_option_by_value("rj").selected + assert self.browser.find_by_name("some-check").checked + assert not self.browser.find_by_name("checked-checkbox").checked # ------- BEGIN OF CLICK PROBLEM TESTS ------- # https://stackoverflow.com/questions/77388720/automation-testing-with-selenium-click-doesnt-works-on-new-safari-17-ios-sonoma diff --git a/tests/test_zopetestbrowser.py b/tests/test_zopetestbrowser.py index aa56af3f5..abaf261d0 100644 --- a/tests/test_zopetestbrowser.py +++ b/tests/test_zopetestbrowser.py @@ -48,24 +48,24 @@ def test_forward_to_none_page(self): browser = Browser("zope.testbrowser") browser.visit(EXAMPLE_APP) browser.forward() - self.assertEqual(EXAMPLE_APP, browser.url) + assert EXAMPLE_APP == browser.url browser.quit() def test_cant_switch_to_frame(self): "zope.testbrowser should not be able to switch to frames" - with self.assertRaises(NotImplementedError) as cm: + with pytest.raises(NotImplementedError) as cm: self.browser.get_iframe("frame_123") self.fail() e = cm.exception - self.assertEqual("zope.testbrowser doesn't support frames.", e.args[0]) + assert "zope.testbrowser doesn't support frames." == e.args[0] def test_simple_type(self): """ zope.testbrowser won't support type method because it doesn't interact with JavaScript """ - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.type("query", "with type method") def test_simple_type_on_element(self): @@ -73,37 +73,37 @@ def test_simple_type_on_element(self): zope.testbrowser won't support type method because it doesn't interact with JavaScript """ - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.find_by_name("query").type("with type method") def test_can_clear_password_field_content(self): "zope.testbrowser should not be able to clear" - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.find_by_name("password").first.clear() def test_can_clear_tel_field_content(self): "zope.testbrowser should not be able to clear" - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.find_by_name("telephone").first.clear() def test_can_clear_text_field_content(self): "zope.testbrowser should not be able to clear" - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.find_by_name("query").first.clear() def test_can_clear_textarea_content(self): "flask should not be able to clear" - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.find_by_name("description").first.clear() def test_can_clear_search_content(self): "flask should not be able to clear" - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.find_by_name("search_keyword").first.clear() def test_can_clear_url_content(self): "flask should not be able to clear" - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.find_by_name("url_input").first.clear() def test_slowly_typing(self): @@ -111,7 +111,7 @@ def test_slowly_typing(self): zope.testbrowser won't support type method because it doesn't interact with JavaScript """ - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.type("query", "with type method", slowly=True) def test_slowly_typing_on_element(self): @@ -119,27 +119,25 @@ def test_slowly_typing_on_element(self): zope.testbrowser won't support type method on element because it doesn't interac with JavaScript """ - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): query = self.browser.find_by_name("query") query.type("with type method", slowly=True) def test_cant_mouseover(self): "zope.testbrowser should not be able to put the mouse over the element" - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.find_by_css("#visible").mouse_over() def test_cant_mouseout(self): "zope.testbrowser should not be able to mouse out of an element" - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): self.browser.find_by_css("#visible").mouse_out() def test_links_with_nested_tags_xpath(self): links = self.browser.find_by_xpath('//a/span[text()="first bar"]/..') - self.assertEqual( - len(links), - 1, - 'Found not exactly one link with a span with text "BAR ONE". %s' % [item.outer_html for item in links], - ) + assert len(links) == 1, 'Found more than one link with a span with text "BAR ONE". %s' % [ + item.outer_html for item in links + ] def test_finding_all_links_by_non_ascii_text(self): "should find links by non ascii text" @@ -151,7 +149,7 @@ def test_finding_all_links_by_non_ascii_text(self): } for key, text in non_ascii_encodings.items(): link = self.browser.links.find_by_text(text) - self.assertEqual(key, link["id"]) + assert key == link["id"] def test_fill_form_missing_values(self): """Missing values should raise an error.""" diff --git a/tests/type.py b/tests/type.py index 7a5707f1f..899640c8c 100644 --- a/tests/type.py +++ b/tests/type.py @@ -10,21 +10,21 @@ def test_simple_type(self): self.browser.visit(EXAMPLE_APP) self.browser.type("query", " with type method") value = self.browser.find_by_name("query").value - self.assertEqual("default value with type method", value) + assert "default value with type method" == value self.browser.type("description", "type into textarea") value = self.browser.find_by_name("description").value - self.assertEqual("type into textarea", value) + assert "type into textarea" == value def test_simple_type_on_element(self): self.browser.visit(EXAMPLE_APP) self.browser.find_by_name("query").type(" with type method") value = self.browser.find_by_name("query").value - self.assertEqual("default value with type method", value) + assert "default value with type method" == value self.browser.find_by_name("description").type("type into textarea") value = self.browser.find_by_name("description").value - self.assertEqual("type into textarea", value) + assert "type into textarea" == value def test_slowly_typing(self): "should be able to slowly type some text in a field" @@ -33,12 +33,12 @@ def test_slowly_typing(self): num = 0 num_max = 6 for key in self.browser.type(name, "typing", slowly=True): - self.assertEqual(self.browser.is_text_present("#%d" % num), True) + assert self.browser.is_text_present("#%d" % num) num += 1 - self.assertEqual(num, num_max) + assert num == num_max element = self.browser.find_by_name(name) - self.assertEqual(element.value, "typing") + assert element.value == "typing" def test_slowly_typing_on_element(self): for name in ["type-input", "type-textarea"]: @@ -48,9 +48,9 @@ def test_slowly_typing_on_element(self): text_input = self.browser.find_by_name(name) typing = text_input.type("typing", slowly=True) for key in typing: - self.assertEqual(self.browser.is_text_present("#%d" % num), True) + assert self.browser.is_text_present("#%d" % num) num += 1 - self.assertEqual(num, num_max) + assert num == num_max element = self.browser.find_by_name(name) - self.assertEqual(element.value, "typing") + assert element.value == "typing" From 421d90481099a8facde22da9195e64cff8199b80 Mon Sep 17 00:00:00 2001 From: Joshua Fehler Date: Mon, 3 Jun 2024 08:27:37 -0400 Subject: [PATCH 2/2] fixup --- tests/element_does_not_exist.py | 10 ++++------ tests/test_djangoclient.py | 5 ++--- tests/test_flaskclient.py | 5 ++--- tests/test_zopetestbrowser.py | 5 ++--- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/tests/element_does_not_exist.py b/tests/element_does_not_exist.py index 14ab80a55..aac6dc41d 100644 --- a/tests/element_does_not_exist.py +++ b/tests/element_does_not_exist.py @@ -25,7 +25,7 @@ def test_element_list_raises_with_unicode_query(self): def test_element_list_contains_right_information_and_raises_right_exception(self): "element list contains right information about query and raises nice exception message" - with pytest.raises(ElementDoesNotExist) as cm: + with pytest.raises(ElementDoesNotExist) as err: element_list = self.browser.find_by_css(".element-that-dont-exists") assert "css" == element_list.find_by assert ".element-that-dont-exists" == element_list.query @@ -33,14 +33,13 @@ def test_element_list_contains_right_information_and_raises_right_exception(self expected_message = 'No elements were found with css ".element-that-dont-exists"' - e = cm.exception - assert expected_message == e.args[0] + assert expected_message == err.value.args[0] def test_element_list_raises_when_element_first_doesnt_exists_in_element_context( self, ): "element list raises exception with right information in element context" - with pytest.raises(ElementDoesNotExist) as cm: + with pytest.raises(ElementDoesNotExist) as err: element_list = self.browser.find_by_css("#inside").find_by_css( ".inner-element-that-dont-exists", ) @@ -50,5 +49,4 @@ def test_element_list_raises_when_element_first_doesnt_exists_in_element_context expected_message = 'No elements were found with css ".inner-element-that-dont-exists"' - e = cm.exception - assert expected_message == e.args[0] + assert expected_message == err.value.args[0] diff --git a/tests/test_djangoclient.py b/tests/test_djangoclient.py index a0ee72756..8263af2a7 100644 --- a/tests/test_djangoclient.py +++ b/tests/test_djangoclient.py @@ -75,12 +75,11 @@ def test_can_clear_text_field_content(self): def test_cant_switch_to_frame(self): "django driver should not be able to switch to frames" - with pytest.raises(NotImplementedError) as cm: + with pytest.raises(NotImplementedError) as err: self.browser.get_iframe("frame_123") self.fail() - e = cm.exception - assert "django doesn't support frames." == e.args[0] + assert "django doesn't support frames." == err.value.args[0] def test_simple_type(self): """ diff --git a/tests/test_flaskclient.py b/tests/test_flaskclient.py index db23dd375..9c1e80c83 100644 --- a/tests/test_flaskclient.py +++ b/tests/test_flaskclient.py @@ -90,12 +90,11 @@ def test_can_clear_url_content(self): def test_cant_switch_to_frame(self): "flask should not be able to switch to frames" - with pytest.raises(NotImplementedError) as cm: + with pytest.raises(NotImplementedError) as err: self.browser.get_iframe("frame_123") self.fail() - e = cm.exception - assert "flask doesn't support frames." == e.args[0] + assert "flask doesn't support frames." == err.value.args[0] def test_simple_type(self): """ diff --git a/tests/test_zopetestbrowser.py b/tests/test_zopetestbrowser.py index abaf261d0..87c28b5d0 100644 --- a/tests/test_zopetestbrowser.py +++ b/tests/test_zopetestbrowser.py @@ -53,12 +53,11 @@ def test_forward_to_none_page(self): def test_cant_switch_to_frame(self): "zope.testbrowser should not be able to switch to frames" - with pytest.raises(NotImplementedError) as cm: + with pytest.raises(NotImplementedError) as err: self.browser.get_iframe("frame_123") self.fail() - e = cm.exception - assert "zope.testbrowser doesn't support frames." == e.args[0] + assert "zope.testbrowser doesn't support frames." == err.value.args[0] def test_simple_type(self): """