howitzer 0.0.3 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/.gitignore +8 -0
  2. data/.rspec +3 -0
  3. data/.travis.yml +4 -0
  4. data/CHANGELOG.md +32 -0
  5. data/GETTING_STARTED.md +529 -0
  6. data/Gemfile +4 -2
  7. data/LICENSE +2 -2
  8. data/README.md +57 -13
  9. data/Rakefile +9 -2
  10. data/bin/howitzer +79 -31
  11. data/generators/base_generator.rb +87 -0
  12. data/generators/config/config_generator.rb +16 -20
  13. data/generators/config/templates/default.yml +26 -7
  14. data/generators/cucumber/cucumber_generator.rb +20 -26
  15. data/generators/{tasks → cucumber}/templates/cucumber.rake +0 -0
  16. data/generators/{config → cucumber}/templates/cucumber.yml +0 -0
  17. data/generators/emails/emails_generator.rb +11 -18
  18. data/generators/emails/templates/example_email.rb +1 -0
  19. data/generators/pages/pages_generator.rb +16 -18
  20. data/generators/pages/templates/example_menu.rb +1 -0
  21. data/generators/pages/templates/example_page.rb +1 -1
  22. data/generators/root/root_generator.rb +18 -20
  23. data/generators/root/templates/.gitignore +2 -1
  24. data/generators/root/templates/Gemfile +3 -2
  25. data/generators/root/templates/Rakefile +10 -0
  26. data/generators/root/templates/boot.rb +3 -9
  27. data/generators/rspec/rspec_generator.rb +23 -0
  28. data/generators/rspec/templates/example_spec.rb +7 -0
  29. data/generators/rspec/templates/rspec.rake +34 -0
  30. data/generators/rspec/templates/spec_helper.rb +56 -0
  31. data/generators/tasks/tasks_generator.rb +11 -17
  32. data/generators/tasks/templates/common.rake +15 -0
  33. data/howitzer.gemspec +13 -2
  34. data/lib/howitzer.rb +1 -0
  35. data/lib/howitzer/helpers.rb +87 -2
  36. data/lib/howitzer/init.rb +0 -1
  37. data/lib/howitzer/patches/rawler_patched.rb +86 -0
  38. data/lib/howitzer/settings.rb +27 -0
  39. data/lib/howitzer/utils.rb +3 -12
  40. data/lib/howitzer/utils/capybara_patched.rb +3 -2
  41. data/lib/howitzer/utils/capybara_settings.rb +158 -24
  42. data/lib/howitzer/utils/data_generator/data_storage.rb +35 -1
  43. data/lib/howitzer/utils/data_generator/gen.rb +45 -3
  44. data/lib/howitzer/utils/email/email.rb +44 -5
  45. data/lib/howitzer/utils/email/mail_client.rb +28 -22
  46. data/lib/howitzer/utils/email/mailgun_helper.rb +30 -4
  47. data/lib/howitzer/utils/locator_store.rb +111 -19
  48. data/lib/howitzer/utils/log.rb +137 -0
  49. data/lib/howitzer/utils/page_validator.rb +86 -0
  50. data/lib/howitzer/vendor/firebug-1.12.1-fx.xpi +0 -0
  51. data/lib/howitzer/vendor/firepath-0.9.7-fx.xpi +0 -0
  52. data/lib/howitzer/version.rb +2 -2
  53. data/lib/howitzer/web_page.rb +159 -19
  54. data/spec/active_resource.rb +0 -0
  55. data/spec/config/custom.yml +1 -0
  56. data/spec/config/default.yml +28 -0
  57. data/spec/spec_helper.rb +46 -1
  58. data/spec/support/boot_helper.rb +15 -0
  59. data/spec/support/generator_helper.rb +13 -0
  60. data/spec/support/logger_helper.rb +12 -0
  61. data/spec/unit/bin/howitzer_spec.rb +175 -0
  62. data/spec/unit/generators/generators_spec.rb +175 -0
  63. data/spec/unit/lib/capybara_settings_spec.rb +170 -0
  64. data/spec/unit/lib/helpers_spec.rb +619 -0
  65. data/spec/unit/lib/init_spec.rb +14 -0
  66. data/spec/unit/lib/settings_spec.rb +17 -0
  67. data/spec/unit/lib/utils/data_generator/data_storage_spec.rb +62 -0
  68. data/spec/unit/lib/utils/data_generator/gen_spec.rb +151 -0
  69. data/spec/unit/lib/utils/email/email_spec.rb +75 -0
  70. data/spec/unit/lib/utils/email/mail_client_spec.rb +115 -0
  71. data/spec/unit/lib/utils/email/mailgun_helper_spec.rb +95 -0
  72. data/spec/unit/lib/utils/locator_store_spec.rb +122 -0
  73. data/spec/unit/lib/utils/log_spec.rb +107 -0
  74. data/spec/unit/lib/utils/page_validator_spec.rb +142 -0
  75. data/spec/unit/lib/web_page_spec.rb +250 -0
  76. data/spec/unit/version_spec.rb +8 -0
  77. metadata +215 -15
  78. data/Gemfile.lock +0 -103
  79. data/History.md +0 -20
  80. data/lib/howitzer/utils/logger.rb +0 -108
  81. data/spec/howitzer/version_spec.rb +0 -8
