rwebspec-webdriver 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/Rakefile +11 -12
  2. data/lib/rwebspec-webdriver/assert.rb +445 -0
  3. data/lib/{rwebspec → rwebspec-webdriver}/clickJSDialog.rb +0 -0
  4. data/lib/{rwebspec → rwebspec-webdriver}/context.rb +13 -11
  5. data/lib/rwebspec-webdriver/database_checker.rb +76 -0
  6. data/lib/rwebspec-webdriver/driver.rb +1011 -0
  7. data/lib/rwebspec-webdriver/element_locator.rb +89 -0
  8. data/lib/rwebspec-webdriver/load_test_helper.rb +174 -0
  9. data/lib/{rwebspec → rwebspec-webdriver}/matchers/contains_text.rb +0 -0
  10. data/lib/rwebspec-webdriver/popup.rb +149 -0
  11. data/lib/rwebspec-webdriver/rspec_helper.rb +101 -0
  12. data/lib/rwebspec-webdriver/test_script.rb +10 -0
  13. data/lib/rwebspec-webdriver/test_utils.rb +219 -0
  14. data/lib/rwebspec-webdriver/testwise_plugin.rb +85 -0
  15. data/lib/rwebspec-webdriver/using_pages.rb +51 -0
  16. data/lib/rwebspec-webdriver/web_browser.rb +744 -0
  17. data/lib/rwebspec-webdriver/web_page.rb +110 -0
  18. data/lib/rwebspec-webdriver/web_testcase.rb +40 -0
  19. data/lib/rwebspec-webdriver.rb +12 -12
  20. metadata +22 -22
  21. data/lib/rwebspec/assert.rb +0 -443
  22. data/lib/rwebspec/database_checker.rb +0 -74
  23. data/lib/rwebspec/driver.rb +0 -1009
  24. data/lib/rwebspec/element_locator.rb +0 -87
  25. data/lib/rwebspec/load_test_helper.rb +0 -172
  26. data/lib/rwebspec/popup.rb +0 -147
  27. data/lib/rwebspec/rspec_helper.rb +0 -99
  28. data/lib/rwebspec/test_script.rb +0 -8
  29. data/lib/rwebspec/test_utils.rb +0 -217
  30. data/lib/rwebspec/testwise_plugin.rb +0 -83
  31. data/lib/rwebspec/using_pages.rb +0 -49
  32. data/lib/rwebspec/web_browser.rb +0 -742
  33. data/lib/rwebspec/web_page.rb +0 -108
  34. data/lib/rwebspec/web_testcase.rb +0 -38
