watirmark 5.14.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. data/app_generators/create_project/create_project_generator.rb +115 -0
  2. data/app_generators/create_project/templates/features/env.rb.erb +8 -0
  3. data/app_generators/create_project/templates/features/model_steps.rb.erb +9 -0
  4. data/app_generators/create_project/templates/features/post_error_steps.rb.erb +15 -0
  5. data/app_generators/create_project/templates/features/sample.feature.erb +5 -0
  6. data/app_generators/create_project/templates/features/site_steps.rb.erb +7 -0
  7. data/app_generators/create_project/templates/generators/controller.rb.erb +9 -0
  8. data/app_generators/create_project/templates/generators/generate.rb.erb +9 -0
  9. data/app_generators/create_project/templates/generators/model.rb.erb +7 -0
  10. data/app_generators/create_project/templates/generators/mvc_generator.rb.erb +100 -0
  11. data/app_generators/create_project/templates/generators/rbeautify.rb.erb +212 -0
  12. data/app_generators/create_project/templates/generators/view.rb.erb +16 -0
  13. data/app_generators/create_project/templates/generators/workflow_loader.rb.erb +1 -0
  14. data/app_generators/create_project/templates/library/base_controller.rb.erb +9 -0
  15. data/app_generators/create_project/templates/library/base_view.rb.erb +6 -0
  16. data/app_generators/create_project/templates/library/configuration.rb.erb +6 -0
  17. data/app_generators/create_project/templates/library/core_libraries.rb.erb +9 -0
  18. data/app_generators/create_project/templates/library/loader.rb.erb +23 -0
  19. data/app_generators/create_project/templates/library/page_load_checker.rb.erb +11 -0
  20. data/app_generators/create_project/templates/library/post_errors_checker.rb.erb +23 -0
  21. data/app_generators/create_project/templates/library/project_require_file.rb.erb +8 -0
  22. data/app_generators/create_project/templates/library/search_controller.rb.erb +12 -0
  23. data/app_generators/create_project/templates/library/workflows.rb.erb +0 -0
  24. data/app_generators/create_project/templates/project/config.yml.erb +3 -0
  25. data/app_generators/create_project/templates/project/gemfile.rb.erb +11 -0
  26. data/app_generators/create_project/templates/project/rakefile.rb.erb +21 -0
  27. data/bin/etapestry/Gemfile +11 -0
  28. data/bin/etapestry/config.yml +3 -0
  29. data/bin/etapestry/features/etapestry_home.feature +5 -0
  30. data/bin/etapestry/features/step_definitions/model_steps.rb +9 -0
  31. data/bin/etapestry/features/step_definitions/post_error_steps.rb +15 -0
  32. data/bin/etapestry/features/step_definitions/site_steps.rb +7 -0
  33. data/bin/etapestry/features/support/env.rb +8 -0
  34. data/bin/etapestry/generators/mvc/mvc_generator.rb +100 -0
  35. data/bin/etapestry/generators/mvc/rbeautify.rb +212 -0
  36. data/bin/etapestry/generators/mvc/templates/controller.rb.erb +9 -0
  37. data/bin/etapestry/generators/mvc/templates/model.rb.erb +7 -0
  38. data/bin/etapestry/generators/mvc/templates/view.rb.erb +16 -0
  39. data/bin/etapestry/generators/mvc/templates/workflow_loader.rb.erb +1 -0
  40. data/bin/etapestry/lib/etapestry.rb +8 -0
  41. data/bin/etapestry/lib/etapestry/checkers/page_load_checker.rb +11 -0
  42. data/bin/etapestry/lib/etapestry/checkers/post_errors_checker.rb +23 -0
  43. data/bin/etapestry/lib/etapestry/configuration.rb +6 -0
  44. data/bin/etapestry/lib/etapestry/core_libraries.rb +9 -0
  45. data/bin/etapestry/lib/etapestry/loader.rb +23 -0
  46. data/bin/etapestry/lib/etapestry/site/base_controller.rb +9 -0
  47. data/bin/etapestry/lib/etapestry/site/base_view.rb +6 -0
  48. data/bin/etapestry/lib/etapestry/site/search_controller.rb +12 -0
  49. data/bin/etapestry/lib/etapestry/workflows.rb +0 -0
  50. data/bin/etapestry/rakefile.rb +21 -0
  51. data/bin/etapestry/script/generate.rb +9 -0
  52. data/bin/twitter/features/hashtag_search.feature +93 -0
  53. data/bin/twitter/features/step_definitions/hashtag_steps.rb +9 -0
  54. data/bin/twitter/lib/twitter/workflows/search/result_controller.rb +13 -0
  55. data/bin/twitter/lib/twitter/workflows/search/result_model.rb +5 -0
  56. data/bin/twitter/lib/twitter/workflows/search/result_view.rb +19 -0
  57. data/bin/watirmark +10 -0
  58. data/lib/watirmark.rb +26 -0
  59. data/lib/watirmark/at_exit.rb +13 -0
  60. data/lib/watirmark/configuration.rb +201 -0
  61. data/lib/watirmark/controller/actions.rb +172 -0
  62. data/lib/watirmark/controller/assertions.rb +116 -0
  63. data/lib/watirmark/controller/controller.rb +191 -0
  64. data/lib/watirmark/controller/dialogs.rb +33 -0
  65. data/lib/watirmark/controller/matcher.rb +19 -0
  66. data/lib/watirmark/cucumber/cuke_helper.rb +150 -0
  67. data/lib/watirmark/cucumber/email_helper.rb +103 -0
  68. data/lib/watirmark/cucumber/env.rb +9 -0
  69. data/lib/watirmark/cucumber/hooks.rb +16 -0
  70. data/lib/watirmark/cucumber/model_helper.rb +34 -0
  71. data/lib/watirmark/cucumber/transforms.rb +55 -0
  72. data/lib/watirmark/exceptions.rb +15 -0
  73. data/lib/watirmark/extensions/ruby_extensions.rb +129 -0
  74. data/lib/watirmark/extensions/webdriver_extensions.rb +150 -0
  75. data/lib/watirmark/formatters/snapshot_formatter.rb +23 -0
  76. data/lib/watirmark/loader.rb +87 -0
  77. data/lib/watirmark/model.rb +3 -0
  78. data/lib/watirmark/models/cucumber_helper.rb +49 -0
  79. data/lib/watirmark/models/debug_methods.rb +21 -0
  80. data/lib/watirmark/models/default_values.rb +21 -0
  81. data/lib/watirmark/models/factory.rb +168 -0
  82. data/lib/watirmark/models/factory_method_generators.rb +84 -0
  83. data/lib/watirmark/models/factory_methods.rb +72 -0
  84. data/lib/watirmark/models/trait.rb +35 -0
  85. data/lib/watirmark/models/upload_csv.rb +24 -0
  86. data/lib/watirmark/page/keyed_element.rb +63 -0
  87. data/lib/watirmark/page/page.rb +50 -0
  88. data/lib/watirmark/page/page_definition.rb +187 -0
  89. data/lib/watirmark/page/process_page.rb +112 -0
  90. data/lib/watirmark/page/radio_maps.rb +53 -0
  91. data/lib/watirmark/profile.rb +22 -0
  92. data/lib/watirmark/rake/smoketest.rb +17 -0
  93. data/lib/watirmark/screenshot.rb +127 -0
  94. data/lib/watirmark/session.rb +115 -0
  95. data/lib/watirmark/version.rb +5 -0
  96. data/spec/assertions_spec.rb +95 -0
  97. data/spec/config_spec.rb +82 -0
  98. data/spec/controller_actions_spec.rb +91 -0
  99. data/spec/controller_spec.rb +426 -0
  100. data/spec/controllers_and_models_spec.rb +52 -0
  101. data/spec/model_factory_spec.rb +568 -0
  102. data/spec/model_traits_spec.rb +141 -0
  103. data/spec/page_spec.rb +127 -0
  104. data/spec/process_page_spec.rb +163 -0
  105. data/spec/spec_helper.rb +17 -0
  106. metadata +238 -0