data/lib/howitzer.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "howitzer/version"
2
+ require "howitzer/settings"
2
3
  require 'howitzer/utils'
3
4
  require 'howitzer/init'
4
5
  require 'howitzer/helpers'
@@ -1,17 +1,38 @@
1
+ DriverNotSpecified = Class.new(StandardError)
2
+ SlBrowserNameNotSpecified = Class.new(StandardError)
3
+ TbBrowserNameNotSpecified = Class.new(StandardError)
4
+ SelBrowserNotSpecified = Class.new(StandardError)
5
+ CHECK_YOUR_SETTINGS_MSG = "Please check your settings"
6
+ DRIVER_NOT_SPECIFIED = DriverNotSpecified.new(CHECK_YOUR_SETTINGS_MSG)
7
+ SL_BROWSER_NAME_NOT_SPECIFIED = SlBrowserNameNotSpecified.new(CHECK_YOUR_SETTINGS_MSG)
8
+ TB_BROWSER_NAME_NOT_SPECIFIED = TbBrowserNameNotSpecified.new(CHECK_YOUR_SETTINGS_MSG)
9
+ SEL_BROWSER_NOT_SPECIFIED = SelBrowserNotSpecified.new(CHECK_YOUR_SETTINGS_MSG)
1
10
 
2
11
  def sauce_driver?
12
+ raise DRIVER_NOT_SPECIFIED if settings.driver.nil?
3
13
  settings.driver.to_sym == :sauce
4
14
  end
5
15
 
16
+ def testingbot_driver?
17
+ raise DRIVER_NOT_SPECIFIED if settings.driver.nil?
18
+ settings.driver.to_sym == :testingbot
19
+ end
20
+
6
21
  def selenium_driver?
22
+ raise DRIVER_NOT_SPECIFIED if settings.driver.nil?
7
23
  settings.driver.to_sym == :selenium
8
24
  end
9
25
 
10
26
  def ie_browser?
11
27
  ie_browsers = [:ie, :iexplore]
12
28
  if sauce_driver?
29
+ raise SL_BROWSER_NAME_NOT_SPECIFIED if settings.sl_browser_name.nil?
13
30
  ie_browsers.include?(settings.sl_browser_name.to_sym)
31
+ elsif testingbot_driver?
32
+ raise TB_BROWSER_NAME_NOT_SPECIFIED if settings.tb_browser_name.nil?
33
+ ie_browsers.include?(settings.tb_browser_name.to_sym)
14
34
  elsif selenium_driver?
35
+ raise SEL_BROWSER_NOT_SPECIFIED if settings.sel_browser.nil?
15
36
  ie_browsers.include?(settings.sel_browser.to_sym)
16
37
  end
17
38
  end
@@ -19,22 +40,58 @@ end
19
40
  def ff_browser?
20
41
  ff_browsers = [:ff, :firefox]
21
42
  if sauce_driver?
43
+ raise SL_BROWSER_NAME_NOT_SPECIFIED if settings.sl_browser_name.nil?
22
44
  ff_browsers.include?(settings.sl_browser_name.to_sym)