@@ -0,0 +1,110 @@
1
+ #***********************************************************
2
+ #* Copyright (c) 2006, Zhimin Zhan.
3
+ #* Distributed open-source, see full license in MIT-LICENSE
4
+ #***********************************************************
5
+ require File.join(File.dirname(__FILE__), 'assert')
6
+ require File.join(File.dirname(__FILE__), 'driver')
7
+ require 'fileutils'
8
+
9
+ module RWebSpec
10
+ module WebDriver
11
+
12
+ # WebPage (children of AbstractWebPage) encapsulates a real web page.
13
+ # For example,
14
+ # beginAt("/home")
15
+ # @web_browser.clickLinkWithText("/login")
16
+ # @web_browser.setFormElement("username", "sa")
17
+ # Can be rewritten to
18
+ # begin_at("/home")
19
+ # home_page = HomePage.new
20
+ # login_page = home_page.clickLoginLink
21
+ # login_page.enterUserName("sa")
22
+ #
23
+ # So you only need change in LoingPage class if UI changes, which happen quite often.
24
+ class AbstractWebPage
25
+
26
+ include RWebSpec::WebDriver::Assert
27
+ include RWebSpec::WebDriver::Driver
28
+
29
+ # browser: passed to do assertion within the page
30
+ # page_text: text used to identify the page, title will be the first candidate
31
+ attr_accessor :page_specific_text
32
+
33
+ def initialize(the_browser, page_specific_text = nil)
34
+ @web_browser = the_browser
35
+ @web_tester = the_browser
36
+ @page_specific_text = page_specific_text
37
+ begin
38
+ snapshot if $ITEST2_DUMP_PAGE
39
+ delay = $ITEST2_PAGE_DELAY
40
+ sleep(delay)
41
+ rescue => e
42
+ end
43
+ assert_on_page
44
+ end
45
+
46
+ # return the browser instance in page objects
47
+ def browser
48
+ @web_browser
49
+ end
50
+
51
+ # Assert is on current page
52
+ # Example
53
+ # home_page = HomePage.new("Welcome to iTest2")
54
+ # ....
55
+ # home_page.assert_on_page # will check the text 'Welcome to iTest2' still present on the page
56
+ def assert_on_page()
57
+ assert_text_present(@page_specific_text) if @page_specific_text
58
+ end
59
+
60
+ def assert_not_on_page()
61
+ assert_text_not_present(@page_specific_text) if @page_specific_text
62
+ end
63
+
64
+ def dump(stream = nil)
65
+ @web_browser.dump_response(stream)
66
+ end
67
+
68
+ # Page source (html)
69
+ def source
70
+ @web_browser.page_source
71
+ end
72
+ alias html source
73
+
74
+ # return current page title
75
+ def title
76
+ @web_browser.page_title
77
+ end
78
+
79
+ # return current page text
80
+ def text
81
+ @web_browser.text
82
+ end
83
+
84
+ def url
85
+ @web_browser.url
86
+ end
87
+
88
+ # TO validate
89
+ def contains?(ary)
90
+ return true if ary.nil?
91
+ the_page_source = source
92
+ found = false
93
+ ary.each_line do |str|
94
+ found ||= the_page_source.include?(str)
95
+ end
96
+ return found
97
+ end
98
+
99
+ # Will save current page source to a file
100
+ # home_page = HomePage.new("Welcome to iTest2")
101
+ # ...
102
+ # home_page.snapshot() # => save to 20090830100102_HomePage.html
103
+ def snapshot(replace_css = false)
104
+ save_current_page(:filename => Time.now.strftime("%m%d%H%M%S") + "_" + self.class.name.gsub(" ", "") + ".html" )
105
+ end
106
+
107
+ end
108
+
109
+ end
110
+ end
@@ -0,0 +1,40 @@
1
+ #***********************************************************
2
+ #* Copyright (c) 2006, Zhimin Zhan.
3
+ #* Distributed open-source, see full license in MIT-LICENSE
4
+ #***********************************************************
5
+
6
+ # Deprecated, use RSpec syntax instead
7
+
8
+ require 'test/unit'
9
+ require File.join(File.dirname(__FILE__), 'assert')
10
+ require File.join(File.dirname(__FILE__), 'driver')
11
+
12
+ module RWebSpec
13
+ module WebDriver
14
+
15
+ class WebTestCase < Test::Unit::TestCase
16
+ include RWebSpec::WebDriver::Driver
17
+ include RWebSpec::WebDriver::Assert
18
+ include RWebSpec::WebDriver::Utils
19
+
20
+ attr_reader :web_tester
21
+
22
+ def initialize(name=nil)
23
+ super(name) if name
24
+ @web_browser = WebBrowser.new
25
+ end
26
+
27
+ def default_test
28
+ super unless (self.class == WebTestCase)
29
+ end
30
+
31
+ def open_browser(baseUrl, relativeUrl)
32
+ context.base_url = baseUrl
33
+ begin_at(relativeUrl)
34
+ end
35
+ alias open_ie open_browser
36
+
37
+ end
38
+
39
+ end
40
+ end
@@ -31,22 +31,22 @@ if RUBY_PLATFORM =~ /mswin/ or RUBY_PLATFORM =~ /mingw/
31
31
  end
32
32
 
33
33
  # Extra full path to load libraries
