howitzer 1.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +32 -0
  4. data/.travis.yml +1 -4
  5. data/.yardopts +1 -2
  6. data/CHANGELOG.md +28 -1
  7. data/Gemfile +6 -0
  8. data/LICENSE +1 -1
  9. data/README.md +55 -85
  10. data/Rakefile +7 -7
  11. data/bin/howitzer +56 -31
  12. data/features/cli_new.feature +162 -79
  13. data/features/cli_update.feature +114 -21
  14. data/features/step_definitions/common_steps.rb +29 -9
  15. data/features/support/env.rb +1 -1
  16. data/features/support/transformers.rb +2 -2
  17. data/generators/base_generator.rb +121 -49
  18. data/generators/config/config_generator.rb +8 -5
  19. data/generators/config/templates/boot.rb +14 -0
  20. data/generators/config/templates/capybara.rb +156 -0
  21. data/generators/config/templates/custom.yml +2 -3
  22. data/generators/config/templates/default.yml +50 -82
  23. data/generators/cucumber/cucumber_generator.rb +9 -9
  24. data/generators/cucumber/templates/common_steps.rb +4 -4
  25. data/generators/cucumber/templates/cucumber.rake +63 -54
  26. data/generators/cucumber/templates/env.rb +24 -23
  27. data/generators/cucumber/templates/transformers.rb +23 -15
  28. data/generators/emails/emails_generator.rb +4 -2
  29. data/generators/emails/templates/example_email.rb +4 -4
  30. data/generators/prerequisites/prerequisites_generator.rb +24 -0
  31. data/generators/prerequisites/templates/base.rb +22 -0
  32. data/generators/prerequisites/templates/factory_girl.rb +30 -0
  33. data/generators/prerequisites/templates/user.rb +7 -0
  34. data/generators/prerequisites/templates/users.rb +12 -0
  35. data/generators/root/root_generator.rb +11 -7
  36. data/generators/root/templates/.rubocop.yml +32 -0
  37. data/generators/root/templates/Gemfile.erb +27 -0
  38. data/generators/root/templates/Rakefile +6 -8
  39. data/generators/rspec/rspec_generator.rb +7 -7
  40. data/generators/rspec/templates/example_spec.rb +1 -1
  41. data/generators/rspec/templates/rspec.rake +48 -29
  42. data/generators/rspec/templates/spec_helper.rb +33 -32
  43. data/generators/tasks/tasks_generator.rb +4 -2
  44. data/generators/tasks/templates/common.rake +1 -16
  45. data/generators/turnip/templates/.rspec +1 -0
  46. data/generators/turnip/templates/common_steps.rb +25 -0
  47. data/generators/turnip/templates/example.feature +8 -0
  48. data/generators/turnip/templates/spec_helper.rb +56 -0
  49. data/generators/turnip/templates/turnip.rake +61 -0
  50. data/generators/turnip/templates/turnip_helper.rb +6 -0
  51. data/generators/turnip/turnip_generator.rb +26 -0
  52. data/generators/web/templates/example_page.rb +15 -0
  53. data/generators/web/templates/menu_section.rb +13 -0
  54. data/generators/web/web_generator.rb +22 -0
  55. data/howitzer.gemspec +14 -21
  56. data/lib/howitzer.rb +47 -7
  57. data/lib/howitzer/cache.rb +70 -0
  58. data/lib/howitzer/capybara_helpers.rb +194 -0
  59. data/lib/howitzer/email.rb +96 -104
  60. data/lib/howitzer/exceptions.rb +10 -6
  61. data/lib/howitzer/log.rb +120 -0
  62. data/lib/howitzer/mail_adapters.rb +7 -0
  63. data/lib/howitzer/mail_adapters/abstract.rb +84 -0
  64. data/lib/howitzer/mail_adapters/mailgun.rb +115 -0
  65. data/lib/howitzer/mailgun_api.rb +9 -0
  66. data/lib/howitzer/mailgun_api/client.rb +79 -0
  67. data/lib/howitzer/mailgun_api/connector.rb +37 -0
  68. data/lib/howitzer/mailgun_api/response.rb +28 -0
  69. data/lib/howitzer/tasks/framework.rake +2 -2
  70. data/lib/howitzer/utils.rb +7 -1
  71. data/lib/howitzer/utils/string_extensions.rb +66 -0
  72. data/lib/howitzer/version.rb +2 -1
  73. data/lib/howitzer/web.rb +11 -0
  74. data/lib/howitzer/web/base_section.rb +27 -0
  75. data/lib/howitzer/web/blank_page.rb +12 -0
  76. data/lib/howitzer/web/capybara_methods_proxy.rb +29 -0
  77. data/lib/howitzer/web/element_dsl.rb +109 -0
  78. data/lib/howitzer/web/iframe_dsl.rb +93 -0
  79. data/lib/howitzer/web/page.rb +173 -0
  80. data/lib/howitzer/web/page_dsl.rb +64 -0
  81. data/lib/howitzer/web/page_validator.rb +118 -0
  82. data/lib/howitzer/web/section.rb +27 -0
  83. data/lib/howitzer/web/section_dsl.rb +154 -0
  84. data/spec/config/custom.yml +10 -1
  85. data/spec/spec_helper.rb +37 -19
  86. data/spec/support/generator_helper.rb +12 -11
  87. data/spec/support/logger_helper.rb +10 -9
  88. data/spec/support/mailgun_unit_client.rb +52 -44
  89. data/spec/support/shared_examples/capybara_context_holder.rb +33 -0
  90. data/spec/support/shared_examples/capybara_methods_proxy.rb +94 -0
  91. data/spec/support/shared_examples/dynamic_section_methods.rb +35 -0
  92. data/spec/support/shared_examples/element_dsl.rb +119 -0
  93. data/spec/unit/generators/base_generator_spec.rb +64 -33
  94. data/spec/unit/generators/config_generator_spec.rb +11 -7
  95. data/spec/unit/generators/cucumber_generator_spec.rb +26 -17
  96. data/spec/unit/generators/emails_generator_spec.rb +10 -6
  97. data/spec/unit/generators/prerequisites_generator_spec.rb +53 -0
  98. data/spec/unit/generators/root_generator_spec.rb +50 -13
  99. data/spec/unit/generators/rspec_generator_spec.rb +9 -9
  100. data/spec/unit/generators/tasks_generator_spec.rb +6 -6
  101. data/spec/unit/generators/turnip_generator_spec.rb +52 -0
  102. data/spec/unit/generators/web_generator_spec.rb +52 -0
  103. data/spec/unit/lib/cache_spec.rb +85 -0
  104. data/spec/unit/lib/capybara_helpers_spec.rb +696 -0
  105. data/spec/unit/lib/email_spec.rb +104 -91
  106. data/spec/unit/lib/howitzer.rb +31 -0
  107. data/spec/unit/lib/init_spec.rb +0 -1
  108. data/spec/unit/lib/log_spec.rb +122 -0
  109. data/spec/unit/lib/mail_adapters/abstract_spec.rb +62 -0
  110. data/spec/unit/lib/mail_adapters/mailgun_spec.rb +163 -0
  111. data/spec/unit/lib/mailgun_api/client_spec.rb +58 -0
  112. data/spec/unit/lib/mailgun_api/connector_spec.rb +54 -0
  113. data/spec/unit/lib/mailgun_api/response_spec.rb +28 -0
  114. data/spec/unit/lib/utils/string_extensions_spec.rb +77 -0
  115. data/spec/unit/lib/web/base_section_spec.rb +41 -0
  116. data/spec/unit/lib/web/element_dsl_spec.rb +17 -0
  117. data/spec/unit/lib/web/iframe_dsl_spec.rb +99 -0
  118. data/spec/unit/lib/web/page_dsl_spec.rb +52 -0
  119. data/spec/unit/lib/web/page_spec.rb +304 -0
  120. data/spec/unit/lib/web/page_validator_spec.rb +218 -0
  121. data/spec/unit/lib/web/section_dsl_spec.rb +165 -0
  122. data/spec/unit/lib/web/section_spec.rb +61 -0
  123. data/spec/unit/version_spec.rb +1 -1
  124. metadata +116 -203
  125. data/GETTING_STARTED.md +0 -774
  126. data/generators/cucumber/templates/cucumber.yml +0 -10
  127. data/generators/pages/pages_generator.rb +0 -21
  128. data/generators/pages/templates/example_menu.rb +0 -15
  129. data/generators/pages/templates/example_page.rb +0 -15
  130. data/generators/root/templates/Gemfile +0 -7
  131. data/generators/root/templates/boot.rb +0 -10
  132. data/lib/howitzer/blank_page.rb +0 -6
  133. data/lib/howitzer/capybara/dsl_ex.rb +0 -15
  134. data/lib/howitzer/capybara/settings.rb +0 -343
  135. data/lib/howitzer/helpers.rb +0 -230
  136. data/lib/howitzer/init.rb +0 -1
  137. data/lib/howitzer/mailgun/client.rb +0 -65
  138. data/lib/howitzer/mailgun/connector.rb +0 -34
  139. data/lib/howitzer/mailgun/response.rb +0 -28
  140. data/lib/howitzer/patches/rawler_patched.rb +0 -86
  141. data/lib/howitzer/settings.rb +0 -27
  142. data/lib/howitzer/utils/data_generator/data_storage.rb +0 -88
  143. data/lib/howitzer/utils/data_generator/gen.rb +0 -135
  144. data/lib/howitzer/utils/locator_store.rb +0 -217
  145. data/lib/howitzer/utils/log.rb +0 -139
  146. data/lib/howitzer/utils/page_validator.rb +0 -133
  147. data/lib/howitzer/vendor/firebug-1.12.1-fx.xpi +0 -0
  148. data/lib/howitzer/vendor/firepath-0.9.7-fx.xpi +0 -0
  149. data/lib/howitzer/web_page.rb +0 -253
  150. data/spec/active_resource.rb +0 -0
  151. data/spec/config/default.yml +0 -26
  152. data/spec/support/boot_helper.rb +0 -15
  153. data/spec/unit/generators/pages_generator_spec.rb +0 -33
  154. data/spec/unit/lib/capybara/dsl_ex_spec.rb +0 -60
  155. data/spec/unit/lib/capybara/settings_spec.rb +0 -441
  156. data/spec/unit/lib/helpers_spec.rb +0 -1129
  157. data/spec/unit/lib/mailgun/client_spec.rb +0 -36
  158. data/spec/unit/lib/mailgun/connector_spec.rb +0 -70
  159. data/spec/unit/lib/mailgun/response_spec.rb +0 -28
  160. data/spec/unit/lib/settings_spec.rb +0 -17
  161. data/spec/unit/lib/utils/data_generator/data_storage_spec.rb +0 -80
  162. data/spec/unit/lib/utils/data_generator/gen_spec.rb +0 -90
  163. data/spec/unit/lib/utils/locator_store_spec.rb +0 -157
  164. data/spec/unit/lib/utils/log_spec.rb +0 -107
  165. data/spec/unit/lib/utils/page_validator_spec.rb +0 -265
  166. data/spec/unit/lib/web_page_spec.rb +0 -346
