playwright-ruby-client 1.15.beta1 → 1.16.beta1

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 (76) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -14
  3. data/documentation/docs/api/browser.md +2 -0
  4. data/documentation/docs/api/browser_context.md +5 -1
  5. data/documentation/docs/api/browser_type.md +1 -0
  6. data/documentation/docs/api/element_handle.md +27 -1
  7. data/documentation/docs/api/experimental/android_device.md +1 -0
  8. data/documentation/docs/api/fetch_request.md +10 -0
  9. data/documentation/docs/api/frame.md +28 -0
  10. data/documentation/docs/api/locator.md +47 -0
  11. data/documentation/docs/api/mouse.md +11 -0
  12. data/documentation/docs/api/page.md +35 -2
  13. data/documentation/docs/api/request.md +34 -1
  14. data/documentation/docs/api/response.md +37 -2
  15. data/documentation/docs/api/tracing.md +42 -8
  16. data/documentation/docs/article/getting_started.md +10 -1
  17. data/documentation/docs/article/guides/download_playwright_driver.md +9 -0
  18. data/documentation/docs/article/guides/inspector.md +1 -1
  19. data/documentation/docs/article/guides/playwright_on_alpine_linux.md +56 -3
  20. data/documentation/docs/article/guides/rails_integration.md +4 -2
  21. data/documentation/docs/article/guides/rails_integration_with_null_driver.md +86 -0
  22. data/documentation/docs/article/guides/recording_video.md +1 -1
  23. data/documentation/docs/article/guides/semi_automation.md +1 -1
  24. data/documentation/docs/article/guides/use_storage_state.md +1 -1
  25. data/documentation/docs/include/api_coverage.md +23 -0
  26. data/documentation/docusaurus.config.js +1 -0
  27. data/documentation/package.json +2 -2
  28. data/documentation/src/pages/index.js +0 -1
  29. data/documentation/static/img/playwright-ruby-client.png +0 -0
  30. data/documentation/yarn.lock +1810 -1790
  31. data/lib/playwright/channel.rb +36 -2
  32. data/lib/playwright/channel_owners/artifact.rb +6 -2
  33. data/lib/playwright/channel_owners/browser.rb +4 -0
  34. data/lib/playwright/channel_owners/browser_context.rb +21 -14
  35. data/lib/playwright/channel_owners/element_handle.rb +10 -2
  36. data/lib/playwright/channel_owners/fetch_request.rb +4 -0
  37. data/lib/playwright/channel_owners/frame.rb +11 -1
  38. data/lib/playwright/channel_owners/page.rb +20 -4
  39. data/lib/playwright/channel_owners/request.rb +53 -17
  40. data/lib/playwright/channel_owners/response.rb +48 -5
  41. data/lib/playwright/connection.rb +5 -3
  42. data/lib/playwright/http_headers.rb +0 -6
  43. data/lib/playwright/locator_impl.rb +12 -0
  44. data/lib/playwright/mouse_impl.rb +9 -0
  45. data/lib/playwright/raw_headers.rb +61 -0
  46. data/lib/playwright/{route_handler_entry.rb → route_handler.rb} +30 -2
  47. data/lib/playwright/tracing_impl.rb +18 -7
  48. data/lib/playwright/transport.rb +2 -0
  49. data/lib/playwright/utils.rb +8 -0
  50. data/lib/playwright/version.rb +2 -2
  51. data/lib/playwright/web_socket_transport.rb +2 -0
  52. data/lib/playwright.rb +2 -1
  53. data/lib/playwright_api/android.rb +6 -6
  54. data/lib/playwright_api/android_device.rb +10 -9
  55. data/lib/playwright_api/browser.rb +10 -8
  56. data/lib/playwright_api/browser_context.rb +12 -8
  57. data/lib/playwright_api/browser_type.rb +8 -7
  58. data/lib/playwright_api/cdp_session.rb +7 -7
  59. data/lib/playwright_api/console_message.rb +6 -6
  60. data/lib/playwright_api/dialog.rb +6 -6
  61. data/lib/playwright_api/element_handle.rb +31 -8
  62. data/lib/playwright_api/fetch_request.rb +77 -0
  63. data/lib/playwright_api/frame.rb +31 -6
  64. data/lib/playwright_api/js_handle.rb +6 -6
  65. data/lib/playwright_api/locator.rb +39 -0
  66. data/lib/playwright_api/mouse.rb +8 -0
  67. data/lib/playwright_api/page.rb +40 -10
  68. data/lib/playwright_api/playwright.rb +6 -6
  69. data/lib/playwright_api/request.rb +30 -4
  70. data/lib/playwright_api/response.rb +31 -8
  71. data/lib/playwright_api/route.rb +6 -6
  72. data/lib/playwright_api/selectors.rb +6 -6
  73. data/lib/playwright_api/tracing.rb +33 -4
  74. data/lib/playwright_api/web_socket.rb +6 -6
  75. data/lib/playwright_api/worker.rb +8 -8
  76. metadata +10 -4
