rwebspec-webdriver 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +12 -0
- data/MIT-LICENSE +21 -0
- data/README +41 -0
- data/Rakefile +99 -0
- data/lib/rspec_extensions.rb +51 -0
- data/lib/rwebspec-webdriver.rb +52 -0
- data/lib/rwebspec/assert.rb +443 -0
- data/lib/rwebspec/clickJSDialog.rb +15 -0
- data/lib/rwebspec/context.rb +24 -0
- data/lib/rwebspec/database_checker.rb +74 -0
- data/lib/rwebspec/driver.rb +1009 -0
- data/lib/rwebspec/element_locator.rb +87 -0
- data/lib/rwebspec/load_test_helper.rb +172 -0
- data/lib/rwebspec/matchers/contains_text.rb +37 -0
- data/lib/rwebspec/popup.rb +147 -0
- data/lib/rwebspec/rspec_helper.rb +99 -0
- data/lib/rwebspec/test_script.rb +8 -0
- data/lib/rwebspec/test_utils.rb +217 -0
- data/lib/rwebspec/testwise_plugin.rb +83 -0
- data/lib/rwebspec/using_pages.rb +49 -0
- data/lib/rwebspec/web_browser.rb +742 -0
- data/lib/rwebspec/web_page.rb +108 -0
- data/lib/rwebspec/web_testcase.rb +38 -0
- data/lib/webdriver_extensions.rb +9 -0
- data/lib/window_script_extensions.rb +19 -0
- metadata +121 -0
data/CHANGELOG
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2006-2008 Zhimin Zhan, zhimin@zhimin.com
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
data/README
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
RWebSpec wraps the popular web testing framework WATIR with RSpec Syntax to provide better easy to read automated web test cases. By using TestWise/Watir recorder, the RWebSpec test scripts can be recorded in Firefox. TestWise, The Next-Generation Functional Testing IDE, makes editing/executing test cases with ease.
|
3
|
+
|
4
|
+
Sample RWebSpec Test:
|
5
|
+
|
6
|
+
load File.dirname(__FILE__) + '/test_helper.rb'
|
7
|
+
|
8
|
+
specification "User Profile" do
|
9
|
+
include TestHelper
|
10
|
+
|
11
|
+
before(:all) do
|
12
|
+
open_browser("http://demo.adminwise.com")
|
13
|
+
reset_database
|
14
|
+
end
|
15
|
+
|
16
|
+
after(:all) do
|
17
|
+
fail_safe { logout }
|
18
|
+
end
|
19
|
+
|
20
|
+
story "[8] User can change password" do
|
21
|
+
login_as("bob", "password")
|
22
|
+
click_link("Profile")
|
23
|
+
click_link("Change password")
|
24
|
+
|
25
|
+
password_change_page = expect_page PasswordChangePage
|
26
|
+
password_change_page.enter_current("password")
|
27
|
+
password_change_page.enter_new("newpass")
|
28
|
+
password_change_page.enter_confirm("newpass")
|
29
|
+
password_change_page.click_button("Change")
|
30
|
+
|
31
|
+
logout
|
32
|
+
login_as("bob", "newpass")
|
33
|
+
assert_link_present_with_text("Profile") # login Ok
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
TestWise Homepage: http://www.testwisely.com/en/testwise
|
41
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec/rake/spectask'
|
3
|
+
require 'rdoc/task'
|
4
|
+
require 'rake/gempackagetask'
|
5
|
+
require 'rdoc' # require rdoc 2
|
6
|
+
gem 'darkfish-rdoc'
|
7
|
+
# require 'darkfish-rdoc'
|
8
|
+
|
9
|
+
$:.unshift(File.dirname(__FILE__) + "/lib")
|
10
|
+
#require 'rwebspec'
|
11
|
+
|
12
|
+
desc "Default task"
|
13
|
+
task :default => [ :clean, :spec, :rdoc, :chm, :gem]
|
14
|
+
|
15
|
+
desc "Continous build"
|
16
|
+
task :build => [:clean, :spec]
|
17
|
+
|
18
|
+
desc "Clean generated files"
|
19
|
+
task :clean do
|
20
|
+
rm_rf 'pkg'
|
21
|
+
rm_rf 'doc'
|
22
|
+
rm_rf 'chm'
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'Run all specs'
|
26
|
+
Spec::Rake::SpecTask.new('spec') do |t|
|
27
|
+
t.spec_opts = ['--format', 'specdoc', '--colour']
|
28
|
+
# t.libs = ["lib", "server/lib" ]
|
29
|
+
t.spec_files = Dir['spec/**/*_spec.rb'].sort
|
30
|
+
end
|
31
|
+
|
32
|
+
# Generate the RDoc documentation
|
33
|
+
# Rake::RDocTask.new { |rdoc|
|
34
|
+
# rdoc.rdoc_dir = 'doc'
|
35
|
+
# rdoc.title = 'rWebUnit'
|
36
|
+
# rdoc.template = "#{ENV['template']}.rb" if ENV['template']
|
37
|
+
# rdoc.rdoc_files.include('README')
|
38
|
+
# rdoc.rdoc_files.include('lib/rwebspec.rb')
|
39
|
+
# rdoc.rdoc_files.include('lib/rwebspec/*.rb')
|
40
|
+
# }
|
41
|
+
|
42
|
+
# using DarkFish - http://deveiate.org/projects/Darkfish-Rdoc/
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
rdoc.rdoc_dir = 'doc'
|
45
|
+
rdoc.title = 'RWebSpec'
|
46
|
+
rdoc.rdoc_files.include('lib/rwebspec.rb')
|
47
|
+
rdoc.rdoc_files.include('lib/rwebspec/*.rb')
|
48
|
+
rdoc.rdoc_files.delete("lib/rwebspec/web_testcase.rb")
|
49
|
+
rdoc.rdoc_files.delete("lib/rwebspec/checkJSDialog.rb")
|
50
|
+
rdoc.options += [
|
51
|
+
'-SHN',
|
52
|
+
'-f', 'darkfish', # This is the important bit
|
53
|
+
]
|
54
|
+
end
|
55
|
+
|
56
|
+
Rake::RDocTask.new("chm") do |rdoc|
|
57
|
+
rdoc.rdoc_dir = 'chm'
|
58
|
+
rdoc.title = 'RWebSpec'
|
59
|
+
rdoc.rdoc_files.include('lib/rwebspec.rb')
|
60
|
+
rdoc.rdoc_files.include('lib/rwebspec/*.rb')
|
61
|
+
rdoc.rdoc_files.delete("lib/rwebspec/web_testcase.rb")
|
62
|
+
rdoc.rdoc_files.delete("lib/rwebspec/checkJSDialog.rb")
|
63
|
+
rdoc.options += [
|
64
|
+
'-SHN',
|
65
|
+
'-f', 'chm', # This is the important bit
|
66
|
+
]
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
spec = Gem::Specification.new do |s|
|
71
|
+
s.platform= Gem::Platform::RUBY
|
72
|
+
s.name = "rwebspec-webdriver"
|
73
|
+
s.version = "0.1"
|
74
|
+
s.summary = "Executable functional specification for web applications in RSpec syntax and Selenium-WebDriver"
|
75
|
+
# s.description = ""
|
76
|
+
|
77
|
+
s.author = "Zhimin Zhan"
|
78
|
+
s.email = "zhimin@agileway.net"
|
79
|
+
s.homepage= "http://github.com/zhimin/rwebspec-webdriver/tree/master"
|
80
|
+
s.rubyforge_project = "rwebspec-webdrive"
|
81
|
+
|
82
|
+
s.has_rdoc = true
|
83
|
+
s.requirements << 'none'
|
84
|
+
s.require_path = "lib"
|
85
|
+
s.autorequire = "rwebspec-webdriver"
|
86
|
+
|
87
|
+
s.files = [ "Rakefile", "README", "CHANGELOG", "MIT-LICENSE" ]
|
88
|
+
s.files = s.files + Dir.glob( "lib/**/*" )
|
89
|
+
s.files = s.files + Dir.glob( "test/**/*" )
|
90
|
+
s.files = s.files + Dir.glob( "sample/**/*")
|
91
|
+
s.files = s.files + Dir.glob( "docs/**/*" )
|
92
|
+
s.add_dependency(%q<rspec>, ["= 1.1.12"])
|
93
|
+
|
94
|
+
s.add_dependency("commonwatir", ">= 1.6.5")
|
95
|
+
end
|
96
|
+
|
97
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
98
|
+
pkg.need_zip = true
|
99
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Spec
|
2
|
+
module Extensions
|
3
|
+
module Main
|
4
|
+
|
5
|
+
alias :spec :describe
|
6
|
+
alias :specification :describe
|
7
|
+
alias :test_suite :describe
|
8
|
+
alias :suite :describe
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# For RSpec 1.1.12
|
15
|
+
module Spec
|
16
|
+
module DSL
|
17
|
+
module Main
|
18
|
+
|
19
|
+
alias :spec :describe
|
20
|
+
alias :specification :describe
|
21
|
+
alias :test_suite :describe
|
22
|
+
alias :suite :describe
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# ZZ patches to RSpec 1.1.4
|
29
|
+
# - add to_s method to example_group
|
30
|
+
module Spec
|
31
|
+
module Example
|
32
|
+
class ExampleGroup
|
33
|
+
def to_s
|
34
|
+
@_defined_description
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module Spec
|
41
|
+
module Example
|
42
|
+
module ExampleGroupMethods
|
43
|
+
|
44
|
+
alias_method :scenario, :it
|
45
|
+
alias_method :story, :it
|
46
|
+
alias_method :test_case, :it
|
47
|
+
alias_method :use_case, :it
|
48
|
+
alias_method :test, :it
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#***********************************************************
|
2
|
+
#* Copyright (c) 2006 - 2009, Zhimin Zhan.
|
3
|
+
#* Distributed open-source, see full license in MIT-LICENSE
|
4
|
+
#***********************************************************
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
|
8
|
+
# Load active_support, so that we can use 1.days.ago
|
9
|
+
begin
|
10
|
+
require 'active_support/basic_object'
|
11
|
+
require 'active_support/duration'
|
12
|
+
rescue LoadError => no_as1_err
|
13
|
+
# active_support 2.0 loaded error
|
14
|
+
end
|
15
|
+
require 'active_support/core_ext'
|
16
|
+
require 'spec'
|
17
|
+
require 'selenium-webdriver'
|
18
|
+
|
19
|
+
unless defined? RWEBSPEC_VERSION
|
20
|
+
RWEBSPEC_VERSION = "0.1"
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
if RUBY_PLATFORM =~ /mswin/ or RUBY_PLATFORM =~ /mingw/
|
25
|
+
$testwise_screenshot_supported = false
|
26
|
+
begin
|
27
|
+
require 'win32/screenshot'
|
28
|
+
$testwise_screenshot_supported = true
|
29
|
+
rescue LoadError => no_screen_library_error
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
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"
|
44
|
+
require File.dirname(__FILE__) + "/rspec_extensions"
|
45
|
+
require File.dirname(__FILE__) + "/webdriver_extensions"
|
46
|
+
if RUBY_PLATFORM =~ /mswin/ or RUBY_PLATFORM =~ /mingw/
|
47
|
+
require File.dirname(__FILE__) + "/window_script_extensions.rb"
|
48
|
+
end
|
49
|
+
|
50
|
+
require File.dirname(__FILE__) + "/rwebspec/matchers/contains_text"
|
51
|
+
require File.dirname(__FILE__) + "/rwebspec/testwise_plugin"
|
52
|
+
|
@@ -0,0 +1,443 @@
|
|
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
|