45
+ elsif testingbot_driver?
46
+ raise TB_BROWSER_NAME_NOT_SPECIFIED if settings.tb_browser_name.nil?
47
+ ff_browsers.include?(settings.tb_browser_name.to_sym)
23
48
  elsif selenium_driver?
49
+ raise SEL_BROWSER_NOT_SPECIFIED if settings.sel_browser.nil?
24
50
  ff_browsers.include?(settings.sel_browser.to_sym)
25
51
  end
26
52
  end
27
53
 
54
+
28
55
  def chrome_browser?
29
56
  chrome_browser = :chrome
30
57
  if sauce_driver?
58
+ raise SL_BROWSER_NAME_NOT_SPECIFIED if settings.sl_browser_name.nil?
31
59
  settings.sl_browser_name.to_sym == chrome_browser
32
- elsif
60
+ elsif testingbot_driver?
61
+ raise TB_BROWSER_NAME_NOT_SPECIFIED if settings.tb_browser_name.nil?
62
+ settings.tb_browser_name.to_sym == chrome_browser
63
+ elsif selenium_driver?
64
+ raise SEL_BROWSER_NOT_SPECIFIED if settings.sel_browser.nil?
33
65
  settings.sel_browser.to_sym == chrome_browser
34
66
  end
35
67
  end
36
68
 
37
69
 
70
+ ##
71
+ #
72
+ # Returns application url including base authentication (if specified in settings)
73
+ #
74
+
75
+ def app_url
76
+ prefix = settings.app_base_auth_login.blank? ? '' : "#{settings.app_base_auth_login}:#{settings.app_base_auth_pass}@"
77
+ app_base_url prefix
78
+ end
79
+
80
+ ##
81
+ # Returns application url without base authentication by default
82
+ #
83
+ # *Parameters:*
84
+ # * +prefix+ - Sets base authentication prefix (defaults to: nil)
85
+ #
86
+
87
+ def app_base_url(prefix=nil)
88
+ "#{settings.app_protocol || 'http'}://#{prefix}#{settings.app_host}"
89
+ end
90
+
91
+ # *Parameters:*
92
+ # * +time_in_numeric+ - Number of seconds
93
+ #
94
+
38
95
  def duration(time_in_numeric)
39
96
  secs = time_in_numeric.to_i
40
97
  mins = secs / 60
@@ -48,20 +105,48 @@ def duration(time_in_numeric)
48
105
  end
49
106
  end
50
107
 
108
+ ##
109
+ #
110
+ # Evaluates given value
111
+ #
112
+ # *Parameters:*
113
+ # * +value+ - Value to be evaluated
114
+ #
115
+
51
116
  def ri(value)
52
117
  raise value.inspect
53
118
  end
54
119
 
55
120
  class String
121
+
122
+ ##
123
+ #
124
+ # Delegates WebPage.open method. Useful in cucumber step definitions
125
+ #
126
+ # *Parameters:*
127
+ # * +*args+ - Url to be opened
128
+ #
129
+
56
130
  def open(*args)
57
131
  as_page_class.open(*args)
58
132
  end
59
133
 
134
+ ##
135
+ #
136
+ # Returns page instance
137
+ #
138
+
139
+
60
140
  def given
61
141
  as_page_class.new
62
142
  end
63
143
 
144
+ ##
145
+ #
146
+ # Returns page class
147
+ #
148
+
64
149
  def as_page_class
65
150
  Object.const_get("#{self.capitalize}Page")
66
151
  end
67
- end
152
+ end
data/lib/howitzer/init.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  include DataGenerator
2
- include Capybara::DSL #TODO should be included to webpage instead of global content
3
2
 
4
3
  # Configure mail client
5
4
  Mailgun::init(settings.mailgun_api_key)
