cuprite 0.7.1 → 0.8

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: 61e6eae56b712430083dd1dc25ae7888016899b9504fcb2795525fe2df0d9b63
4
- data.tar.gz: 26f55efb799bff8ffa704fd1955dc01b03c11db3f44806f3a1c8284d84237ae8
3
+ metadata.gz: dcb46f5716c12a1a33acb66d1e7827897f1331447806f52379571226ac4dfe9c
4
+ data.tar.gz: 8ca919e8ebdfef7a4a16613b0c0620084365d3231dbbe5b7d96bc18bf0f1cf9a
5
5
  SHA512:
6
- metadata.gz: a8eb4c7caeeaf86f24ebef9bf37edf6bf3e6ccf474633be8c69a1b4296abfcb5df040ede0c5feccecc930393312408800a928f3671aeb658a7d5beadb08a3c0a
7
- data.tar.gz: 44387ad8fa9b9a87a236d2df3d754155ad4ed280348d65da2479b1a5a08e6be215ebf2ad652c1159188f08f6f231fbeeeddd2ce767d5bc9a53b1c0e7f39fbdf1
6
+ metadata.gz: a3451efdac94c66d55d8afb49ee5497a91c48d7b2b9b0e9728b49f9c44ad4fa7c5d780a81ec7a4650f9a35a2370846b7da5782e9c6867cd0774d3204509e085a
7
+ data.tar.gz: 6e33306c0157a88640d5b546faddef248576208eca188fe4898ff898023717a2439a138dbdfe98670b6cae4b03a5b81cce2b5eaa93d73c2f266f6761bd72603d
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2018 Machinio
3
+ Copyright (c) 2018-2019 Machinio
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -6,7 +6,6 @@ module Capybara::Cuprite
6
6
  class Browser < Ferrum::Browser
7
7
  extend Forwardable
8
8
 
9
- delegate %i[find_or_create_page] => :targets
10
9
  delegate %i[send_keys select set hover trigger before_click switch_to_frame
11
10
  find_modal accept_confirm dismiss_confirm accept_prompt
12
11
  dismiss_prompt reset_modals] => :page
@@ -19,6 +18,22 @@ module Capybara::Cuprite
19
18
  self.url_whitelist = options[:url_whitelist]
20
19
 
21
20
  super
21
+ @page = false
22
+ end
23
+
24
+ def page
25
+ raise Ferrum::NoSuchPageError if @page.nil?
26
+ @page ||= default_context.page
27
+ end
28
+
29
+ def reset
30
+ super
31
+ @page = default_context.page
32
+ end
33
+
34
+ def quit
35
+ super
36
+ @page = false
22
37
  end
23
38
 
24
39
  def url_whitelist=(patterns)
@@ -53,16 +68,46 @@ module Capybara::Cuprite
53
68
  find_all(method, selector, { "objectId" => object_id })
54
69
  end
55
70
 
71
+ def window_handle
72
+ page.target_id
73
+ end
74
+
75
+ def window_handles
76
+ targets.keys
77
+ end
78
+
56
79
  def within_window(locator = nil, &block)
80
+ original = window_handle
81
+
57
82
  if Capybara::VERSION.to_f < 3.0
58
83
  target_id = window_handles.find do |target_id|
59
- page = find_or_create_page(target_id)
84
+ page = targets[target_id].page
60
85
  locator == page.frame_name
61
86
  end
62
87
  locator = target_id if target_id
63
88
  end
64
89
 
65
- targets.within_window(locator, &block)
90
+ if window_handles.include?(locator)
91
+ switch_to_window(locator)
92
+ yield
93
+ else
94
+ raise Ferrum::NoSuchPageError
95
+ end
96
+ ensure
97
+ switch_to_window(original)
98
+ end
99
+
100
+ def switch_to_window(target_id)
101
+ target = targets[target_id]
102
+ raise Ferrum::NoSuchPageError unless target
103
+ @page = target.page
104
+ end
105
+
106
+ def close_window(target_id)
107
+ target = targets[target_id]
108
+ raise Ferrum::NoSuchPageError unless target
109
+ @page = nil if @page == target.page
110
+ target.page.close
66
111
  end
67
112
 
68
113
  def browser_error
@@ -50,7 +50,7 @@ module Capybara::Cuprite
50
50
  end
51
51
 
52
52
  def frame_url
53
- browser.frame_url
53
+ evaluate_script("window.location.href")
54
54
  end
55
55
 
56
56
  def html
@@ -71,7 +71,7 @@ module Capybara::Cuprite
71
71
  end
72
72
 
73
73
  def frame_title
74
- browser.frame_title
74
+ evaluate_script("document.title")
75
75
  end
