playwright-ruby-client 0.0.8 → 1.58.1.alpha1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/AGENTS.md +4 -0
  3. data/CLAUDE/api_generation.md +28 -0
  4. data/CLAUDE/ci_expectations.md +23 -0
  5. data/CLAUDE/gem_release_flow.md +39 -0
  6. data/CLAUDE/past_upgrade_pr_patterns.md +42 -0
  7. data/CLAUDE/playwright_upgrade_workflow.md +35 -0
  8. data/CLAUDE/rspec_debugging.md +30 -0
  9. data/CLAUDE/unimplemented_examples.md +18 -0
  10. data/CLAUDE.md +32 -0
  11. data/CONTRIBUTING.md +5 -0
  12. data/README.md +60 -16
  13. data/documentation/README.md +33 -0
  14. data/documentation/babel.config.js +3 -0
  15. data/documentation/docs/api/api_request.md +7 -0
  16. data/documentation/docs/api/api_request_context.md +298 -0
  17. data/documentation/docs/api/api_response.md +114 -0
  18. data/documentation/docs/api/browser.md +237 -0
  19. data/documentation/docs/api/browser_context.md +503 -0
  20. data/documentation/docs/api/browser_type.md +184 -0
  21. data/documentation/docs/api/cdp_session.md +44 -0
  22. data/documentation/docs/api/clock.md +154 -0
  23. data/documentation/docs/api/console_message.md +85 -0
  24. data/documentation/docs/api/dialog.md +84 -0
  25. data/documentation/docs/api/download.md +111 -0
  26. data/documentation/docs/api/element_handle.md +694 -0
  27. data/documentation/docs/api/experimental/_category_.yml +3 -0
  28. data/documentation/docs/api/experimental/android.md +42 -0
  29. data/documentation/docs/api/experimental/android_device.md +109 -0
  30. data/documentation/docs/api/experimental/android_input.md +43 -0
  31. data/documentation/docs/api/experimental/android_socket.md +7 -0
  32. data/documentation/docs/api/experimental/android_web_view.md +7 -0
  33. data/documentation/docs/api/file_chooser.md +53 -0
  34. data/documentation/docs/api/frame.md +1218 -0
  35. data/documentation/docs/api/frame_locator.md +348 -0
  36. data/documentation/docs/api/js_handle.md +121 -0
  37. data/documentation/docs/api/keyboard.md +170 -0
  38. data/documentation/docs/api/locator.md +1495 -0
  39. data/documentation/docs/api/locator_assertions.md +827 -0
  40. data/documentation/docs/api/mouse.md +86 -0
  41. data/documentation/docs/api/page.md +1946 -0
  42. data/documentation/docs/api/page_assertions.md +65 -0
  43. data/documentation/docs/api/playwright.md +66 -0
  44. data/documentation/docs/api/request.md +255 -0
  45. data/documentation/docs/api/response.md +176 -0
  46. data/documentation/docs/api/route.md +205 -0
  47. data/documentation/docs/api/selectors.md +63 -0
  48. data/documentation/docs/api/touchscreen.md +22 -0
  49. data/documentation/docs/api/tracing.md +129 -0
  50. data/documentation/docs/api/web_socket.md +51 -0
  51. data/documentation/docs/api/worker.md +83 -0
  52. data/documentation/docs/article/api_coverage.mdx +11 -0
  53. data/documentation/docs/article/getting_started.md +161 -0
  54. data/documentation/docs/article/guides/_category_.yml +3 -0
  55. data/documentation/docs/article/guides/download_playwright_driver.md +55 -0
  56. data/documentation/docs/article/guides/inspector.md +31 -0
  57. data/documentation/docs/article/guides/launch_browser.md +121 -0
  58. data/documentation/docs/article/guides/playwright_on_alpine_linux.md +112 -0
  59. data/documentation/docs/article/guides/rails_integration.md +278 -0
  60. data/documentation/docs/article/guides/rails_integration_with_null_driver.md +145 -0
  61. data/documentation/docs/article/guides/recording_video.md +79 -0
  62. data/documentation/docs/article/guides/rspec_integration.md +59 -0
  63. data/documentation/docs/article/guides/semi_automation.md +71 -0
  64. data/documentation/docs/article/guides/use_storage_state.md +78 -0
  65. data/documentation/docs/include/api_coverage.md +671 -0
  66. data/documentation/docusaurus.config.js +114 -0
  67. data/documentation/package.json +39 -0
  68. data/documentation/sidebars.js +15 -0
  69. data/documentation/src/components/HomepageFeatures.js +61 -0
  70. data/documentation/src/components/HomepageFeatures.module.css +13 -0
  71. data/documentation/src/css/custom.css +44 -0
  72. data/documentation/src/pages/index.js +49 -0
  73. data/documentation/src/pages/index.module.css +41 -0
  74. data/documentation/src/pages/markdown-page.md +7 -0
  75. data/documentation/static/.nojekyll +0 -0
  76. data/documentation/static/img/playwright-logo.svg +9 -0
  77. data/documentation/static/img/playwright-ruby-client.png +0 -0
  78. data/documentation/static/img/undraw_dropdown_menu.svg +1 -0
  79. data/documentation/static/img/undraw_web_development.svg +1 -0
  80. data/documentation/static/img/undraw_windows.svg +1 -0
  81. data/documentation/yarn.lock +9005 -0
  82. data/lib/playwright/{input_types/android_input.rb → android_input_impl.rb} +5 -1
  83. data/lib/playwright/api_implementation.rb +18 -0
  84. data/lib/playwright/api_response_impl.rb +77 -0
  85. data/lib/playwright/channel.rb +62 -1
  86. data/lib/playwright/channel_owner.rb +70 -7
  87. data/lib/playwright/channel_owners/android.rb +16 -3
  88. data/lib/playwright/channel_owners/android_device.rb +22 -66
  89. data/lib/playwright/channel_owners/api_request_context.rb +247 -0
  90. data/lib/playwright/channel_owners/artifact.rb +40 -0
  91. data/lib/playwright/channel_owners/binding_call.rb +70 -0
  92. data/lib/playwright/channel_owners/browser.rb +114 -22
  93. data/lib/playwright/channel_owners/browser_context.rb +589 -15
  94. data/lib/playwright/channel_owners/browser_type.rb +90 -1
  95. data/lib/playwright/channel_owners/cdp_session.rb +19 -0
  96. data/lib/playwright/channel_owners/dialog.rb +32 -0
  97. data/lib/playwright/channel_owners/element_handle.rb +107 -43
  98. data/lib/playwright/channel_owners/fetch_request.rb +8 -0
  99. data/lib/playwright/channel_owners/frame.rb +334 -104
  100. data/lib/playwright/channel_owners/js_handle.rb +9 -13
  101. data/lib/playwright/channel_owners/local_utils.rb +82 -0
  102. data/lib/playwright/channel_owners/page.rb +778 -95
  103. data/lib/playwright/channel_owners/playwright.rb +25 -30
  104. data/lib/playwright/channel_owners/request.rb +120 -18
  105. data/lib/playwright/channel_owners/response.rb +113 -0
  106. data/lib/playwright/channel_owners/route.rb +181 -0
  107. data/lib/playwright/channel_owners/stream.rb +30 -0
  108. data/lib/playwright/channel_owners/tracing.rb +117 -0
  109. data/lib/playwright/channel_owners/web_socket.rb +96 -0
  110. data/lib/playwright/channel_owners/worker.rb +46 -0
  111. data/lib/playwright/channel_owners/writable_stream.rb +14 -0
  112. data/lib/playwright/clock_impl.rb +67 -0
  113. data/lib/playwright/connection.rb +111 -63
  114. data/lib/playwright/console_message_impl.rb +29 -0
  115. data/lib/playwright/download_impl.rb +32 -0
  116. data/lib/playwright/errors.rb +42 -5
  117. data/lib/playwright/event_emitter.rb +17 -3
  118. data/lib/playwright/event_emitter_proxy.rb +49 -0
  119. data/lib/playwright/events.rb +10 -5
  120. data/lib/playwright/file_chooser_impl.rb +24 -0
  121. data/lib/playwright/frame_locator_impl.rb +66 -0
  122. data/lib/playwright/har_router.rb +89 -0
  123. data/lib/playwright/http_headers.rb +14 -0
  124. data/lib/playwright/input_files.rb +102 -15
  125. data/lib/playwright/javascript/expression.rb +7 -11
  126. data/lib/playwright/javascript/regex.rb +23 -0
  127. data/lib/playwright/javascript/source_url.rb +16 -0
  128. data/lib/playwright/javascript/value_parser.rb +108 -19
  129. data/lib/playwright/javascript/value_serializer.rb +47 -8
  130. data/lib/playwright/javascript/visitor_info.rb +26 -0
  131. data/lib/playwright/javascript.rb +2 -10
  132. data/lib/playwright/{input_types/keyboard.rb → keyboard_impl.rb} +6 -2
  133. data/lib/playwright/locator_assertions_impl.rb +571 -0
  134. data/lib/playwright/locator_impl.rb +544 -0
  135. data/lib/playwright/locator_utils.rb +136 -0
  136. data/lib/playwright/mouse_impl.rb +57 -0
  137. data/lib/playwright/page_assertions_impl.rb +154 -0
  138. data/lib/playwright/playwright_api.rb +102 -30
  139. data/lib/playwright/raw_headers.rb +61 -0
  140. data/lib/playwright/route_handler.rb +78 -0
  141. data/lib/playwright/select_option_values.rb +34 -13
  142. data/lib/playwright/selectors_impl.rb +45 -0
  143. data/lib/playwright/test.rb +102 -0
  144. data/lib/playwright/timeout_settings.rb +9 -4
  145. data/lib/playwright/touchscreen_impl.rb +14 -0
  146. data/lib/playwright/transport.rb +61 -10
  147. data/lib/playwright/url_matcher.rb +24 -2
  148. data/lib/playwright/utils.rb +48 -13
  149. data/lib/playwright/version.rb +2 -1
  150. data/lib/playwright/video.rb +54 -0
  151. data/lib/playwright/waiter.rb +166 -0
  152. data/lib/playwright/web_socket_client.rb +167 -0
  153. data/lib/playwright/web_socket_transport.rb +116 -0
  154. data/lib/playwright.rb +188 -11
  155. data/lib/playwright_api/android.rb +46 -11
  156. data/lib/playwright_api/android_device.rb +182 -31
  157. data/lib/playwright_api/android_input.rb +22 -13
  158. data/lib/playwright_api/android_socket.rb +18 -0
  159. data/lib/playwright_api/android_web_view.rb +24 -0
  160. data/lib/playwright_api/api_request.rb +26 -0
  161. data/lib/playwright_api/api_request_context.rb +311 -0
  162. data/lib/playwright_api/api_response.rb +92 -0
  163. data/lib/playwright_api/browser.rb +116 -103
  164. data/lib/playwright_api/browser_context.rb +290 -389
  165. data/lib/playwright_api/browser_type.rb +96 -118
  166. data/lib/playwright_api/cdp_session.rb +36 -39
  167. data/lib/playwright_api/clock.rb +121 -0
  168. data/lib/playwright_api/console_message.rb +35 -19
  169. data/lib/playwright_api/dialog.rb +53 -50
  170. data/lib/playwright_api/download.rb +49 -43
  171. data/lib/playwright_api/element_handle.rb +354 -402
  172. data/lib/playwright_api/file_chooser.rb +15 -18
  173. data/lib/playwright_api/frame.rb +703 -603
  174. data/lib/playwright_api/frame_locator.rb +285 -0
  175. data/lib/playwright_api/js_handle.rb +50 -76
  176. data/lib/playwright_api/keyboard.rb +67 -146
  177. data/lib/playwright_api/locator.rb +1304 -0
  178. data/lib/playwright_api/locator_assertions.rb +704 -0
  179. data/lib/playwright_api/mouse.rb +23 -29
  180. data/lib/playwright_api/page.rb +1196 -1176
  181. data/lib/playwright_api/page_assertions.rb +60 -0
  182. data/lib/playwright_api/playwright.rb +54 -122
  183. data/lib/playwright_api/request.rb +112 -74
  184. data/lib/playwright_api/response.rb +92 -20
  185. data/lib/playwright_api/route.rb +152 -62
  186. data/lib/playwright_api/selectors.rb +47 -61
  187. data/lib/playwright_api/touchscreen.rb +8 -2
  188. data/lib/playwright_api/tracing.rb +128 -0
  189. data/lib/playwright_api/web_socket.rb +43 -5
  190. data/lib/playwright_api/worker.rb +74 -34
  191. data/playwright.gemspec +14 -9
  192. data/sig/playwright.rbs +658 -0
  193. metadata +216 -50
  194. data/docs/api_coverage.md +0 -354
  195. data/lib/playwright/channel_owners/chromium_browser.rb +0 -8
  196. data/lib/playwright/channel_owners/chromium_browser_context.rb +0 -8
  197. data/lib/playwright/channel_owners/console_message.rb +0 -21
  198. data/lib/playwright/channel_owners/firefox_browser.rb +0 -8
  199. data/lib/playwright/channel_owners/selectors.rb +0 -4
  200. data/lib/playwright/channel_owners/webkit_browser.rb +0 -8
  201. data/lib/playwright/input_type.rb +0 -19
  202. data/lib/playwright/input_types/mouse.rb +0 -4
  203. data/lib/playwright/input_types/touchscreen.rb +0 -4
  204. data/lib/playwright/javascript/function.rb +0 -67
  205. data/lib/playwright/wait_helper.rb +0 -73
  206. data/lib/playwright_api/accessibility.rb +0 -93
  207. data/lib/playwright_api/binding_call.rb +0 -23
  208. data/lib/playwright_api/chromium_browser_context.rb +0 -57
  209. data/lib/playwright_api/video.rb +0 -24