@@ -0,0 +1,86 @@
1
+ module Rawler
2
+ class Base
3
+ def record_response(code, link, from_url, redirection=nil)
4
+ message = "#{code} - #{link}"
5
+
6
+ if code.to_i >= 300
7
+ message += " - Called from: #{from_url}"
8
+ end
9
+
10
+ message += " - Following redirection to: #{redirection}" if redirection
11
+ log_fields = {code: code, link: link, message: message}
12
+
13
+ code = code.to_i
14
+ case code / 100
15
+ when 1,2
16
+ Rawler.output.info(message)
17
+ add_xml_log_item(log_fields) if settings.add_rawler_xml_log
18
+ add_html_log_item(log_fields) if settings.add_rawler_html_log
19
+ when 3 then
20
+ Rawler.output.warn(message)
21
+ add_xml_log_item(log_fields) if settings.add_rawler_xml_log
22
+ add_html_log_item(log_fields) if settings.add_rawler_html_log
23
+ when 4,5 then
24
+ Rawler.output.error(message)
25
+ log_fields[:failed] = true
26
+ add_xml_log_item(log_fields) if settings.add_rawler_xml_log
27
+ add_html_log_item(log_fields) if settings.add_rawler_html_log
28
+ else
29
+ Rawler.output.error("Unknown code #{message}")
30
+ log_fields[:failed] = true
31
+ log_fields[:message] = "Unknown code #{message}"
32
+ add_xml_log_item(log_fields) if settings.add_rawler_xml_log
33
+ add_html_log_item(log_fields) if settings.add_rawler_html_log
34
+ end
35
+ @logfile.puts(message) if Rawler.log
36
+ end
37
+
38
+ def add_xml_log_item(fields)
39
+ log_file_path = File.expand_path(settings.rawler_xml_log, "#{settings.log_dir}")
40
+
41
+ doc = File.exists?(log_file_path) ? Nokogiri::XML::Document.parse(File.read log_file_path) : Nokogiri::XML::Document.new
42
+
43
+ doc.encoding = 'UTF-8'
44
+
45
+ if doc.root
46
+ tests = doc.root > ("testcase")
47
+ failures = doc.root > ("testcase failure")
48
+ doc.root[:failures] = failures.to_a.size.to_s
49
+ doc.root[:tests] = tests.to_a.size.to_s
50
+ doc.root[:time] = "#{tests.to_a.size} sec."
51
+ else
52
+ root = doc.create_element('testsuite')
53
+ root[:errors] = "0"
54
+ root[:failures] = "0"
55
+ root[:name] = "Check links"
56
+ root[:skipped] = "0"
57
+ root[:tests] = "0"
58
+ root[:time] = "0 sec."
59
+ doc.root = root
60
+ end
61
+
62
+ testcase = doc.create_element('testcase')
63
+ testcase[:classname] = "Check links"
64
+ testcase[:name] = "Check: link '#{fields[:link]}'"
65
+ testcase[:time] = "1"
66
+
67
+ if fields[:failed]
68
+ failure = doc.create_element('failure', message: "Failed responce code: '#{fields[:code]}'", type:'failed')
69
+ failure << doc.create_cdata("#{fields[:message]}")
70
+ testcase << failure
71
+ end
72
+
73
+ testcase << doc.create_element('system-out')
74
+ testcase << doc.create_element('system-err')
75
+ doc.root << testcase
76
+
77
+ File.open(log_file_path, 'w+') do |f|
78
+ f.write(doc.serialize(:encoding => 'UTF-8', :save_with => Nokogiri::XML::Node::SaveOptions::FORMAT))
79
+ end
80
+ end
81
+
82
+ def add_html_log_item(fields)
83
+ #Todo: should be implemented
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,27 @@
1
+ require 'sexy_settings'
2
+
3
+ SexySettings.configure do |config|
4
+ config.path_to_default_settings = File.expand_path("config/default.yml", Dir.pwd)
5
+ config.path_to_custom_settings = File.expand_path("config/custom.yml", Dir.pwd)
6
+ end
7
+
8
+ ##
9
+ #
10
+ # Returns settings as singleton object
11
+ #
12
+ # *Example:*
13
+ #
14
+ # +settings.app_host+
15
+
16
+ def settings
17
+ SexySettings::Base.instance
18
+ end
19
+
20
+ ##
21
+ #
22
+ # Returns logger as singleton object
23
+ #
24
+
25
+ def log
26
+ Howitzer::Log.instance
27
+ end
@@ -1,14 +1,5 @@
1
- require 'sexy_settings'
2
1
  require 'repeater'
