capybara-playwright-driver 0.3.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56e2d2acc8b4d6a6d29738d3975365d0862d6c160ce638e51c7a0e769ac0036f
4
- data.tar.gz: 4e03613985cac14593ab704fadafb314f10fb217c72d0efc3c2d2e3016b0e81e
3
+ metadata.gz: f12da8f24faaf7dca07c39e57c8ea56d79395a89c2240d99ff48fdc065e10dc1
4
+ data.tar.gz: 07c2560cc17f103aecd41ddd7267e9eb0abd310546f32756a852cc61e3e3f92d
5
5
  SHA512:
6
- metadata.gz: a34891f5ac1177ac7c8a7a0502fca4b6c8148291263de22f8d26b32af116fed576f1b718218ce347bd47be1717b59b87f5de5a1ceac3544a69fe79face267dda
7
- data.tar.gz: 1512b23ee56efdc085f303815f44ef5fd7844ec027f3fe83eb8e59de3a4095059462d5f4584f8889692e2e3e9218c8e48e2724be7c713e7afea8ef33c8714b14
6
+ metadata.gz: 0d1de191eff8c0a8a3da8366c38e367eaf215a836c5148cc1ed001c9af28b13f9d9126685a43fb0c871829f9b97e5ec55d0d1cbc77d44da5fb4e42b907941e2f
7
+ data.tar.gz: d7be26ec2e30b783a24324c923ac5ca9164a88077c7010a39e95757b3a0ef68bd156f849354085e8344f76a7f9a38843bc972ad516bd8c1416964aa2a486f538
data/README.md CHANGED
@@ -26,17 +26,18 @@ Capybara.save_path = 'tmp/capybara'
26
26
  # run
27
27
  Capybara.app_host = 'https://github.com'
28
28
  visit '/'
29
- fill_in('q', with: 'Capybara')
29
+ first('div.search-input-container').click
30
+ fill_in('query-builder-test', with: 'Capybara')
30
31
 
31
32
  ## [REMARK] We can use Playwright-native selector and action, instead of Capybara DSL.
32
- # find('a[data-item-type="global_search"]').click
33
+ # first('[aria-label="Capybara, Search all of GitHub"]').click
33
34
  page.driver.with_playwright_page do |page|
34
- page.click('a[data-item-type="global_search"]')
35
+ page.get_by_label('Capybara, Search all of GitHub').click
35
36
  end
36
37
 
37
- all('.repo-list-item').each do |li|
38
+ all('[data-testid="results-list"] h3').each do |li|
38
39
  #puts "#{li.all('a').first.text} by Capybara"
39
- puts "#{li.with_playwright_element_handle { |handle| handle.query_selector('a').text_content }} by Playwright"
40
+ puts "#{li.with_playwright_element_handle { |handle| handle.text_content }} by Playwright"
40
41
  end