@@ -0,0 +1,60 @@
1
+ module Playwright
2
+ #
3
+ # The `PageAssertions` class provides assertion methods that can be used to make assertions about the `Page` state in the tests.
4
+ #
5
+ # ```python sync
6
+ # import re
7
+ # from playwright.sync_api import Page, expect
8
+ #
9
+ # def test_navigates_to_login_page(page: Page) -> None:
10
+ # # ..
11
+ # page.get_by_text("Sign in").click()
12
+ # expect(page).to_have_url(re.compile(r".*/login"))
13
+ # ```
14
+ class PageAssertions < PlaywrightApi
15
+
16
+ #
17
+ # The opposite of [`method: PageAssertions.toHaveTitle`].
18
+ def not_to_have_title(titleOrRegExp, timeout: nil)
19
+ wrap_impl(@impl.not_to_have_title(unwrap_impl(titleOrRegExp), timeout: unwrap_impl(timeout)))
20
+ end
21
+
22
+ #
23
+ # The opposite of [`method: PageAssertions.toHaveURL`].
24
+ def not_to_have_url(urlOrRegExp, ignoreCase: nil, timeout: nil)
25
+ wrap_impl(@impl.not_to_have_url(unwrap_impl(urlOrRegExp), ignoreCase: unwrap_impl(ignoreCase), timeout: unwrap_impl(timeout)))
26
+ end
27
+
28
+ #
29
+ # Ensures the page has the given title.
30
+ #
31
+ # **Usage**
32
+ #
33
+ # ```python sync
34
+ # import re
35
+ # from playwright.sync_api import expect
36
+ #
37
+ # # ...
38
+ # expect(page).to_have_title(re.compile(r".*checkout"))
39
+ # ```
40
+ def to_have_title(titleOrRegExp, timeout: nil)
41
+ wrap_impl(@impl.to_have_title(unwrap_impl(titleOrRegExp), timeout: unwrap_impl(timeout)))
42
+ end
43
+
44
+ #
45
+ # Ensures the page is navigated to the given URL.
46
+ #
47
+ # **Usage**
48
+ #
49
+ # ```python sync
50
+ # import re
51
+ # from playwright.sync_api import expect
52
+ #
53
+ # # ...
54
+ # expect(page).to_have_url(re.compile(".*checkout"))
55
+ # ```
56
+ def to_have_url(urlOrRegExp, ignoreCase: nil, timeout: nil)
57
+ wrap_impl(@impl.to_have_url(unwrap_impl(urlOrRegExp), ignoreCase: unwrap_impl(ignoreCase), timeout: unwrap_impl(timeout)))
58
+ end
59
+ end
60
+ end
@@ -1,102 +1,37 @@
1
1
  module Playwright
2
+ #
2
3
  # Playwright module provides a method to launch a browser instance. The following is a typical example of using Playwright
3
4
  # to drive automation:
4
- #
5
5
  #
6
- # ```js
7
- # const { chromium, firefox, webkit } = require('playwright');
8
- #
9
- # (async () => {
10
- # const browser = await chromium.launch(); // Or 'firefox' or 'webkit'.
11
- # const page = await browser.newPage();
12
- # await page.goto('http://example.com');
13
- # // other actions...
14
- # await browser.close();
15
- # })();
16
- # ```
17
- #
18
- # ```python async
19
- # import asyncio
20
- # from playwright.async_api import async_playwright
21
- #
22
- # async def run(playwright):
23
- # chromium = playwright.chromium # or "firefox" or "webkit".
24
- # browser = await chromium.launch()
25
- # page = await browser.new_page()
26
- # await page.goto("http://example.com")
27
- # # other actions...
28
- # await browser.close()
29
- #
30
- # async def main():
31
- # async with async_playwright() as playwright:
32
- # await run(playwright)
33
- # asyncio.run(main())
34
- # ```
35
- #
36
6
  # ```python sync
37
- # from playwright.sync_api import sync_playwright
38
- #
39
- # def run(playwright):
7
+ # from playwright.sync_api import sync_playwright, Playwright
8
+ #
9
+ # def run(playwright: Playwright):
40
10
  # chromium = playwright.chromium # or "firefox" or "webkit".
