Skip to content

Commit 74ec8de

Browse files
committed
Test coroutine download_request
1 parent d130d2b commit 74ec8de

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

tests/tests_asyncio/test_playwright_requests.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
)
1616
from scrapy import Spider, Request, FormRequest
1717

18-
from scrapy_playwright.handler import DEFAULT_CONTEXT_NAME
18+
from scrapy_playwright.handler import DEFAULT_CONTEXT_NAME, _SCRAPY_ASYNC_API
1919
from scrapy_playwright.page import PageMethod
2020

2121
from tests import allow_windows, make_handler, assert_correct_response
@@ -51,12 +51,22 @@ async def test_basic_response(self):
5151
req = Request(server.urljoin("/index.html"), meta=meta)
5252
resp = await handler._download_request(req, Spider("foo"))
5353

54+
if _SCRAPY_ASYNC_API:
55+
req2 = Request(server.urljoin("/gallery.html"), meta=meta)
56+
resp2 = await handler.download_request(req2)
57+
5458
assert_correct_response(resp, req)
5559
assert resp.css("a::text").getall() == ["Lorem Ipsum", "Infinite Scroll"]
5660
assert isinstance(resp.meta["playwright_page"], PlaywrightPage)
5761
assert resp.meta["playwright_page"].url == resp.url
5862
await resp.meta["playwright_page"].close()
5963

64+
if _SCRAPY_ASYNC_API:
65+
assert_correct_response(resp2, req2)
66+
assert isinstance(resp2.meta["playwright_page"], PlaywrightPage)
67+
assert resp2.meta["playwright_page"].url == resp2.url
68+
await resp2.meta["playwright_page"].close()
69+
6070
@allow_windows
6171
async def test_post_request(self):
6272
async with make_handler({"PLAYWRIGHT_BROWSER_TYPE": self.browser_type}) as handler:

0 commit comments

Comments
 (0)