2
+ require 'capybara'
3
+ require 'selenium-webdriver'
3
4
 
4
- SexySettings.configure do |config|
5
- config.path_to_default_settings = File.expand_path("config/default.yml", Dir.pwd)
6
- config.path_to_custom_settings = File.expand_path("config/custom.yml", Dir.pwd)
7
- end
8
-
9
- def settings
10
- SexySettings::Base.instance()
11
- end
12
-
13
-
14
- Dir[File.join(File.dirname(__FILE__), "./utils/**/*.rb")].each {|f| require f}
5
+ Dir[File.join(File.dirname(__FILE__), "./utils/**/*.rb")].each {|f| require f}
@@ -12,11 +12,12 @@ module CapybaraPatched
12
12
  class_eval <<-RUBY
13
13
  def #{method}(*args, &block)
14
14
  retryable(tries:3, logger: log, trace: true, on: RETRY_ON) do
15
- current_node.send(:#{method}, *args.flatten, &block)
15
+ @touched = true
16
+ current_scope.send(:#{method}, *args.flatten, &block)
16
17
  end
17
18
  end
18
19
  RUBY
19
20
  end
20
21
  end
21
22
  end
22
- end
23
+ end
@@ -1,37 +1,81 @@
1
- require 'howitzer/utils/logger'
1
+ ##
2
+ #
3
+ # Predefined Capybara settings and capybara drivers
4
+ #
5
+
6
+ require 'howitzer/utils/log'
2
7
  module CapybaraSettings
3
8
  extend self
4
9
 
10
+ ##
11
+ #
12
+ # Predefined settings of Firefox browser
13
+ #
14
+ # *Returns:*
15
+ # * +Hash+ - Settings that can be changed
16
+ #
17
+
18
+
5
19
  def self.base_ff_profile_settings
6
20
  profile = Selenium::WebDriver::Firefox::Profile.new
7
21
  profile["network.http.phishy-userpass-length"] = 255
8
22
  profile["browser.safebrowsing.malware.enabled"] = false
9
23
  profile["network.automatic-ntlm-auth.allow-non-fqdn"] = true
10
24
  profile["network.ntlm.send-lm-response"] = true
11
- profile["network.automatic-ntlm-auth.trusted-uris"] = settings.app_main_host
25
+ profile["network.automatic-ntlm-auth.trusted-uris"] = settings.app_host
12
26
  profile
13
27
  end
14
28
 
15
- Capybara.run_server = false
16
- Capybara.app_host = ''
17
- Capybara.default_wait_time = settings.timeout_small
18
- Capybara.ignore_hidden_elements = true
19
- case settings.driver.to_sym
20
- when :selenium
29
+ class << self
30
+
31
+ ##
32
+ #
33
+ #Defines driver based on specified test environment settings
34
+ #
35
+
36
+ def define_driver
37
+ case settings.driver.to_sym
38
+ when :selenium
39
+ define_selenium_driver
40
+ when :selenium_dev
41
+ define_selenium_dev_driver
42
+ when :webkit
43
+ define_webkit_driver
44
+ when :poltergeist
45
+ define_poltergeist_driver
46
+ when :sauce
47
+ define_sauce_driver
48
+ when :testingbot
49
+ define_testingbot_driver
50
+ else
51
+ log.error "Unknown '#{settings.driver}' driver. Check your settings, it should be one of [selenium, selenium_dev, webkit, sauce, testingbot]"
52
+ end
53
+ end
54
+
55
+ private
56
+
57
+ def define_selenium_driver
21
58
  Capybara.register_driver :selenium do |app|
22
59
  params = {browser: settings.sel_browser.to_sym}
23
60
  params[:profile] = base_ff_profile_settings if ff_browser?
24
61
  Capybara::Selenium::Driver.new app, params
25
62
  end
26
- when :selenium_dev
63
+ end
64
+
65
+ def define_selenium_dev_driver
27
66
  Capybara.register_driver :selenium_dev do |app|
28
67
  profile = base_ff_profile_settings
29
- fb_name = "firebug-#{settings.sel_firebug_version}-fx.xpi"
30
- fp_name = "firepath-#{settings.sel_firepath_version}.xpi"
31
- [fb_name, fp_name].each do |name|
32
- profile.add_extension(File.expand_path(name, File.join('shared', 'vendor', 'firebug')))
68
+ vendor_dir = settings.custom_vendor_dir || File.join(File.dirname(__FILE__), '..', 'vendor')
69
+ raise "Vendor directory was not found('#{vendor_dir}')." unless Dir.exist?(vendor_dir)
70
+ %w(firebug*.xpi firepath*.xpi).each do |file_name|
71
+ full_path_pattern = File.join(File.expand_path(vendor_dir), file_name)
72
+ if (full_path = Dir[full_path_pattern].first)
73
+ profile.add_extension full_path
74
+ else
75
+ raise "Extension was not found by '#{full_path_pattern}' pattern!"
76
+ end
33
77
  end
34
- profile['extensions.firebug.currentVersion'] = settings.sel_firebug_version # avoid 'first run' tab
78
+ profile['extensions.firebug.currentVersion'] = 'Last' # avoid 'first run' tab
35
79
  profile["extensions.firebug.previousPlacement"] = 1
36
80
  profile["extensions.firebug.onByDefault"] = true
37
81
  profile["extensions.firebug.defaultPanelName"] = "firepath"
@@ -41,18 +85,30 @@ module CapybaraSettings
41
85
 
42
86
  Capybara::Selenium::Driver.new app, browser: :firefox, profile: profile
43
87
  end
44
- when :webkit
88
+ end
89
+
90
+ def define_webkit_driver
45
91
  require 'capybara-webkit'
46
- when :poltergeist
92
+ end
93
+
94
+ def define_poltergeist_driver
47
95
  require 'capybara/poltergeist'
48
96
  Capybara.register_driver :poltergeist do |app|
49
- Capybara::Poltergeist::Driver.new(app, settings.poltergeist_settings)
97
+ Capybara::Poltergeist::Driver.new(
98
+ app, {
99
+ js_errors: !settings.pjs_ignore_js_errors,
100
+ phantomjs_options: ["--ignore-ssl-errors=#{settings.pjs_ignore_ssl_errors ? 'yes' : 'no'}" ]
101
+ }
102
+ )
50
103
  end
51
- when :sauce
104
+ end
105
+
106
+ def define_sauce_driver
107
+ task_name = ENV['RAKE_TASK'].to_s.sub(/(?:r?spec|cucumber):?(.*)/, '\1').upcase
52
108
  caps_opts = {
53
109
  platform: settings.sl_platform,
54
110
  browser_name: settings.sl_browser_name,
55
- name: 'Capybara test name should be overwritten',
111
+ name: "#{ENV['RAKE_TASK'] ? (task_name.empty? ? 'ALL' : task_name) : 'CUSTOM'} #{settings.sl_browser_name.upcase}",
56
112
  "max-duration" => settings.sl_max_duration,
57
113
  'idle-timeout' => settings.sl_idle_timeout,
58
114
  'selenium-version' => settings.sl_selenium_version,
@@ -72,15 +128,59 @@ module CapybaraSettings
72
128
  }
73
129
 
74
130
  Capybara.register_driver :sauce do |app|
75
- Capybara::Selenium::Driver.new(app, options)
131
+ driver = Capybara::Selenium::Driver.new(app, options)
132
+ driver.browser.file_detector = lambda do |args|
133
+ str = args.first.to_s
134
+ str if File.exist?(str)
135
+ end
136
+ driver
76
137
  end
138
+ end
77
139
 
78
- else
79
- log.error "Unknown '#{settings.driver}' driver. Check your settings, it should be one of [selenium, selenium_dev, webkit, sauce]"
140
+ def define_testingbot_driver
141
+ require 'testingbot'
142
+ task_name = ENV['RAKE_TASK'].to_s.sub(/(?:r?spec|cucumber):?(.*)/, '\1').upcase
143
+ caps_opts = {
144
+ platform: settings.tb_platform,
145
+ browser_name: settings.tb_browser_name,
146
+ name: "#{ENV['RAKE_TASK'] ? (task_name.empty? ? 'ALL' : task_name) : 'CUSTOM'} #{settings.tb_browser_name.upcase}",
147
+ maxduration: settings.tb_max_duration.to_i,
148
+ idletimeout: settings.tb_idle_timeout.to_i,
149
+ 'selenium-version' => settings.tb_selenium_version,
150
+ screenshot: settings.tb_record_screenshot,
151
+ 'avoid-proxy' => settings.tb_avoid_proxy
152
+ }
153
+
154
+ unless (settings.tb_browser_version.to_s || "").empty?
155
+ caps_opts['version'] = settings.tb_browser_version.to_s
156
+ end
157
+ options = {
158
+ url: settings.tb_url,
159
+ desired_capabilities: Selenium::WebDriver::Remote::Capabilities.new(caps_opts),
160
+ http_client: Selenium::WebDriver::Remote::Http::Default.new.tap{|c| c.timeout = settings.timeout_medium},
161
+ browser: :remote
162
+ }
163
+ Capybara.register_driver :testingbot do |app|
164
+ driver = Capybara::Selenium::Driver.new(app, options)
165
+ driver.browser.file_detector = lambda do |args|
166
+ str = args.first.to_s
167
+ str if File.exist?(str)
168
+ end
169
+ driver
170
+ end
171
+ end
80
172
  end
81
173
 
82
- Capybara.default_driver = settings.driver.to_sym
83
- Capybara.javascript_driver = settings.driver.to_sym
174
+ ##
175
+ #
176
+ # Returns url of current Sauce Labs job
177
+ #
178
+ # *Parameters:*
179
+ # * +name+ - Your account name
180
+ #
181
+ # *Returns:*
182
+ # * +string+ - URL address of last running Sauce Labs job
183
+ #
84
184
 
85
185
  def sauce_resource_path(name)
86
186
  host = "https://#{settings.sl_user}:#{settings.sl_api_key}@saucelabs.com"
@@ -88,6 +188,15 @@ module CapybaraSettings
88
188
  "#{host}#{path}"
89
189
  end
90
190
 
191
+ ##
192
+ #
193
+ # Sends http request to change current Sauce Labs job status - pass/fail
194
+ #
195
+ # *Parameters:*
196
+ # * +json_data+ - test status as hash (for details see Saucelab documentation)
197
+ #
198
+
199
+
91
200
  def update_sauce_job_status(json_data = {})
92
201
  host = "http://#{settings.sl_user}:#{settings.sl_api_key}@saucelabs.com"
93
202
  path = "/rest/v1/#{settings.sl_user}/jobs/#{session_id}"
@@ -95,6 +204,14 @@ module CapybaraSettings
95
204
  RestClient.put url, json_data.to_json, content_type: :json, accept: :json
96
205
  end
97
206
 
207
+ ##
208
+ #
209
+ # Returns custom name for Sauce Labs job
210
+ #
211
+ # *Returns:*
212
+ # * +string+ - Return name of current Sauce Labs job
213
+ #
214
+
98
215
  def suite_name
99
216
  res = if ENV['RAKE_TASK']
100
217
  res = ENV['RAKE_TASK'].sub(/(?:r?spec|cucumber):?(.*)/, '\1').upcase
@@ -105,9 +222,26 @@ module CapybaraSettings
105
222
  "#{res} #{settings.sl_browser_name.upcase}"
106
223
  end
107
224
 
225
+ ##
226
+ #
227
+ # Returns current session id
228
+ #
229
+
108
230
  def session_id
109
231
  Capybara.current_session.driver.browser.instance_variable_get(:@bridge).session_id
110
232
  end
111
233
 
234
+ Capybara.run_server = false
235
+ Capybara.app_host = ''
236
+ Capybara.default_wait_time = settings.timeout_small
237
+ Capybara.ignore_hidden_elements = true
238
+ Capybara.visible_text_only = true
239
+ Capybara.match = :one
240
+ Capybara.exact_options = true
241
+ Capybara.default_driver = settings.driver.to_sym
242
+ Capybara.javascript_driver = settings.driver.to_sym
243
+
244
+ define_driver
245
+
112
246
  end
113
247