testcentricity_web 2.1.10 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +138 -116
- data/lib/devices/devices.yml +86 -44
- data/lib/testcentricity_web/browser_helper.rb +1 -0
- data/lib/testcentricity_web/elements/cell_element.rb +9 -2
- data/lib/testcentricity_web/elements/checkbox.rb +1 -0
- data/lib/testcentricity_web/elements/list.rb +8 -1
- data/lib/testcentricity_web/elements/list_element.rb +12 -2
- data/lib/testcentricity_web/elements/radio.rb +1 -0
- data/lib/testcentricity_web/elements/select_list.rb +2 -0
- data/lib/testcentricity_web/elements/table.rb +198 -59
- data/lib/testcentricity_web/environment.rb +19 -1
- data/lib/testcentricity_web/page_sections_helper.rb +26 -14
- data/lib/testcentricity_web/ui_elements_helper.rb +59 -60
- data/lib/testcentricity_web/version.rb +1 -1
- data/lib/testcentricity_web/webdriver_helper.rb +172 -81
- data/testcentricity_web.gemspec +2 -2
- metadata +5 -5
@@ -29,8 +29,10 @@ module TestCentricity
|
|
29
29
|
attr_accessor :test_environment
|
30
30
|
attr_accessor :browser
|
31
31
|
attr_accessor :browser_size
|
32
|
+
attr_accessor :session_state
|
32
33
|
attr_accessor :os
|
33
34
|
attr_accessor :device
|
35
|
+
attr_accessor :device_name
|
34
36
|
attr_accessor :device_type
|
35
37
|
attr_accessor :device_os
|
36
38
|
attr_accessor :device_orientation
|
@@ -114,6 +116,14 @@ module TestCentricity
|
|
114
116
|
@browser_size
|
115
117
|
end
|
116
118
|
|
119
|
+
def self.session_state=(session_state)
|
120
|
+
@session_state = session_state
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.session_state
|
124
|
+
@session_state
|
125
|
+
end
|
126
|
+
|
117
127
|
# @deprecated Please use {#os=} instead
|
118
128
|
def self.set_os(os)
|
119
129
|
warn "[DEPRECATION] 'TestCentricity::Environ.set_os' is deprecated. Please use 'Environ.os =' instead."
|
@@ -149,13 +159,21 @@ module TestCentricity
|
|
149
159
|
end
|
150
160
|
|
151
161
|
def self.device_type=(type)
|
152
|
-
@device_type = type.downcase
|
162
|
+
@device_type = type.downcase.to_sym
|
153
163
|
end
|
154
164
|
|
155
165
|
def self.device_type
|
156
166
|
@device_type
|
157
167
|
end
|
158
168
|
|
169
|
+
def self.device_name=(name)
|
170
|
+
@device_name = name
|
171
|
+
end
|
172
|
+
|
173
|
+
def self.device_name
|
174
|
+
@device_name
|
175
|
+
end
|
176
|
+
|
159
177
|
def self.device_os=(os)
|
160
178
|
@device_os = os.downcase.to_sym
|
161
179
|
end
|
@@ -11,6 +11,10 @@ module TestCentricity
|
|
11
11
|
attr_accessor :parent
|
12
12
|
attr_accessor :parent_list
|
13
13
|
attr_accessor :list_index
|
14
|
+
attr_accessor :locator_type
|
15
|
+
|
16
|
+
XPATH_SELECTORS = ['//', '[@', '[contains(@']
|
17
|
+
CSS_SELECTORS = ['#', ':nth-child(', ':nth-of-type(', '^=', '$=', '*=']
|
14
18
|
|
15
19
|
def initialize(name, parent, locator, context)
|
16
20
|
@name = name
|
@@ -19,6 +23,18 @@ module TestCentricity
|
|
19
23
|
@context = context
|
20
24
|
@parent_list = nil
|
21
25
|
@list_index = nil
|
26
|
+
|
27
|
+
is_xpath = XPATH_SELECTORS.any? { |selector| @locator.include?(selector) }
|
28
|
+
is_css = CSS_SELECTORS.any? { |selector| @locator.include?(selector) }
|
29
|
+
if is_xpath && !is_css
|
30
|
+
@locator_type = :xpath
|
31
|
+
elsif is_css && !is_xpath
|
32
|
+
@locator_type = :css
|
33
|
+
elsif !is_css && !is_xpath
|
34
|
+
@locator_type = :css
|
35
|
+
else
|
36
|
+
raise "Cannot determine type of locator for PageSection '#{@name}' - locator = #{@locator}"
|
37
|
+
end
|
22
38
|
end
|
23
39
|
|
24
40
|
def get_locator
|
@@ -31,9 +47,10 @@ module TestCentricity
|
|
31
47
|
unless @parent_list.nil?
|
32
48
|
locator = "#{@parent_list.get_locator}|#{locator}"
|
33
49
|
unless @list_index.nil?
|
34
|
-
|
50
|
+
case @locator_type
|
51
|
+
when :xpath
|
35
52
|
locator = "(#{locator})[#{@list_index}]"
|
36
|
-
|
53
|
+
when :css
|
37
54
|
locator = "#{locator}:nth-of-type(#{@list_index})"
|
38
55
|
end
|
39
56
|
end
|
@@ -46,6 +63,10 @@ module TestCentricity
|
|
46
63
|
end
|
47
64
|
end
|
48
65
|
|
66
|
+
def get_locator_type
|
67
|
+
@locator_type
|
68
|
+
end
|
69
|
+
|
49
70
|
def set_list_index(list, index = 1)
|
50
71
|
@parent_list = list unless list.nil?
|
51
72
|
@list_index = index
|
@@ -792,19 +813,10 @@ module TestCentricity
|
|
792
813
|
|
793
814
|
def find_section
|
794
815
|
locator = get_locator
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
case type
|
799
|
-
when :css
|
800
|
-
locator = locator.delete('|')
|
801
|
-
when :xpath
|
802
|
-
locator = locator.delete('|')
|
803
|
-
end
|
804
|
-
obj = page.find(type, locator, :wait => 0.1)
|
805
|
-
[obj, type]
|
816
|
+
locator = locator.delete('|')
|
817
|
+
obj = page.find(@locator_type, locator, :wait => 0.1)
|
818
|
+
[obj, @locator_type]
|
806
819
|
rescue
|
807
|
-
retry if (tries -= 1) > 0
|
808
820
|
[nil, nil]
|
809
821
|
end
|
810
822
|
end
|
@@ -23,7 +23,10 @@ module TestCentricity
|
|
23
23
|
include Test::Unit::Assertions
|
24
24
|
|
25
25
|
attr_reader :parent, :locator, :context, :type, :name
|
26
|
-
attr_accessor :alt_locator
|
26
|
+
attr_accessor :alt_locator, :locator_type
|
27
|
+
|
28
|
+
XPATH_SELECTORS = ['//', '[@', '[contains(@']
|
29
|
+
CSS_SELECTORS = ['#', ':nth-child(', ':nth-of-type(', '^=', '$=', '*=']
|
27
30
|
|
28
31
|
def initialize(name, parent, locator, context)
|
29
32
|
@name = name
|
@@ -32,6 +35,22 @@ module TestCentricity
|
|
32
35
|
@context = context
|
33
36
|
@type = nil
|
34
37
|
@alt_locator = nil
|
38
|
+
set_locator_type
|
39
|
+
end
|
40
|
+
|
41
|
+
def set_locator_type(locator = nil)
|
42
|
+
locator = @locator if locator.nil?
|
43
|
+
is_xpath = XPATH_SELECTORS.any? { |selector| locator.include?(selector) }
|
44
|
+
is_css = CSS_SELECTORS.any? { |selector| locator.include?(selector) }
|
45
|
+
if is_xpath && !is_css
|
46
|
+
@locator_type = :xpath
|
47
|
+
elsif is_css && !is_xpath
|
48
|
+
@locator_type = :css
|
49
|
+
elsif !is_css && !is_xpath
|
50
|
+
@locator_type = :css
|
51
|
+
else
|
52
|
+
raise "Cannot determine type of locator for UIElement '#{@name}' - locator = #{locator}"
|
53
|
+
end
|
35
54
|
end
|
36
55
|
|
37
56
|
def get_object_type
|
@@ -66,8 +85,8 @@ module TestCentricity
|
|
66
85
|
# basket_link.click
|
67
86
|
#
|
68
87
|
def click
|
69
|
-
obj, = find_element
|
70
|
-
object_not_found_exception(obj,
|
88
|
+
obj, type = find_element
|
89
|
+
object_not_found_exception(obj, type)
|
71
90
|
begin
|
72
91
|
obj.click
|
73
92
|
rescue
|
@@ -81,8 +100,8 @@ module TestCentricity
|
|
81
100
|
# file_image.double_click
|
82
101
|
#
|
83
102
|
def double_click
|
84
|
-
obj, = find_element
|
85
|
-
object_not_found_exception(obj,
|
103
|
+
obj, type = find_element
|
104
|
+
object_not_found_exception(obj, type)
|
86
105
|
page.driver.browser.action.double_click(obj.native).perform
|
87
106
|
end
|
88
107
|
|
@@ -92,8 +111,8 @@ module TestCentricity
|
|
92
111
|
# basket_item_image.right_click
|
93
112
|
#
|
94
113
|
def right_click
|
95
|
-
obj, = find_element
|
96
|
-
object_not_found_exception(obj,
|
114
|
+
obj, type = find_element
|
115
|
+
object_not_found_exception(obj, type)
|
97
116
|
page.driver.browser.action.context_click(obj.native).perform
|
98
117
|
end
|
99
118
|
|
@@ -111,8 +130,8 @@ module TestCentricity
|
|
111
130
|
end
|
112
131
|
|
113
132
|
def set(value)
|
114
|
-
obj, = find_element
|
115
|
-
object_not_found_exception(obj,
|
133
|
+
obj, type = find_element
|
134
|
+
object_not_found_exception(obj, type)
|
116
135
|
obj.set(value)
|
117
136
|
end
|
118
137
|
|
@@ -123,8 +142,8 @@ module TestCentricity
|
|
123
142
|
# comment_field.send_keys(:enter)
|
124
143
|
#
|
125
144
|
def send_keys(*keys)
|
126
|
-
obj, = find_element
|
127
|
-
object_not_found_exception(obj,
|
145
|
+
obj, type = find_element
|
146
|
+
object_not_found_exception(obj, type)
|
128
147
|
obj.send_keys(*keys)
|
129
148
|
end
|
130
149
|
|
@@ -164,7 +183,11 @@ module TestCentricity
|
|
164
183
|
invisible = !obj.visible? if exists
|
165
184
|
end
|
166
185
|
# the object is visible if it exists and it is not invisible
|
167
|
-
exists && !invisible
|
186
|
+
if exists && !invisible
|
187
|
+
true
|
188
|
+
else
|
189
|
+
false
|
190
|
+
end
|
168
191
|
end
|
169
192
|
|
170
193
|
# Is UI object hidden (not visible)?
|
@@ -194,8 +217,8 @@ module TestCentricity
|
|
194
217
|
# login_button.disabled?
|
195
218
|
#
|
196
219
|
def disabled?
|
197
|
-
obj, = find_element
|
198
|
-
object_not_found_exception(obj,
|
220
|
+
obj, type = find_element
|
221
|
+
object_not_found_exception(obj, type)
|
199
222
|
obj.disabled?
|
200
223
|
end
|
201
224
|
|
@@ -285,8 +308,8 @@ module TestCentricity
|
|
285
308
|
end
|
286
309
|
|
287
310
|
def get_value(visible = true)
|
288
|
-
obj, = find_element(visible)
|
289
|
-
object_not_found_exception(obj,
|
311
|
+
obj, type = find_element(visible)
|
312
|
+
object_not_found_exception(obj, type)
|
290
313
|
case obj.tag_name.downcase
|
291
314
|
when 'input', 'select', 'textarea'
|
292
315
|
obj.value
|
@@ -312,35 +335,37 @@ module TestCentricity
|
|
312
335
|
# basket_link.hover
|
313
336
|
#
|
314
337
|
def hover
|
315
|
-
obj, = find_element
|
316
|
-
object_not_found_exception(obj,
|
338
|
+
obj, type = find_element
|
339
|
+
object_not_found_exception(obj, type)
|
317
340
|
obj.hover
|
318
341
|
end
|
319
342
|
|
320
343
|
def drag_by(right_offset, down_offset)
|
321
|
-
obj, = find_element
|
322
|
-
object_not_found_exception(obj,
|
344
|
+
obj, type = find_element
|
345
|
+
object_not_found_exception(obj, type)
|
346
|
+
page.driver.browser.action.click_and_hold(obj.native).perform
|
347
|
+
sleep(1)
|
323
348
|
obj.drag_by(right_offset, down_offset)
|
324
349
|
end
|
325
350
|
|
326
351
|
def drag_and_drop(target, right_offset = nil, down_offset = nil)
|
327
|
-
source, = find_element
|
328
|
-
object_not_found_exception(source,
|
352
|
+
source, type = find_element
|
353
|
+
object_not_found_exception(source, type)
|
329
354
|
page.driver.browser.action.click_and_hold(source.native).perform
|
330
|
-
sleep(
|
355
|
+
sleep(1)
|
331
356
|
target_drop, = target.find_element
|
332
357
|
page.driver.browser.action.move_to(target_drop.native, right_offset.to_i, down_offset.to_i).release.perform
|
333
358
|
end
|
334
359
|
|
335
360
|
def get_attribute(attrib)
|
336
|
-
obj, = find_element(false)
|
337
|
-
object_not_found_exception(obj,
|
361
|
+
obj, type = find_element(false)
|
362
|
+
object_not_found_exception(obj, type)
|
338
363
|
obj[attrib]
|
339
364
|
end
|
340
365
|
|
341
366
|
def get_native_attribute(attrib)
|
342
|
-
obj, = find_element(false)
|
343
|
-
object_not_found_exception(obj,
|
367
|
+
obj, type = find_element(false)
|
368
|
+
object_not_found_exception(obj, type)
|
344
369
|
obj.native.attribute(attrib)
|
345
370
|
end
|
346
371
|
|
@@ -354,43 +379,17 @@ module TestCentricity
|
|
354
379
|
def find_object(visible = true)
|
355
380
|
@alt_locator.nil? ? obj_locator = @locator : obj_locator = @alt_locator
|
356
381
|
parent_section = @context == :section && !@parent.get_locator.nil?
|
357
|
-
|
358
|
-
attributes = [:id, :ignore_parent_xpath, :ignore_parent_css, :xpath_css, :css_xpath, :xpath, :css]
|
359
|
-
tries ||= 6
|
360
|
-
else
|
361
|
-
attributes = [:id, :xpath, :css]
|
362
|
-
tries ||= 2
|
363
|
-
end
|
382
|
+
parent_section ? tries ||= 2 : tries ||= 1
|
364
383
|
|
365
|
-
|
366
|
-
if parent_section
|
384
|
+
if parent_section && tries > 1
|
367
385
|
parent_locator = @parent.get_locator
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
obj = page.find(:css, parent_locator, :wait => 0.01).find(:css, obj_locator, :wait => 0.01, :visible => visible)
|
372
|
-
when :xpath
|
373
|
-
parent_locator = parent_locator.delete('|')
|
374
|
-
obj = page.find(:xpath, "#{parent_locator}#{obj_locator}", :wait => 0.01, :visible => visible)
|
375
|
-
when :css_xpath
|
376
|
-
type = :xpath
|
377
|
-
parent_locator = parent_locator.gsub('|', ' ')
|
378
|
-
obj = page.find(:css, parent_locator, :wait => 0.01).find(:xpath, obj_locator, :wait => 0.01, :visible => visible)
|
379
|
-
when :xpath_css
|
380
|
-
type = :css
|
381
|
-
parent_locator = parent_locator.gsub('|', ' ')
|
382
|
-
obj = page.find(:xpath, parent_locator, :wait => 0.01).find(:css, obj_locator, :wait => 0.01, :visible => visible)
|
383
|
-
when :ignore_parent_css
|
384
|
-
type = :css
|
385
|
-
obj = page.find(:css, obj_locator, :wait => 0.01, :visible => visible)
|
386
|
-
when :ignore_parent_xpath
|
387
|
-
type = :xpath
|
388
|
-
obj = page.find(:xpath, obj_locator, :wait => 0.01, :visible => visible)
|
389
|
-
end
|
386
|
+
parent_locator = parent_locator.gsub('|', ' ')
|
387
|
+
parent_locator_type = @parent.get_locator_type
|
388
|
+
obj = page.find(parent_locator_type, parent_locator, :wait => 0.01).find(@locator_type, obj_locator, :wait => 0.01, :visible => visible)
|
390
389
|
else
|
391
|
-
obj = page.find(
|
390
|
+
obj = page.find(@locator_type, obj_locator, :wait => 0.01, :visible => visible)
|
392
391
|
end
|
393
|
-
[obj,
|
392
|
+
[obj, @locator_type]
|
394
393
|
rescue
|
395
394
|
retry if (tries -= 1) > 0
|
396
395
|
[nil, nil]
|
@@ -6,6 +6,8 @@ module TestCentricity
|
|
6
6
|
module WebDriverConnect
|
7
7
|
include Capybara::DSL
|
8
8
|
|
9
|
+
attr_accessor :webdriver_path
|
10
|
+
|
9
11
|
def self.initialize_web_driver(app_host = nil)
|
10
12
|
Capybara.app_host = app_host unless app_host.nil?
|
11
13
|
browser = ENV['WEB_BROWSER']
|
@@ -14,7 +16,7 @@ module TestCentricity
|
|
14
16
|
Environ.platform = :desktop
|
15
17
|
Environ.browser = browser
|
16
18
|
Environ.device = false
|
17
|
-
Environ.
|
19
|
+
Environ.device_name = 'browser'
|
18
20
|
|
19
21
|
case browser.downcase.to_sym
|
20
22
|
when :appium
|
@@ -50,6 +52,7 @@ module TestCentricity
|
|
50
52
|
initialize_browser_size
|
51
53
|
end
|
52
54
|
|
55
|
+
Environ.session_state = :running
|
53
56
|
puts "Using #{Environ.browser} browser via #{context}"
|
54
57
|
end
|
55
58
|
|
@@ -57,7 +60,7 @@ module TestCentricity
|
|
57
60
|
Capybara.app_host = url
|
58
61
|
end
|
59
62
|
|
60
|
-
# Set the WebDriver path for Chrome, IE, or Edge browsers
|
63
|
+
# Set the WebDriver path for Chrome, Firefox, IE, or Edge browsers
|
61
64
|
def self.set_webdriver_path(project_path)
|
62
65
|
path_to_driver = nil
|
63
66
|
# check for existence of /webdrivers or /features/support/drivers folders
|
@@ -76,31 +79,75 @@ module TestCentricity
|
|
76
79
|
elsif OS.windows?
|
77
80
|
path_to_driver = 'windows/chromedriver.exe'
|
78
81
|
end
|
79
|
-
|
82
|
+
@webdriver_path = File.join(project_path, base_path, path_to_driver)
|
83
|
+
Selenium::WebDriver::Chrome.driver_path = @webdriver_path
|
80
84
|
# when :firefox
|
81
85
|
# if OS.osx?
|
82
86
|
# path_to_driver = 'mac/geckodriver'
|
83
87
|
# elsif OS.windows?
|
84
88
|
# path_to_driver = 'windows/geckodriver.exe'
|
85
89
|
# end
|
86
|
-
#
|
90
|
+
# @webdriver_path = File.join(project_path, base_path, path_to_driver)
|
91
|
+
# Selenium::WebDriver::Firefox.driver_path = @webdriver_path
|
87
92
|
when :ie
|
88
93
|
path_to_driver = 'windows/IEDriverServer.exe'
|
89
|
-
|
94
|
+
@webdriver_path = File.join(project_path, base_path, path_to_driver)
|
95
|
+
Selenium::WebDriver::IE.driver_path = @webdriver_path
|
90
96
|
when :edge
|
91
97
|
path_to_driver = 'windows/MicrosoftWebDriver.exe'
|
92
|
-
|
98
|
+
@webdriver_path = File.join(project_path, base_path, path_to_driver)
|
99
|
+
Selenium::WebDriver::Edge.driver_path = @webdriver_path
|
93
100
|
else
|
94
|
-
if ENV['HOST_BROWSER']
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
101
|
+
if ENV['HOST_BROWSER']
|
102
|
+
case ENV['HOST_BROWSER'].downcase.to_sym
|
103
|
+
when :chrome
|
104
|
+
if OS.osx?
|
105
|
+
path_to_driver = 'mac/chromedriver'
|
106
|
+
elsif OS.windows?
|
107
|
+
path_to_driver = 'windows/chromedriver.exe'
|
108
|
+
end
|
109
|
+
@webdriver_path = File.join(project_path, base_path, path_to_driver)
|
110
|
+
Selenium::WebDriver::Chrome.driver_path = @webdriver_path
|
111
|
+
# when :firefox
|
112
|
+
# if OS.osx?
|
113
|
+
# path_to_driver = 'mac/geckodriver'
|
114
|
+
# elsif OS.windows?
|
115
|
+
# path_to_driver = 'windows/geckodriver.exe'
|
116
|
+
# end
|
117
|
+
# @webdriver_path = File.join(project_path, base_path, path_to_driver)
|
118
|
+
# Selenium::WebDriver::Firefox.driver_path = @webdriver_path
|
99
119
|
end
|
100
|
-
Selenium::WebDriver::Chrome.driver_path = File.join(project_path, base_path, path_to_driver)
|
101
120
|
end
|
102
121
|
end
|
103
|
-
puts "The webdriver path is: #{
|
122
|
+
puts "The webdriver path is: #{@webdriver_path}" unless path_to_driver.nil?
|
123
|
+
end
|
124
|
+
|
125
|
+
def self.initialize_browser_size
|
126
|
+
# tile browser windows if running in multiple parallel threads and BROWSER_TILE environment variable is true
|
127
|
+
if ENV['PARALLEL'] && ENV['BROWSER_TILE']
|
128
|
+
thread = ENV['TEST_ENV_NUMBER'].to_i
|
129
|
+
if thread > 1
|
130
|
+
Browsers.set_browser_window_position(100 * thread - 1, 100 * thread - 1)
|
131
|
+
sleep(1)
|
132
|
+
end
|
133
|
+
else
|
134
|
+
Browsers.set_browser_window_position(50, 50)
|
135
|
+
sleep(1)
|
136
|
+
end
|
137
|
+
|
138
|
+
browser = Environ.browser.to_s
|
139
|
+
if Environ.is_desktop?
|
140
|
+
if ENV['BROWSER_SIZE'] == 'max'
|
141
|
+
Browsers.maximize_browser
|
142
|
+
elsif ENV['BROWSER_SIZE']
|
143
|
+
Browsers.set_browser_window_size(ENV['BROWSER_SIZE'])
|
144
|
+
else
|
145
|
+
Browsers.set_browser_window_size(Browsers.browser_size(browser, ENV['ORIENTATION']))
|
146
|
+
end
|
147
|
+
elsif Environ.is_mobile? && !Environ.is_device?
|
148
|
+
Browsers.set_browser_window_size(Browsers.browser_size(browser, ENV['ORIENTATION']))
|
149
|
+
end
|
150
|
+
Environ.session_state = :running
|
104
151
|
end
|
105
152
|
|
106
153
|
private
|
@@ -108,7 +155,7 @@ module TestCentricity
|
|
108
155
|
def self.initialize_appium
|
109
156
|
Environ.device = true
|
110
157
|
Environ.platform = :mobile
|
111
|
-
Environ.
|
158
|
+
Environ.device_name = ENV['APP_DEVICE']
|
112
159
|
Environ.device_os = ENV['APP_PLATFORM_NAME']
|
113
160
|
Environ.device_orientation = ENV['ORIENTATION'] if ENV['ORIENTATION']
|
114
161
|
Capybara.default_driver = :appium
|
@@ -148,48 +195,113 @@ module TestCentricity
|
|
148
195
|
browser = ENV['WEB_BROWSER']
|
149
196
|
|
150
197
|
case browser.downcase.to_sym
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
198
|
+
when :firefox, :chrome, :ie, :safari, :edge
|
199
|
+
Environ.platform = :desktop
|
200
|
+
else
|
201
|
+
Environ.platform = :mobile
|
202
|
+
Environ.device_name = Browsers.mobile_device_name(browser)
|
156
203
|
end
|
157
204
|
|
158
205
|
Capybara.default_driver = :selenium
|
159
206
|
Capybara.register_driver :selenium do |app|
|
160
207
|
case browser.downcase.to_sym
|
161
|
-
|
162
|
-
|
208
|
+
when :ie, :safari, :edge
|
209
|
+
Capybara::Selenium::Driver.new(app, :browser => browser.to_sym)
|
210
|
+
|
211
|
+
when :firefox
|
212
|
+
if ENV['LOCALE']
|
213
|
+
profile = Selenium::WebDriver::Firefox::Profile.new
|
214
|
+
profile['intl.accept_languages'] = ENV['LOCALE']
|
215
|
+
Capybara::Selenium::Driver.new(app, :profile => profile)
|
216
|
+
else
|
217
|
+
Capybara::Selenium::Driver.new(app, :browser => :firefox)
|
218
|
+
end
|
219
|
+
|
220
|
+
when :chrome
|
221
|
+
ENV['LOCALE'] ? args = ['--disable-infobars', "--lang=#{ENV['LOCALE']}"] : args = ['--disable-infobars']
|
222
|
+
Capybara::Selenium::Driver.new(app, :browser => :chrome, :args => args)
|
163
223
|
|
164
|
-
when :firefox
|
165
|
-
if ENV['LOCALE']
|
166
|
-
profile = Selenium::WebDriver::Firefox::Profile.new
|
167
|
-
profile['intl.accept_languages'] = ENV['LOCALE']
|
168
|
-
Capybara::Selenium::Driver.new(app, :profile => profile)
|
169
224
|
else
|
170
|
-
|
171
|
-
|
225
|
+
user_agent = Browsers.mobile_device_agent(browser)
|
226
|
+
ENV['HOST_BROWSER'] ? host_browser = ENV['HOST_BROWSER'].downcase.to_sym : host_browser = :firefox
|
227
|
+
case host_browser
|
228
|
+
when :firefox
|
229
|
+
profile = Selenium::WebDriver::Firefox::Profile.new
|
230
|
+
profile['general.useragent.override'] = user_agent
|
231
|
+
profile['intl.accept_languages'] = ENV['LOCALE'] if ENV['LOCALE']
|
232
|
+
Capybara::Selenium::Driver.new(app, :profile => profile)
|
233
|
+
|
234
|
+
when :chrome
|
235
|
+
ENV['LOCALE'] ?
|
236
|
+
args = ["--user-agent='#{user_agent}'", "--lang=#{ENV['LOCALE']}", '--disable-infobars'] :
|
237
|
+
args = ["--user-agent='#{user_agent}'", '--disable-infobars']
|
238
|
+
Capybara::Selenium::Driver.new(app, :browser => :chrome, :args => args)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
172
243
|
|
173
|
-
|
174
|
-
|
175
|
-
|
244
|
+
def self.new_initialize_local_browser
|
245
|
+
if OS.osx?
|
246
|
+
Environ.os = 'OS X'
|
247
|
+
elsif OS.windows?
|
248
|
+
Environ.os = 'Windows'
|
249
|
+
end
|
176
250
|
|
251
|
+
browser = ENV['WEB_BROWSER']
|
252
|
+
|
253
|
+
case browser.downcase.to_sym
|
254
|
+
when :firefox, :chrome, :ie, :safari, :edge
|
255
|
+
Environ.platform = :desktop
|
177
256
|
else
|
178
|
-
|
179
|
-
|
180
|
-
|
257
|
+
Environ.platform = :mobile
|
258
|
+
Environ.device_name = Browsers.mobile_device_name(browser)
|
259
|
+
end
|
260
|
+
|
261
|
+
Capybara.default_driver = :selenium
|
262
|
+
Capybara.register_driver :selenium do |app|
|
263
|
+
case browser.downcase.to_sym
|
264
|
+
when :ie, :safari, :edge
|
265
|
+
Capybara::Selenium::Driver.new(app, browser: browser.to_sym)
|
181
266
|
when :firefox
|
182
267
|
profile = Selenium::WebDriver::Firefox::Profile.new
|
183
|
-
profile['
|
268
|
+
profile['browser.download.dir'] = '/tmp/webdriver-downloads'
|
269
|
+
profile['browser.download.folderList'] = 2
|
270
|
+
profile['browser.helperApps.neverAsk.saveToDisk'] = 'text/csv, application/x-msexcel, application/excel, application/x-excel, application/vnd.ms-excel, image/png, image/jpeg, text/html, text/plain, application/pdf, application/octet-stream'
|
271
|
+
profile['pdfjs.disabled'] = true
|
184
272
|
profile['intl.accept_languages'] = ENV['LOCALE'] if ENV['LOCALE']
|
185
|
-
|
186
|
-
|
273
|
+
options = Selenium::WebDriver::Firefox::Options.new(profile: profile)
|
274
|
+
if @webdriver_path.blank?
|
275
|
+
Capybara::Selenium::Driver.new(app, browser: :firefox, options: options)
|
276
|
+
else
|
277
|
+
Capybara::Selenium::Driver.new(app, browser: :firefox, options: options, driver_path: @webdriver_path)
|
278
|
+
end
|
187
279
|
when :chrome
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
Capybara::Selenium::Driver.new(app, :
|
192
|
-
|
280
|
+
options = Selenium::WebDriver::Chrome::Options.new
|
281
|
+
options.add_argument('--disable-infobars')
|
282
|
+
options.add_argument("--lang=#{ENV['LOCALE']}") if ENV['LOCALE']
|
283
|
+
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
|
284
|
+
else
|
285
|
+
user_agent = Browsers.mobile_device_agent(browser)
|
286
|
+
ENV['HOST_BROWSER'] ? host_browser = ENV['HOST_BROWSER'].downcase.to_sym : host_browser = :firefox
|
287
|
+
case host_browser
|
288
|
+
when :firefox
|
289
|
+
profile = Selenium::WebDriver::Firefox::Profile.new
|
290
|
+
profile['general.useragent.override'] = user_agent
|
291
|
+
profile['intl.accept_languages'] = ENV['LOCALE'] if ENV['LOCALE']
|
292
|
+
options = Selenium::WebDriver::Firefox::Options.new(profile: profile)
|
293
|
+
if @webdriver_path.blank?
|
294
|
+
Capybara::Selenium::Driver.new(app, browser: :firefox, options: options)
|
295
|
+
else
|
296
|
+
Capybara::Selenium::Driver.new(app, browser: :firefox, options: options, driver_path: @webdriver_path)
|
297
|
+
end
|
298
|
+
when :chrome
|
299
|
+
options = Selenium::WebDriver::Chrome::Options.new
|
300
|
+
options.add_argument('--disable-infobars')
|
301
|
+
options.add_argument("--user-agent='#{user_agent}'")
|
302
|
+
options.add_argument("--lang=#{ENV['LOCALE']}") if ENV['LOCALE']
|
303
|
+
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
|
304
|
+
end
|
193
305
|
end
|
194
306
|
end
|
195
307
|
end
|
@@ -200,9 +312,10 @@ module TestCentricity
|
|
200
312
|
if ENV['BS_REAL_MOBILE'] || ENV['BS_PLATFORM']
|
201
313
|
Environ.platform = :mobile
|
202
314
|
Environ.device = true
|
203
|
-
Environ.
|
315
|
+
Environ.device_name = ENV['BS_DEVICE']
|
204
316
|
Environ.device_os = ENV['BS_OS']
|
205
317
|
Environ.device_orientation = ENV['ORIENTATION'] if ENV['ORIENTATION']
|
318
|
+
Environ.device_type = ENV['DEVICE_TYPE'] if ENV['DEVICE_TYPE']
|
206
319
|
|
207
320
|
elsif ENV['BS_OS']
|
208
321
|
Environ.os = "#{ENV['BS_OS']} #{ENV['BS_OS_VERSION']}"
|
@@ -262,7 +375,7 @@ module TestCentricity
|
|
262
375
|
capabilities['javascriptEnabled'] = 'true'
|
263
376
|
capabilities['cleanSession'] = 'true'
|
264
377
|
end
|
265
|
-
Capybara::Selenium::Driver.new(app, :
|
378
|
+
Capybara::Selenium::Driver.new(app, browser: :remote, url: endpoint, desired_capabilities: capabilities)
|
266
379
|
end
|
267
380
|
|
268
381
|
Environ.browser = browser
|
@@ -278,9 +391,10 @@ module TestCentricity
|
|
278
391
|
Environ.os = ENV['CB_OS']
|
279
392
|
Environ.platform = :desktop
|
280
393
|
elsif ENV['CB_PLATFORM']
|
281
|
-
Environ.
|
394
|
+
Environ.device_name = ENV['CB_PLATFORM']
|
282
395
|
Environ.device = true
|
283
396
|
Environ.platform = :mobile
|
397
|
+
Environ.device_type = ENV['DEVICE_TYPE'] if ENV['DEVICE_TYPE']
|
284
398
|
end
|
285
399
|
|
286
400
|
endpoint = "http://#{ENV['CB_USERNAME']}:#{ENV['CB_AUTHKEY']}@hub.crossbrowsertesting.com:80/wd/hub"
|
@@ -296,7 +410,7 @@ module TestCentricity
|
|
296
410
|
elsif ENV['CB_PLATFORM']
|
297
411
|
capabilities['os_api_name'] = ENV['CB_PLATFORM']
|
298
412
|
end
|
299
|
-
Capybara::Selenium::Driver.new(app, :
|
413
|
+
Capybara::Selenium::Driver.new(app, browser: :remote, url: endpoint, desired_capabilities: capabilities)
|
300
414
|
end
|
301
415
|
|
302
416
|
Environ.browser = browser
|
@@ -317,12 +431,12 @@ module TestCentricity
|
|
317
431
|
Capybara.default_driver = :poltergeist
|
318
432
|
Capybara.register_driver :poltergeist do |app|
|
319
433
|
options = {
|
320
|
-
:
|
321
|
-
:
|
322
|
-
:
|
323
|
-
:
|
324
|
-
:
|
325
|
-
:
|
434
|
+
js_errors: true,
|
435
|
+
timeout: 120,
|
436
|
+
debug: false,
|
437
|
+
phantomjs_options: ['--load-images=no', '--disk-cache=false'],
|
438
|
+
inspector: true,
|
439
|
+
window_size: [width, height]
|
326
440
|
}
|
327
441
|
Capybara::Poltergeist::Driver.new(app, options)
|
328
442
|
end
|
@@ -333,7 +447,7 @@ module TestCentricity
|
|
333
447
|
endpoint = ENV['REMOTE_ENDPOINT'] || 'http://127.0.0.1:4444/wd/hub'
|
334
448
|
capabilities = Selenium::WebDriver::Remote::Capabilities.send(browser.downcase.to_sym)
|
335
449
|
Capybara.register_driver :remote_browser do |app|
|
336
|
-
Capybara::Selenium::Driver.new(app, :
|
450
|
+
Capybara::Selenium::Driver.new(app, browser: :remote, url: endpoint, desired_capabilities: capabilities)
|
337
451
|
end
|
338
452
|
Capybara.current_driver = :remote_browser
|
339
453
|
Capybara.default_driver = :remote_browser
|
@@ -346,7 +460,7 @@ module TestCentricity
|
|
346
460
|
Environ.platform = :desktop
|
347
461
|
Environ.os = ENV['SL_OS']
|
348
462
|
elsif ENV['SL_PLATFORM']
|
349
|
-
Environ.
|
463
|
+
Environ.device_name = ENV['SL_DEVICE']
|
350
464
|
Environ.platform = :mobile
|
351
465
|
end
|
352
466
|
|
@@ -368,7 +482,7 @@ module TestCentricity
|
|
368
482
|
capabilities['deviceOrientation'] = ENV['ORIENTATION'] if ENV['ORIENTATION']
|
369
483
|
end
|
370
484
|
|
371
|
-
Capybara::Selenium::Driver.new(app, :
|
485
|
+
Capybara::Selenium::Driver.new(app, browser: :remote, url: endpoint, desired_capabilities: capabilities)
|
372
486
|
end
|
373
487
|
|
374
488
|
Environ.browser = browser
|
@@ -386,9 +500,10 @@ module TestCentricity
|
|
386
500
|
Environ.device_orientation = ENV['ORIENTATION']
|
387
501
|
end
|
388
502
|
Environ.device_os = ENV['TB_PLATFORM']
|
389
|
-
Environ.
|
503
|
+
Environ.device_name = ENV['TB_DEVICE']
|
390
504
|
Environ.device = true
|
391
505
|
Environ.platform = :mobile
|
506
|
+
Environ.device_type = ENV['DEVICE_TYPE'] if ENV['DEVICE_TYPE']
|
392
507
|
else
|
393
508
|
Environ.platform = :desktop
|
394
509
|
end
|
@@ -414,7 +529,7 @@ module TestCentricity
|
|
414
529
|
capabilities['deviceName'] = ENV['TB_DEVICE']
|
415
530
|
end
|
416
531
|
|
417
|
-
Capybara::Selenium::Driver.new(app, :
|
532
|
+
Capybara::Selenium::Driver.new(app, browser: :remote, url: endpoint, desired_capabilities: capabilities)
|
418
533
|
end
|
419
534
|
|
420
535
|
Environ.browser = browser
|
@@ -423,29 +538,5 @@ module TestCentricity
|
|
423
538
|
Capybara.run_server = false
|
424
539
|
|
425
540
|
end
|
426
|
-
|
427
|
-
def self.initialize_browser_size
|
428
|
-
# tile browser windows if running in multiple parallel threads and BROWSER_TILE environment variable is true
|
429
|
-
if ENV['PARALLEL'] && ENV['BROWSER_TILE']
|
430
|
-
thread = ENV['TEST_ENV_NUMBER'].to_i
|
431
|
-
if thread > 1
|
432
|
-
Browsers.set_browser_window_position(100 * thread - 1, 100 * thread - 1)
|
433
|
-
sleep(1)
|
434
|
-
end
|
435
|
-
end
|
436
|
-
|
437
|
-
browser = Environ.browser.to_s
|
438
|
-
if Environ.is_desktop?
|
439
|
-
if ENV['BROWSER_SIZE'] == 'max'
|
440
|
-
Browsers.maximize_browser
|
441
|
-
elsif ENV['BROWSER_SIZE']
|
442
|
-
Browsers.set_browser_window_size(ENV['BROWSER_SIZE'])
|
443
|
-
else
|
444
|
-
Browsers.set_browser_window_size(Browsers.browser_size(browser, ENV['ORIENTATION']))
|
445
|
-
end
|
446
|
-
elsif Environ.is_mobile? && !Environ.is_device?
|
447
|
-
Browsers.set_browser_window_size(Browsers.browser_size(browser, ENV['ORIENTATION']))
|
448
|
-
end
|
449
|
-
end
|
450
541
|
end
|
451
542
|
end
|