41
11
  # browser = chromium.launch()
42
12
  # page = browser.new_page()
43
13
  # page.goto("http://example.com")
44
14
  # # other actions...
45
15
  # browser.close()
46
- #
16
+ #
47
17
  # with sync_playwright() as playwright:
48
18
  # run(playwright)
49
19
  # ```
50
20
  class Playwright < PlaywrightApi
51
21
 
52
- # This object can be used to launch or connect to Chromium, returning instances of `ChromiumBrowser`.
22
+ #
23
+ # This object can be used to launch or connect to Chromium, returning instances of `Browser`.
53
24
  def chromium # property
54
25
  wrap_impl(@impl.chromium)
55
26
  end
56
27
 
28
+ #
57
29
  # Returns a dictionary of devices to be used with [`method: Browser.newContext`] or [`method: Browser.newPage`].
58
- #
59
30
  #
60
- # ```js
61
- # const { webkit, devices } = require('playwright');
62
- # const iPhone = devices['iPhone 6'];
63
- #
64
- # (async () => {
65
- # const browser = await webkit.launch();
66
- # const context = await browser.newContext({
67
- # ...iPhone
68
- # });
69
- # const page = await context.newPage();
70
- # await page.goto('http://example.com');
71
- # // other actions...
72
- # await browser.close();
73
- # })();
74
- # ```
75
- #
76
- # ```python async
77
- # import asyncio
78
- # from playwright.async_api import async_playwright
79
- #
80
- # async def run(playwright):
81
- # webkit = playwright.webkit
82
- # iphone = playwright.devices["iPhone 6"]
83
- # browser = await webkit.launch()
84
- # context = await browser.new_context(**iphone)
85
- # page = await context.new_page()
86
- # await page.goto("http://example.com")
87
- # # other actions...
88
- # await browser.close()
89
- #
90
- # async def main():
91
- # async with async_playwright() as playwright:
92
- # await run(playwright)
93
- # asyncio.run(main())
94
- # ```
95
- #
96
31
  # ```python sync
