Skip to content

Commit

Permalink
tests: Remove deprecated methods from test suite (#1294)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsfehler authored Jun 11, 2024
1 parent 8d828f7 commit c514c4a
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 54 deletions.
87 changes: 46 additions & 41 deletions tests/form_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions tests/lxml_drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/test_webdriver_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions tests/type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c514c4a

Please sign in to comment.