@@ -0,0 +1,21 @@
1
+ module Watirmark
2
+ module Model
3
+
4
+ DebugModelValues = Hash.new{|h,k| h[k]=Hash.new}
5
+
6
+ module DebugMethods
7
+ def model_name=(name)
8
+ @model_name = name
9
+ add_debug_overrides
10
+ end
11
+
12
+ def add_debug_overrides
13
+ return unless @model_name && DebugModelValues != {}
14
+ Watirmark.logger.warn "Adding DEBUG overrides for #@model_name"
15
+ update DebugModelValues['*'] if DebugModelValues['*']
16
+ update DebugModelValues[@model_name] if DebugModelValues[@model_name]
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module Watirmark
2
+ module Model
3
+ class DefaultValues < Hash
4
+
5
+ # This is a workaround for zip being defined in Enumerable and
6
+ # we want to use zip in the model as a zip code
7
+ undef :zip
8
+
9
+ # This works around an issue that gets hit when
10
+ # running from rake and the model has default.desc set.
11
+ # If we don't have it here it thinks we're trying to call rakes' #desc
12
+ def desc(&block)
13
+ self[:desc] = block
14
+ end
15
+
16
+ def method_missing(name, &block)
17
+ self[name] = block
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,168 @@
1
+ require_relative 'cucumber_helper'
2
+ require_relative 'default_values'
3
+ require_relative 'factory_methods'
4
+ require_relative 'factory_method_generators'
5
+ require_relative 'debug_methods'
6
+
7
+ module Watirmark
8
+ module Model
9
+
10
+ class Factory
11
+ extend FactoryMethods
12
+
13
+ include CucumberHelper
14
+ include DebugMethods
15
+ include FactoryMethodGenerators
16
+
17
+ attr_accessor :defaults, :model_name, :models, :parent, :children, :model_type
18
+ attr_reader :keywords
19
+
20
+ def initialize(params={})
21
+ @params = params
22
+ @model_type = self.class.model_type_name
23
+ @search = self.class.search || Proc.new{nil}
24
+ @keywords = self.class.keys.dup || []
25
+ @children = self.class.children.dup.map(&:new)
26
+ set_model_name
27
+ set_default_values
28
+ create_model_getters_and_setters
29
+ set_initial_values
30
+ Watirmark.logger.info inspect
31
+ end
32
+
33
+ def uuid
34
+ @uuid ||= (Watirmark::Configuration.instance.uuid || UUID.new.generate(:compact)[0..9]).to_s
35
+ end
36
+
37
+ def strip_equals_from_method_name(method)
38
+ method.to_s.delete('=').to_sym
39
+ end
40
+
41
+ # The search_term, used for a controller's search can be defined in this model
42
+ # or will look in a parent's model. This allows us to define it once for a composed model
43
+ def search_term
44
+ instance_eval(&@search) || (parent.search_term if parent)
45
+ end
46
+
47
+
48
+ def add_model(model)
49
+ @children << model
50
+ create_child_methods
51
+ Watirmark.logger.info "Added Model #{model.inspect} to #{model_name || model_class_name}"
52
+ end
53
+
54
+
55
+ def find(model_class)
56
+ return self if self.kind_of? model_class
57
+ @children.each do |m|
58
+ return m if m.model_type == model_class
59
+ found_model = m.find model_class
60
+ return found_model if found_model
61
+ end
62
+ nil
63
+ end
64
+
65
+
66
+ def inspect
67
+ model_friendly_name = @model_name ? "#@model_name: " : nil
68
+ model_details = " #{to_h}" unless to_h.empty?
69
+ included_models = "\n #{@children.map(&:inspect).join("\n ")}" unless @children.empty?
70
+ "#{model_friendly_name}#{model_class_name}#{model_details}#{included_models}"
71
+ end
72
+
73
+
74
+ def model_class_name
75
+ name = self.class.inspect.to_s
76
+ name = self.class.superclass.to_s if name.to_s =~ /Class/
77
+ name = 'Model' if name.to_s =~ /Module/
78
+ name.sub!(/.+::/,'')
79
+ name
80
+ end
81
+
82
+
83
+ def includes? hash
84
+ hash.each_pair { |key, value| return false unless send("#{key}") == value }
85
+ true
86
+ end
87
+
88
+
89
+ # Update the model using the provided hash
90
+ def update hash
91
+ remove_empty_entries hash
92
+ hash.each_pair { |key, value| send "#{key}=", value }
93
+ self
94
+ end
95
+
96
+
97
+ # Update the model using the provided hash but only if exists (TODO: may not be needed any more)
98
+ def update_existing_members hash
99
+ remove_empty_entries hash
100
+ hash.each_pair { |key, value| send "#{key}=", value if respond_to? "#{key}=".to_sym }
101
+ self
102
+ end
103
+
104
+ def remove_empty_entries hash
105
+ hash.delete(':')
106
+ hash.delete_if {|k| k =~ /^\s+$/}
107
+ end
108
+
109
+ def to_h
110
+ h = {}
111
+ @keywords.each do |key|
112
+ begin
113
+ name = key
114
+ value = send(key)
115
+ if value.kind_of?(Proc)
116
+ h[name] = instance_eval(&value) unless value.nil?
117
+ else
118
+ h[name] = value unless value.nil?
119
+ end
120
+ rescue NoMethodError
121
+ h[name] = "[defined at runtime]"
122
+ end
123
+ end
124
+ h
125
+ end
126
+
127
+
128
+ private
129
+
130
+ def set_model_name
131
+ if @params[:model_name]
132
+ @model_name = @params[:model_name]
133
+ @params.delete(:model_name)
134
+ end
135
+ end
136
+
137
+ def create_model_getters_and_setters
138
+ create_keyword_methods
139
+ create_child_methods
140
+ end
141
+
142
+ def set_default_values
143
+ @defaults = self.class.default.dup
144
+ @traits = self.class.included_traits || []
145
+ include_defaults_from_traits @traits
146
+ end
147
+
148
+ def set_initial_values
149
+ update @params
150
+ add_debug_overrides
151
+ end
152
+
153
+
154
+ def include_defaults_from_traits(traits)
155
+ traits.each do |trait_name|
156
+ trait = Watirmark::Model::Traits.instance[trait_name]
157
+ trait.defaults.each {|k, v| @defaults[k] = v unless @defaults.key?(k)}
158
+ trait.traits.each {|t| include_defaults_from_traits([t])}
159
+ end
160
+ end
161
+
162
+ def method_name model
163
+ model.model_class_name.to_s.sub(/Model$/, '').underscore
164
+ end
165
+
166
+ end
167
+ end
168
+ end
@@ -0,0 +1,84 @@
1
+ module Watirmark
2
+ module Model
3
+ module FactoryMethodGenerators
4
+
5
+ # Act like an OpenStruct so we can be backward compatible with older controllers
6
+ def method_missing(key, *args, &block)
7
+ create_getters_and_setters strip_equals_from_method_name(key)
8
+ send key, *args
9
+ end
10
+
11
+ private
12
+
13
+ def create_keyword_methods
14
+ @keywords.each do |key|
15
+ create_getters_and_setters key
16
+ set_default_value key
17
+ end
18
+ end
19
+
20
+ def create_getters_and_setters key
21
+ @keywords << key unless @keywords.include? key #handle call from method_missing
22
+ create_getter_method key
23
+ create_setter_method key
24
+ end
25
+
26
+ def create_getter_method(key)
27
+ meta_def key do
28
+ normalize instance_variable_get("@#{key}")
29
+ end
30
+ end
31
+
32
+ def create_setter_method(key)
33
+ meta_def "#{key}=" do |value|
34
+ instance_variable_set "@#{key}", value
35
+ end
36
+ end
37
+
38
+ def set_default_value key
39
+ send("#{key}=", get_default_value(key)) if send(key).nil?
40
+ end
41
+
42
+ def get_default_value(key)
43
+ @defaults.key?(key) ? @defaults[key] : nil
44
+ end
45
+
46
+ # if the value is a proc, evaluate it, otherwise just return
47
+ def normalize(val)
48
+ val.kind_of?(Proc) ? instance_eval(&val) : val
49
+ end
50
+
51
+
52
+ def create_child_methods
53
+ @children.each do |model|
54
+ model.parent = self
55
+ create_model_collection model
56
+ create_model_method model
57
+ end
58
+ end
59
+
60
+ def collection_name model
61
+ method_name(model).pluralize
62
+ end
63
+
64
+
65
+ def create_model_collection model
66
+ @collection ||= []
67
+ @collection << model unless @collection.include? model
68
+ meta_def collection_name(model).pluralize do
69
+ @collection
70
+ end
71
+ end
72
+
73
+
74
+ def create_model_method model
75
+ unless respond_to? method_name(model)
76
+ meta_def method_name(model) do
77
+ model
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+
@@ -0,0 +1,72 @@
1
+ module Watirmark
2
+ module Model
3
+ module FactoryMethods
4
+ attr_accessor :search, :model_type_name, :included_traits
5
+ attr_writer :default, :keys
6
+
7
+ def inherited(klass)
8
+ unless self == Factory
9
+ add_keywords_to_subclass klass
10
+ add_defaults_to_subclass klass
11
+ add_traits_to_subclass klass
12
+ end
13
+ end
14
+
15
+ def default
16
+ @default ||= DefaultValues.new
17
+ end
18
+
19
+ def keys
20
+ @keys ||= []
21
+ end
22
+
23
+ def defaults(&block)
24
+ default.instance_exec &block
25
+ end
26
+
27
+ def children
28
+ @children ||= []
29
+ end
30
+
31
+ def model *models
32
+ models.each { |model| raise Watirmark::ModelCreationError unless Class === model }
33
+ @children = children + models
34
+ @children.uniq!
35
+ end
36
+
37
+ def model_type(c_name)
38
+ @model_type_name = c_name
39
+ end
40
+
41
+ def search_term &block
42
+ @search = block
43
+ end
44
+
45
+ def traits(*names)
46
+ @included_traits = [*names].flatten
47
+ end
48
+
49
+ def keywords(*args)
50
+ @keys = [*args].flatten
51
+ end
52
+
53
+ private
54
+
55
+ def add_keywords_to_subclass klass
56
+ if @keys
57
+ klass.keys = []
58
+ klass.keys += @keys.dup
59
+ end
60
+ end
61
+
62
+ def add_defaults_to_subclass klass
63
+ klass.default = @default.dup if @default
64
+ end
65
+
66
+ def add_traits_to_subclass klass
67
+ klass.included_traits = @included_traits.dup if @included_traits
68
+ end
69
+
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,35 @@
1
+ require 'singleton'
2
+ module Watirmark
3
+ module Model
4
+ def self.trait(name, &block)
5
+ new_trait = Trait.new
6
+ new_trait.instance_eval(&block)
7
+ Watirmark::Model::Traits.instance[name] = new_trait
8
+ end
9
+
10
+ class Trait
11
+ attr_accessor :defaults
12
+
13
+ def initialize
14
+ @defaults = {}
15
+ @traits = []
16
+ end
17
+
18
+ def traits(*names)
19
+ if names.empty?
20
+ @traits
21
+ else
22
+ @traits += names
23
+ end
24
+ end
25
+
26
+ def method_missing(sym, *args, &block)
27
+ @defaults[sym] = block
28
+ end
29
+ end
30
+
31
+ class Traits < Hash
32
+ include Singleton
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,24 @@
1
+ module Watirmark
2
+ module Model
3
+ class UploadCSV < Factory
4
+ require 'csv'
5
+ require 'tempfile'
6
+
7
+ def create_csv(table)
8
+ Watirmark.logger.info "Creating temporary CSV: #{csv_file}"
9
+ Watirmark.logger.info table.inspect
10
+ CSV.open(csv_file, 'wb') do |csv|
11
+ table.each do |line|
12
+ csv << line
13
+ end
14
+ end
15
+ end
16
+
17
+ def csv_file
18
+ @file ||= Tempfile.new(%w(csv_data .csv))
19
+ @file.path
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,63 @@
1
+ require 'watirmark/page/radio_maps'
2
+
3
+ module Watirmark
4
+
5
+ module KeywordMethods
6
+ attr_accessor :keyword, :radio_map
7
+ end
8
+
9
+ class KeyedElement
10
+ attr_reader :keyword, :process_page, :permissions
11
+
12
+ def initialize(context, options)
13
+ @context = context
14
+ @keyword = options[:keyword]
15
+ @block = options[:block]
16
+ @process_page = options[:process_page]
17
+ @permissions = options[:permissions] || {}
18
+ @map = Watirmark::RadioMap.new(options[:map]) if options[:map]
19
+ end
20
+
21
+ def get *args
22
+ @process_page.activate
23
+ watir_object = @context.instance_exec(*args, &@block)
24
+ watir_object.extend(KeywordMethods)
25
+ watir_object.radio_map = @map if @map
26
+ watir_object.keyword = @keyword
27
+ watir_object
28
+ end
29
+
30
+ def set val
31
+ return if val.nil?
32
+ @process_page.activate
33
+ element = get
34
+ val = @map.lookup(val) if @map
35
+ case val
36
+ when 'nil'
37
+ element.clear # workaround to empty element values
38
+ else
39
+ case element
40
+ when Watir::Radio
41
+ element.set val
42
+ when Watir::CheckBox
43
+ val ? element.set : element.clear
44
+ when Watir::Select
45
+ element.select val
46
+ when Watir::Button
47
+ element.click
48
+ else
49
+ element.value = val
50
+ end
51
+ end
52
+ end
53
+
54
+ def populate_allowed?
55
+ @permissions[:populate]
56
+ end
57
+
58
+ def verify_allowed?
59
+ @permissions[:verify]
60
+ end
61
+
62
+ end
63
+ end