34
- require File.dirname(__FILE__) + "/rwebspec/using_pages"
35
- require File.dirname(__FILE__) + "/rwebspec/test_utils"
36
- require File.dirname(__FILE__) + "/rwebspec/web_page"
37
- require File.dirname(__FILE__) + "/rwebspec/assert"
38
- require File.dirname(__FILE__) + "/rwebspec/web_browser"
39
- require File.dirname(__FILE__) + "/rwebspec/driver"
40
- # require File.dirname(__FILE__) + "/rwebspec/test_script"
41
- require File.dirname(__FILE__) + "/rwebspec/context"
42
- require File.dirname(__FILE__) + "/rwebspec/rspec_helper"
43
- # require File.dirname(__FILE__) + "/rwebspec/load_test_helper"
34
+ require File.dirname(__FILE__) + "/rwebspec-webdriver/using_pages"
35
+ require File.dirname(__FILE__) + "/rwebspec-webdriver/test_utils"
36
+ require File.dirname(__FILE__) + "/rwebspec-webdriver/web_page"
37
+ require File.dirname(__FILE__) + "/rwebspec-webdriver/assert"
38
+ require File.dirname(__FILE__) + "/rwebspec-webdriver/web_browser"
39
+ require File.dirname(__FILE__) + "/rwebspec-webdriver/driver"
40
+ # require File.dirname(__FILE__) + "/rwebspec-webdriver/test_script"
41
+ require File.dirname(__FILE__) + "/rwebspec-webdriver/context"
42
+ require File.dirname(__FILE__) + "/rwebspec-webdriver/rspec_helper"
43
+ # require File.dirname(__FILE__) + "/rwebspec-webdriver/load_test_helper"
44
44
  require File.dirname(__FILE__) + "/rspec_extensions"
45
45
  require File.dirname(__FILE__) + "/webdriver_extensions"
46
46
  if RUBY_PLATFORM =~ /mswin/ or RUBY_PLATFORM =~ /mingw/
47
47
  require File.dirname(__FILE__) + "/window_script_extensions.rb"
48
48
  end
49
49
 
50
- require File.dirname(__FILE__) + "/rwebspec/matchers/contains_text"
51
- require File.dirname(__FILE__) + "/rwebspec/testwise_plugin"
50
+ require File.dirname(__FILE__) + "/rwebspec-webdriver/matchers/contains_text"
51
+ require File.dirname(__FILE__) + "/rwebspec-webdriver/testwise_plugin"
52
52
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rwebspec-webdriver
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Zhimin Zhan
@@ -15,7 +15,7 @@ autorequire: rwebspec-webdriver
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-12 00:00:00 +10:00
18
+ date: 2011-07-13 00:00:00 +10:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -80,23 +80,23 @@ files:
80
80
  - CHANGELOG
81
81
  - MIT-LICENSE
82
82
  - lib/rspec_extensions.rb
83
- - lib/rwebspec/assert.rb
84
- - lib/rwebspec/clickJSDialog.rb
85
- - lib/rwebspec/context.rb
86
- - lib/rwebspec/database_checker.rb
87
- - lib/rwebspec/driver.rb
88
- - lib/rwebspec/element_locator.rb
89
- - lib/rwebspec/load_test_helper.rb
90
- - lib/rwebspec/matchers/contains_text.rb
91
- - lib/rwebspec/popup.rb
92
- - lib/rwebspec/rspec_helper.rb
93
- - lib/rwebspec/test_script.rb
94
- - lib/rwebspec/test_utils.rb
95
- - lib/rwebspec/testwise_plugin.rb
96
- - lib/rwebspec/using_pages.rb
97
- - lib/rwebspec/web_browser.rb
98
- - lib/rwebspec/web_page.rb
99
- - lib/rwebspec/web_testcase.rb
83
+ - lib/rwebspec-webdriver/assert.rb
84
+ - lib/rwebspec-webdriver/clickJSDialog.rb
85
+ - lib/rwebspec-webdriver/context.rb
86
+ - lib/rwebspec-webdriver/database_checker.rb
87
+ - lib/rwebspec-webdriver/driver.rb
88
+ - lib/rwebspec-webdriver/element_locator.rb
89
+ - lib/rwebspec-webdriver/load_test_helper.rb
90
+ - lib/rwebspec-webdriver/matchers/contains_text.rb
91
+ - lib/rwebspec-webdriver/popup.rb
92
+ - lib/rwebspec-webdriver/rspec_helper.rb
93
+ - lib/rwebspec-webdriver/test_script.rb
94
+ - lib/rwebspec-webdriver/test_utils.rb
95
+ - lib/rwebspec-webdriver/testwise_plugin.rb
96
+ - lib/rwebspec-webdriver/using_pages.rb
97
+ - lib/rwebspec-webdriver/web_browser.rb
98
+ - lib/rwebspec-webdriver/web_page.rb
99
+ - lib/rwebspec-webdriver/web_testcase.rb
100
100
  - lib/rwebspec-webdriver.rb