97
- # from playwright.sync_api import sync_playwright
98
- #
99
- # def run(playwright):
32
+ # from playwright.sync_api import sync_playwright, Playwright
33
+ #
34
+ # def run(playwright: Playwright):
100
35
  # webkit = playwright.webkit
101
36
  # iphone = playwright.devices["iPhone 6"]
102
37
  # browser = webkit.launch()
@@ -105,7 +40,7 @@ module Playwright
105
40
  # page.goto("http://example.com")
106
41
  # # other actions...
107
42
  # browser.close()
108
- #
43
+ #
109
44
  # with sync_playwright() as playwright:
110
45
  # run(playwright)
111
46
  # ```
@@ -113,58 +48,51 @@ module Playwright
113
48
  wrap_impl(@impl.devices)
114
49
  end
115
50
 
116
- # Playwright methods might throw errors if they are unable to fulfill a request. For example,
117
- # [`method: Page.waitForSelector`] might fail if the selector doesn't match any nodes during the given timeframe.
118
- #
119
- # For certain types of errors Playwright uses specific error classes. These classes are available via
120
- # [`playwright.errors`](#playwrighterrors).
121
- #
122
- # An example of handling a timeout error:
123
- #
124
51
  #
125
- # ```js
126
- # try {
127
- # await page.waitForSelector('.foo');
128
- # } catch (e) {
129
- # if (e instanceof playwright.errors.TimeoutError) {
130
- # // Do something if this is a timeout.
131
- # }
132
- # }
133
- # ```
134
- #
135
- # ```python async
136
- # try:
137
- # await page.wait_for_selector(".foo")
138
- # except TimeoutError as e:
139
- # # do something if this is a timeout.
140
- # ```
141
- #
142
- # ```python sync
143
- # try:
144
- # page.wait_for_selector(".foo")
145
- # except TimeoutError as e:
146
- # # do something if this is a timeout.
147
- # ```
148
- def errors # property
149
- raise NotImplementedError.new('errors is not implemented yet.')
150
- end
151
-
152
- # This object can be used to launch or connect to Firefox, returning instances of `FirefoxBrowser`.
52
+ # This object can be used to launch or connect to Firefox, returning instances of `Browser`.
153
53
  def firefox # property
154
54
  wrap_impl(@impl.firefox)
155
55
  end
156
56
 
57
+ #
58
+ # Exposes API that can be used for the Web API testing.
59
+ def request # property
60
+ raise NotImplementedError.new('request is not implemented yet.')
61
+ end
62
+
63
+ #
157
64
  # Selectors can be used to install custom selector engines. See
158
- # [Working with selectors](./selectors.md#working-with-selectors) for more information.
65
+ # [extensibility](../extensibility.md) for more information.
159
66
  def selectors # property
160
- raise NotImplementedError.new('selectors is not implemented yet.')
67
+ wrap_impl(@impl.selectors)
161
68
  end
162
69
 