41
42
  ```
42
43
 
@@ -14,23 +14,31 @@ module Capybara
14
14
 
15
15
  class NoSuchWindowError < StandardError ; end
16
16
 
17
- def initialize(driver:, playwright_browser:, page_options:, record_video: false)
17
+ def initialize(driver:, playwright_browser:, page_options:, record_video: false, callback_on_save_trace: nil, default_timeout: nil, default_navigation_timeout: nil)
18
18
  @driver = driver
19
19
  @playwright_browser = playwright_browser
20
20
  @page_options = page_options
21
21
  if record_video
22
22
  @page_options[:record_video_dir] ||= tmpdir
23
23
  end
24
+ @callback_on_save_trace = callback_on_save_trace
25
+ @default_timeout = default_timeout
26
+ @default_navigation_timeout = default_navigation_timeout
24
27
  @playwright_page = create_page(create_browser_context)
25
28
  end
26
29
 
27
30
  private def create_browser_context
28
31
  @playwright_browser.new_context(**@page_options).tap do |browser_context|
32
+ browser_context.default_timeout = @default_timeout if @default_timeout
33
+ browser_context.default_navigation_timeout = @default_navigation_timeout if @default_navigation_timeout
29
34
  browser_context.on('page', ->(page) {
30
35
  unless @playwright_page
31
36
  @playwright_page = page
32
37
  end
33
38
  })
39
+ if @callback_on_save_trace
40
+ browser_context.tracing.start(screenshots: true, snapshots: true)
41
+ end
34
42
  end
35
43
  end
36
44
 
@@ -45,6 +53,14 @@ module Capybara
45
53
  end
46
54
 
47
55
  def clear_browser_contexts
56
+ if @callback_on_save_trace
57
+ @playwright_browser.contexts.each do |browser_context|
58
+ filename = SecureRandom.hex(8)
59
+ zip_path = File.join(tmpdir, "#{filename}.zip")
60
+ browser_context.tracing.stop(path: zip_path)
61
+ @callback_on_save_trace.call(zip_path)
62
+ end
63
+ end
48
64
  @playwright_browser.contexts.each(&:close)
49
65
  end
50
66
 
@@ -21,7 +21,8 @@ module Capybara
21
21
  ignoreDefaultArgs: nil,
22
22
  proxy: nil,
23
23
  slowMo: nil,
24
- timeout: nil,
24
+ # timeout: nil,
25
+ tracesDir: nil,
25
26
  }.keys
26
27
 
27
28
  def value
@@ -9,6 +9,15 @@ module Capybara
9
9
  def initialize(app, **options)
10
10
  @browser_runner = BrowserRunner.new(options)
11
11
  @page_options = PageOptions.new(options)
12
+ if options[:timeout].is_a?(Numeric) # just for compatibility with capybara-selenium-driver
13
+ @default_navigation_timeout = options[:timeout] * 1000
14
+ end
15
+ if options[:default_timeout].is_a?(Numeric)
16
+ @default_timeout = options[:default_timeout] * 1000
17
+ end
18
+ if options[:default_navigation_timeout].is_a?(Numeric)
19
+ @default_navigation_timeout = options[:default_navigation_timeout] * 1000
20
+ end
12
21
  end
13
22
 
14
23
  def wait?; true; end
@@ -20,6 +29,9 @@ module Capybara
20
29
  playwright_browser: playwright_browser,
21
30
  page_options: @page_options.value,
22
31
  record_video: callback_on_save_screenrecord?,
32
+ callback_on_save_trace: @callback_on_save_trace,
33
+ default_timeout: @default_timeout,
34
+ default_navigation_timeout: @default_navigation_timeout,
23
35
  )
24
36
  end
25
37
 
@@ -35,11 +35,46 @@ module Capybara
35
35
  @callback_on_save_screenrecord&.call(video_path)
36
36
  end
37
37
 
38
+ # Register trace save process.
39
+ # The callback is called just after trace is saved.
40
+ #
41
+ # The trace.zip path (String) is called back into the given block
42
+ def on_save_trace(&block)
43
+ @callback_on_save_trace = block
44
+ end
45
+
38
46
  def with_playwright_page(&block)
39
47
  raise ArgumentError.new('block must be given') unless block
40
48
 
41
49
  @browser&.with_playwright_page(&block)
42
50
  end
51
+
52
+ # Start Playwright tracing (doc: https://playwright.dev/docs/api/class-tracing#tracing-start)
53
+ def start_tracing(name: nil, screenshots: false, snapshots: false, sources: false, title: nil)
54
+ # Ensure playwright page is initialized.
55
+ browser
56
+
57
+ with_playwright_page do |playwright_page|
58
+ playwright_page.context.tracing.start(name: name, screenshots: screenshots, snapshots: snapshots, sources: sources, title: title)
59
+ end
60
+ end
61
+
62
+ # Stop Playwright tracing (doc: https://playwright.dev/docs/api/class-tracing#tracing-stop)
63
+ def stop_tracing(path: nil)
64
+ with_playwright_page do |playwright_page|
65
+ playwright_page.context.tracing.stop(path: path)
66
+ end
67
+ end
68
+
69
+ # Trace execution of the given block. The tracing is automatically stopped when the block is finished.
70
+ def trace(name: nil, screenshots: false, snapshots: false, sources: false, title: nil, path: nil, &block)
71
+ raise ArgumentError.new('block must be given') unless block
72
+
73
+ start_tracing(name: name, screenshots: screenshots, snapshots: snapshots, sources: sources, title: title)
74
+ block.call
75
+ ensure
76
+ stop_tracing(path: path)
77
+ end
43
78
  end
44
79
  end
45
80
  end
@@ -239,7 +239,13 @@ module Capybara
239
239
 
240
240
  class TextInput < Settable
241
241
  def set(value, **options)
242
- @element.fill(value.to_s, timeout: @timeout)
242
+ text = value.to_s
243
+ if text.end_with?("\n")
244
+ @element.fill(text[0...-1], timeout: @timeout)
245
+ @element.press('Enter', timeout: @timeout)
246
+ else
247
+ @element.fill(text, timeout: @timeout)
248
+ end
243
249
  rescue ::Playwright::TimeoutError
244
250
  raise if @element.editable?
245
251
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Capybara
4
4
  module Playwright
5
- VERSION = '0.3.2'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-playwright-driver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - YusukeIwaki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-28 00:00:00.000000000 Z
11
+ date: 2023-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara