|
15 | 15 | ) |
16 | 16 | from scrapy import Spider, Request, FormRequest |
17 | 17 |
|
18 | | -from scrapy_playwright.handler import DEFAULT_CONTEXT_NAME |
| 18 | +from scrapy_playwright.handler import DEFAULT_CONTEXT_NAME, _SCRAPY_ASYNC_API |
19 | 19 | from scrapy_playwright.page import PageMethod |
20 | 20 |
|
21 | 21 | from tests import allow_windows, make_handler, assert_correct_response |
@@ -51,12 +51,22 @@ async def test_basic_response(self): |
51 | 51 | req = Request(server.urljoin("/index.html"), meta=meta) |
52 | 52 | resp = await handler._download_request(req, Spider("foo")) |
53 | 53 |
|
| 54 | + if _SCRAPY_ASYNC_API: |
| 55 | + req2 = Request(server.urljoin("/gallery.html"), meta=meta) |
| 56 | + resp2 = await handler.download_request(req2) |
| 57 | + |
54 | 58 | assert_correct_response(resp, req) |
55 | 59 | assert resp.css("a::text").getall() == ["Lorem Ipsum", "Infinite Scroll"] |
56 | 60 | assert isinstance(resp.meta["playwright_page"], PlaywrightPage) |
57 | 61 | assert resp.meta["playwright_page"].url == resp.url |
58 | 62 | await resp.meta["playwright_page"].close() |
59 | 63 |
|
| 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 | + |
60 | 70 | @allow_windows |
61 | 71 | async def test_post_request(self): |
62 | 72 | async with make_handler({"PLAYWRIGHT_BROWSER_TYPE": self.browser_type}) as handler: |
|
0 commit comments