163
- # This object can be used to launch or connect to WebKit, returning instances of `WebKitBrowser`.
70
+ #
71
+ # This object can be used to launch or connect to WebKit, returning instances of `Browser`.
164
72
  def webkit # property
165
73
  wrap_impl(@impl.webkit)
166
74
  end
167
75
 
76
+ #
77
+ # Terminates this instance of Playwright in case it was created bypassing the Python context manager. This is useful in REPL applications.
78
+ #
79
+ # ```py
80
+ # from playwright.sync_api import sync_playwright
81
+ #
82
+ # playwright = sync_playwright().start()
83
+ #
84
+ # browser = playwright.chromium.launch()
85
+ # page = browser.new_page()
86
+ # page.goto("https://playwright.dev/")
87
+ # page.screenshot(path="example.png")
88
+ # browser.close()
89
+ #
90
+ # playwright.stop()
91
+ # ```
92
+ def stop
93
+ raise NotImplementedError.new('stop is not implemented yet.')
94
+ end
95
+
168
96
  # @nodoc
169
97
  def android
170
98
  wrap_impl(@impl.android)
@@ -177,20 +105,24 @@ module Playwright
177
105
 
178
106
  # -- inherited from EventEmitter --
179
107
  # @nodoc
180
- def on(event, callback)
181
- wrap_impl(@impl.on(unwrap_impl(event), unwrap_impl(callback)))
108
+ def once(event, callback)
109
+ event_emitter_proxy.once(event, callback)
182
110
  end
183
111
 
184
112
  # -- inherited from EventEmitter --
185
113
  # @nodoc
186
- def off(event, callback)
187
- wrap_impl(@impl.off(unwrap_impl(event), unwrap_impl(callback)))
114
+ def on(event, callback)
115
+ event_emitter_proxy.on(event, callback)
188
116
  end
189
117
 
190
118
  # -- inherited from EventEmitter --
191
119
  # @nodoc
192
- def once(event, callback)
193
- wrap_impl(@impl.once(unwrap_impl(event), unwrap_impl(callback)))
120
+ def off(event, callback)
121
+ event_emitter_proxy.off(event, callback)
122
+ end
123
+
124
+ private def event_emitter_proxy
125
+ @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
194
126
  end
195
127
  end
196
128
  end
@@ -1,30 +1,33 @@
1
1
  module Playwright
2
+ #
2
3
  # Whenever the page sends a request for a network resource the following sequence of events are emitted by `Page`:
3
4
  # - [`event: Page.request`] emitted when the request is issued by the page.
4
5
  # - [`event: Page.response`] emitted when/if the response status and headers are received for the request.
5
- # - [`event: Page.requestfinished`] emitted when the response body is downloaded and the request is complete.
6
- #
6
+ # - [`event: Page.requestFinished`] emitted when the response body is downloaded and the request is complete.
7
+ #
7
8
  # If request fails at some point, then instead of `'requestfinished'` event (and possibly instead of 'response' event),
8
- # the [`event: Page.requestfailed`] event is emitted.
9
- #
10
- # > NOTE: HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will
11
- # complete with `'requestfinished'` event.
12
- #
13
- # If request gets a 'redirect' response, the request is successfully finished with the 'requestfinished' event, and a new
9
+ # the [`event: Page.requestFailed`] event is emitted.
10
+ #
11
+ # **NOTE**: HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will complete
12
+ # with `'requestfinished'` event.
13
+ #
14
+ # If request gets a 'redirect' response, the request is successfully finished with the `requestfinished` event, and a new
14
15
  # request is issued to a redirected url.
15
16
  class Request < PlaywrightApi
16
17
 
18
+ #
19
+ # An object with all the request HTTP headers associated with this request. The header names are lower-cased.
20
+ def all_headers
21
+ wrap_impl(@impl.all_headers)
22
+ end
23
+
24
+ #
17
25
  # The method returns `null` unless this request has failed, as reported by `requestfailed` event.
18
- #
26
+ #
27
+ # **Usage**
28
+ #
19
29
  # Example of logging of all the failed requests:
20
- #
21
30
  #
22
- # ```js
23
- # page.on('requestfailed', request => {
24
- # console.log(request.url() + ' ' + request.failure().errorText);
25
- # });
26
- # ```
27
- #
28
31
  # ```py
29
32
  # page.on("requestfailed", lambda request: print(request.url + " " + request.failure))
30
33
  # ```
@@ -32,81 +35,101 @@ module Playwright
32
35
  wrap_impl(@impl.failure)
33
36
  end
34
37
 
38
+ #
35
39
  # Returns the `Frame` that initiated this request.