@@ -1,5 +1,5 @@
1
1
  ---
2
- sidebar_position: 8
2
+ sidebar_position: 40
3
3
  ---
4
4
 
5
5
  # Playwright on Alpine Linux
@@ -33,7 +33,23 @@ Playwright server is running on a container of [official Docker image](https://h
33
33
 
34
34
  ![overview](https://user-images.githubusercontent.com/11763113/124934448-ad4d0700-e03f-11eb-942e-b9f3282bb703.png)
35
35
 
36
- ## Playwright client
36
+ ### Playwright Server v.s. Browser Server
37
+
38
+ Playwright provides two kind of methods to share the browser environments for clients.
39
+
40
+ When you want to share only one browser environment, Browser server is suitable. This feature is officially supported in Playwright.
41
+
42
+ * Server can be launched with [BrowserType#launchServer](https://playwright.dev/docs/api/class-browsertype#browser-type-launch-server) instead of `BrowserType#launch`.
43
+ * Client can connect to server with [BrowserType#connect](https://playwright.dev/docs/api/class-browsertype#browser-type-connect). In playwright-ruby-client, `BrowserType#connect` and not implemented yet and use `Playwright#connect_to_browser_server()` instead.
44
+
45
+ Another method is sharing all browser environment. This method is very simple, but not an official feature, and can be changed in future.
46
+
47
+ * Server can be launched with `playwright run-server` (CLI command).
48
+ * Client can connect to server with `Playwright.connect_to_playwright_server` instead of `Playwright.create`
49
+
50
+ ## Playwright server/client
51
+
52
+ ### Client code
37
53
 
38
54
  Many example uses `Playwright#create`, which internally uses Pipe (stdin/stdout) transport for Playwright-protocol messaging. Instead, **just use `Playwright#connect_to_playwright_server(endpoint)`** for WebSocket transport.
39
55
 
@@ -51,7 +67,7 @@ end
51
67
 
52
68
  `wss://example.com:8888/ws` is an example of endpoint URL of the Playwright server. In local development environment, it is typically `"ws://127.0.0.1:#{port}/ws"`.
53
69
 
54
- ## Playwright server
70
+ ### Server code
55
71
 
56
72
  With the [official Docker image](https://hub.docker.com/_/microsoft-playwright) or in the local development environment with Node.js, just execute `npx playwright install && npx playwright run-server $PORT`. (`$PORT` is a port number of the server)
57
73
 
@@ -67,6 +83,43 @@ ENV PORT 8888
67
83
  CMD ["./node_modules/.bin/playwright", "run-server", "$PORT"]
68
84
  ```
69
85
 
86
+ ## Browser server/client
87
+
88
+ ### Client code
89
+
90
+ Use `Playwright#connect_to_playwright_server` and pass the WebSocket URL for browser server.
91
+ Note that this method requires a block with `Browser`, not `Playwright` or `BrowserType`.
92
+
93
+ ```ruby
94
+ Playwright.connect_to_playwright_server(ws_url) do |browser|
95
+ page = browser.new_page
96
+ page.goto(...)
97
+ ...
98
+ end
99
+ ```
100
+
101
+ ### Server code
102
+
103
+ For instant use, `npx playwright launch-server chromium` generates a WebSocket endpoint URL with a random path.
104
+
105
+ More customization can be done by implementing JavaScript server like below:
106
+
107
+ ```js
108
+ const playwright = require('playwright')
109
+
110
+ option = {
111
+ channel: 'chrome-canary',
112
+ headless: false,
113
+ port: 8080,
114
+ wsPath: 'ws',
115
+ }
116
+ playwright.chromium.launchServer(option).then((server) => { console.log(server.wsEndpoint()) })
117
+ ```
118
+
119
+ `port` and `wsPath` would be useful for generating static WebSocket endpoint URL.
120
+ Other available options for `BrowserType#launchServer` can be found here:
121
+ https://playwright.dev/docs/api/class-browsertype#browser-type-launch-server
122
+
70
123
  ## Debugging for connection
71
124
 
72
125
  The client and server are really quiet. This chapter shows how to check if the communication on the WebSocket works well or not.
@@ -2,9 +2,11 @@
2
2
  sidebar_position: 3
3
3
  ---
4
4
 
5
- # Integration into Ruby on Rails application
5
+ # Capybara driver for Ruby on Rails application
6
6
 
7
- `playwright-ruby-client` is a client library just for browser automation. `capybara-playwright-driver` provides the [Capybara](https://github.com/teamcapybara/capybara) driver based on playwright-ruby-client and makes it easy to integrate into Ruby on Rails applications.
7
+ `playwright-ruby-client` is a client library just for browser automation, while Rails uses [Capybara](https://github.com/teamcapybara/capybara) for system testing.
8
+
9
+ `capybara-playwright-driver` provides a [Capybara](https://github.com/teamcapybara/capybara) driver based on playwright-ruby-client and makes it easy to integrate into Ruby on Rails applications.
8
10
 
9
11
  ## Installation
10
12
 
@@ -0,0 +1,86 @@
1
+ ---
2
+ sidebar_position: 4
3
+ ---
4
+
5
+ # Use Capybara without DSL
6
+
7
+ :::note
8
+
9
+ This article shows advanced-level configuration of Capybara and RSpec for more accurate automation/testing.
10
+ If you want to just integrate Playwright into Rails application, refer the basic [configuration guide](./rails_integration)
11
+ :::
12
+
13
+ ## Background
14
+
15
+ [capybara-playwright-driver](./rails_integration) is easy to configure and migrate from Selenium or another Capybara driver, however it is a little **inaccurate** and would sometimes cause 'flaky test' problem originated from the internal implementation of Capybara DSL.
16
+
17
+ Also **we cannot use most of useful Playwright features in Capybara driver**, such as auto-waiting, various kind of selectors, and some users would want to use Playwright features as it is without Capybara DSL.
18
+
19
+ This article shows how to use playwright-ruby-client without Capybara DSL in Rails and RSpec.
20
+
21
+ ## Configure Capybara driver just for launching Rails server
22
+
23
+ Capybara prepares the test server only when the configured driver returns true on `needs_server?` method. So we have to implement minimum driver like this:
24
+
25
+ ```ruby {5-7} title=spec/support/capybara_null_driver.rb
26
+ RSpec.configure do |config|
27
+ require 'capybara'
28
+
29
+ class CapybaraNullDriver < Capybara::Driver::Base
30
+ def needs_server?
31
+ true
32
+ end
33
+ end
34
+
35
+ Capybara.register_driver(:null) { CapybaraNullDriver.new }
36
+
37
+ ...
38
+ end
39
+ ```
40
+
41
+ ## Launch browser on each test
42
+
43
+ Now Capybara DSL is unavailable with CapybaraNullDriver, we have to manually launch browsers using playwright-ruby-client.
44
+
45
+ ```rb
46
+ RSpec.configure do |config|
47
+ require 'capybara'
48
+
49
+ ...
50
+
51
+ require 'playwright'
52
+
53
+ config.around(driver: :null) do |example|
54
+ Capybara.current_driver = :null
55
+
56
+ # Rails server is launched here, at the first time of accessing Capybara.current_session.server
57
+ base_url = Capybara.current_session.server.base_url
58
+
59
+ Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright|
60
+ # pass any option for Playwright#launch and Browser#new_page as you prefer.
61
+ playwright.chromium.launch(headless: false) do |browser|
62
+ @playwright_page = browser.new_page(baseURL: base_url)
63
+ example.run
64
+ end
65
+ end
66
+ end
67
+ end
68
+ ```
69
+
70
+ With the configuration above, we can describe system-test codes with native Playwright methods like below:
71
+
72
+ ```rb
73
+ require 'rails_helper'
74
+
75
+ describe 'example', driver: :null do
76
+ let!(:user) { FactoryBot.create(:user) }
77
+ let(:page) { @playwright_page }
78
+
79
+ it 'can browse' do
80
+ page.goto("/tests/#{user.id}")
81
+ page.wait_for_selector('input').type('hoge')
82
+ page.keyboard.press('Enter')
83
+ expect(page.text_content('#content')).to include('hoge')
84
+ end
85
+ end
86
+ ```
@@ -1,5 +1,5 @@
1
1
  ---
2
- sidebar_position: 4
2
+ sidebar_position: 10
3
3
  ---
4
4
 
5
5
  # Recording video
@@ -1,5 +1,5 @@
1
1
  ---
2
- sidebar_position: 5
2
+ sidebar_position: 20
3
3
  ---
4
4
 
5
5
  # Semi-automation
@@ -1,5 +1,5 @@
1
1
  ---
2
- sidebar_position: 6
2
+ sidebar_position: 21
3
3
  ---
4
4
 
5
5
  # Reuse Cookie and LocalStorage
@@ -2,9 +2,12 @@
2
2
 
3
3
  ## Request
4
4
 
5
+ * all_headers
5
6
  * failure
6
7
  * frame
7
8
  * headers
9
+ * headers_array
10
+ * header_value
8
11
  * navigation_request?
9
12
  * method
10
13
  * post_data
@@ -14,15 +17,20 @@
14
17
  * redirected_to
15
18
  * resource_type
16
19
  * response
20
+ * sizes
17
21
  * timing
18
22
  * url
19
23
 
20
24
  ## Response
21
25
 
26
+ * all_headers
22
27
  * body
23
28
  * finished
24
29
  * frame
25
30
  * headers
31
+ * headers_array
32
+ * header_value
33
+ * header_values
26
34
  * json
27
35
  * ok
28
36
  * request
@@ -40,6 +48,13 @@
40
48
  * fulfill
41
49
  * request
42
50
 
51
+ ## FetchRequest
52
+
53
+ * ~~dispose~~
54
+ * ~~fetch~~
55
+ * ~~get~~
56
+ * ~~post~~
57
+
43
58
  ## WebSocket
44
59
 
45
60
  * closed?
@@ -62,6 +77,7 @@
62
77
  * down
63
78
  * move
64
79
  * up
80
+ * wheel
65
81
 
66
82
  ## Touchscreen
67
83
 
@@ -108,6 +124,7 @@
108
124
  * scroll_into_view_if_needed
109
125
  * select_option
110
126
  * select_text
127
+ * set_checked
111
128
  * set_input_files
112
129
  * tap_point
113
130
  * text_content
@@ -166,6 +183,7 @@
166
183
  * query_selector
167
184
  * query_selector_all
168
185
  * select_option
186
+ * set_checked
169
187
  * set_content
170
188
  * set_input_files
171
189
  * tap_point
@@ -269,6 +287,7 @@
269
287
  * route
270
288
  * screenshot
271
289
  * select_option
290
+ * set_checked
272
291
  * set_content
273
292
  * set_default_navigation_timeout
274
293
  * set_default_timeout
@@ -375,7 +394,9 @@
375
394
  ## Tracing
376
395
 
377
396
  * start
397
+ * start_chunk
378
398
  * stop
399
+ * stop_chunk
379
400
 
380
401
  ## Locator
381
402
 
@@ -414,11 +435,13 @@
414
435
  * scroll_into_view_if_needed
415
436
  * select_option
416
437
  * select_text
438
+ * set_checked
417
439
  * set_input_files
418
440
  * tap_point
419
441
  * text_content
420
442
  * type
421
443
  * uncheck
444
+ * wait_for
422
445
 
423
446
  ## Android
424
447
 
@@ -10,6 +10,7 @@ module.exports = {
10
10
  organizationName: 'YusukeIwaki', // Usually your GitHub org/user name.
11
11
  projectName: 'playwright-ruby-client', // Usually your repo name.
12
12
  themeConfig: {
13
+ image: 'img/playwright-ruby-client.png',
13
14
  navbar: {
14
15
  title: 'playwright-ruby-client',
15
16
  logo: {
@@ -14,8 +14,8 @@
14
14
  "write-heading-ids": "docusaurus write-heading-ids"
15
15
  },
16
16
  "dependencies": {
17
- "@docusaurus/core": "2.0.0-beta.0",
18
- "@docusaurus/preset-classic": "2.0.0-beta.0",
17
+ "@docusaurus/core": "^2.0.0-beta.6",
18
+ "@docusaurus/preset-classic": "^2.0.0-beta.6",
19
19
  "@mdx-js/react": "^1.6.21",
20
20
  "@svgr/webpack": "^5.5.0",
21
21
  "clsx": "^1.1.1",
@@ -39,7 +39,6 @@ export default function Home() {
39
39
  const { siteConfig } = useDocusaurusContext();
40
40
  return (
41
41
  <Layout
42
- title={siteConfig.title}
43
42
  description="Cross-browser end-to-end testing for modern web apps">
44
43
  <HomepageHeader />
45
44
  <main>