Skip to content

Commit 26fb595

Browse files
committed
Fix test, remove redundant test
1 parent 2d42b3a commit 26fb595

1 file changed

Lines changed: 16 additions & 39 deletions

File tree

tests/tests_asyncio/test_page_methods.py

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import pytest
99
from scrapy import Spider, Request
10-
from scrapy.http.response.html import HtmlResponse
1110

1211
from playwright.async_api import Page
1312
from scrapy_playwright.page import PageMethod
@@ -80,53 +79,31 @@ async def test_mixed(self):
8079

8180
@allow_windows
8281
async def test_page_method_navigation(self):
82+
"""A PageMethod that navigates to a different page must produce a response
83+
whose headers and status match the final page's body, not the initial one.
84+
"""
8385
async with make_handler({"PLAYWRIGHT_BROWSER_TYPE": self.browser_type}) as handler:
8486
req = Request(
8587
url=self.static_server.urljoin("/index.html"),
8688
meta={
8789
"playwright": True,
88-
"playwright_page_methods": [PageMethod("click", "a.lorem_ipsum")],
90+
"playwright_page_methods": [PageMethod("click", "a.json")],
8991
},
9092
)
9193
resp = await handler._download_request(req, Spider("foo"))
9294

93-
assert isinstance(resp, HtmlResponse)
94-
assert resp.request is req
95-
assert resp.url == self.static_server.urljoin("/lorem_ipsum.html")
96-
assert resp.status == 200
97-
assert "playwright" in resp.flags
98-
assert resp.css("title::text").get() == "Lorem Ipsum"
99-
text = resp.css("p::text").get()
100-
assert text == "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
101-
102-
@allow_windows
103-
async def test_page_method_navigation_headers_match_body(self):
104-
"""A PageMethod that navigates to a different page must produce a response
105-
whose headers and status match the final page's body, not the initial one.
106-
"""
107-
async with make_handler({"PLAYWRIGHT_BROWSER_TYPE": self.browser_type}) as handler:
108-
with StaticMockServer() as server:
109-
req = Request(
110-
url=server.urljoin("/index.html"),
111-
meta={
112-
"playwright": True,
113-
"playwright_page_methods": [PageMethod("click", "a.json")],
114-
},
115-
)
116-
resp = await handler._download_request(req, Spider("foo"))
117-
118-
assert resp.request is req
119-
assert resp.url == server.urljoin("/data/quotes1.json")
120-
assert resp.status == 200
121-
assert "playwright" in resp.flags
122-
# headers must match the final (JSON) page, not the initial HTML page
123-
assert resp.headers.get("Content-Type", b"").startswith(b"application/json")
124-
# parse body and verify it's JSON, not HTML
125-
body = json.loads(resp.css("pre::text").get())
126-
assert isinstance(body, dict)
127-
assert isinstance(body.get("quotes"), list)
128-
assert body.get("has_next") is True
129-
assert body.get("page") == 1
95+
assert resp.request is req
96+
assert resp.url == self.static_server.urljoin("/data/quotes1.json")
97+
assert resp.status == 200
98+
assert "playwright" in resp.flags
99+
# headers must match the final (JSON) page, not the initial HTML page
100+
assert resp.headers.get("Content-Type", b"").startswith(b"application/json")
101+
# parse body and verify it's JSON, not HTML
102+
body = json.loads(resp.css("pre::text").get())
103+
assert isinstance(body, dict)
104+
assert isinstance(body.get("quotes"), list)
105+
assert body.get("has_next") is True
106+
assert body.get("page") == 1
130107

131108
@allow_windows
132109
async def test_page_method_infinite_scroll(self):

0 commit comments

Comments
 (0)