chemlab 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chemlab/attributable.rb +2 -0
- data/lib/chemlab/component.rb +55 -8
- data/lib/chemlab/configuration.rb +8 -6
- data/lib/chemlab/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c09a8e6e3c407893b4df27fadd71ffff047f3ea3df27b34a1ad7f1c0b8119de9
|
4
|
+
data.tar.gz: c79979483ff6d8dc48716c3d6be27e683117bba9c346b925e6b7013e0d616238
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96fc1f354f2b5568362c01688d265be896ca238f24819f075f1d16aa6b4f43c7b9cacf72662cd110d46dda4ee2bf6448b6a870927f9f1c9d2847fafa53949130
|
7
|
+
data.tar.gz: f1aa2b1677db2f65e134db511b4741fc4a8977c1d0098c1f5eb1f246a6107ab45576df778b93117b93b617e94234a481a4ebd58d5c4fa7417b505e4002cbbecd
|
data/lib/chemlab/attributable.rb
CHANGED
data/lib/chemlab/component.rb
CHANGED
@@ -46,18 +46,18 @@ module Chemlab
|
|
46
46
|
public_elements << { type: watir_method, name: name, args: args }
|
47
47
|
|
48
48
|
# @return [Watir::Element] the raw Watir element
|
49
|
-
define_method("#{name}_element") do
|
50
|
-
find_element(watir_method, name, args.first, &block)
|
49
|
+
define_method("#{name}_element") do |**find_args|
|
50
|
+
find_element(watir_method, name, args.first, **find_args, &block)
|
51
51
|
end
|
52
52
|
|
53
53
|
# @return [Boolean] true if the element is present
|
54
|
-
define_method("#{name}?") do
|
55
|
-
public_send("#{name}_element").present?
|
54
|
+
define_method("#{name}?") do |wait: nil, wait_until: nil|
|
55
|
+
public_send("#{name}_element", wait: wait, wait_until: wait_until).present?
|
56
56
|
end
|
57
57
|
|
58
58
|
# === GETTER / CLICKER === #
|
59
|
-
define_method(name) do
|
60
|
-
element = public_send("#{name}_element")
|
59
|
+
define_method(name) do |wait: nil, wait_until: :exists?|
|
60
|
+
element = public_send("#{name}_element", wait: wait, wait_until: wait_until)
|
61
61
|
if Element::CLICKABLES.include? watir_method
|
62
62
|
element.wait_until(&:present?).click
|
63
63
|
elsif Element::INPUTS.include? watir_method
|
@@ -132,12 +132,59 @@ module Chemlab
|
|
132
132
|
# @api private
|
133
133
|
# @example
|
134
134
|
# #find_element(:text_field, :username) #=>
|
135
|
-
def find_element(watir_method, name, locator = nil, &block)
|
135
|
+
def find_element(watir_method, name, locator = nil, **args, &block)
|
136
136
|
locator = { css: %([data-qa-selector="#{name}"]) } if locator.nil?
|
137
137
|
|
138
|
+
# extract extraneous arguments from the locator and insert them into args
|
139
|
+
chemlab_options, locator = extract_chemlab_options(locator)
|
140
|
+
args.merge!(chemlab_options)
|
141
|
+
|
142
|
+
old_timeout = Chemlab.configuration.default_timeout
|
143
|
+
args[:wait] ||= old_timeout
|
144
|
+
|
138
145
|
return instance_exec(&block) if block_given?
|
139
146
|
|
140
|
-
Chemlab.configuration.browser.session.engine.public_send(watir_method, locator)
|
147
|
+
element = Chemlab.configuration.browser.session.engine.public_send(watir_method, locator)
|
148
|
+
|
149
|
+
return element if args[:wait_until].nil?
|
150
|
+
|
151
|
+
begin
|
152
|
+
# change timeout temporarily to the wait specified
|
153
|
+
change_timeout(args[:wait])
|
154
|
+
|
155
|
+
# perform wait(s) on the element
|
156
|
+
element.wait_until do |conditions|
|
157
|
+
break conditions.public_send(args[:wait_until]) unless args[:wait_until].respond_to?(:each)
|
158
|
+
|
159
|
+
args[:wait_until].each { |condition| conditions.public_send(condition) }
|
160
|
+
end
|
161
|
+
|
162
|
+
element
|
163
|
+
ensure
|
164
|
+
# reset timeout
|
165
|
+
change_timeout(old_timeout)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
# Extract Chemlab specific options from an array
|
170
|
+
# @param [Array<Hash>] args given arguments
|
171
|
+
# @return [Array<Array<Hash>>] first array returned are the chemlab options, second is the resulting array
|
172
|
+
# @example
|
173
|
+
# arr = { id: 'test', foo: 'bar', wait: 10 }
|
174
|
+
# a, b = extract_chemlab_options!(**arr)
|
175
|
+
# a #=> { wait: 10 }
|
176
|
+
# b #=> { id: 'test', foo: 'bar' }
|
177
|
+
def extract_chemlab_options(**args)
|
178
|
+
[args.keys.each_with_object({}) do |arg, chemlab_opts|
|
179
|
+
chemlab_opts[arg] = args.delete(arg) if %i[wait wait_until].include?(arg)
|
180
|
+
end, args]
|
181
|
+
end
|
182
|
+
|
183
|
+
# Set / Reset default Chemlab timeout
|
184
|
+
# @param [Integer] timeout the timeout to set (defaults to +Chemlab.configuration.default_timeout)
|
185
|
+
# @return [Integer] the new timeout
|
186
|
+
def change_timeout(timeout = Chemlab.configuration.default_timeout)
|
187
|
+
Chemlab.configuration.default_timeout = timeout
|
141
188
|
end
|
142
189
|
|
143
190
|
protected
|
@@ -4,6 +4,8 @@ module Chemlab
|
|
4
4
|
# Chemlab Configuration
|
5
5
|
class Configuration
|
6
6
|
include Runtime::Logger
|
7
|
+
include Attributable
|
8
|
+
extend Forwardable
|
7
9
|
|
8
10
|
# Chemlab Terminal Banner
|
9
11
|
BANNER = <<~'BANNER'
|
@@ -59,13 +61,13 @@ module Chemlab
|
|
59
61
|
CONF
|
60
62
|
end
|
61
63
|
|
62
|
-
|
63
|
-
|
64
|
-
attr_accessor name
|
65
|
-
end
|
64
|
+
attribute :base_url
|
65
|
+
attribute :hide_banner
|
66
66
|
|
67
|
-
|
68
|
-
|
67
|
+
# Delegate `default_timeout` to Watir.default_timeout
|
68
|
+
# Chemlab.configuration.default_timeout #=> Watir.default_timeout
|
69
|
+
# Chemlab.configuration.default_timeout = Watir.default_timeout = 30
|
70
|
+
def_delegators Watir, :default_timeout, :default_timeout=
|
69
71
|
|
70
72
|
attr_reader :browser, :libraries
|
71
73
|
|
data/lib/chemlab/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chemlab
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitLab Quality
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: climate_control
|