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,50 @@
1
+ require 'watirmark/page/page_definition'
2
+
3
+ module Watirmark
4
+ class Page
5
+ extend PageDefinition
6
+
7
+ attr_accessor :browser
8
+ attr_reader :keyed_elements
9
+
10
+ def initialize(browser=self.class.browser)
11
+ @browser = browser
12
+ @keyed_elements = []
13
+ create_keyword_methods
14
+ end
15
+
16
+ def keywords
17
+ self.class.keywords
18
+ end
19
+
20
+ def native_keywords
21
+ self.class.native_keywords
22
+ end
23
+
24
+ def process_pages
25
+ self.class.process_pages
26
+ end
27
+
28
+ def process_page(x)
29
+ process_pages.each { |page| return page if page.name == x }
30
+ end
31
+
32
+ private
33
+
34
+ def create_keyword_methods
35
+ keywords = self.class.keyword_metadata || {}
36
+ keywords.each_key do |key|
37
+ keyed_element = KeyedElement.new(self, keywords[key])
38
+ @keyed_elements << keyed_element
39
+ meta_def key do |*args|
40
+ keyed_element.get *args
41
+ end
42
+ meta_def "#{key}=" do |*args|
43
+ keyed_element.set *args
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ Page = Watirmark::Page
@@ -0,0 +1,187 @@
1
+ require 'watirmark/page/process_page'
2
+
3
+ module Watirmark
4
+ module ProcessPageDefinition
5
+ attr_accessor :process_pages,
6
+ :process_page_navigate_method,
7
+ :process_page_active_page_method,
8
+ :process_page_submit_method
9
+
10
+ def process_page(name, method=nil)
11
+ @current_process_page = find_or_create_process_page(name)
12
+ yield
13
+ @current_process_page = @current_process_page.parent
14
+ end
15
+
16
+ def process_page_alias(x)
17
+ @current_process_page.alias << x
18
+ end
19
+
20
+ def always_activate_parent
21
+ @current_process_page.always_activate_parent = @current_process_page.parent.name
22
+ end
23
+
24
+ def process_page_navigate_method(proc=nil)
25
+ @process_page_navigate_method = proc
26
+ end
27
+
28
+ def process_page_submit_method(proc)
29
+ @process_page_submit_method = proc
30
+ end
31
+
32
+ def process_page_active_page_method(proc)
33
+ @process_page_active_page_method = proc
34
+ end
35
+
36
+ private
37
+
38
+ def add_superclass_process_pages_to_subclass(klass)
39
+ klass.process_pages = (@process_pages ? @process_pages.dup : klass.process_pages = [])
40
+ end
41
+
42
+
43
+ def create_default_process_page(klass)
44
+ klass.instance_variable_set :@current_process_page, ProcessPage.new
45
+ current_page = klass.instance_variable_get(:@current_process_page)
46
+ current_page.root = true
47
+ klass.process_pages << current_page
48
+ end
49
+
50
+ def find_or_create_process_page(name)
51
+ mypage = find_process_page(name)
52
+ unless mypage
53
+ mypage = ProcessPage.new(name,
54
+ @current_process_page,
55
+ @process_page_active_page_method,
56
+ @process_page_navigate_method,
57
+ @process_page_submit_method
58
+ )
59
+ @process_pages ||= []
60
+ @process_pages << mypage
61
+ end
62
+ mypage
63
+ end
64
+
65
+ def find_process_page(name)
66
+ if @current_process_page.root
67
+ underscored_name = name
68
+ else
69
+ underscored_name = (@current_process_page.underscored_name + '_' + name).downcase.gsub!(/\s+/, '_')
70
+ end
71
+ @process_pages.find { |p| p.underscored_name == underscored_name }
72
+ end
73
+ end
74
+
75
+
76
+
77
+ module PageDefinition
78
+ include ProcessPageDefinition
79
+ attr_accessor :kwds, :perms, :kwd_metadata
80
+
81
+ @@browser = nil
82
+
83
+ def inherited(klass)
84
+ add_superclass_keywords_to_subclass(klass)
85
+ add_superclass_keyword_metadata_to_subclass(klass)
86
+ add_superclass_process_pages_to_subclass(klass)
87
+ create_default_process_page(klass)
88
+ end
89
+
90
+ def keyword(name, map=nil, &block)
91
+ create_new_keyword(name, map, permissions={:populate => true, :verify => true}, &block)
92
+ end
93
+
94
+ def populate_keyword(name, map=nil, &block)
95
+ create_new_keyword(name, map, permissions={:populate => true}, &block)
96
+ end
97
+
98
+ def verify_keyword(name, map=nil, &block)
99
+ create_new_keyword(name, map, permissions={:verify => true}, &block)
100
+ end
101
+
102
+ def private_keyword(name, map=nil, &block)
103
+ create_new_keyword(name, map, &block)
104
+ end
105
+ alias :navigation_keyword :private_keyword
106
+
107
+ # Create an alias to an existing keyword
108
+ def keyword_alias(keyword_alias_name, keyword_name)
109
+ keyword_data = @kwd_metadata[self.to_s][keyword_name]
110
+ create_new_keyword(keyword_alias_name, keyword_data[:map], keyword_data[:permissions], &keyword_data[:block])
111
+ end
112
+
113
+ def browser
114
+ @@browser ||= Watirmark::Session.instance.openbrowser
115
+ end
116
+
117
+ def browser=(x)
118
+ @@browser = x
119
+ end
120
+
121
+ def browser_exists?
122
+ !! @@browser
123
+ end
124
+
125
+ def keywords
126
+ @kwds.values.flatten.uniq.sort_by { |key| key.to_s }
127
+ end
128
+
129
+ def native_keywords
130
+ @kwds[self.to_s].sort_by { |key| key.to_s }
131
+ end
132
+
133
+ def keyword_metadata
134
+ @kwd_metadata ||= nested_hash
135
+ @kwd_metadata.values.inject(:merge)
136
+ end
137
+
138
+ private
139
+ def nested_hash
140
+ Hash.new { |h, k| h[k] = Hash.new { |h, k| h[k]=Hash.new } }
141
+ end
142
+
143
+ def create_new_keyword(name, map=nil, permissions, &block)
144
+ keyword_name = name.to_sym
145
+ add_to_keywords(keyword_name)
146
+ add_to_current_process_page(keyword_name, permissions)
147
+ add_keyword_metadata(keyword_name, map, permissions, block)
148
+ end
149
+
150
+ def add_keyword_metadata(name, map, permissions, block)
151
+ @kwd_metadata ||= nested_hash
152
+ @kwd_metadata[self.to_s][name][:keyword] = name
153
+ @kwd_metadata[self.to_s][name][:map] = map
154
+ @kwd_metadata[self.to_s][name][:permissions] = permissions
155
+ @kwd_metadata[self.to_s][name][:block] = block
156
+ @kwd_metadata[self.to_s][name][:process_page] = @current_process_page
157
+ end
158
+
159
+ def add_to_current_process_page(name, permissions)
160
+ @current_process_page << name if permissions
161
+ end
162
+
163
+ def add_to_keywords(method_sym)
164
+ @kwds ||= Hash.new { |h, k| h[k] = Array.new }
165
+ @kwds[self.to_s] << method_sym unless @kwds.include?(method_sym)
166
+ end
167
+
168
+ def add_superclass_keywords_to_subclass(klass)
169
+ update_subclass_variables(klass, method='kwds', default=Hash.new { |h, k| h[k] = Array.new })
170
+ end
171
+
172
+ def add_superclass_keyword_metadata_to_subclass(klass)
173
+ update_subclass_variables(klass, method='kwd_metadata', default=Hash.new { |h, k| h[k] = Hash.new { |h, k| h[k] = Hash.new } })
174
+ end
175
+
176
+ def update_subclass_variables(klass, method, default)
177
+ var = self.send(method)
178
+ if var
179
+ klass.send("#{method}=", default) unless klass.send(method)
180
+ var.each_key do |k|
181
+ klass.send(method).store(k, var.fetch(k).dup)
182
+ end
183
+ end
184
+ end
185
+ end
186
+
187
+ end
@@ -0,0 +1,112 @@
1
+ module Watirmark
2
+ class ProcessPage
3
+
4
+ attr_reader :parent, :keywords
5
+ attr_accessor :alias, :name, :root, :always_activate_parent
6
+ attr_accessor :submit_method, :active_page_method, :navigate_method
7
+
8
+ @@navigate_method_default ||= Proc.new {}
9
+ @@submit_method_default ||= Proc.new {}
10
+ @@active_page_method_default ||= Proc.new {}
11
+
12
+ class << self
13
+ def navigate_method_default=(proc)
14
+ @@navigate_method_default = proc
15
+ end
16
+
17
+ def submit_method_default=(proc)
18
+ @@submit_method_default = proc
19
+ end
20
+
21
+ def active_page_method_default=(proc)
22
+ @@active_page_method_default = proc
23
+ end
24
+
25
+ def navigate_method_default
26
+ @@navigate_method_default
27
+ end
28
+
29
+ def submit_method_default
30
+ @@submit_method_default
31
+ end
32
+
33
+ def active_page_method_default
34
+ @@active_page_method_default
35
+ end
36
+ end
37
+
38
+ def initialize(name='', parent=nil, active_page=nil, navigate_page=nil, submit_page=nil)
39
+ @name = name
40
+ @parent = parent
41
+ @keywords = []
42
+ @root = false
43
+ @always_activate_parent = false
44
+ @alias = []
45
+ @active_page_method = active_page if active_page
46
+ @navigate_method = navigate_page if navigate_page
47
+ @submit_method = submit_page if submit_page
48
+ end
49
+
50
+ # Give the full name of this process page, including the
51
+ # parent process pages. The argument allows us to
52
+ # easily get the full path for alias names.
53
+ def underscored_name(name=@name)
54
+ u_name = (@parent && !@parent.root) ? "#{@parent.underscored_name}_#{name}" : name
55
+ u_name.downcase.gsub(/\s+/, '_') if u_name
56
+ end
57
+
58
+ def activate
59
+ return if (@root || active?)
60
+ if @always_activate_parent
61
+ @parent.goto_process_page
62
+ else
63
+ @parent.activate if @parent
64
+ end
65
+ goto_process_page
66
+ end
67
+
68
+ def <<(x)
69
+ @keywords << x.to_sym
70
+ end
71
+
72
+ def goto_process_page
73
+ unless navigate
74
+ aliases.each do |alias_name|
75
+ alias_process_page = self.dup
76
+ alias_process_page.alias = []
77
+ alias_process_page.name = alias_name
78
+ alias_process_page.alias = nil
79
+ alias_process_page.goto_process_page
80
+ end
81
+ end
82
+ end
83
+
84
+ def navigate
85
+ instance_eval &(@navigate_method || @@navigate_method_default)
86
+ end
87
+
88
+ def submit
89
+ instance_eval &(@submit_method || @@submit_method_default)
90
+ end
91
+
92
+ def active_page
93
+ instance_eval &(@active_page_method || @@active_page_method_default)
94
+ end
95
+
96
+ def aliases
97
+ @alias ||= []
98
+ end
99
+
100
+ def active?
101
+ page = active_page
102
+ return true if in_submenu(page, underscored_name)
103
+ aliases.each { |a| return true if in_submenu(page, underscored_name(a)) } unless aliases.empty?
104
+ false
105
+ end
106
+
107
+ def in_submenu(active_page, requested_page)
108
+ !!(active_page.to_s.downcase.delete('>').gsub(/\s+/, '_') =~ /^#{requested_page}/)
109
+ end
110
+
111
+ end
112
+ end
@@ -0,0 +1,53 @@
1
+ module Watirmark
2
+
3
+ class RadioMapElement
4
+ attr_accessor :list, :value
5
+
6
+ def initialize(*args)
7
+ @list= *args
8
+ @value = nil
9
+ end
10
+
11
+ def map_to(x)
12
+ @value = x
13
+ end
14
+
15
+ alias :maps_to :map_to
16
+
17
+ end
18
+
19
+ class RadioMap
20
+ def initialize hash={}
21
+ @maps = []
22
+ hash.each_pair do |key, val|
23
+ values(key).maps_to(val)
24
+ end
25
+ end
26
+
27
+ def values(*args)
28
+ element = RadioMapElement.new(*args)
29
+ @maps << element
30
+ element
31
+ end
32
+
33
+ alias :value :values
34
+
35
+ def lookup(x)
36
+ return nil if x.nil?
37
+ @maps.each do |map|
38
+ if Array === map.list
39
+ map.list.each do |items|
40
+ [*items].each do |item|
41
+ return map.value if item.matches x
42
+ end
43
+ end
44
+ else
45
+ return map.value if map.list.matches x
46
+ end
47
+ end
48
+ raise Watirmark::TestError, "No map value exists for '#{x}'" unless x
49
+ x
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,22 @@
1
+ require 'ruby-prof'
2
+
3
+ class Profiler
4
+ def self.profile(options={}, &block)
5
+ RubyProf.start
6
+ beginning = Time.now
7
+ puts '-----------------------'
8
+ puts options[:name]
9
+ puts '-----------------------'
10
+ block.call
11
+ result = RubyProf.stop
12
+ result.eliminate_methods!([/IO/, /Net::/, /Global/])
13
+ printer = RubyProf::FlatPrinter.new(result)
14
+ printer.print(STDOUT, :min_percent=> (options[:min_percent] || 1))
15
+ puts "----> Time elapsed #{Time.now - beginning} seconds"
16
+ end
17
+ end
18
+
19
+
20
+ #require 'watirmark/profile'
21
+ # Profiler.profile(:name => "#{element.keyword}, #{element}") do
22
+
@@ -0,0 +1,17 @@
1
+ module SmokeTest
2
+
3
+ class << self
4
+ def rspec_task(task_name, files, tag=:smoke)
5
+ RSpec::Core::RakeTask.new(task_name) do |spec|
6
+ spec.rspec_opts = "--tag #{tag} -fd -fh --out spec/reports/#{spec.name}.html --backtrace"
7
+ spec.pattern = files
8
+ end
9
+ end
10
+
11
+ def cucumber_task(task_name, files=nil, tag=:smoke)
12
+ Cucumber::Rake::Task.new(task_name) do |t|
13
+ t.cucumber_opts = "--tags @#{tag} -r features #{FileList[files]} -b --format html -o reports/report.html --format pretty"
14
+ end
15
+ end
16
+ end
17
+ end