40
+ #
41
+ # **Usage**
42
+ #
43
+ # ```py
44
+ # frame_url = request.frame.url
45
+ # ```
46
+ #
47
+ # **Details**
48
+ #
49
+ # Note that in some cases the frame is not available, and this method will throw.
50
+ # - When request originates in the Service Worker. You can use `request.serviceWorker()` to check that.
51
+ # - When navigation request is issued before the corresponding frame is created. You can use [`method: Request.isNavigationRequest`] to check that.
52
+ #
53
+ # Here is an example that handles all the cases:
36
54
  def frame
37
55
  wrap_impl(@impl.frame)
38
56
  end
39
57
 
40
- # An object with HTTP headers associated with the request. All header names are lower-case.
58
+ #
59
+ # An object with the request HTTP headers. The header names are lower-cased.
60
+ # Note that this method does not return security-related headers, including cookie-related ones.
61
+ # You can use [`method: Request.allHeaders`] for complete list of headers that include `cookie` information.
41
62
  def headers
42
63
  wrap_impl(@impl.headers)
43
64
  end
44
65
 
66
+ #
67
+ # An array with all the request HTTP headers associated with this request. Unlike [`method: Request.allHeaders`], header names are NOT lower-cased.
68
+ # Headers with multiple entries, such as `Set-Cookie`, appear in the array multiple times.
69
+ def headers_array
70
+ wrap_impl(@impl.headers_array)
71
+ end
72
+
73
+ #
74
+ # Returns the value of the header matching the name. The name is case-insensitive.
75
+ def header_value(name)
76
+ wrap_impl(@impl.header_value(unwrap_impl(name)))
77
+ end
78
+
79
+ #
45
80
  # Whether this request is driving frame's navigation.
81
+ #
82
+ # Some navigation requests are issued before the corresponding frame is created, and therefore
83
+ # do not have [`method: Request.frame`] available.
46
84
  def navigation_request?
47
85
  wrap_impl(@impl.navigation_request?)
48
86
  end
49
87
 
88
+ #
50
89
  # Request's method (GET, POST, etc.)
51
90
  def method
52
91
  wrap_impl(@impl.method)
53
92
  end
54
93
 
94
+ #
55
95
  # Request's post body, if any.
56
96
  def post_data
57
97
  wrap_impl(@impl.post_data)
58
98
  end
59
99
 
100
+ #
60
101
  # Request's post body in a binary form, if any.
61
102
  def post_data_buffer
62
103
  wrap_impl(@impl.post_data_buffer)
63
104
  end
64
105
 
106
+ #
65
107
  # Returns parsed request's body for `form-urlencoded` and JSON as a fallback if any.
66
- #
108
+ #
67
109
  # When the response is `application/x-www-form-urlencoded` then a key/value object of the values will be returned.
68
110
  # Otherwise it will be parsed as JSON.
69
111
  def post_data_json
70
112
  wrap_impl(@impl.post_data_json)
71
113
  end
72
114
 
115
+ #
73
116
  # Request that was redirected by the server to this one, if any.
74
- #
117
+ #
75
118
  # When the server responds with a redirect, Playwright creates a new `Request` object. The two requests are connected by
76
119
  # `redirectedFrom()` and `redirectedTo()` methods. When multiple server redirects has happened, it is possible to
77
120
  # construct the whole redirect chain by repeatedly calling `redirectedFrom()`.
78
- #
121
+ #
122
+ # **Usage**
123
+ #
79
124
  # For example, if the website `http://example.com` redirects to `https://example.com`:
80
- #
81
125
  #
82
- # ```js
83
- # const response = await page.goto('http://example.com');
84
- # console.log(response.request().redirectedFrom().url()); // 'http://example.com'
85
- # ```
86
- #
87
- # ```python async
88
- # response = await page.goto("http://example.com")
89
- # print(response.request.redirected_from.url) # "http://example.com"
90
- # ```
91
- #
92
126
  # ```python sync
93
127
  # response = page.goto("http://example.com")
94
128
  # print(response.request.redirected_from.url) # "http://example.com"
95
129
  # ```
96
- #
130
+ #
97
131
  # If the website `https://google.com` has no redirects:
98
- #
99
132
  #
100
- # ```js
101
- # const response = await page.goto('https://google.com');
102
- # console.log(response.request().redirectedFrom()); // null
103
- # ```
104
- #
105
- # ```python async
106
- # response = await page.goto("https://google.com")
107
- # print(response.request.redirected_from) # None
108
- # ```
109
- #
110
133
  # ```python sync
111
134
  # response = page.goto("https://google.com")
112
135
  # print(response.request.redirected_from) # None
@@ -115,15 +138,13 @@ module Playwright
115
138
  wrap_impl(@impl.redirected_from)
116
139
  end
117
140
 
