test: update the tests accordingly

This commit is contained in:
Karim shoair
2026-02-06 02:45:13 +02:00
parent aa7a95fb70
commit 9acc8194c5
3 changed files with 6 additions and 6 deletions
-1
View File
@@ -17,7 +17,6 @@ def configure_selector_mock():
mock_response.html_content = "<html><body>Test content</body></html>" mock_response.html_content = "<html><body>Test content</body></html>"
mock_response.encoding = "utf-8" mock_response.encoding = "utf-8"
mock_response.get_all_text.return_value = "Test content" mock_response.get_all_text.return_value = "Test content"
mock_response.css_first.return_value = mock_response
mock_response.css.return_value = [mock_response] mock_response.css.return_value = [mock_response]
return mock_response return mock_response
+3 -3
View File
@@ -147,7 +147,7 @@ class TestTextMatching:
class TestSimilarElements: class TestSimilarElements:
def test_finding_similar_products(self, page): def test_finding_similar_products(self, page):
"""Test finding similar product elements""" """Test finding similar product elements"""
first_product = page.css_first(".product") first_product = page.css(".product").first
similar_products = first_product.find_similar() similar_products = first_product.find_similar()
assert len(similar_products) == 2 assert len(similar_products) == 2
@@ -255,7 +255,7 @@ class TestElementNavigation:
class TestJSONAndAttributes: class TestJSONAndAttributes:
def test_json_conversion(self, page): def test_json_conversion(self, page):
"""Test converting content to JSON""" """Test converting content to JSON"""
script_content = page.css("#page-data::text")[0] script_content = page.css("#page-data::text")[0].get()
assert issubclass(type(script_content.sort()), str) assert issubclass(type(script_content.sort()), str)
page_data = script_content.json() page_data = script_content.json()
assert page_data["totalProducts"] == 3 assert page_data["totalProducts"] == 3
@@ -282,7 +282,7 @@ class TestJSONAndAttributes:
assert list(key_value[0].keys()) == ["data-id"] assert list(key_value[0].keys()) == ["data-id"]
# JSON attribute conversion # JSON attribute conversion
attr_json = page.css_first("#products").attrib["schema"].json() attr_json = page.css("#products").first.attrib["schema"].json()
assert attr_json == {"jsonable": "data"} assert attr_json == {"jsonable": "data"}
assert isinstance(page.css("#products")[0].attrib.json_string, bytes) assert isinstance(page.css("#products")[0].attrib.json_string, bytes)
+3 -2
View File
@@ -121,11 +121,12 @@ class TestAdvancedSelectors:
# ::text pseudo-element # ::text pseudo-element
texts = page.css("p::text") texts = page.css("p::text")
assert len(texts) == 2 assert len(texts) == 2
assert isinstance(texts[0], TextHandler) assert isinstance(texts[0], Selector)
assert isinstance(texts[0].get(), TextHandler)
# ::attr() pseudo-element # ::attr() pseudo-element
attrs = page.css("div::attr(class)") attrs = page.css("div::attr(class)")
assert "container" in attrs assert "container" in attrs.getall()
def test_complex_attribute_operations(self, complex_html): def test_complex_attribute_operations(self, complex_html):
"""Test complex attribute handling""" """Test complex attribute handling"""