howitzer 1.1.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +32 -0
- data/.travis.yml +1 -4
- data/.yardopts +1 -2
- data/CHANGELOG.md +28 -1
- data/Gemfile +6 -0
- data/LICENSE +1 -1
- data/README.md +55 -85
- data/Rakefile +7 -7
- data/bin/howitzer +56 -31
- data/features/cli_new.feature +162 -79
- data/features/cli_update.feature +114 -21
- data/features/step_definitions/common_steps.rb +29 -9
- data/features/support/env.rb +1 -1
- data/features/support/transformers.rb +2 -2
- data/generators/base_generator.rb +121 -49
- data/generators/config/config_generator.rb +8 -5
- data/generators/config/templates/boot.rb +14 -0
- data/generators/config/templates/capybara.rb +156 -0
- data/generators/config/templates/custom.yml +2 -3
- data/generators/config/templates/default.yml +50 -82
- data/generators/cucumber/cucumber_generator.rb +9 -9
- data/generators/cucumber/templates/common_steps.rb +4 -4
- data/generators/cucumber/templates/cucumber.rake +63 -54
- data/generators/cucumber/templates/env.rb +24 -23
- data/generators/cucumber/templates/transformers.rb +23 -15
- data/generators/emails/emails_generator.rb +4 -2
- data/generators/emails/templates/example_email.rb +4 -4
- data/generators/prerequisites/prerequisites_generator.rb +24 -0
- data/generators/prerequisites/templates/base.rb +22 -0
- data/generators/prerequisites/templates/factory_girl.rb +30 -0
- data/generators/prerequisites/templates/user.rb +7 -0
- data/generators/prerequisites/templates/users.rb +12 -0
- data/generators/root/root_generator.rb +11 -7
- data/generators/root/templates/.rubocop.yml +32 -0
- data/generators/root/templates/Gemfile.erb +27 -0
- data/generators/root/templates/Rakefile +6 -8
- data/generators/rspec/rspec_generator.rb +7 -7
- data/generators/rspec/templates/example_spec.rb +1 -1
- data/generators/rspec/templates/rspec.rake +48 -29
- data/generators/rspec/templates/spec_helper.rb +33 -32
- data/generators/tasks/tasks_generator.rb +4 -2
- data/generators/tasks/templates/common.rake +1 -16
- data/generators/turnip/templates/.rspec +1 -0
- data/generators/turnip/templates/common_steps.rb +25 -0
- data/generators/turnip/templates/example.feature +8 -0
- data/generators/turnip/templates/spec_helper.rb +56 -0
- data/generators/turnip/templates/turnip.rake +61 -0
- data/generators/turnip/templates/turnip_helper.rb +6 -0
- data/generators/turnip/turnip_generator.rb +26 -0
- data/generators/web/templates/example_page.rb +15 -0
- data/generators/web/templates/menu_section.rb +13 -0
- data/generators/web/web_generator.rb +22 -0
- data/howitzer.gemspec +14 -21
- data/lib/howitzer.rb +47 -7
- data/lib/howitzer/cache.rb +70 -0
- data/lib/howitzer/capybara_helpers.rb +194 -0
- data/lib/howitzer/email.rb +96 -104
- data/lib/howitzer/exceptions.rb +10 -6
- data/lib/howitzer/log.rb +120 -0
- data/lib/howitzer/mail_adapters.rb +7 -0
- data/lib/howitzer/mail_adapters/abstract.rb +84 -0
- data/lib/howitzer/mail_adapters/mailgun.rb +115 -0
- data/lib/howitzer/mailgun_api.rb +9 -0
- data/lib/howitzer/mailgun_api/client.rb +79 -0
- data/lib/howitzer/mailgun_api/connector.rb +37 -0
- data/lib/howitzer/mailgun_api/response.rb +28 -0
- data/lib/howitzer/tasks/framework.rake +2 -2
- data/lib/howitzer/utils.rb +7 -1
- data/lib/howitzer/utils/string_extensions.rb +66 -0
- data/lib/howitzer/version.rb +2 -1
- data/lib/howitzer/web.rb +11 -0
- data/lib/howitzer/web/base_section.rb +27 -0
- data/lib/howitzer/web/blank_page.rb +12 -0
- data/lib/howitzer/web/capybara_methods_proxy.rb +29 -0
- data/lib/howitzer/web/element_dsl.rb +109 -0
- data/lib/howitzer/web/iframe_dsl.rb +93 -0
- data/lib/howitzer/web/page.rb +173 -0
- data/lib/howitzer/web/page_dsl.rb +64 -0
- data/lib/howitzer/web/page_validator.rb +118 -0
- data/lib/howitzer/web/section.rb +27 -0
- data/lib/howitzer/web/section_dsl.rb +154 -0
- data/spec/config/custom.yml +10 -1
- data/spec/spec_helper.rb +37 -19
- data/spec/support/generator_helper.rb +12 -11
- data/spec/support/logger_helper.rb +10 -9
- data/spec/support/mailgun_unit_client.rb +52 -44
- data/spec/support/shared_examples/capybara_context_holder.rb +33 -0
- data/spec/support/shared_examples/capybara_methods_proxy.rb +94 -0
- data/spec/support/shared_examples/dynamic_section_methods.rb +35 -0
- data/spec/support/shared_examples/element_dsl.rb +119 -0
- data/spec/unit/generators/base_generator_spec.rb +64 -33
- data/spec/unit/generators/config_generator_spec.rb +11 -7
- data/spec/unit/generators/cucumber_generator_spec.rb +26 -17
- data/spec/unit/generators/emails_generator_spec.rb +10 -6
- data/spec/unit/generators/prerequisites_generator_spec.rb +53 -0
- data/spec/unit/generators/root_generator_spec.rb +50 -13
- data/spec/unit/generators/rspec_generator_spec.rb +9 -9
- data/spec/unit/generators/tasks_generator_spec.rb +6 -6
- data/spec/unit/generators/turnip_generator_spec.rb +52 -0
- data/spec/unit/generators/web_generator_spec.rb +52 -0
- data/spec/unit/lib/cache_spec.rb +85 -0
- data/spec/unit/lib/capybara_helpers_spec.rb +696 -0
- data/spec/unit/lib/email_spec.rb +104 -91
- data/spec/unit/lib/howitzer.rb +31 -0
- data/spec/unit/lib/init_spec.rb +0 -1
- data/spec/unit/lib/log_spec.rb +122 -0
- data/spec/unit/lib/mail_adapters/abstract_spec.rb +62 -0
- data/spec/unit/lib/mail_adapters/mailgun_spec.rb +163 -0
- data/spec/unit/lib/mailgun_api/client_spec.rb +58 -0
- data/spec/unit/lib/mailgun_api/connector_spec.rb +54 -0
- data/spec/unit/lib/mailgun_api/response_spec.rb +28 -0
- data/spec/unit/lib/utils/string_extensions_spec.rb +77 -0
- data/spec/unit/lib/web/base_section_spec.rb +41 -0
- data/spec/unit/lib/web/element_dsl_spec.rb +17 -0
- data/spec/unit/lib/web/iframe_dsl_spec.rb +99 -0
- data/spec/unit/lib/web/page_dsl_spec.rb +52 -0
- data/spec/unit/lib/web/page_spec.rb +304 -0
- data/spec/unit/lib/web/page_validator_spec.rb +218 -0
- data/spec/unit/lib/web/section_dsl_spec.rb +165 -0
- data/spec/unit/lib/web/section_spec.rb +61 -0
- data/spec/unit/version_spec.rb +1 -1
- metadata +116 -203
- data/GETTING_STARTED.md +0 -774
- data/generators/cucumber/templates/cucumber.yml +0 -10
- data/generators/pages/pages_generator.rb +0 -21
- data/generators/pages/templates/example_menu.rb +0 -15
- data/generators/pages/templates/example_page.rb +0 -15
- data/generators/root/templates/Gemfile +0 -7
- data/generators/root/templates/boot.rb +0 -10
- data/lib/howitzer/blank_page.rb +0 -6
- data/lib/howitzer/capybara/dsl_ex.rb +0 -15
- data/lib/howitzer/capybara/settings.rb +0 -343
- data/lib/howitzer/helpers.rb +0 -230
- data/lib/howitzer/init.rb +0 -1
- data/lib/howitzer/mailgun/client.rb +0 -65
- data/lib/howitzer/mailgun/connector.rb +0 -34
- data/lib/howitzer/mailgun/response.rb +0 -28
- data/lib/howitzer/patches/rawler_patched.rb +0 -86
- data/lib/howitzer/settings.rb +0 -27
- data/lib/howitzer/utils/data_generator/data_storage.rb +0 -88
- data/lib/howitzer/utils/data_generator/gen.rb +0 -135
- data/lib/howitzer/utils/locator_store.rb +0 -217
- data/lib/howitzer/utils/log.rb +0 -139
- data/lib/howitzer/utils/page_validator.rb +0 -133
- data/lib/howitzer/vendor/firebug-1.12.1-fx.xpi +0 -0
- data/lib/howitzer/vendor/firepath-0.9.7-fx.xpi +0 -0
- data/lib/howitzer/web_page.rb +0 -253
- data/spec/active_resource.rb +0 -0
- data/spec/config/default.yml +0 -26
- data/spec/support/boot_helper.rb +0 -15
- data/spec/unit/generators/pages_generator_spec.rb +0 -33
- data/spec/unit/lib/capybara/dsl_ex_spec.rb +0 -60
- data/spec/unit/lib/capybara/settings_spec.rb +0 -441
- data/spec/unit/lib/helpers_spec.rb +0 -1129
- data/spec/unit/lib/mailgun/client_spec.rb +0 -36
- data/spec/unit/lib/mailgun/connector_spec.rb +0 -70
- data/spec/unit/lib/mailgun/response_spec.rb +0 -28
- data/spec/unit/lib/settings_spec.rb +0 -17
- data/spec/unit/lib/utils/data_generator/data_storage_spec.rb +0 -80
- data/spec/unit/lib/utils/data_generator/gen_spec.rb +0 -90
- data/spec/unit/lib/utils/locator_store_spec.rb +0 -157
- data/spec/unit/lib/utils/log_spec.rb +0 -107
- data/spec/unit/lib/utils/page_validator_spec.rb +0 -265
- data/spec/unit/lib/web_page_spec.rb +0 -346
data/lib/howitzer/helpers.rb
DELETED
@@ -1,230 +0,0 @@
|
|
1
|
-
require 'howitzer/exceptions'
|
2
|
-
|
3
|
-
module Helpers
|
4
|
-
|
5
|
-
CHECK_YOUR_SETTINGS_MSG = "Please check your settings"
|
6
|
-
|
7
|
-
##
|
8
|
-
#
|
9
|
-
# Returns whether or not the current driver is SauceLabs.
|
10
|
-
#
|
11
|
-
|
12
|
-
def sauce_driver?
|
13
|
-
log.error Howitzer::DriverNotSpecifiedError, CHECK_YOUR_SETTINGS_MSG if settings.driver.nil?
|
14
|
-
settings.driver.to_s.to_sym == :sauce
|
15
|
-
end
|
16
|
-
|
17
|
-
##
|
18
|
-
#
|
19
|
-
# Returns whether or not the current driver is TestingBot.
|
20
|
-
#
|
21
|
-
|
22
|
-
def testingbot_driver?
|
23
|
-
log.error Howitzer::DriverNotSpecifiedError, CHECK_YOUR_SETTINGS_MSG if settings.driver.nil?
|
24
|
-
settings.driver.to_s.to_sym == :testingbot
|
25
|
-
end
|
26
|
-
|
27
|
-
##
|
28
|
-
#
|
29
|
-
# Returns whether or not the current driver is Selenium.
|
30
|
-
#
|
31
|
-
|
32
|
-
def selenium_driver?
|
33
|
-
log.error Howitzer::DriverNotSpecifiedError, CHECK_YOUR_SETTINGS_MSG if settings.driver.nil?
|
34
|
-
settings.driver.to_s.to_sym == :selenium
|
35
|
-
end
|
36
|
-
|
37
|
-
##
|
38
|
-
#
|
39
|
-
# Returns whether or not the current driver is Selenium Grid.
|
40
|
-
#
|
41
|
-
|
42
|
-
def selenium_grid_driver?
|
43
|
-
log.error Howitzer::DriverNotSpecifiedError, CHECK_YOUR_SETTINGS_MSG if settings.driver.nil?
|
44
|
-
settings.driver.to_s.to_sym == :selenium_grid
|
45
|
-
end
|
46
|
-
|
47
|
-
##
|
48
|
-
#
|
49
|
-
# Returns whether or not the current driver is PhantomJS.
|
50
|
-
#
|
51
|
-
|
52
|
-
def phantomjs_driver?
|
53
|
-
log.error Howitzer::DriverNotSpecifiedError, CHECK_YOUR_SETTINGS_MSG if settings.driver.nil?
|
54
|
-
settings.driver.to_s.to_sym == :phantomjs
|
55
|
-
end
|
56
|
-
|
57
|
-
##
|
58
|
-
#
|
59
|
-
# Returns whether or not the current browser is Internet Explorer.
|
60
|
-
#
|
61
|
-
|
62
|
-
def ie_browser?
|
63
|
-
browser? :ie, :iexplore
|
64
|
-
end
|
65
|
-
|
66
|
-
##
|
67
|
-
#
|
68
|
-
# Returns whether or not the current browser is FireFox.
|
69
|
-
#
|
70
|
-
|
71
|
-
def ff_browser?
|
72
|
-
browser? :ff, :firefox
|
73
|
-
end
|
74
|
-
|
75
|
-
##
|
76
|
-
#
|
77
|
-
# Returns whether or not the current browser is Google Chrome.
|
78
|
-
#
|
79
|
-
|
80
|
-
def chrome_browser?
|
81
|
-
browser? :chrome
|
82
|
-
end
|
83
|
-
|
84
|
-
##
|
85
|
-
#
|
86
|
-
# Returns whether or not the current browser is Opera.
|
87
|
-
#
|
88
|
-
|
89
|
-
def opera_browser?
|
90
|
-
browser? :opera
|
91
|
-
end
|
92
|
-
|
93
|
-
##
|
94
|
-
#
|
95
|
-
# Returns whether or not the current browser is Safari.
|
96
|
-
#
|
97
|
-
|
98
|
-
def safari_browser?
|
99
|
-
browser? :safari
|
100
|
-
end
|
101
|
-
|
102
|
-
##
|
103
|
-
#
|
104
|
-
# Returns application url including base authentication (if specified in settings)
|
105
|
-
#
|
106
|
-
|
107
|
-
def app_url
|
108
|
-
prefix = settings.app_base_auth_login.blank? ? '' : "#{settings.app_base_auth_login}:#{settings.app_base_auth_pass}@"
|
109
|
-
app_base_url prefix
|
110
|
-
end
|
111
|
-
|
112
|
-
##
|
113
|
-
#
|
114
|
-
# Returns application url without base authentication by default
|
115
|
-
#
|
116
|
-
# *Parameters:*
|
117
|
-
# * +prefix+ - Sets base authentication prefix (defaults to: nil)
|
118
|
-
#
|
119
|
-
|
120
|
-
def app_base_url(prefix=nil)
|
121
|
-
"#{settings.app_protocol || 'http'}://#{prefix}#{settings.app_host}"
|
122
|
-
end
|
123
|
-
|
124
|
-
##
|
125
|
-
#
|
126
|
-
# Returns formatted duration time
|
127
|
-
#
|
128
|
-
# *Parameters:*
|
129
|
-
# * +time_in_numeric+ - Number of seconds
|
130
|
-
#
|
131
|
-
|
132
|
-
def duration(time_in_numeric)
|
133
|
-
secs = time_in_numeric.to_i
|
134
|
-
mins = secs / 60
|
135
|
-
hours = mins / 60
|
136
|
-
if hours > 0
|
137
|
-
"[#{hours}h #{mins % 60}m #{secs % 60}s]"
|
138
|
-
elsif mins > 0
|
139
|
-
"[#{mins}m #{secs % 60}s]"
|
140
|
-
elsif secs >= 0
|
141
|
-
"[0m #{secs}s]"
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
##
|
146
|
-
#
|
147
|
-
# Evaluates given value
|
148
|
-
#
|
149
|
-
# *Parameters:*
|
150
|
-
# * +value+ - Value to be evaluated
|
151
|
-
#
|
152
|
-
|
153
|
-
def ri(value)
|
154
|
-
raise value.inspect
|
155
|
-
end
|
156
|
-
|
157
|
-
private
|
158
|
-
|
159
|
-
def browser?(*browser_aliases)
|
160
|
-
if sauce_driver?
|
161
|
-
log.error Howitzer::SlBrowserNotSpecifiedError, CHECK_YOUR_SETTINGS_MSG if settings.sl_browser_name.nil?
|
162
|
-
browser_aliases.include?(settings.sl_browser_name.to_s.to_sym)
|
163
|
-
elsif testingbot_driver?
|
164
|
-
log.error Howitzer::TbBrowserNotSpecifiedError, CHECK_YOUR_SETTINGS_MSG if settings.tb_browser_name.nil?
|
165
|
-
browser_aliases.include?(settings.tb_browser_name.to_s.to_sym)
|
166
|
-
elsif selenium_driver? || selenium_grid_driver?
|
167
|
-
log.error Howitzer::SelBrowserNotSpecifiedError, CHECK_YOUR_SETTINGS_MSG if settings.sel_browser.nil?
|
168
|
-
browser_aliases.include?(settings.sel_browser.to_s.to_sym)
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
end
|
173
|
-
|
174
|
-
include Helpers
|
175
|
-
|
176
|
-
class String
|
177
|
-
|
178
|
-
##
|
179
|
-
#
|
180
|
-
# Delegates WebPage.open method. Useful in cucumber step definitions
|
181
|
-
#
|
182
|
-
# *Parameters:*
|
183
|
-
# * +*args+ - Url to be opened
|
184
|
-
#
|
185
|
-
|
186
|
-
def open(*args)
|
187
|
-
as_page_class.open(*args)
|
188
|
-
end
|
189
|
-
|
190
|
-
##
|
191
|
-
#
|
192
|
-
# Returns page instance
|
193
|
-
#
|
194
|
-
|
195
|
-
def given
|
196
|
-
as_page_class.given
|
197
|
-
end
|
198
|
-
|
199
|
-
##
|
200
|
-
#
|
201
|
-
# Waits until page is opened or raise error
|
202
|
-
#
|
203
|
-
|
204
|
-
def wait_for_opened
|
205
|
-
as_page_class.wait_for_opened
|
206
|
-
end
|
207
|
-
|
208
|
-
##
|
209
|
-
#
|
210
|
-
# Returns page class
|
211
|
-
#
|
212
|
-
|
213
|
-
def as_page_class
|
214
|
-
as_class('Page')
|
215
|
-
end
|
216
|
-
|
217
|
-
##
|
218
|
-
#
|
219
|
-
# Returns email class
|
220
|
-
#
|
221
|
-
|
222
|
-
def as_email_class
|
223
|
-
as_class('Email')
|
224
|
-
end
|
225
|
-
|
226
|
-
private
|
227
|
-
def as_class(type)
|
228
|
-
"#{self.gsub(/\s/, '_').camelize}#{type}".constantize
|
229
|
-
end
|
230
|
-
end
|
data/lib/howitzer/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
include DataGenerator
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'rest_client'
|
2
|
-
require 'json'
|
3
|
-
require 'howitzer/mailgun/response'
|
4
|
-
require 'howitzer/exceptions'
|
5
|
-
|
6
|
-
module Mailgun
|
7
|
-
|
8
|
-
# A Mailgun::Client object is used to communicate with the Mailgun API. It is a
|
9
|
-
# wrapper around RestClient so you don't have to worry about the HTTP aspect
|
10
|
-
# of communicating with our API.
|
11
|
-
|
12
|
-
class Client
|
13
|
-
attr_reader :api_key
|
14
|
-
|
15
|
-
def initialize(api_key, api_host="api.mailgun.net", api_version="v3", ssl=true)
|
16
|
-
endpoint = endpoint_generator(api_host, api_version, ssl)
|
17
|
-
@api_key = api_key
|
18
|
-
@http_client = RestClient::Resource.new(endpoint,
|
19
|
-
:user => "api",
|
20
|
-
:password => api_key,
|
21
|
-
:user_agent => "mailgun-sdk-ruby/1.0.1")
|
22
|
-
end
|
23
|
-
|
24
|
-
# Generic Mailgun GET Handler
|
25
|
-
#
|
26
|
-
# @param [String] resource_path This is the API resource you wish to interact
|
27
|
-
# with. Be sure to include your domain, where necessary.
|
28
|
-
# @param [Hash] params This should be a standard Hash for query
|
29
|
-
# containing required parameters for the requested resource.
|
30
|
-
# @return [Mailgun::Response] A Mailgun::Response object.
|
31
|
-
|
32
|
-
def get(resource_path, params=nil, accept="*/*")
|
33
|
-
http_params = {:accept => accept}
|
34
|
-
http_params = http_params.merge(params: params) if params
|
35
|
-
response = @http_client[resource_path].get(http_params)
|
36
|
-
Response.new(response)
|
37
|
-
rescue => e
|
38
|
-
log.error Howitzer::CommunicationError, e.message
|
39
|
-
end
|
40
|
-
|
41
|
-
def get_url(url, params=nil, accept="*/*")
|
42
|
-
response = ::RestClient::Request.execute(
|
43
|
-
method: :get,
|
44
|
-
url: url,
|
45
|
-
user: 'api',
|
46
|
-
password: api_key,
|
47
|
-
user_agent: 'mailgun-sdk-ruby',
|
48
|
-
accept: accept,
|
49
|
-
params: params
|
50
|
-
)
|
51
|
-
Response.new(response)
|
52
|
-
rescue => e
|
53
|
-
log.error Howitzer::CommunicationError, e.message
|
54
|
-
end
|
55
|
-
|
56
|
-
private
|
57
|
-
|
58
|
-
def endpoint_generator(api_host, api_version, ssl)
|
59
|
-
scheme = "http#{'s' if ssl}"
|
60
|
-
res = "#{scheme}://#{api_host}"
|
61
|
-
res << "/#{api_version}" if api_version
|
62
|
-
res
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'singleton'
|
2
|
-
require 'howitzer/mailgun/client'
|
3
|
-
require 'howitzer/exceptions'
|
4
|
-
|
5
|
-
module Mailgun
|
6
|
-
class Connector
|
7
|
-
include Singleton
|
8
|
-
|
9
|
-
attr_reader :api_key
|
10
|
-
|
11
|
-
def client(api_key=settings.mailgun_key)
|
12
|
-
check_api_key(api_key)
|
13
|
-
if @api_key == api_key && @api_key
|
14
|
-
@client
|
15
|
-
else
|
16
|
-
@api_key = api_key
|
17
|
-
@client = Mailgun::Client.new(@api_key)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def domain
|
22
|
-
@domain || change_domain
|
23
|
-
end
|
24
|
-
|
25
|
-
def change_domain(domain_name=settings.mailgun_domain)
|
26
|
-
@domain = domain_name
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
def check_api_key(api_key)
|
31
|
-
log.error Howitzer::InvalidApiKeyError, "Api key can not be blank" if api_key.blank?
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'howitzer/exceptions'
|
2
|
-
|
3
|
-
module Mailgun
|
4
|
-
# A Mailgun::Response object is instantiated for each response generated
|
5
|
-
# by the Client request. The Response object supports deserialization of
|
6
|
-
# the JSON result.
|
7
|
-
|
8
|
-
class Response
|
9
|
-
|
10
|
-
attr_accessor :body
|
11
|
-
attr_accessor :code
|
12
|
-
|
13
|
-
def initialize(response)
|
14
|
-
@body = response.body
|
15
|
-
@code = response.code
|
16
|
-
end
|
17
|
-
|
18
|
-
# Return response as Ruby Hash
|
19
|
-
#
|
20
|
-
# @return [Hash] A standard Ruby Hash containing the HTTP result.
|
21
|
-
|
22
|
-
def to_h
|
23
|
-
JSON.parse(@body)
|
24
|
-
rescue Exception => e
|
25
|
-
log.error Howitzer::ParseError, e.message
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,86 +0,0 @@
|
|
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
|