playwright-ruby-client 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,24 +30,28 @@ module Playwright
30
30
  @contexts << context
31
31
  context.browser = self
32
32
  context.options = params
33
+ return context unless block
33
34
 
34
- if block
35
- begin
36
- block.call(context)
37
- ensure
38
- context.close
39
- end
40
- else
41
- context
35
+ begin
36
+ block.call(context)
37
+ ensure
38
+ context.close
42
39
  end
43
40
  end
44
41
 
45
- def new_page(**options)
42
+ def new_page(**options, &block)
46
43
  context = new_context(**options)
47
44
  page = context.new_page
48
45
  page.owned_context = context
49
46
  context.owner_page = page
50
- page
47
+
48
+ return page unless block
49
+
50
+ begin
51
+ block.call(page)
52
+ ensure
53
+ page.close
54
+ end
51
55
  end
52
56
 
53
57
  def close
@@ -113,10 +113,17 @@ module Playwright
113
113
  end
114
114
 
115
115
  # @returns [Playwright::Page]
116
- def new_page
116
+ def new_page(&block)
117
117
  raise 'Please use browser.new_context' if @owner_page
118
118
  resp = @channel.send_message_to_server('newPage')
119
- ChannelOwners::Page.from(resp)
119
+ page = ChannelOwners::Page.from(resp)
120
+ return page unless block
121
+
122
+ begin
123
+ block.call(page)
124
+ ensure
125
+ page.close
126
+ end
120
127
  end
121
128
 
122
129
  def cookies(urls: nil)
@@ -11,15 +11,12 @@ module Playwright
11
11
  def launch(options, &block)
12
12
  resp = @channel.send_message_to_server('launch', options.compact)
13
13
  browser = ChannelOwners::Browser.from(resp)
14
+ return browser unless block
14
15
 
15
- if block
16
- begin
17
- block.call(browser)
18
- ensure
19
- browser.close
20
- end
21
- else
22
- browser
16
+ begin
17
+ block.call(browser)
18
+ ensure
19
+ browser.close
23
20
  end
24
21
  end
25
22
 
@@ -15,17 +15,17 @@ module Playwright
15
15
  end
16
16
 
17
17
  # Stop tracing.
18
- def stop
18
+ def stop(path: nil)
19
19
  @channel.send_message_to_server('tracingStop')
20
- end
21
20
 
22
- def export(path)
23
- resp = @channel.send_message_to_server('tracingExport')
24
- artifact = ChannelOwners::Artifact.from(resp)
25
- # if self._context._browser:
26
- # artifact._is_remote = self._context._browser._is_remote
27
- artifact.save_as(path)
28
- artifact.delete
21
+ if path
22
+ resp = @channel.send_message_to_server('tracingExport')
23
+ artifact = ChannelOwners::Artifact.from(resp)
24
+ # if self._context._browser:
25
+ # artifact._is_remote = self._context._browser._is_remote
26
+ artifact.save_as(path)
27
+ artifact.delete
28
+ end
29
29
  end
30
30
  end
31
31
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Playwright
4
- VERSION = '0.6.3'
4
+ VERSION = '0.6.4'
5
5
  COMPATIBLE_PLAYWRIGHT_VERSION = '1.12.0'
6
6
  end
@@ -1,12 +1,13 @@
1
1
  module Playwright
2
- # Playwright has **experimental** support for Android automation. You can access android namespace via:
2
+ # Playwright has **experimental** support for Android automation. See [here](./mobile.md) for more information. You can
3
+ # access android namespace via:
3
4
  #
4
5
  # An example of the Android automation script would be:
5
6
  #
6
7
  # Note that since you don't need Playwright to install web browsers when testing Android, you can omit browser download
7
8
  # via setting the following environment variable when installing Playwright:
8
9
  #
9
- # ```sh js
10
+ # ```bash js
10
11
  # PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm i -D playwright
11
12
  # ```
12
13
  class Android < PlaywrightApi
@@ -125,8 +125,9 @@ module Playwright
125
125
  storageState: nil,
126
126
  timezoneId: nil,
127
127
  userAgent: nil,
128
- viewport: nil)
129
- wrap_impl(@impl.new_page(acceptDownloads: unwrap_impl(acceptDownloads), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), reducedMotion: unwrap_impl(reducedMotion), screen: unwrap_impl(screen), storageState: unwrap_impl(storageState), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport)))
128
+ viewport: nil,
129
+ &block)
130
+ wrap_impl(@impl.new_page(acceptDownloads: unwrap_impl(acceptDownloads), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), reducedMotion: unwrap_impl(reducedMotion), screen: unwrap_impl(screen), storageState: unwrap_impl(storageState), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
130
131
  end
131
132
 
132
133
  # > NOTE: Tracing is only supported on Chromium-based browsers.
@@ -208,8 +208,8 @@ module Playwright
208
208
  end
209
209
 
210
210
  # Creates a new page in the browser context.
211
- def new_page
212
- wrap_impl(@impl.new_page)
211
+ def new_page(&block)
212
+ wrap_impl(@impl.new_page(&wrap_block_call(block)))
213
213
  end
214
214
 
215
215
  # Returns all open pages in the context.
@@ -83,9 +83,9 @@ module Playwright
83
83
  proxy: nil,
84
84
  slowMo: nil,
85
85
  timeout: nil,
86
- traceDir: nil,
86
+ tracesDir: nil,
87
87
  &block)
