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/settings.rb
DELETED
@@ -1,27 +0,0 @@
|
|
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,88 +0,0 @@
|
|
1
|
-
module DataGenerator
|
2
|
-
|
3
|
-
##
|
4
|
-
#
|
5
|
-
# Data can be stored in memory using DataStorage
|
6
|
-
#
|
7
|
-
|
8
|
-
module DataStorage
|
9
|
-
SPECIAL_NS_LIST = ['sauce']
|
10
|
-
@data ||= {}
|
11
|
-
|
12
|
-
class << self
|
13
|
-
attr_reader :data
|
14
|
-
##
|
15
|
-
#
|
16
|
-
# Saves data into memory. Marking by namespace and key
|
17
|
-
#
|
18
|
-
# *Parameters:*
|
19
|
-
# * +ns+ - Namespace
|
20
|
-
# * +key+ - Key that should be uniq in namespace
|
21
|
-
# * +value+ - Data value
|
22
|
-
#
|
23
|
-
|
24
|
-
|
25
|
-
def store(ns, key, value)
|
26
|
-
check_ns(ns)
|
27
|
-
@data[ns][key] = value
|
28
|
-
end
|
29
|
-
|
30
|
-
##
|
31
|
-
#
|
32
|
-
# Gets data from memory. Can get all namespace or single data value in namespace using key
|
33
|
-
#
|
34
|
-
# *Parameters:*
|
35
|
-
# * +ns+ - Namespace
|
36
|
-
# * +key+ - Key that isn't necessary required (default to: nil)
|
37
|
-
#
|
38
|
-
|
39
|
-
def extract(ns, key=nil)
|
40
|
-
check_ns(ns)
|
41
|
-
key ? @data[ns][key] : @data[ns]
|
42
|
-
end
|
43
|
-
|
44
|
-
##
|
45
|
-
#
|
46
|
-
# Deletes all records from namespace
|
47
|
-
#
|
48
|
-
# *Parameters:*
|
49
|
-
# * +ns+ - Namespace
|
50
|
-
#
|
51
|
-
|
52
|
-
def clear_ns(ns)
|
53
|
-
init_ns(ns)
|
54
|
-
end
|
55
|
-
|
56
|
-
##
|
57
|
-
#
|
58
|
-
# Deletes all namespaces with data
|
59
|
-
#
|
60
|
-
# *Parameters:*
|
61
|
-
# * +exception_list+ - Array of special namespaces for excluding
|
62
|
-
#
|
63
|
-
|
64
|
-
def clear_all_ns(exception_list=SPECIAL_NS_LIST)
|
65
|
-
(@data.keys - exception_list).each {|ns| clear_ns(ns) }
|
66
|
-
end
|
67
|
-
|
68
|
-
private
|
69
|
-
|
70
|
-
def check_ns(ns)
|
71
|
-
if ns
|
72
|
-
init_ns(ns) if ns_absent?(ns)
|
73
|
-
else
|
74
|
-
log.error 'Data storage namespace can not be empty'
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def ns_absent?(ns)
|
79
|
-
!@data.key?(ns)
|
80
|
-
end
|
81
|
-
|
82
|
-
def init_ns(ns)
|
83
|
-
@data[ns] = {}
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
@@ -1,135 +0,0 @@
|
|
1
|
-
module DataGenerator
|
2
|
-
module Gen
|
3
|
-
|
4
|
-
##
|
5
|
-
#
|
6
|
-
# This module generates uniq User object with uniq generated data.
|
7
|
-
# Examples:
|
8
|
-
# member = Gen::user #user.email: 'u<XXXX>@<settings.mail_pop3_domain>'
|
9
|
-
# member = Gen::user('user@test.com') #user.email: 'member@test.com'
|
10
|
-
# member = Gen::user(settings.def_test_user) #user.email: settings.def_test_user
|
11
|
-
|
12
|
-
class << self
|
13
|
-
|
14
|
-
##
|
15
|
-
#
|
16
|
-
# Generates new User object with generated data.
|
17
|
-
#
|
18
|
-
# *Parameters:*
|
19
|
-
# * +params+ - Custom parameters
|
20
|
-
#
|
21
|
-
# *Returns:*
|
22
|
-
# * +user+ - New generated User object
|
23
|
-
#
|
24
|
-
|
25
|
-
|
26
|
-
def user(params={})
|
27
|
-
prefix = serial
|
28
|
-
default = {
|
29
|
-
email: gen_user_email(prefix),
|
30
|
-
login: nil,
|
31
|
-
first_name: gen_first_name(prefix),
|
32
|
-
last_name: gen_last_name(prefix),
|
33
|
-
password: settings.def_test_pass
|
34
|
-
}
|
35
|
-
User.new(default.merge(params))
|
36
|
-
end
|
37
|
-
|
38
|
-
##
|
39
|
-
#
|
40
|
-
# Gets User object by it's number
|
41
|
-
#
|
42
|
-
# *Parameters:*
|
43
|
-
# * +num+ - User number
|
44
|
-
#
|
45
|
-
# *Returns:*
|
46
|
-
# * +user+ - User object
|
47
|
-
#
|
48
|
-
|
49
|
-
def given_user_by_number(num)
|
50
|
-
data = DataStorage.extract('user', num.to_i)
|
51
|
-
unless data
|
52
|
-
data = Gen::user
|
53
|
-
DataStorage.store('user', num.to_i, data)
|
54
|
-
end
|
55
|
-
data
|
56
|
-
end
|
57
|
-
|
58
|
-
##
|
59
|
-
#
|
60
|
-
# Generates uniq string
|
61
|
-
# @return [String] Generated string
|
62
|
-
#
|
63
|
-
# *Returns:*
|
64
|
-
# * +string+ - Generated string
|
65
|
-
#
|
66
|
-
|
67
|
-
def serial
|
68
|
-
a = [('a'..'z').to_a, (0..9).to_a].flatten.shuffle
|
69
|
-
"#{Time.now.utc.strftime("%j%H%M%S")}#{a[0..4].join}"
|
70
|
-
end
|
71
|
-
|
72
|
-
##
|
73
|
-
#
|
74
|
-
# Deletes mailboxes for all users that were generated before
|
75
|
-
#@deprecated
|
76
|
-
|
77
|
-
#:nocov:
|
78
|
-
def delete_all_mailboxes
|
79
|
-
warn "[WARN] Method '#{__method__}' has not been using anymore. You have to remove usage from here #{caller.first}"
|
80
|
-
end
|
81
|
-
#:nocov:
|
82
|
-
|
83
|
-
private
|
84
|
-
|
85
|
-
def gen_user_email(serial=nil)
|
86
|
-
"#{gen_user_name(serial)}@#{settings.mailgun_domain}"
|
87
|
-
end
|
88
|
-
|
89
|
-
def gen_user_name(serial=nil)
|
90
|
-
gen_entity('u', serial)
|
91
|
-
end
|
92
|
-
|
93
|
-
def gen_first_name(serial=nil)
|
94
|
-
gen_entity('FirstName', serial)
|
95
|
-
end
|
96
|
-
|
97
|
-
def gen_last_name(serial=nil)
|
98
|
-
gen_entity('LastName', serial)
|
99
|
-
end
|
100
|
-
|
101
|
-
def gen_entity(prefix, serial)
|
102
|
-
"#{prefix}#{serial.nil? ? self.serial : serial}"
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
class User < Object
|
107
|
-
|
108
|
-
attr_reader :login, :domain, :email, :password, :first_name, :last_name, :full_name
|
109
|
-
|
110
|
-
def initialize(params={})
|
111
|
-
@email = params.delete(:email)
|
112
|
-
@email_name, @domain = @email.to_s.split('@')
|
113
|
-
@login = params.delete(:login) || @email_name
|
114
|
-
@password = params.delete(:password)
|
115
|
-
@first_name = params.delete(:first_name)
|
116
|
-
@last_name = params.delete(:last_name)
|
117
|
-
@full_name = "#@first_name #@last_name"
|
118
|
-
end
|
119
|
-
|
120
|
-
#@deprecated
|
121
|
-
#:nocov:
|
122
|
-
def create_mailbox
|
123
|
-
warn "[WARN] Method '#{__method__}' has not been using anymore. You have to remove usage from here #{caller.first}"
|
124
|
-
end
|
125
|
-
#:nocov:
|
126
|
-
|
127
|
-
#@deprecated
|
128
|
-
#:nocov:
|
129
|
-
def delete_mailbox
|
130
|
-
warn "[WARN] Method '#{__method__}' has not been using anymore. You have to remove usage from here #{caller.first}"
|
131
|
-
end
|
132
|
-
#:nocov:
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
@@ -1,217 +0,0 @@
|
|
1
|
-
require 'howitzer/exceptions'
|
2
|
-
|
3
|
-
#The following are locator aliases:
|
4
|
-
#
|
5
|
-
#1) locator
|
6
|
-
#Type: :css(by default), :xpath
|
7
|
-
#Method example: find, all, first
|
8
|
-
#
|
9
|
-
#2) link_locator
|
10
|
-
#Type: id, text
|
11
|
-
#Method example: click_link, find_link
|
12
|
-
#
|
13
|
-
#3) button_locator
|
14
|
-
#Type: id, name, value
|
15
|
-
#Method example: click_button, find_button
|
16
|
-
#
|
17
|
-
#4) field_locator
|
18
|
-
#Type: name, id, text
|
19
|
-
#Method example: find_field, fill_in
|
20
|
-
|
21
|
-
|
22
|
-
module LocatorStore
|
23
|
-
|
24
|
-
def self.included(base)
|
25
|
-
base.extend(ClassMethods)
|
26
|
-
end
|
27
|
-
|
28
|
-
module ClassMethods
|
29
|
-
LOCATOR_TYPES = [:base, :link, :field, :button]
|
30
|
-
|
31
|
-
##
|
32
|
-
#
|
33
|
-
# Adds css or xpath locator into LocatorStore.
|
34
|
-
# Also locator can be set by lambda expression. For example: lambda{|name|{xpath: ".//a[@id='#{name}']"}}
|
35
|
-
#
|
36
|
-
# *Parameters:*
|
37
|
-
# * +name+ - Locator name
|
38
|
-
# * +params+ - String for css locator or hash with :xpath key and string value for xpath locator
|
39
|
-
#
|
40
|
-
|
41
|
-
def add_locator(name, params)
|
42
|
-
add_locator_by_type(:base, name, params)
|
43
|
-
end
|
44
|
-
|
45
|
-
##
|
46
|
-
#
|
47
|
-
# Adds locator for link into LocatorStore. Link can be found by: id, text
|
48
|
-
# Capybara methods that can work with this locator type are: click_link, find_link
|
49
|
-
#
|
50
|
-
# *Parameters:*
|
51
|
-
# * +name+ - Locator name
|
52
|
-
# * +params+ - ID or text of link
|
53
|
-
#
|
54
|
-
|
55
|
-
def add_link_locator(name, params)
|
56
|
-
add_locator_by_type(:link, name, params)
|
57
|
-
end
|
58
|
-
|
59
|
-
##
|
60
|
-
#
|
61
|
-
# Adds locator for field into LocatorStore. Field can be found by: name, id, text
|
62
|
-
# Capybara methods that can work with this locator type are: find_field, fill_in
|
63
|
-
#
|
64
|
-
# *Parameters:*
|
65
|
-
# * +name+ - Locator name
|
66
|
-
# * +params+ - Name, ID or text of field
|
67
|
-
#
|
68
|
-
|
69
|
-
def add_field_locator(name, params)
|
70
|
-
add_locator_by_type(:field, name, params)
|
71
|
-
end
|
72
|
-
|
73
|
-
##
|
74
|
-
#
|
75
|
-
# Add locator for button into LocatorStore. Button can be found by: id, name, value
|
76
|
-
# Capybara methods that can work with this locator type are: click_button, find_button
|
77
|
-
#
|
78
|
-
# *Parameters:*
|
79
|
-
# * +name+ - Locator name
|
80
|
-
# * +params+ - Name, ID or value
|
81
|
-
#
|
82
|
-
|
83
|
-
def add_button_locator(name, params)
|
84
|
-
add_locator_by_type(:button, name, params)
|
85
|
-
end
|
86
|
-
|
87
|
-
##
|
88
|
-
#
|
89
|
-
# Takes css or xpath locator from LocatorStore by name
|
90
|
-
#
|
91
|
-
# *Parameters:*
|
92
|
-
# * +name+ - Locator name
|
93
|
-
#
|
94
|
-
|
95
|
-
def locator(name)
|
96
|
-
locator_by_type(:base, name)
|
97
|
-
end
|
98
|
-
|
99
|
-
##
|
100
|
-
#
|
101
|
-
# Take link locator from LocatorStore by name
|
102
|
-
#
|
103
|
-
# *Parameters:*
|
104
|
-
# * +name+ - Locator name
|
105
|
-
#
|
106
|
-
|
107
|
-
def link_locator(name)
|
108
|
-
locator_by_type(:link, name)
|
109
|
-
end
|
110
|
-
|
111
|
-
##
|
112
|
-
#
|
113
|
-
# Take field locator from LocatorStore by name
|
114
|
-
#
|
115
|
-
# *Parameters:*
|
116
|
-
# * +name+ - Locator name
|
117
|
-
#
|
118
|
-
|
119
|
-
def field_locator(name)
|
120
|
-
locator_by_type(:field, name)
|
121
|
-
end
|
122
|
-
|
123
|
-
##
|
124
|
-
#
|
125
|
-
# Take button locator from LocatorStore be name
|
126
|
-
#
|
127
|
-
# *Parameters:*
|
128
|
-
# * +name+ - Locator name
|
129
|
-
#
|
130
|
-
|
131
|
-
def button_locator(name)
|
132
|
-
locator_by_type(:button, name)
|
133
|
-
end
|
134
|
-
|
135
|
-
##
|
136
|
-
#
|
137
|
-
# Get locator set by lambda.
|
138
|
-
# For example: find(apply(locator(:locator_name), 'register')).click
|
139
|
-
#
|
140
|
-
# *Parameters:*
|
141
|
-
# * +locator+ - Locator set with lambda expression
|
142
|
-
# * +values+ - Arguments that should be matched lambda expression params
|
143
|
-
#
|
144
|
-
|
145
|
-
def apply(locator, *values)
|
146
|
-
locator.call(*values).to_a.flatten
|
147
|
-
end
|
148
|
-
|
149
|
-
def find_element(name)
|
150
|
-
type, locator = find_locator(name)
|
151
|
-
if type == :base
|
152
|
-
send :find, locator
|
153
|
-
else
|
154
|
-
send "find_#{type}", locator
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
def first_element(name)
|
159
|
-
type, locator = find_locator(name)
|
160
|
-
if type == :base
|
161
|
-
send :first, locator
|
162
|
-
else
|
163
|
-
send :first, type, locator
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
protected
|
168
|
-
|
169
|
-
def find_locator(name)
|
170
|
-
name = name.to_s.to_sym
|
171
|
-
LOCATOR_TYPES.each do|type|
|
172
|
-
return [type, locator_by_type(type, name)] if (@locators || {}).fetch(self.name, {}).fetch(type, {})[name]
|
173
|
-
end
|
174
|
-
log.error(Howitzer::LocatorNotDefinedError, name)
|
175
|
-
end
|
176
|
-
|
177
|
-
# looks up locator in current and all super classes
|
178
|
-
def parent_locator(type, name)
|
179
|
-
if !@locators.nil? && @locators.key?(self.name) && @locators[self.name].key?(type) && @locators[self.name][type].key?(name)
|
180
|
-
@locators[self.name][type][name]
|
181
|
-
else
|
182
|
-
self.superclass.parent_locator(type, name) unless self.superclass == Object
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
private
|
187
|
-
|
188
|
-
def locator_by_type(type, name)
|
189
|
-
locator = parent_locator(type, name)
|
190
|
-
log.error(Howitzer::LocatorNotDefinedError, name) if locator.nil?
|
191
|
-
locator
|
192
|
-
end
|
193
|
-
|
194
|
-
def add_locator_by_type(type, name, params)
|
195
|
-
@locators ||= {}
|
196
|
-
@locators[self.name] ||= {}
|
197
|
-
@locators[self.name][type] ||= {}
|
198
|
-
log.error Howitzer::BadLocatorParamsError, args.inspect if params.nil? || (!params.is_a?(Proc) && params.empty?)
|
199
|
-
case params.class.name
|
200
|
-
when 'Hash'
|
201
|
-
@locators[self.name][type][name] = [params.keys.first.to_s.to_sym, params.values.first.to_s]
|
202
|
-
when 'Proc'
|
203
|
-
@locators[self.name][type][name] = params
|
204
|
-
else
|
205
|
-
@locators[self.name][type][name] = params.to_s
|
206
|
-
end
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
#delegate class methods to instance
|
211
|
-
ClassMethods.public_instance_methods.each do |name|
|
212
|
-
define_method(name) do |*args|
|
213
|
-
self.class.send(name, *args)
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
end
|