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/utils/log.rb
DELETED
@@ -1,139 +0,0 @@
|
|
1
|
-
require 'log4r'
|
2
|
-
require 'fileutils'
|
3
|
-
|
4
|
-
module Howitzer
|
5
|
-
class Log
|
6
|
-
include Singleton
|
7
|
-
include Log4r
|
8
|
-
|
9
|
-
[:debug, :info, :warn, :fatal].each do |method_name|
|
10
|
-
define_method method_name do |text|
|
11
|
-
@logger.send(method_name, text)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
##
|
16
|
-
#
|
17
|
-
# Prints log entry about error with ERROR severity
|
18
|
-
# *Examples:*
|
19
|
-
# log.error MyException, 'Some error text', caller
|
20
|
-
# log.error 'Some error text', caller
|
21
|
-
# log.error MyException, 'Some caller text'
|
22
|
-
# log.error 'Some error text'
|
23
|
-
# log.error err_object
|
24
|
-
#
|
25
|
-
# *Parameters:*
|
26
|
-
# * +args+ - see example
|
27
|
-
#
|
28
|
-
|
29
|
-
def error(*args)
|
30
|
-
object = if args.first.nil?
|
31
|
-
$!
|
32
|
-
else
|
33
|
-
case args.size
|
34
|
-
when 1
|
35
|
-
args.first.is_a?(Exception) ? args.first : RuntimeError.new(args.first)
|
36
|
-
when 2
|
37
|
-
if args.first.is_a?(Class) && args.first < Exception
|
38
|
-
args.first.new(args.last)
|
39
|
-
else
|
40
|
-
exception = RuntimeError.new(args.first)
|
41
|
-
exception.set_backtrace(args.last)
|
42
|
-
exception
|
43
|
-
end
|
44
|
-
when 3
|
45
|
-
exception = args.first.new(args[1])
|
46
|
-
exception.set_backtrace(args.last)
|
47
|
-
exception
|
48
|
-
#:nocov:
|
49
|
-
else nil
|
50
|
-
#:nocov:
|
51
|
-
end
|
52
|
-
end
|
53
|
-
err_backtrace = object.backtrace ? "\n\t#{object.backtrace.join("\n\t")}" : nil
|
54
|
-
@logger.error("[#{object.class}] #{object.message}#{err_backtrace}")
|
55
|
-
fail(object)
|
56
|
-
end
|
57
|
-
|
58
|
-
##
|
59
|
-
#
|
60
|
-
# Prints feature name into log with INFO severity
|
61
|
-
#
|
62
|
-
# *Parameters:*
|
63
|
-
# * +text+ - Feature name
|
64
|
-
#
|
65
|
-
|
66
|
-
def print_feature_name(text)
|
67
|
-
log_without_formatting{ info "*** Feature: #{text.upcase} ***" }
|
68
|
-
end
|
69
|
-
|
70
|
-
##
|
71
|
-
#
|
72
|
-
# Returns formatted howitzer settings
|
73
|
-
#
|
74
|
-
|
75
|
-
def settings_as_formatted_text
|
76
|
-
log_without_formatting{ info settings.as_formatted_text }
|
77
|
-
end
|
78
|
-
|
79
|
-
##
|
80
|
-
#
|
81
|
-
# Prints scenario name into log with INFO severity
|
82
|
-
#
|
83
|
-
# *Parameters:*
|
84
|
-
# * +text+ - Scenario name
|
85
|
-
#
|
86
|
-
def print_scenario_name(text)
|
87
|
-
log_without_formatting{ info " => Scenario: #{text}" }
|
88
|
-
end
|
89
|
-
|
90
|
-
private
|
91
|
-
|
92
|
-
def initialize
|
93
|
-
@logger = Logger.new("ruby_log")
|
94
|
-
@logger.add(console_log)
|
95
|
-
@logger.add(error_log)
|
96
|
-
@logger.add(txt_log) if !settings.log_dir.to_s.empty? && !settings.txt_log.to_s.empty?
|
97
|
-
self.base_formatter = default_formatter
|
98
|
-
Logger["ruby_log"].level = settings.debug_mode ? ALL : INFO
|
99
|
-
Logger["ruby_log"].trace = true
|
100
|
-
end
|
101
|
-
|
102
|
-
def log_without_formatting
|
103
|
-
self.base_formatter = blank_formatter
|
104
|
-
yield
|
105
|
-
self.base_formatter = default_formatter
|
106
|
-
end
|
107
|
-
|
108
|
-
def console_log
|
109
|
-
StdoutOutputter.new(:console).tap{|o| o.only_at(INFO, DEBUG, WARN)}
|
110
|
-
end
|
111
|
-
|
112
|
-
def error_log
|
113
|
-
StderrOutputter.new(:error, 'level' => ERROR)
|
114
|
-
end
|
115
|
-
|
116
|
-
def txt_log
|
117
|
-
FileUtils.mkdir_p(settings.log_dir) unless File.exists?(settings.log_dir)
|
118
|
-
filename = File.join(settings.log_dir, settings.txt_log)
|
119
|
-
FileOutputter.new(:txt_log, :filename => filename, :trunc => true)
|
120
|
-
end
|
121
|
-
|
122
|
-
def blank_formatter
|
123
|
-
PatternFormatter.new(:pattern => "%m")
|
124
|
-
end
|
125
|
-
|
126
|
-
def default_formatter
|
127
|
-
if settings.hide_datetime_from_log
|
128
|
-
params = {pattern: "[%l] %m"}
|
129
|
-
else
|
130
|
-
params = {pattern: "%d [%l] :: %m", date_pattern: "%Y/%m/%d %H:%M:%S"}
|
131
|
-
end
|
132
|
-
PatternFormatter.new(params)
|
133
|
-
end
|
134
|
-
|
135
|
-
def base_formatter=(formatter)
|
136
|
-
@logger.outputters.each {|outputter| outputter.formatter = formatter}
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
@@ -1,133 +0,0 @@
|
|
1
|
-
require 'howitzer/exceptions'
|
2
|
-
|
3
|
-
module Howitzer
|
4
|
-
module Utils
|
5
|
-
module PageValidator
|
6
|
-
@validations = {}
|
7
|
-
|
8
|
-
def self.included(base) #:nodoc:
|
9
|
-
base.extend(ClassMethods)
|
10
|
-
end
|
11
|
-
|
12
|
-
##
|
13
|
-
#
|
14
|
-
# Returns validation list
|
15
|
-
#
|
16
|
-
# @return [Hash]
|
17
|
-
#
|
18
|
-
def self.validations
|
19
|
-
@validations
|
20
|
-
end
|
21
|
-
|
22
|
-
##
|
23
|
-
#
|
24
|
-
# Returns page list
|
25
|
-
#
|
26
|
-
# @return [Array]
|
27
|
-
#
|
28
|
-
def self.pages
|
29
|
-
@pages ||= []
|
30
|
-
end
|
31
|
-
|
32
|
-
##
|
33
|
-
# Check if any validations are defined, if no, tries to find old style, else raise error
|
34
|
-
#
|
35
|
-
# @raise [Howitzer::NoValidationError] If no one validation is defined for page
|
36
|
-
#
|
37
|
-
|
38
|
-
def check_validations_are_defined!
|
39
|
-
if validations.nil? && !old_url_validation_present?
|
40
|
-
log.error Howitzer::NoValidationError, "No any page validation was found for '#{self.class.name}' page"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
def validations
|
47
|
-
PageValidator.validations[self.class.name]
|
48
|
-
end
|
49
|
-
|
50
|
-
def old_url_validation_present?
|
51
|
-
if self.class.const_defined?("URL_PATTERN")
|
52
|
-
self.class.validates :url, pattern: self.class.const_get("URL_PATTERN")
|
53
|
-
warn "[Deprecated] Old style page validation is using. Please use new style:\n\t validates :url, pattern: URL_PATTERN"
|
54
|
-
true
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
module ClassMethods
|
59
|
-
|
60
|
-
##
|
61
|
-
#
|
62
|
-
# Adds validation to validation list
|
63
|
-
#
|
64
|
-
# @param [Symbol or String] name Which validation type. Possible values [:url, :element_presence, :title]
|
65
|
-
# @option options [Hash] Validation options
|
66
|
-
# :pattern => [Regexp] For :url and :title validation types
|
67
|
-
# :locator => [String] For :element_presence (Existing locator name)
|
68
|
-
# @raise [Howitzer::UnknownValidationError] If unknown validation type was passed
|
69
|
-
#
|
70
|
-
def validates(name, options)
|
71
|
-
log.error TypeError, "Expected options to be Hash, actual is '#{options.class}'" unless options.class == Hash
|
72
|
-
PageValidator.validations[self.name] ||= {}
|
73
|
-
case name.to_s.to_sym
|
74
|
-
when :url
|
75
|
-
validate_by_pattern(:url, options)
|
76
|
-
when :element_presence
|
77
|
-
validate_element options
|
78
|
-
when :title
|
79
|
-
validate_by_pattern(:title, options)
|
80
|
-
else
|
81
|
-
log.error Howitzer::UnknownValidationError, "unknown '#{name}' validation name"
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
##
|
86
|
-
# Check whether page is opened or no
|
87
|
-
#
|
88
|
-
# @raise [Howitzer::NoValidationError] If no one validation is defined for page
|
89
|
-
#
|
90
|
-
# *Returns:*
|
91
|
-
# * +boolean+
|
92
|
-
#
|
93
|
-
|
94
|
-
def opened?
|
95
|
-
validation_list = PageValidator.validations[self.name]
|
96
|
-
if validation_list.blank?
|
97
|
-
log.error Howitzer::NoValidationError, "No any page validation was found for '#{self.name}' page"
|
98
|
-
else
|
99
|
-
!validation_list.any? {|(_, validation)| !validation.call(self)}
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
##
|
104
|
-
#
|
105
|
-
# Finds all matched pages which are satisfy of defined validations
|
106
|
-
#
|
107
|
-
# *Returns:*
|
108
|
-
# * +array+ - page names
|
109
|
-
#
|
110
|
-
|
111
|
-
def matched_pages
|
112
|
-
PageValidator.pages.select{|klass| klass.opened? }
|
113
|
-
end
|
114
|
-
|
115
|
-
private
|
116
|
-
|
117
|
-
def validate_element(options)
|
118
|
-
locator = options[:locator] || options["locator"]
|
119
|
-
log.error Howitzer::WrongOptionError, "Please specify ':locator' option as one of page locator names" if locator.nil? || locator.empty?
|
120
|
-
PageValidator.validations[self.name][:element_presence] = lambda { |web_page| web_page.first_element(locator) }
|
121
|
-
end
|
122
|
-
|
123
|
-
def validate_by_pattern(name, options)
|
124
|
-
pattern = options[:pattern] || options["pattern"]
|
125
|
-
log.error Howitzer::WrongOptionError, "Please specify ':pattern' option as Regexp object" if pattern.nil? || !pattern.is_a?(Regexp)
|
126
|
-
PageValidator.validations[self.name][name] = lambda { |web_page| pattern === web_page.send(name) }
|
127
|
-
end
|
128
|
-
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
end
|
133
|
-
end
|
Binary file
|
Binary file
|
data/lib/howitzer/web_page.rb
DELETED
@@ -1,253 +0,0 @@
|
|
1
|
-
require 'singleton'
|
2
|
-
require 'rspec/expectations'
|
3
|
-
require 'howitzer/utils/locator_store'
|
4
|
-
require 'howitzer/utils/page_validator'
|
5
|
-
require 'howitzer/capybara/dsl_ex'
|
6
|
-
require 'howitzer/exceptions'
|
7
|
-
|
8
|
-
class WebPage
|
9
|
-
|
10
|
-
BLANK_PAGE = 'about:blank' # @deprecated , use BlankPage instead
|
11
|
-
UnknownPage = Class.new
|
12
|
-
|
13
|
-
include LocatorStore
|
14
|
-
include Howitzer::Utils::PageValidator
|
15
|
-
include RSpec::Matchers
|
16
|
-
include Howitzer::Capybara::DslEx
|
17
|
-
extend Howitzer::Capybara::DslEx
|
18
|
-
include Singleton
|
19
|
-
|
20
|
-
def self.inherited(subclass)
|
21
|
-
subclass.class_eval { include Singleton }
|
22
|
-
Howitzer::Utils::PageValidator.pages << subclass
|
23
|
-
end
|
24
|
-
|
25
|
-
##
|
26
|
-
#
|
27
|
-
# Opens web-site by given url
|
28
|
-
#
|
29
|
-
# *Parameters:*
|
30
|
-
# * +url+ - Url string that will be opened
|
31
|
-
#
|
32
|
-
# *Returns:*
|
33
|
-
# * +WebPage+ - New instance of current class
|
34
|
-
#
|
35
|
-
|
36
|
-
def self.open(url = "#{app_url unless self == BlankPage}#{self::URL}")
|
37
|
-
log.info "Open #{self.name} page by '#{url}' url"
|
38
|
-
retryable(tries: 2, logger: log, trace: true, on: Exception) do |retries|
|
39
|
-
log.info 'Retry...' unless retries.zero?
|
40
|
-
visit url
|
41
|
-
end
|
42
|
-
given
|
43
|
-
end
|
44
|
-
|
45
|
-
##
|
46
|
-
#
|
47
|
-
# Returns singleton instance of current web page
|
48
|
-
#
|
49
|
-
# *Returns:*
|
50
|
-
# * +WebPage+ - Singleton instance
|
51
|
-
#
|
52
|
-
|
53
|
-
def self.given
|
54
|
-
wait_for_opened
|
55
|
-
self.instance
|
56
|
-
end
|
57
|
-
|
58
|
-
##
|
59
|
-
#
|
60
|
-
# Returns current url
|
61
|
-
#
|
62
|
-
# *Returns:*
|
63
|
-
# * +string+ - Current url
|
64
|
-
#
|
65
|
-
|
66
|
-
def self.url
|
67
|
-
self.current_url
|
68
|
-
end
|
69
|
-
|
70
|
-
##
|
71
|
-
#
|
72
|
-
# Returns body text of html page
|
73
|
-
#
|
74
|
-
# *Returns:*
|
75
|
-
# * +string+ - Body text
|
76
|
-
#
|
77
|
-
|
78
|
-
def self.text
|
79
|
-
page.find('body').text
|
80
|
-
end
|
81
|
-
|
82
|
-
##
|
83
|
-
#
|
84
|
-
# Tries to identify current page name or raise error if ambiguous page matching
|
85
|
-
#
|
86
|
-
# *Returns:*
|
87
|
-
# * +string+ - page name
|
88
|
-
#
|
89
|
-
|
90
|
-
def self.current_page
|
91
|
-
page_list = matched_pages
|
92
|
-
if page_list.count.zero?
|
93
|
-
UnknownPage
|
94
|
-
elsif page_list.count > 1
|
95
|
-
log.error Howitzer::AmbiguousPageMatchingError,
|
96
|
-
"Current page matches more that one page class (#{page_list.join(', ')}).\n\tCurrent url: #{current_url}\n\tCurrent title: #{title}"
|
97
|
-
elsif page_list.count == 1
|
98
|
-
page_list.first
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
##
|
103
|
-
#
|
104
|
-
# Waits until web page is not opened, or raise error after timeout
|
105
|
-
#
|
106
|
-
# *Parameters:*
|
107
|
-
# * +time_out+ - Seconds that will be waiting for web page to be loaded
|
108
|
-
#
|
109
|
-
|
110
|
-
def self.wait_for_opened(timeout=settings.timeout_small)
|
111
|
-
end_time = ::Time.now + timeout
|
112
|
-
until ::Time.now > end_time
|
113
|
-
self.opened? ? return : sleep(0.5)
|
114
|
-
end
|
115
|
-
log.error Howitzer::IncorrectPageError, "Current page: #{self.current_page}, expected: #{self}.\n\tCurrent url: #{current_url}\n\tCurrent title: #{title}"
|
116
|
-
end
|
117
|
-
|
118
|
-
def initialize
|
119
|
-
check_validations_are_defined!
|
120
|
-
page.driver.browser.manage.window.maximize if settings.maximized_window
|
121
|
-
end
|
122
|
-
|
123
|
-
##
|
124
|
-
#
|
125
|
-
# Fills in field that using Tinymce API
|
126
|
-
#
|
127
|
-
# *Parameters:*
|
128
|
-
# * +name+ - Frame name that contains Tinymce field
|
129
|
-
# * +Hash+ - Not required options
|
130
|
-
#
|
131
|
-
|
132
|
-
def tinymce_fill_in(name, options = {})
|
133
|
-
if %w[selenium selenium_dev sauce].include? settings.driver
|
134
|
-
page.driver.browser.switch_to.frame("#{name}_ifr")
|
135
|
-
page.find(:css, '#tinymce').native.send_keys(options[:with])
|
136
|
-
page.driver.browser.switch_to.default_content
|
137
|
-
else
|
138
|
-
page.execute_script("tinyMCE.get('#{name}').setContent('#{options[:with]}')")
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
##
|
143
|
-
#
|
144
|
-
# Accepts or declines JS alert box by given flag
|
145
|
-
#
|
146
|
-
# *Parameters:*
|
147
|
-
# * +flag+ [TrueClass,FalseClass] - Determines accept or decline alert box
|
148
|
-
#
|
149
|
-
|
150
|
-
def click_alert_box(flag)
|
151
|
-
if %w[selenium selenium_dev sauce].include? settings.driver
|
152
|
-
if flag
|
153
|
-
page.driver.browser.switch_to.alert.accept
|
154
|
-
else
|
155
|
-
page.driver.browser.switch_to.alert.dismiss
|
156
|
-
end
|
157
|
-
else
|
158
|
-
if flag
|
159
|
-
page.evaluate_script('window.confirm = function() { return true; }')
|
160
|
-
else
|
161
|
-
page.evaluate_script('window.confirm = function() { return false; }')
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
##
|
167
|
-
#
|
168
|
-
# Clicks on button or link using JS event call
|
169
|
-
#
|
170
|
-
# *Parameters:*
|
171
|
-
# * +css_locator+ - Css locator of link or button
|
172
|
-
#
|
173
|
-
|
174
|
-
def js_click(css_locator)
|
175
|
-
page.execute_script("$('#{css_locator}').trigger('click')")
|
176
|
-
sleep settings.timeout_tiny
|
177
|
-
end
|
178
|
-
|
179
|
-
# @deprecated
|
180
|
-
# With Capybara 2.x it is extra
|
181
|
-
#:nocov:
|
182
|
-
def wait_for_ajax(timeout=settings.timeout_small, message=nil)
|
183
|
-
end_time = ::Time.now + timeout
|
184
|
-
until ::Time.now > end_time
|
185
|
-
return true if page.evaluate_script('$.active') == 0
|
186
|
-
sleep 0.25
|
187
|
-
end
|
188
|
-
log.error message || 'Timed out waiting for ajax requests to complete'
|
189
|
-
end
|
190
|
-
#:nocov:
|
191
|
-
|
192
|
-
##
|
193
|
-
# @deprecated
|
194
|
-
#
|
195
|
-
# Waits until web page is loaded
|
196
|
-
#
|
197
|
-
# *Parameters:*
|
198
|
-
# * +expected_url+ - Url that will be waiting for
|
199
|
-
# * +time_out+ - Seconds that will be waiting for web-site to be loaded until raise error
|
200
|
-
#
|
201
|
-
|
202
|
-
def wait_for_url(expected_url, timeout=settings.timeout_small)
|
203
|
-
warn '[Deprecated] This method is deprecated, and will be removed in next version of Howitzer'
|
204
|
-
end_time = ::Time.now + timeout
|
205
|
-
until ::Time.now > end_time
|
206
|
-
operator = expected_url.is_a?(Regexp) ? :=~ : :==
|
207
|
-
return true if current_url.send(operator, expected_url).tap{|res| sleep 1 unless res}
|
208
|
-
end
|
209
|
-
log.error Howitzer::IncorrectPageError, "Current url: #{current_url}, expected: #{expected_url}"
|
210
|
-
end
|
211
|
-
|
212
|
-
##
|
213
|
-
# @deprecated
|
214
|
-
#
|
215
|
-
# Waits until web is loaded with expected title
|
216
|
-
#
|
217
|
-
# *Parameters:*
|
218
|
-
# * +expected_title+ - Page title that will be waited for
|
219
|
-
# * +time_out+ - Seconds that will be waiting for web-site to be loaded until raise error
|
220
|
-
#
|
221
|
-
|
222
|
-
def wait_for_title(expected_title, timeout=settings.timeout_small)
|
223
|
-
warn '[Deprecated] This method is deprecated, and will be removed in next version of Howitzer'
|
224
|
-
end_time = ::Time.now + timeout
|
225
|
-
until ::Time.now > end_time
|
226
|
-
operator = expected_title.is_a?(Regexp) ? :=~ : :==
|
227
|
-
return true if title.send(operator, expected_title).tap{|res| sleep 1 unless res}
|
228
|
-
end
|
229
|
-
log.error Howitzer::IncorrectPageError, "Current title: #{title}, expected: #{expected_title}"
|
230
|
-
end
|
231
|
-
|
232
|
-
##
|
233
|
-
#
|
234
|
-
# Reloads current page
|
235
|
-
#
|
236
|
-
|
237
|
-
def reload
|
238
|
-
log.info "Reload '#{current_url}'"
|
239
|
-
visit current_url
|
240
|
-
end
|
241
|
-
|
242
|
-
##
|
243
|
-
#
|
244
|
-
# Returns Page title
|
245
|
-
#
|
246
|
-
# *Returns:*
|
247
|
-
# * +string+ - Page title
|
248
|
-
#
|
249
|
-
|
250
|
-
def title
|
251
|
-
page.title
|
252
|
-
end
|
253
|
-
end
|