101
101
  - lib/webdriver_extensions.rb
102
102
  - lib/window_script_extensions.rb
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  version: "0"
130
130
  requirements:
131
131
  - none
132
- rubyforge_project: rwebspec-webdrive
132
+ rubyforge_project: rwebspec-webdriver
133
133
  rubygems_version: 1.4.2
134
134
  signing_key:
135
135
  specification_version: 3
@@ -1,443 +0,0 @@
1
- require 'test/unit/assertions'
2
-
3
- # http://selenium.googlecode.com/svn/trunk/docs/api/rb/Selenium/WebDriver/SearchContext.html#find_element-instance_method
4
-
5
- module RWebSpec
6
- module Assert
7
- include Test::Unit::Assertions
8
-
9
- def assert_not(condition, msg = "")
10
- perform_assertion { assert(!condition, msg) }
11
- end
12
-
13
- def assert_nil(actual, msg="")
14
- perform_assertion { assert(actual.nil?, msg) }
15
- end
16
-
17
- def assert_not_nil(actual, msg="")
18
- perform_assertion { assert(!actual.nil?, msg) }
19
- end
20
-
21
- def fail(message)
22
- perform_assertion { assert(false, message) }
23
- end
24
-
25
- # assertions
26
- def assert_title_equals(title)
27
- assert_equals(title, @web_browser.page_title)
28
- end
29
-
30
- alias assert_title assert_title_equals
31
-
32
- # Assert text present in page source (html)
33
- # assert_text_in_page_source("<b>iTest2</b> Cool") # <b>iTest2</b> Cool
34
- def assert_text_in_page_source(text)
35
- perform_assertion { assert((@web_browser.page_source.include? text), 'expected html: ' + text + ' not found') }
36
- end
37
-
38
- # Assert text not present in page source (html)
39
- # assert_text_not_in_page_source("<b>iTest2</b> Cool") # <b>iTest2</b> Cool
40
- def assert_text_not_in_page_source(text)
41
- perform_assertion { assert(!(@web_browser.page_source.include? text), 'expected html: ' + text + ' found') }
42
- end
43
-
44
- # Assert text present in page source (html)
45
- # assert_text_present("iTest2 Cool") # <b>iTest2</b> Cool
46
- def assert_text_present(text)
47
- perform_assertion { assert((@web_browser.text.include? text), 'expected text: ' + text + ' not found') }
48
- end
49
-
50
- # Assert text not present in page source (html)
51
- # assert_text_not_present("iTest2 Cool") # <b>iTest2</b> Cool
52
- def assert_text_not_present(text)
53
- perform_assertion { assert(!(@web_browser.text.include? text), 'expected text: ' + text + ' found') }
54
- end
55
-
56
-
57
- ##
58
- # Link
59
- # @NOTE: this is different from Watir version
60
-
61
- # Assert a link containing specified text in the page
62
- #
63
- # <a href="">Click Me</a>
64
- # assert_link_present_with_text("Click ") # =>
65
- #
66
- def assert_link_present_with_text(link_text, opts = {})
67
- begin
68
- if opts && opts[:partial]
69
- elem = @web_browser.find_element(:partial_link_text, link_text)
70
- else
71
- elem = @web_browser.find_element(:link_text, link_text)
72
- end
73
- rescue => e
74
- puts "Failed to find the link text :#{e}"
75
- end
76
-
77
- if elem
78
- return true
79
- else
80
- fail("can't find the link with text: #{link_text}")
81
- end
82
- end
83
-
84
- def assert_link_not_present_with_text(link_text, opts = {})
85
- begin
86
- if opts && opts[:partial]
87
- elem = @web_browser.find_element(:partial_link_text, link_text)
88
- else
89
- elem = @web_browser.find_element(:link_text, link_text)
90
- end
91
- rescue => e
92
- puts "Failed to find the link text :#{e}"
93
- end
94
- if elem
95
- fail("unexpected link (exact): #{link_text} found")
96
- else
97
- return true
98
- end
99
- end
100
-
101
-
102
- ##
103
- # Checkbox
104
- def assert_checkbox_not_selected(checkbox_name)
105
- elem = find_element(:name, checkbox_name)
106
- fail "Checkbox with name:#{checkbox_name} not found" unless elem.tag_name == "input"
107
- assert !elem.selected?
108
- end
109
-
110
- alias assert_checkbox_not_checked assert_checkbox_not_selected
111
-
112
- def assert_checkbox_selected(checkbox_name)
113
- elem = find_element(:name, checkbox_name)
114
- fail "Checkbox with name:#{checkbox_name} not found" unless elem.tag_name == "input"
115
- assert elem.selected?
116
- end
117
-
118
- alias assert_checkbox_checked assert_checkbox_selected
119
-
120
- ##
121
- # select
122
- def assert_option_value_not_present(select_name, option_value)
123
- select_element = find_element(:name, select_name)
124
- options = select_element.find_elements(:xpath, ".//option")
125
- option_values = options.collect { |x| x.attribute('value') }
126
- if option_values.include?(option_value)
127
- fail "Unexpected select option value #{option_value}"
128
- else
129
- return true
130
- end
131
- end
132
-
133
- alias assert_select_value_not_present assert_option_value_not_present
134
-
135
- def assert_option_not_present(select_name, option_label)
136
- select_element = find_element(:name, select_name)
137
- options = select_element.find_elements(:xpath, ".//option")
138
- option_labels= options.collect { |x| x.attribute('value') }
139
- if option_labels.include?(option_label)
140
- fail "Unexpected select option label #{option_label}"
141
- else
142
- return true
143
- end
144
- end
145
-
146
- alias assert_select_label_not_present assert_option_not_present
147
-
148
- def assert_option_value_present(select_name, option_value)
149
- select_element = find_element(:name, select_name)
150
- options = select_element.find_elements(:xpath, ".//option")
151
- option_values = options.collect { |x| x.attribute('value') }
152
- if option_values.include?(option_value)
153
- return true
154
- else
155
- fail "Unexpected select option value #{option_value}"
156
- end
157
- end
158
-
159
- alias assert_select_value_present assert_option_value_present
160
- alias assert_menu_value_present assert_option_value_present
161
-
162
- def assert_option_present(select_name, option_label)
163
- select_element = find_element(:name, select_name)
164
- options = select_element.find_elements(:xpath, ".//option")
165
- option_labels = options.collect { |x| x.text }
166
- if option_labels.include?(option_label)
167
- return true
168
- else
169
- fail "Unexpected select option label #{option_label}"
170
- end
171
- end
172
-
173
- alias assert_select_label_present assert_option_present
174
- alias assert_menu_label_present assert_option_present
175
-
176
- def assert_option_equals(select_name, option_label)
177
- select_element = find_element(:name, select_name)
178
- options = select_element.find_elements(:xpath, ".//option")
179
- selected_label_list = []
180
- options.each do |op|
181
- selected_label_list << op.text if op.selected?
182
- end
183
- assert selected_label_list.join(",").to_s == option_label
184
- end
185
-
186
- alias assert_select_label assert_option_equals
187
- alias assert_menu_label assert_option_equals
188
-
189
- def assert_option_value_equals(select_name, option_value)
190
- select_element = find_element(:name, select_name)
191
- options = select_element.find_elements(:xpath, ".//option")
192
- selected_value_list = []
193
- options.each do |op|
194
- selected_value_list << op.attribute('value') if op.selected?
195
- end
196
- assert selected_value_list.join(",").to_s == option_value
197
- end
198
-
199
- alias assert_select_value assert_option_value_equals
200
- alias assert_menu_value assert_option_value_equals
201
-
202
- ##
203
- # radio
204
-
205
- # radio_group is the name field, radio options 'value' field
206
- def assert_radio_option_not_present(radio_group, radio_option)
207
- begin
208
- elem = find_element(:xpath, "//input[@type='radio' and @name='#{radio_group}' and @value='#{radio_option}']")
209
- rescue => e
210
- end
211
-
212
- if elem
213
- fail("unexpected radio option: " + radio_option + " found")
214
- else
215
- return true
216
- end
217
- end
218
-
219
- def assert_radio_option_present(radio_group, radio_option)
220
- elem = find_element(:xpath, "//input[@type='radio' and @name='#{radio_group}' and @value='#{radio_option}']")
221
- if elem
222
- return true
223
- else
224
- fail("can't find the radio option : '#{radio_option}'")
225
- end
226
- end
227
-
228
- def assert_radio_option_selected(radio_group, radio_option)
229
- elem = find_element(:xpath, "//input[@type='radio' and @name='#{radio_group}' and @value='#{radio_option}']")
230
- assert elem.selected?
231
- end
232
-
233
- alias assert_radio_button_checked assert_radio_option_selected
234
- alias assert_radio_option_checked assert_radio_option_selected
235
-
236
- def assert_radio_option_not_selected(radio_group, radio_option)
237
- elem = find_element(:xpath, "//input[@type='radio' and @name='#{radio_group}' and @value='#{radio_option}']")
238
- assert !elem.selected?
239
- end
240
-
241
- alias assert_radio_button_not_checked assert_radio_option_not_selected
242
- alias assert_radio_option_not_checked assert_radio_option_not_selected
243
-
244
- ##
245
- # Button
246
-
247
- def assert_button_present(button_id)
248
- find_element(:id, button_id)
249
- end
250
-
251
- def assert_button_not_present(button_id)
252
- elem = safe_find_element_by_id(button_id)
253
- if elem && elem.tag_name == "button" then
254
- fail("Unexpected button with this id: #{button_id}")
255
- end
256
- return true
257
- end
258
-
259
- def assert_button_present_with_text(button_text)
260
- input_buttons = find_elements(:xpath, "//input[@type = 'button' or @type = 'submit']")
261
- input_button_values = input_buttons.collect { |x| x.attribute('value') }
262
- if input_button_values.include?(button_text)
263
- return true
264
- else
265
- #TODO check for just <button tag
266
- fail("can't find the button with text: #{button_text}")
267
- end
268
- end
269
-
270
- def assert_button_not_present_with_text(button_text)
271
- input_buttons = find_elements(:xpath, "//input[@type = 'button' or @type = 'submit']")
272
- input_button_values = input_buttons.collect { |x| x.attribute('value') }
273
- if input_button_values.include?(button_text)
274
- fail("can't find the button with text: #{button_text}")
275
- else
276
- #TODO check for just <button tag
277
- return true
278
- end
279
- end
280
-
281
- ## General
282
- #
283
-
284
- def assert_equals(expected, actual, msg=nil)
285
- perform_assertion { assert(expected == actual, (msg.nil?) ? "Expected: #{expected} diff from actual: #{actual}" : msg) }
286
- end
287
-
288
-
289
- # Check a HTML element exists or not
290
- # Example:
291
- # assert_exists("label", "receipt_date")
292
- # assert_exists(:span, :receipt_date)
293
- def assert_exists(tag, element_id)
294
- elem = find_element(:id, element_id)
295
- if elem
296
- return true
297
- else
298
- fail("Element '#{tag}' with id: '#{element_id}' not found")
299
- end
300
- end
301
-
302
- alias assert_exists? assert_exists
303
- alias assert_element_exists assert_exists
304
-
305
- def assert_not_exists(tag, element_id)
306
- elem = find_element(:id, element_id)
307
- if elem
308
- fail("#{tag} with #{element_id} not expected there, but exists")
309
- else
310
- return true
311
- end
312
- end
313
-
314
- alias assert_not_exists? assert_not_exists
315
- alias assert_element_not_exists? assert_not_exists
316
-
317
-
318
- # Assert tag with element id is visible?, eg.
319
- # assert_visible(:div, "public_notice")
320
- # assert_visible(:span, "public_span")
321
- def assert_visible(tag, element_id)
322
- element = find_element(:id, element_id)
323
- perform_assertion { assert(element.displayed?, "Element '#{tag}' with id: '#{element_id}' not visible") }
324
- end
325
-
326
- # Assert tag with element id is hidden?, example
327
- # assert_hidden(:div, "secret")
328
- # assert_hidden(:span, "secret_span")
329
- def assert_hidden(tag, element_id)
330
- element = find_element(:id, element_id)
331
- perform_assertion { assert(!element.displayed?, "Element '#{tag}' with id: '#{element_id}' is visible") }
332
- end
333
-
334
- alias assert_not_visible assert_hidden
335
-
336
- def assert_disabled(tag, element_id)
337
- element = find_element(:id, element_id)
338
- assert !element.enabled?
339
- end
340
-
341
- def assert_enabled(tag, element_id)
342
- element = find_element(:id, element_id)
343
- puts "XXX :#{element.tag_name}"
344
- assert element.enabled?
345
- end
346
-
347
-
348
- # Assert given text appear inside a table (inside <table> tag like below)
349
- #
350
- # <table id="t1">
351
- #
352
- # <tbody>
353
- # <tr id="row_1">
354
- # <td id="cell_1_1">A</td>
355
- # <td id="cell_1_2">B</td>
356
- # </tr>
357
- # <tr id="row_2">
358
- # <td id="cell_2_1">a</td>
359
- # <td id="cell_2_2">b</td>
360
- # </tr>
361
- # </tbody>
362
- #
363
- # </table>
364
- #
365
- # The plain text view of above table
366
- # A B a b
367
- #
368
- # Examples
369
- # assert_text_present_in_table("t1", ">A<") # => true
370
- # assert_text_present_in_table("t1", ">A<", :just_plain_text => true) # => false
371
- def assert_text_present_in_table(table_id, text, options = {:just_plain_text => false})
372
- perform_assertion { assert(table_source(table_id, options).include?(text), "the text #{text} not found in table #{table_id}") }
373
- end
374
-
375
- alias assert_text_in_table assert_text_present_in_table
376
-
377
- def assert_text_not_present_in_table(table_id, text, options = {:just_plain_text => false})
378
- perform_assertion { assert_not(table_source(table_id, options).include?(text), "the text #{text} not found in table #{table_id}") }
379
- end
380
-
381
- alias assert_text_not_in_table assert_text_not_present_in_table
382
-
383
- # Assert a text field (with given name) has the value
384
- #
385
- # <input id="tid" name="text1" value="text already there" type="text">
386
- #
387
- # assert_text_field_value("text1", "text already there") => true
388
- #
389
- def assert_text_field_value(textfield_name, text)
390
- perform_assertion { assert_equal(text, text_field(:name, textfield_name).attribute('value') ) }
391
- end
392
-
393
-
394
- #-- Not tested
395
- # -----
396
-
397
- def assert_text_in_element(element_id, text)
398
- elem = element_by_id(element_id)
399
- assert_not_nil(elem.innerText, "element #{element_id} has no text")
400
- perform_assertion { assert(elem.innerText.include?(text), "the text #{text} not found in element #{element_id}") }
401
- end
402
-
403
- # Use
404
- #
405
-
406
- #TODO for drag-n-drop, check the postion in list
407
- # def assert_position_in_list(list_element_id)
408
- # raise "not implemented"
409
- # end
410
-
411
- private
412
- def table_source(table_id, options)
413
- elem_table = table(:id, table_id.to_s)
414
- elem_table_text = elem_table.text
415
- elem_table_html = is_firefox? ? elem_table.innerHTML : elem_table.html
416
- table_source = options[:just_plain_text] ? elem_table_text : elem_table_html
417
- end
418
-
419
-
420
- def perform_assertion(&block)
421
- begin
422
- yield
423
- return true
424
- rescue StandardError => e
425
- # puts "[DEBUG] Assertion error: #{e}"
426
- take_screenshot
427
- raise e
428
- end
429
- end
430
-
431
- #
432
- def safe_find_element_by_id(an_id)
433
- begin
434
- find_element(:id, an_id)
435
- rescue => e
436
- puts "Not found, but not throwing an error"
437
- nil
438
- end
439
- end
440
-
441
-
442
- end
443
- end