From c514c4a5d7f8eb485f96cde09ae52862d3c69437 Mon Sep 17 00:00:00 2001 From: jsfehler Date: Tue, 11 Jun 2024 07:00:20 -0400 Subject: [PATCH] tests: Remove deprecated methods from test suite (#1294) --- tests/form_elements.py | 87 ++++++++++++++++++---------------- tests/lxml_drivers.py | 4 +- tests/test_webdriver_remote.py | 2 +- tests/type.py | 20 ++++---- 4 files changed, 59 insertions(+), 54 deletions(-) diff --git a/tests/form_elements.py b/tests/form_elements.py index 98a89e146..bbdb08be2 100644 --- a/tests/form_elements.py +++ b/tests/form_elements.py @@ -31,9 +31,10 @@ def wrapper(self, *args, **kwargs): class FormElementsTest: def test_fill(self): - self.browser.fill("query", "LT-CS-01/2018") - value = self.browser.find_by_name("query").value - assert "LT-CS-01/2018" == value + my_input = "LT-CS-01/2018" + elem = self.browser.find_by_name("query") + elem.fill(my_input) + assert my_input == elem.value def test_fill_element(self): self.browser.find_by_name("q").fill("new query") @@ -83,7 +84,7 @@ def test_clicking_submit_button_posts_button_value_if_value_present(self): 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("query").fill("my name") self.browser.find_by_name("send").click() assert "My name is: Master Splinter" in self.browser.html @@ -139,30 +140,34 @@ def test_can_select_a_option_via_element(self): 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" - assert not self.browser.find_by_name("some-check").checked - self.browser.check("some-check") - assert self.browser.find_by_name("some-check").checked + """should provide a way to check a radio checkbox""" + elem = self.browser.find_by_name("some-check") + assert not elem.checked + elem.check() + assert elem.checked def test_check_keeps_checked_if_called_multiple_times(self): - "should keep a checkbox checked if check() is called multiple times" - assert not self.browser.find_by_name("some-check").checked - self.browser.check("some-check") - self.browser.check("some-check") - assert self.browser.find_by_name("some-check").checked + """should keep a checkbox checked if check() is called multiple times""" + elem = self.browser.find_by_name("some-check") + assert not elem.checked + elem.check() + elem.check() + assert elem.checked def test_can_uncheck_a_checkbox(self): - "should provide a way to uncheck a radio checkbox" - assert self.browser.find_by_name("checked-checkbox").checked - self.browser.uncheck("checked-checkbox") - assert not self.browser.find_by_name("checked-checkbox").checked + """should provide a way to uncheck a radio checkbox""" + elem = self.browser.find_by_name("checked-checkbox") + assert elem.checked + elem.uncheck() + assert not elem.checked def test_uncheck_should_keep_unchecked_if_called_multiple_times(self): - "should keep a checkbox unchecked if uncheck() is called multiple times" - assert self.browser.find_by_name("checked-checkbox").checked - self.browser.uncheck("checked-checkbox") - self.browser.uncheck("checked-checkbox") - assert not self.browser.find_by_name("checked-checkbox").checked + """should keep a checkbox unchecked if uncheck() is called multiple times""" + elem = self.browser.find_by_name("checked-checkbox") + assert elem.checked + elem.uncheck() + elem.uncheck() + assert not elem.checked def test_can_fill_text_field_in_form(self): "should provide a away to change field value" @@ -179,7 +184,7 @@ def test_can_fill_password_field_in_form(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.browser.find_by_name("query").fill("my name") 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 @@ -245,31 +250,31 @@ def test_fill_form_missing_values_ignore_missing(self): assert "new query" == value def test_can_clear_text_field_content(self): - self.browser.fill("query", "random query") - value = self.browser.find_by_name("query").value - assert "random query" == value + my_input = "random query" + elem = self.browser.find_by_name("query") + elem.fill(my_input) + assert my_input == elem.value - self.browser.find_by_name("query").clear() - value = self.browser.find_by_name("query").value - assert not value + elem.clear() + assert not elem.value def test_can_clear_password_field_content(self): - self.browser.fill("password", "1nF4m310") - value = self.browser.find_by_name("password").value - assert "1nF4m310" == value + my_input = "1nF4m310" + elem = self.browser.find_by_name("password") + elem.fill(my_input) + assert my_input == elem.value - self.browser.find_by_name("password").clear() - value = self.browser.find_by_name("password").value - assert not value + elem.clear() + assert not elem.value def test_can_clear_tel_field_content(self): - self.browser.fill("telephone", "5553743980") - value = self.browser.find_by_name("telephone").value - assert "5553743980" == value + my_input = "5553743980" + elem = self.browser.find_by_name("telephone") + elem.fill(my_input) + assert my_input == elem.value - self.browser.find_by_name("telephone").clear() - value = self.browser.find_by_name("telephone").value - assert not value + elem.clear() + assert not elem.value @skip_if_django def test_can_clear_textarea_content(self): diff --git a/tests/lxml_drivers.py b/tests/lxml_drivers.py index 8d0feaebc..c89fe7b78 100644 --- a/tests/lxml_drivers.py +++ b/tests/lxml_drivers.py @@ -72,7 +72,7 @@ def test_simple_type(self): because it doesn't interact with JavaScript """ with pytest.raises(NotImplementedError): - self.browser.type("query", "with type method") + self.browser.find_by_name("query").type("with type method") def test_simple_type_on_element(self): """ @@ -88,7 +88,7 @@ def test_slowly_typing(self): because it doesn't interact with JavaScript """ with pytest.raises(NotImplementedError): - self.browser.type("query", "with type method", slowly=True) + self.browser.find_by_name("query").type("with type method", slowly=True) def test_slowly_typing_on_element(self): """ diff --git a/tests/test_webdriver_remote.py b/tests/test_webdriver_remote.py index 239bf77de..4987349aa 100644 --- a/tests/test_webdriver_remote.py +++ b/tests/test_webdriver_remote.py @@ -133,7 +133,7 @@ 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.browser.find_by_name("query").fill("my name") 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 diff --git a/tests/type.py b/tests/type.py index 899640c8c..686618607 100644 --- a/tests/type.py +++ b/tests/type.py @@ -6,33 +6,33 @@ class SlowlyTypeTest: def test_simple_type(self): - "should provide a away to change field value using type method" + """should provide a away to change field value using type method""" self.browser.visit(EXAMPLE_APP) - self.browser.type("query", " with type method") - value = self.browser.find_by_name("query").value - assert "default value with type method" == value + elem = self.browser.find_by_name("query") + elem.type(" with type method") + assert "default value with type method" == elem.value - self.browser.type("description", "type into textarea") + self.browser.find_by_name("description").type("type into textarea") value = self.browser.find_by_name("description").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 - assert "default value with type method" == value + elem = self.browser.find_by_name("query") + elem.type(" with type method") + assert "default value with type method" == elem.value self.browser.find_by_name("description").type("type into textarea") value = self.browser.find_by_name("description").value assert "type into textarea" == value def test_slowly_typing(self): - "should be able to slowly type some text in a field" + """should be able to slowly type some text in a field""" for name in ["type-input", "type-textarea"]: self.browser.visit(EXAMPLE_APP + "type") num = 0 num_max = 6 - for key in self.browser.type(name, "typing", slowly=True): + for key in self.browser.find_by_name(name).type("typing", slowly=True): assert self.browser.is_text_present("#%d" % num) num += 1 assert num == num_max