76
76
 
77
77
  def find_xpath(selector)
@@ -129,7 +129,7 @@ module Capybara::Cuprite
129
129
  end
130
130
 
131
131
  def open_new_window
132
- browser.open_new_window
132
+ browser.create_page
133
133
  end
134
134
 
135
135
  def switch_to_window(handle)
@@ -141,7 +141,7 @@ module Capybara::Cuprite
141
141
  end
142
142
 
143
143
  def no_such_window_error
144
- Ferrum::NoSuchWindowError
144
+ Ferrum::NoSuchPageError
145
145
  end
146
146
 
147
147
  def reset!
@@ -1,13 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "forwardable"
4
+
3
5
  module Capybara::Cuprite
4
6
  module Page
5
7
  MODAL_WAIT = ENV.fetch("CUPRITE_MODAL_WAIT", 0.05).to_f
8
+ TRIGGER_CLICK_WAIT = ENV.fetch("CUPRITE_TRIGGER_CLICK_WAIT", 0.1).to_f
9
+
10
+ extend Forwardable
11
+ delegate %i[at_css at_xpath css xpath
12
+ current_url current_title body
13
+ execution_id evaluate evaluate_on evaluate_async execute] => :active_frame
14
+
6
15
 
7
16
  def initialize(*args)
8
- super
17
+ @frame_stack = []
9
18
  @accept_modal = []
10
19
  @modal_messages = []
20
+ super
11
21
  end
12
22
 
13
23
  def set(node, value)
@@ -21,7 +31,7 @@ module Capybara::Cuprite
21
31
 
22
32
  def trigger(node, event)
23
33
  options = {}
24
- options.merge!(wait: Ferrum::Mouse::CLICK_WAIT) if event.to_s == "click"
34
+ options.merge!(wait: TRIGGER_CLICK_WAIT) if event.to_s == "click" && TRIGGER_CLICK_WAIT > 0
25
35
  evaluate_on(node: node, expression: %(_cuprite.trigger(this, "#{event}")), **options)
26
36
  end
27
37
 
@@ -59,7 +69,7 @@ module Capybara::Cuprite
59
69
 
60
70
  def find_modal(options)
61
71
  start = Ferrum.monotonic_time
62
- timeout = options.fetch(:wait) { session_wait_time }
72
+ timeout = options.fetch(:wait, browser.timeout)
63
73
  expect_text = options[:text]
64
74
  expect_regexp = expect_text.is_a?(Regexp) ? expect_text : Regexp.escape(expect_text.to_s)
65
75
  not_found_msg = "Unable to find modal dialog"
@@ -104,6 +114,10 @@ module Capybara::Cuprite
104
114
  end
105
115
  end
106
116
 
117
+ def title
118
+ active_frame.current_title
119
+ end
120
+
107
121
  private
108
122
 
109
123
  def prepare_page
@@ -144,7 +158,11 @@ module Capybara::Cuprite
144
158
  options.merge!(promptText: response) if response
145
159
  command("Page.handleJavaScriptDialog", **options)
146
160
  else
147
- warn "Modal window has been opened, but you didn't wrap your code into (`accept_prompt` | `dismiss_prompt` | `accept_confirm` | `dismiss_confirm` | `accept_alert`), accepting by default"
161
+ with_text = params["message"] ? "with text `#{params["message"]}` " : ""
162
+ warn "Modal window #{with_text}has been opened, but you didn't wrap "\
163
+ "your code into (`accept_prompt` | `dismiss_prompt` | "\
164
+ "`accept_confirm` | `dismiss_confirm` | `accept_alert`), "\
165
+ "accepting by default"
148
166
  options = { accept: true }
149
167
  response = params["defaultPrompt"]
150
168
  options.merge!(promptText: response) if response
@@ -162,5 +180,13 @@ module Capybara::Cuprite
162
180
  raise
163
181
  end
164
182
  end
183
+
184
+ def active_frame
185
+ if @frame_stack.empty?
186
+ main_frame
187
+ else
188
+ @frames[@frame_stack.last]
189
+ end
190
+ end
165
191
  end
166
192
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Capybara
4
4
  module Cuprite
5
- VERSION = "0.7.1"
5
+ VERSION = "0.8"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cuprite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: '0.8'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Vorotilin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-20 00:00:00.000000000 Z
11
+ date: 2019-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -34,16 +34,16 @@ dependencies:
34
34
  name: ferrum
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ">="
37
+ - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 0.2.1
39
+ version: 0.6.0
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - ">="
44
+ - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: 0.2.1
46
+ version: 0.6.0
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: image_size
49
49
  requirement: !ruby/object:Gem::Requirement