@@ -1,10 +0,0 @@
1
- <%
2
- rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
3
- rerun_opts = rerun.to_s.strip.empty? ? "--format progress features" : "--format pretty #{rerun}"
4
- std_opts = "--verbose --expand --format html --out=./log/log.html --format junit --out=./log --format pretty features --tags ~@wip --tags ~@bug"
5
- %>
6
- default: -r features <%= std_opts %> --tags ~@demo features
7
- wip: -r features --tags @wip --wip features
8
- demo: -r features <%= std_opts %> --tags @demo features
9
- bug: -r features --tags @bug --wip features
10
- rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
@@ -1,21 +0,0 @@
1
- require_relative '../base_generator'
2
-
3
- module Howitzer
4
- class PagesGenerator < BaseGenerator
5
- def manifest
6
- { files:
7
- [
8
- { source: 'example_page.rb', destination: 'pages/example_page.rb'},
9
- { source: 'example_menu.rb', destination: 'pages/example_menu.rb'}
10
- ]
11
- }
12
- end
13
-
14
- protected
15
- def banner
16
- <<-EOS
17
- * PageOriented pattern structure generation ...
18
- EOS
19
- end
20
- end
21
- end
@@ -1,15 +0,0 @@
1
- module ExampleMenu
2
-
3
- def self.included(base)
4
- base.class_eval do
5
- add_locator :menu_button, ".menuButton"
6
- add_locator :account, xpath: ".//*[@id='metaMenu']//a[contains(., 'Account')]"
7
- add_locator :log_out, xpath: ".//*[@id='metaMenu']//a[contains(., 'Log Out')]"
8
- end
9
- end
10
-
11
- def open_menu
12
- log.info "Open menu"
13
- click_link locator(:menu_button)
14
- end
15
- end
@@ -1,15 +0,0 @@
1
- require_relative 'example_menu'
2
-
3
- class ExamplePage < WebPage
4
- URL = '/'
5
- validates :url, pattern: /\A(?:.*?:\/\/)?[^\/]*\/?\z/
6
-
7
- add_field_locator :search_input, 'lst-ib'
8
- add_button_locator :search_btn, 'btnK'
9
-
10
- include ExampleMenu
11
-
12
- def fill_keyword(data)
13
- fill_in field_locator(:search_input), data
14
- end
15
- end
@@ -1,7 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Uncomment it if you are going to use 'webkit' driver. QT library should be installed. See https://github.com/thoughtbot/capybara-webkit/wiki/Installing-Qt-and-compiling-capybara-webkit
4
- #
5
- # gem 'capybara-webkit'
6
-
7
- gem 'howitzer'
@@ -1,10 +0,0 @@
1
- Dir.chdir(File.join(File.dirname(__FILE__), '.'))
2
-
3
- def settings
4
- SexySettings::Base.instance()
5
- end
6
-
7
- require 'howitzer'
8
-
9
- Dir[File.join(File.dirname(__FILE__), "./emails/**/*.rb")].each {|f| require f}
10
- Dir[File.join(File.dirname(__FILE__), "./pages/**/*.rb")].each {|f| require f}
@@ -1,6 +0,0 @@
1
- require 'howitzer/web_page'
2
-
3
- class BlankPage < WebPage
4
- URL = 'about:blank'
5
- validates :url, pattern: /^about:blank$/
6
- end
@@ -1,15 +0,0 @@
1
- require 'capybara'
2
- module Howitzer
3
- module Capybara
4
- module DslEx
5
- include ::Capybara::DSL
6
-
7
- # It flattens arguments of all DSL methods to support locator store DSL
8
- ::Capybara::Session::DSL_METHODS.each do |method|
9
- define_method method do |*args, &block|
10
- super(*args.map{|el| args.first == el && el.respond_to?(:flatten) ? el.flatten : el}.flatten, &block)
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,343 +0,0 @@
1
- require 'selenium-webdriver'
2
- require 'capybara'
3
- require 'howitzer/utils/log'
4
- require 'howitzer/helpers'
5
- module Capybara
6
- module Settings
7
- extend self
8
-
9
- ##
10
- #
11
- # Predefined settings of Firefox browser
12
- #
13
- # *Returns:*
14
- # * +Hash+ - Settings that can be changed
15
- #
16
-
17
-
18
- def self.base_ff_profile_settings
19
- profile = ::Selenium::WebDriver::Firefox::Profile.new
20
- profile['network.http.phishy-userpass-length'] = 255
21
- profile['browser.safebrowsing.malware.enabled'] = false
22
- profile['network.automatic-ntlm-auth.allow-non-fqdn'] = true
23
- profile['network.ntlm.send-lm-response'] = true
24
- profile['network.automatic-ntlm-auth.trusted-uris'] = settings.app_host
25
- profile
26
- end
27
-
28
- class << self
29
-
30
- ##
31
- #
32
- #Defines driver based on specified test environment settings
33
- #
34
-
35
- def define_driver
36
- case settings.driver.to_s.to_sym
37
- when :selenium
38
- define_selenium_driver
39
- when :selenium_dev
40
- define_selenium_dev_driver
41
- when :webkit
42
- define_webkit_driver
43
- when :poltergeist
44
- define_poltergeist_driver
45
- when :phantomjs
46
- define_phantomjs_driver
47
- when :sauce
48
- define_sauce_driver
49
- when :testingbot
50
- define_testingbot_driver
51
- when :browserstack
52
- define_browserstack_driver
53
- when :selenium_grid
54
- define_selenium_grid_driver
55
- else
56
- log.error "Unknown '#{settings.driver}' driver. Check your settings, it should be one of [selenium, selenium_grid, selenium_dev, webkit, poltergeist, phantomjs, sauce, testingbot, browserstack]"
57
- end
58
- end
59
-
60
- private
61
- def define_selenium_grid_driver
62
- Capybara.register_driver :selenium_grid do |app|
63
- caps = if ie_browser?
64
- ::Selenium::WebDriver::Remote::Capabilities.internet_explorer
65
- elsif ff_browser?
66
- ::Selenium::WebDriver::Remote::Capabilities.firefox
67
- elsif chrome_browser?
68
- ::Selenium::WebDriver::Remote::Capabilities.chrome
69
- elsif opera_browser?
70
- ::Selenium::WebDriver::Remote::Capabilities.opera
71
- elsif safari_browser?
72
- ::Selenium::WebDriver::Remote::Capabilities.safari
73
- else
74
- log.error "Unknown '#{settings.sel_browser}' sel_browser. Check your settings, it should be one of [:ie, :iexplore, :ff, :firefox, :chrome, :opera, safari]"
75
- end
76
-
77
- Capybara::Selenium::Driver.new(app, :browser => :remote, :url => settings.sel_hub_url, :desired_capabilities => caps)
78
- end
79
- end
80
-
81
- def define_selenium_driver
82
- Capybara.register_driver :selenium do |app|
83
- params = {browser: settings.sel_browser.to_s.to_sym}
84
- params[:profile] = base_ff_profile_settings if ff_browser?
85
- Capybara::Selenium::Driver.new app, params
86
- end
87
- end
88
-
89
- def define_selenium_dev_driver
90
- Capybara.register_driver :selenium_dev do |app|
91
- profile = base_ff_profile_settings
92
- vendor_dir = settings.custom_vendor_dir || File.join(File.dirname(__FILE__), '..', 'vendor')
93
- log.error "Vendor directory was not found('#{vendor_dir}')." unless Dir.exist?(vendor_dir)
94
- %w(firebug*.xpi firepath*.xpi).each do |file_name|
95
- full_path_pattern = File.join(File.expand_path(vendor_dir), file_name)
96
- if (full_path = Dir[full_path_pattern].first)
97
- profile.add_extension full_path
98
- else
99
- log.error "Extension was not found by '#{full_path_pattern}' pattern!"
100
- end
101
- end
102
- profile['extensions.firebug.currentVersion'] = 'Last' # avoid 'first run' tab
103
- profile['extensions.firebug.previousPlacement'] = 1
104
- profile['extensions.firebug.onByDefault'] = true
105
- profile['extensions.firebug.defaultPanelName'] = 'firepath'
106
- profile['extensions.firebug.script.enableSites'] = true
107
- profile['extensions.firebug.net.enableSites'] = true
108
- profile['extensions.firebug.console.enableSites'] = true
109
-
110
- Capybara::Selenium::Driver.new app, browser: :firefox, profile: profile
111
- end
112
- end
113
-
114
- def define_webkit_driver
115
- require 'capybara-webkit'
116
- end
117
-
118
- def define_poltergeist_driver
119
- require 'capybara/poltergeist'
120
- Capybara.register_driver :poltergeist do |app|
121
- Capybara::Poltergeist::Driver.new(
122
- app, {
123
- js_errors: !settings.pjs_ignore_js_errors,
124
- phantomjs_options: ["--ignore-ssl-errors=#{settings.pjs_ignore_ssl_errors ? 'yes' : 'no'}" ]
125
- }
126
- )
127
- end
128
- end
129
-
130
- def define_phantomjs_driver
131
- Capybara.register_driver :phantomjs do |app|
132
- Capybara::Selenium::Driver.new(
133
- app, browser: :phantomjs,
134
- desired_capabilities: {
135
- javascript_enabled: !settings.pjs_ignore_js_errors
136
- },
137
- args: ["--ignore-ssl-errors=#{settings.pjs_ignore_ssl_errors ? 'yes' : 'no'}" ]
138
- )
139
- end
140
- end
141
-
142
- def define_sauce_driver
143
- task_name = rake_task_name
144
- caps_opts = {
145
- platform: settings.sl_platform,
146
- browser_name: settings.sl_browser_name,
147
- name: "#{ENV['RAKE_TASK'] ? (task_name.empty? ? 'ALL' : task_name) : 'CUSTOM'} #{settings.sl_browser_name.upcase}",
148
- 'max-duration' => settings.sl_max_duration,
149
- 'idle-timeout' => settings.sl_idle_timeout,
150
- 'selenium-version' => settings.sl_selenium_version,
151
- 'record-screenshots' => settings.sl_record_screenshot,
152
- 'video-upload-on-pass' => settings.sl_video_upload_on_pass
153
- }
154
-
155
- unless (settings.sl_browser_version.to_s || '').empty?
156
- caps_opts['version'] = settings.sl_browser_version.to_s
157
- end
158
-
159
- options = {
160
- url: settings.sl_url,
161
- desired_capabilities: ::Selenium::WebDriver::Remote::Capabilities.new(caps_opts),
162
- http_client: ::Selenium::WebDriver::Remote::Http::Default.new.tap{|c| c.timeout = settings.timeout_medium},
163
- browser: :remote
164
- }
165
-
166
- Capybara.register_driver :sauce do |app|
167
- driver = Capybara::Selenium::Driver.new(app, options)
168
- driver.browser.file_detector = lambda do |args|
169
- str = args.first.to_s
170
- str if File.exist?(str)
171
- end
172
- driver
173
- end
174
- end
175
-
176
- def define_testingbot_driver
177
- require 'testingbot'
178
- task_name = rake_task_name
179
- caps_opts = {
180
- platform: settings.tb_platform,
181
- browser_name: settings.tb_browser_name,
182
- name: "#{ENV['RAKE_TASK'] ? (task_name.empty? ? 'ALL' : task_name) : 'CUSTOM'} #{settings.tb_browser_name.upcase}",
183
- maxduration: settings.tb_max_duration.to_i,
184
- idletimeout: settings.tb_idle_timeout.to_i,
185
- 'selenium-version' => settings.tb_selenium_version,
186
- screenshot: settings.tb_record_screenshot,
187
- 'avoid-proxy' => settings.tb_avoid_proxy
188
- }
189
-
190
- unless (settings.tb_browser_version.to_s || "").empty?
191
- caps_opts['version'] = settings.tb_browser_version.to_s
192
- end
193
- options = {
194
- url: settings.tb_url,
195
- desired_capabilities: ::Selenium::WebDriver::Remote::Capabilities.new(caps_opts),
196
- http_client: ::Selenium::WebDriver::Remote::Http::Default.new.tap{|c| c.timeout = settings.timeout_medium},
197
- browser: :remote
198
- }
199
- Capybara.register_driver :testingbot do |app|
200
- driver = Capybara::Selenium::Driver.new(app, options)
201
- driver.browser.file_detector = lambda do |args|
202
- str = args.first.to_s
203
- str if File.exist?(str)
204
- end
205
- driver
206
- end
207
- end
208
- end
209
-
210
- def define_browserstack_driver
211
- task_name = rake_task_name
212
- caps_opts = {
213
- name: "#{ENV['RAKE_TASK'] ? (task_name.empty? ? 'ALL' : task_name) : 'CUSTOM'} #{settings.bs_mobile ? settings.bs_m_browser : settings.bs_browser_name.upcase}",
214
- maxduration: settings.bs_max_duration.to_i,
215
- idletimeout: settings.bs_idle_timeout.to_i,
216
- project: settings.bs_project,
217
- build: settings.bs_build,
218
- resolution: settings.bs_resolution
219
- }
220
-
221
- if settings.bs_local
222
- caps_opts['browserstack.local'] = settings.bs_local
223
- caps_opts['browserstack.localIdentifier'] = settings.bs_local_ID
224
- end
225
-
226
- if settings.bs_mobile
227
- caps_opts[:browserName] = settings.bs_m_browser
228
- caps_opts[:platform] = settings.bs_m_platform
229
- caps_opts[:device] = settings.bs_m_device
230
- else
231
- caps_opts[:os] = settings.bs_os_name
232
- caps_opts[:os_version] = settings.bs_os_version
233
- caps_opts[:browser] = settings.bs_browser_name
234
- caps_opts[:browser_version] = settings.bs_browser_version
235
- end
236
-
237
- options = {
238
- url: settings.bs_url,
239
- desired_capabilities: ::Selenium::WebDriver::Remote::Capabilities.new(caps_opts),
240
- browser: :remote
241
- }
242
- Capybara.register_driver :browserstack do |app|
243
- driver = Capybara::Selenium::Driver.new(app, options)
244
- driver.browser.file_detector = lambda do |args|
245
- str = args.first.to_s
246
- str if File.exist?(str)
247
- end
248
-
249
- driver
250
- end
251
- end
252
-
253
- ##
254
- #
255
- # Returns url of current Sauce Labs job
256
- #
257
- # *Parameters:*
258
- # * +name+ - Your account name
259
- #
260
- # *Returns:*
261
- # * +string+ - URL address of last running Sauce Labs job
262
- #
263
-
264
- def sauce_resource_path(name)
265
- host = "https://#{settings.sl_user}:#{settings.sl_api_key}@saucelabs.com"
266
- path = "/rest/#{settings.sl_user}/jobs/#{session_id}/results/#{name}"
267
- "#{host}#{path}"
268
- end
269
-
270
- ##
271
- #
272
- # Sends http request to change current Sauce Labs job status - pass/fail
273
- #
274
- # *Parameters:*
275
- # * +json_data+ - test status as hash (for details see Saucelab documentation)
276
- #
277
-
278
-
279
- def update_sauce_job_status(json_data = {})
280
- host = "http://#{settings.sl_user}:#{settings.sl_api_key}@saucelabs.com"
281
- path = "/rest/v1/#{settings.sl_user}/jobs/#{session_id}"
282
- url = "#{host}#{path}"
283
- ::RestClient.put url, json_data.to_json, content_type: :json, accept: :json
284
- end
285
-
286
- ##
287
- #
288
- # Returns custom name for Sauce Labs job
289
- #
290
- # *Returns:*
291
- # * +string+ - Return name of current Sauce Labs job
292
- #
293
-
294
- def suite_name
295
- res = if ENV['RAKE_TASK']
296
- res = ENV['RAKE_TASK'].sub(/(?:r?spec|cucumber):?(.*)/, '\1').upcase
297
- res.empty? ? 'ALL' : res
298
- else
299
- 'CUSTOM'
300
- end
301
- "#{res} #{settings.sl_browser_name.upcase}"
302
- end
303
-
304
- ##
305
- #
306
- # Returns current session id
307
- #
308
-
309
- def session_id
310
- Capybara.current_session.driver.browser.instance_variable_get(:@bridge).session_id
311
- end
312
-
313
- ##
314
- #
315
- # Returns custom name for rake task
316
- #
317
- # *Returns:*
318
- # * +string+ - Returns rake task name
319
- #
320
-
321
- def rake_task_name
322
- ENV['RAKE_TASK'].to_s.sub(/(?:r?spec|cucumber):?(.*)/, '\1').upcase
323
- end
324
-
325
- Capybara.run_server = false
326
- Capybara.app_host = ''
327
- Capybara.asset_host = app_base_url
328
- Capybara.default_max_wait_time = settings.timeout_small
329
- Capybara.ignore_hidden_elements = true
330
- Capybara.visible_text_only = true
331
- Capybara.match = :one
332
- Capybara.exact_options = true
333
- Capybara.default_driver = settings.driver.to_s.to_sym
334
- Capybara.javascript_driver = settings.driver.to_s.to_sym
335
-
336
- define_driver
337
-
338
- end
339
- end
340
-
341
- # @deprecated
342
- #
343
- CapybaraSettings = Capybara::Settings