88
- wrap_impl(@impl.launch(args: unwrap_impl(args), channel: unwrap_impl(channel), chromiumSandbox: unwrap_impl(chromiumSandbox), devtools: unwrap_impl(devtools), downloadsPath: unwrap_impl(downloadsPath), env: unwrap_impl(env), executablePath: unwrap_impl(executablePath), firefoxUserPrefs: unwrap_impl(firefoxUserPrefs), handleSIGHUP: unwrap_impl(handleSIGHUP), handleSIGINT: unwrap_impl(handleSIGINT), handleSIGTERM: unwrap_impl(handleSIGTERM), headless: unwrap_impl(headless), ignoreDefaultArgs: unwrap_impl(ignoreDefaultArgs), proxy: unwrap_impl(proxy), slowMo: unwrap_impl(slowMo), timeout: unwrap_impl(timeout), traceDir: unwrap_impl(traceDir), &wrap_block_call(block)))
88
+ wrap_impl(@impl.launch(args: unwrap_impl(args), channel: unwrap_impl(channel), chromiumSandbox: unwrap_impl(chromiumSandbox), devtools: unwrap_impl(devtools), downloadsPath: unwrap_impl(downloadsPath), env: unwrap_impl(env), executablePath: unwrap_impl(executablePath), firefoxUserPrefs: unwrap_impl(firefoxUserPrefs), handleSIGHUP: unwrap_impl(handleSIGHUP), handleSIGINT: unwrap_impl(handleSIGINT), handleSIGTERM: unwrap_impl(handleSIGTERM), headless: unwrap_impl(headless), ignoreDefaultArgs: unwrap_impl(ignoreDefaultArgs), proxy: unwrap_impl(proxy), slowMo: unwrap_impl(slowMo), timeout: unwrap_impl(timeout), tracesDir: unwrap_impl(tracesDir), &wrap_block_call(block)))
89
89
  end
90
90
 
91
91
  # Returns the persistent browser context instance.
@@ -131,7 +131,7 @@ module Playwright
131
131
  slowMo: nil,
132
132
  timeout: nil,
133
133
  timezoneId: nil,
134
- traceDir: nil,
134
+ tracesDir: nil,
135
135
  userAgent: nil,
136
136
  viewport: nil)
137
137
  raise NotImplementedError.new('launch_persistent_context is not implemented yet.')
@@ -5,35 +5,29 @@ module Playwright
5
5
  # Start with specifying the folder traces will be stored in:
6
6
  #
7
7
  # ```python sync
8
- # browser = chromium.launch(traceDir='traces')
8
+ # browser = chromium.launch()
9
9
  # context = browser.new_context()
10
- # context.tracing.start(name="trace", screenshots=True, snapshots=True)
10
+ # context.tracing.start(screenshots=True, snapshots=True)
11
11
  # page.goto("https://playwright.dev")
12
- # context.tracing.stop()
13
- # context.tracing.export("trace.zip")
12
+ # context.tracing.stop(path = "trace.zip")
14
13
  # ```
15
14
  class Tracing < PlaywrightApi
16
15
 
17
- # Export trace into the file with the given name. Should be called after the tracing has stopped.
18
- def export(path)
19
- wrap_impl(@impl.export(unwrap_impl(path)))
20
- end
21
-
22
16
  # Start tracing.
23
17
  #
24
18
  # ```python sync
25
19
  # context.tracing.start(name="trace", screenshots=True, snapshots=True)
26
20
  # page.goto("https://playwright.dev")
27
21
  # context.tracing.stop()
28
- # context.tracing.export("trace.zip")
22
+ # context.tracing.stop(path = "trace.zip")
29
23
  # ```
30
24
  def start(name: nil, screenshots: nil, snapshots: nil)
31
25
  wrap_impl(@impl.start(name: unwrap_impl(name), screenshots: unwrap_impl(screenshots), snapshots: unwrap_impl(snapshots)))
32
26
  end
33
27
 
34
28
  # Stop tracing.
35
- def stop
36
- wrap_impl(@impl.stop)
29
+ def stop(path: nil)
30
+ wrap_impl(@impl.stop(path: unwrap_impl(path)))
37
31
  end
38
32
  end
39
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: playwright-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - YusukeIwaki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-07 00:00:00.000000000 Z
11
+ date: 2021-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -230,6 +230,7 @@ files:
230
230
  - documentation/docs/article/guides/download_playwright_driver.md
231
231
  - documentation/docs/article/guides/launch_browser.md
232
232
  - documentation/docs/article/guides/rails_integration.md
233
+ - documentation/docs/article/guides/recording_video.md
233
234
  - documentation/docs/include/api_coverage.md
234
235
  - documentation/docusaurus.config.js
235
236
  - documentation/package.json