141
+ #
118
142
  # New request issued by the browser if the server responded with redirect.
119
- #
143
+ #
144
+ # **Usage**
145
+ #
120
146
  # This method is the opposite of [`method: Request.redirectedFrom`]:
121
- #
122
147
  #
123
- # ```js
124
- # console.log(request.redirectedFrom().redirectedTo() === request); // true
125
- # ```
126
- #
127
148
  # ```py
128
149
  # assert request.redirected_from.redirected_to == request
129
150
  # ```
@@ -131,6 +152,7 @@ module Playwright
131
152
  wrap_impl(@impl.redirected_to)
132
153
  end
133
154
 
155
+ #
134
156
  # Contains the request's resource type as it was perceived by the rendering engine. ResourceType will be one of the
135
157
  # following: `document`, `stylesheet`, `image`, `media`, `font`, `script`, `texttrack`, `xhr`, `fetch`, `eventsource`,
136
158
  # `websocket`, `manifest`, `other`.
@@ -138,31 +160,37 @@ module Playwright
138
160
  wrap_impl(@impl.resource_type)
139
161
  end
140
162
 
163
+ #
141
164
  # Returns the matching `Response` object, or `null` if the response was not received due to error.
142
165
  def response
143
166
  wrap_impl(@impl.response)
144
167
  end
145
168
 
169
+ #
170
+ # The Service `Worker` that is performing the request.
171
+ #
172
+ # **Details**
173
+ #
174
+ # This method is Chromium only. It's safe to call when using other browsers, but it will always be `null`.
175
+ #
176
+ # Requests originated in a Service Worker do not have a [`method: Request.frame`] available.
177
+ def service_worker
178
+ raise NotImplementedError.new('service_worker is not implemented yet.')
179
+ end
180
+
181
+ #
182
+ # Returns resource size information for given request.
183
+ def sizes
184
+ wrap_impl(@impl.sizes)
185
+ end
186
+
187
+ #
146
188
  # Returns resource timing information for given request. Most of the timing values become available upon the response,
147
189
  # `responseEnd` becomes available when request finishes. Find more information at
148
190
  # [Resource Timing API](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming).
149
- #
150
- #
151
- # ```js
152
- # const [request] = await Promise.all([
153
- # page.waitForEvent('requestfinished'),
154
- # page.goto('http://example.com')
155
- # ]);
156
- # console.log(request.timing());
157
- # ```
158
- #
159
- # ```python async
160
- # async with page.expect_event("requestfinished") as request_info:
161
- # await page.goto("http://example.com")
162
- # request = await request_info.value
163
- # print(request.timing)
164
- # ```
165
- #
191
+ #
192
+ # **Usage**
193
+ #
166
194
  # ```python sync
167
195
  # with page.expect_event("requestfinished") as request_info:
168
196
  # page.goto("http://example.com")
@@ -173,32 +201,42 @@ module Playwright
173
201
  wrap_impl(@impl.timing)
174
202
  end
175
203
 
204
+ #
176
205
  # URL of the request.
177
206
  def url
178
207
  wrap_impl(@impl.url)
179
208
  end
180
209
 
181
210
  # @nodoc
182
- def after_initialize
183
- wrap_impl(@impl.after_initialize)
211
+ def apply_fallback_overrides(overrides)
212
+ wrap_impl(@impl.apply_fallback_overrides(unwrap_impl(overrides)))
213
+ end
214
+
215
+ # @nodoc
216
+ def header_values(name)
217
+ wrap_impl(@impl.header_values(unwrap_impl(name)))
184
218
  end
185
219
 
186
220
  # -- inherited from EventEmitter --
187
221
  # @nodoc
188
- def on(event, callback)
189
- wrap_impl(@impl.on(unwrap_impl(event), unwrap_impl(callback)))
222
+ def once(event, callback)
223
+ event_emitter_proxy.once(event, callback)
190
224
  end
191
225
 
192
226
  # -- inherited from EventEmitter --
193
227
  # @nodoc
194
- def off(event, callback)
195
- wrap_impl(@impl.off(unwrap_impl(event), unwrap_impl(callback)))
228
+ def on(event, callback)
229
+ event_emitter_proxy.on(event, callback)
196
230
  end
197
231
 
198
232
  # -- inherited from EventEmitter --
199
233
  # @nodoc
200
- def once(event, callback)
201
- wrap_impl(@impl.once(unwrap_impl(event), unwrap_impl(callback)))
234
+ def off(event, callback)
235
+ event_emitter_proxy.off(event, callback)
236
+ end
237
+
238
+ private def event_emitter_proxy
239
+ @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
202
240
  end
203
241
  end
204
242
  end