rwebspec-webdriver 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +5 -0
- data/Rakefile +1 -1
- data/lib/rwebspec-webdriver/driver.rb +2 -157
- data/lib/rwebspec-webdriver/test_utils.rb +161 -0
- data/lib/rwebspec-webdriver/web_browser.rb +1 -1
- data/lib/rwebspec-webdriver.rb +1 -1
- metadata +4 -4
data/CHANGELOG
CHANGED
data/Rakefile
CHANGED
@@ -69,7 +69,7 @@ end
|
|
69
69
|
spec = Gem::Specification.new do |s|
|
70
70
|
s.platform= Gem::Platform::RUBY
|
71
71
|
s.name = "rwebspec-webdriver"
|
72
|
-
s.version = "0.
|
72
|
+
s.version = "0.3.0"
|
73
73
|
s.summary = "Executable functional specification for web applications in RSpec syntax and Selenium-WebDriver"
|
74
74
|
# s.description = ""
|
75
75
|
|
@@ -127,6 +127,7 @@ module RWebSpec
|
|
127
127
|
#
|
128
128
|
def close_all_browsers
|
129
129
|
#TODO
|
130
|
+
close_browser
|
130
131
|
end
|
131
132
|
|
132
133
|
# Verify the next page following an operation.
|
@@ -590,59 +591,7 @@ module RWebSpec
|
|
590
591
|
#= Convenient functions
|
591
592
|
#
|
592
593
|
|
593
|
-
|
594
|
-
# may be appeal to someone.
|
595
|
-
|
596
|
-
# Example:
|
597
|
-
# on @page do |i|
|
598
|
-
# i.enter_text('btn1')
|
599
|
-
# i.click_button('btn1')
|
600
|
-
# end
|
601
|
-
def on(page, & block)
|
602
|
-
yield page
|
603
|
-
end
|
604
|
-
|
605
|
-
# fail the test if user can perform the operation
|
606
|
-
#
|
607
|
-
# Example:
|
608
|
-
# shall_not_allow { 1/0 }
|
609
|
-
def shall_not_allow(& block)
|
610
|
-
operation_performed_ok = false
|
611
|
-
begin
|
612
|
-
yield
|
613
|
-
operation_performed_ok = true
|
614
|
-
rescue
|
615
|
-
end
|
616
|
-
raise "Operation shall not be allowed" if operation_performed_ok
|
617
|
-
end
|
618
|
-
|
619
|
-
alias do_not_allow shall_not_allow
|
620
|
-
|
621
|
-
# Does not provide real function, other than make enhancing test syntax
|
622
|
-
#
|
623
|
-
# Example:
|
624
|
-
# allow { click_button('Register') }
|
625
|
-
def allow(& block)
|
626
|
-
yield
|
627
|
-
end
|
628
|
-
|
629
|
-
alias shall_allow allow
|
630
|
-
alias allowing allow
|
631
|
-
|
632
|
-
# try operation, ignore if errors occur
|
633
|
-
#
|
634
|
-
# Example:
|
635
|
-
# failsafe { click_link("Logout") } # try logout, but it still OK if not being able to (already logout))
|
636
|
-
def failsafe(& block)
|
637
|
-
begin
|
638
|
-
yield
|
639
|
-
rescue =>e
|
640
|
-
end
|
641
|
-
end
|
642
|
-
|
643
|
-
alias fail_safe failsafe
|
644
|
-
|
645
|
-
|
594
|
+
|
646
595
|
# Execute the provided block until either (1) it returns true, or
|
647
596
|
# (2) the timeout (in seconds) has been reached. If the timeout is reached,
|
648
597
|
# a TimeOutException will be raised. The block will always
|
@@ -749,84 +698,6 @@ module RWebSpec
|
|
749
698
|
|
750
699
|
=end
|
751
700
|
|
752
|
-
# Try the operation up to specified times, and sleep given interval (in seconds)
|
753
|
-
# Error will be ignored until timeout
|
754
|
-
# Example
|
755
|
-
# repeat_try(3, 2) { click_button('Search' } # 3 times, 6 seconds in total
|
756
|
-
# repeat_try { click_button('Search' } # using default 5 tries, 2 second interval
|
757
|
-
def repeat_try(num_tries = @@default_timeout || 30, interval = @@default_polling_interval || 1, & block)
|
758
|
-
num_tries ||= 1
|
759
|
-
(num_tries - 1).times do |num|
|
760
|
-
begin
|
761
|
-
yield
|
762
|
-
return
|
763
|
-
rescue => e
|
764
|
-
# puts "debug: #{num} failed: #{e}"
|
765
|
-
sleep interval
|
766
|
-
end
|
767
|
-
end
|
768
|
-
|
769
|
-
# last try, throw error if still fails
|
770
|
-
begin
|
771
|
-
yield
|
772
|
-
rescue => e
|
773
|
-
raise e.to_s + " after trying #{num_tries} times every #{interval} seconds"
|
774
|
-
end
|
775
|
-
yield
|
776
|
-
end
|
777
|
-
|
778
|
-
# TODO: syntax
|
779
|
-
|
780
|
-
# Try the operation up to specified timeout (in seconds), and sleep given interval (in seconds).
|
781
|
-
# Error will be ignored until timeout
|
782
|
-
# Example
|
783
|
-
# try { click_link('waiting')}
|
784
|
-
# try(10, 2) { click_button('Search' } # try to click the 'Search' button upto 10 seconds, try every 2 seconds
|
785
|
-
# try { click_button('Search' }
|
786
|
-
def try_until(timeout = @@default_timeout, polling_interval = @@default_polling_interval || 1, & block)
|
787
|
-
start_time = Time.now
|
788
|
-
|
789
|
-
last_error = nil
|
790
|
-
until (duration = Time.now - start_time) > timeout
|
791
|
-
begin
|
792
|
-
return if yield
|
793
|
-
last_error = nil
|
794
|
-
rescue => e
|
795
|
-
last_error = e
|
796
|
-
end
|
797
|
-
sleep polling_interval
|
798
|
-
end
|
799
|
-
|
800
|
-
raise "Timeout after #{duration.to_i} seconds with error: #{last_error}." if last_error
|
801
|
-
raise "Timeout after #{duration.to_i} seconds."
|
802
|
-
end
|
803
|
-
|
804
|
-
alias try_upto try_until
|
805
|
-
|
806
|
-
def try(timeout = @@default_timeout, polling_interval = @@default_polling_interval || 1, &block)
|
807
|
-
puts "Warning: method 'try' is deprecated (won't support in RWebSpec 3), use try_until instead."
|
808
|
-
try_until(timeout, polling_interval) {
|
809
|
-
yield
|
810
|
-
}
|
811
|
-
end
|
812
|
-
|
813
|
-
##
|
814
|
-
# Convert :first to 1, :second to 2, and so on...
|
815
|
-
def symbol_to_sequence(symb)
|
816
|
-
value = {:zero => 0,
|
817
|
-
:first => 1,
|
818
|
-
:second => 2,
|
819
|
-
:third => 3,
|
820
|
-
:fourth => 4,
|
821
|
-
:fifth => 5,
|
822
|
-
:sixth => 6,
|
823
|
-
:seventh => 7,
|
824
|
-
:eighth => 8,
|
825
|
-
:ninth => 9,
|
826
|
-
:tenth => 10}[symb]
|
827
|
-
return value || symb.to_i
|
828
|
-
end
|
829
|
-
|
830
701
|
# Clear popup windows such as 'Security Alert' or 'Security Information' popup window,
|
831
702
|
#
|
832
703
|
# Screenshot see http://kb2.adobe.com/cps/165/tn_16588.html
|
@@ -966,32 +837,6 @@ module RWebSpec
|
|
966
837
|
end
|
967
838
|
|
968
839
|
|
969
|
-
# use win32screenshot library to save curernt active window, which shall be IE
|
970
|
-
#
|
971
|
-
def take_screenshot
|
972
|
-
if $testwise_screenshot_supported && is_windows?
|
973
|
-
begin
|
974
|
-
screenshot_image_filename = "screenshot_" + Time.now.strftime("%m%d%H%M%S") + ".jpg"
|
975
|
-
the_dump_dir = default_dump_dir
|
976
|
-
FileUtils.mkdir_p(the_dump_dir) unless File.exists?(the_dump_dir)
|
977
|
-
screenshot_image_filepath = File.join(the_dump_dir, screenshot_image_filename)
|
978
|
-
screenshot_image_filepath.gsub!("/", "\\") if is_windows?
|
979
|
-
|
980
|
-
FileUtils.rm_f(screenshot_image_filepath) if File.exist?(screenshot_image_filepath)
|
981
|
-
|
982
|
-
case @web_browser.underlying_browser.browser
|
983
|
-
when :internet_explorer
|
984
|
-
Win32::Screenshot::Take.of(:window, :title => /internet\sexplorer/i).write(screenshot_image_filepath)
|
985
|
-
else
|
986
|
-
Win32::Screenshot::Take.of(:foreground).write(screenshot_image_filepath)
|
987
|
-
end
|
988
|
-
notify_screenshot_location(screenshot_image_filepath)
|
989
|
-
rescue => e
|
990
|
-
puts "error on taking screenshot: #{e}"
|
991
|
-
end
|
992
|
-
end
|
993
|
-
end
|
994
|
-
|
995
840
|
end
|
996
841
|
|
997
842
|
end
|
@@ -9,6 +9,167 @@ module RWebSpec
|
|
9
9
|
module WebDriver
|
10
10
|
module Utils
|
11
11
|
|
12
|
+
@@default_polling_interval = 1 # second
|
13
|
+
@@default_timeout = 30 # seconds
|
14
|
+
|
15
|
+
# Using Ruby block syntax to create interesting domain specific language,
|
16
|
+
# may be appeal to someone.
|
17
|
+
|
18
|
+
# Example:
|
19
|
+
# on @page do |i|
|
20
|
+
# i.enter_text('btn1')
|
21
|
+
# i.click_button('btn1')
|
22
|
+
# end
|
23
|
+
def on(page, & block)
|
24
|
+
yield page
|
25
|
+
end
|
26
|
+
|
27
|
+
# fail the test if user can perform the operation
|
28
|
+
#
|
29
|
+
# Example:
|
30
|
+
# shall_not_allow { 1/0 }
|
31
|
+
def shall_not_allow(& block)
|
32
|
+
operation_performed_ok = false
|
33
|
+
begin
|
34
|
+
yield
|
35
|
+
operation_performed_ok = true
|
36
|
+
rescue
|
37
|
+
end
|
38
|
+
raise "Operation shall not be allowed" if operation_performed_ok
|
39
|
+
end
|
40
|
+
|
41
|
+
alias do_not_allow shall_not_allow
|
42
|
+
|
43
|
+
# Does not provide real function, other than make enhancing test syntax
|
44
|
+
#
|
45
|
+
# Example:
|
46
|
+
# allow { click_button('Register') }
|
47
|
+
def allow(& block)
|
48
|
+
yield
|
49
|
+
end
|
50
|
+
|
51
|
+
alias shall_allow allow
|
52
|
+
alias allowing allow
|
53
|
+
|
54
|
+
# try operation, ignore if errors occur
|
55
|
+
#
|
56
|
+
# Example:
|
57
|
+
# failsafe { click_link("Logout") } # try logout, but it still OK if not being able to (already logout))
|
58
|
+
def failsafe(& block)
|
59
|
+
begin
|
60
|
+
yield
|
61
|
+
rescue =>e
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
alias fail_safe failsafe
|
66
|
+
|
67
|
+
|
68
|
+
# Try the operation up to specified times, and sleep given interval (in seconds)
|
69
|
+
# Error will be ignored until timeout
|
70
|
+
# Example
|
71
|
+
# repeat_try(3, 2) { click_button('Search' } # 3 times, 6 seconds in total
|
72
|
+
# repeat_try { click_button('Search' } # using default 5 tries, 2 second interval
|
73
|
+
def repeat_try(num_tries = @@default_timeout || 30, interval = @@default_polling_interval || 1, & block)
|
74
|
+
num_tries ||= 1
|
75
|
+
(num_tries - 1).times do |num|
|
76
|
+
begin
|
77
|
+
yield
|
78
|
+
return
|
79
|
+
rescue => e
|
80
|
+
# puts "debug: #{num} failed: #{e}"
|
81
|
+
sleep interval
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# last try, throw error if still fails
|
86
|
+
begin
|
87
|
+
yield
|
88
|
+
rescue => e
|
89
|
+
raise e.to_s + " after trying #{num_tries} times every #{interval} seconds"
|
90
|
+
end
|
91
|
+
yield
|
92
|
+
end
|
93
|
+
|
94
|
+
# TODO: syntax
|
95
|
+
|
96
|
+
# Try the operation up to specified timeout (in seconds), and sleep given interval (in seconds).
|
97
|
+
# Error will be ignored until timeout
|
98
|
+
# Example
|
99
|
+
# try { click_link('waiting')}
|
100
|
+
# try(10, 2) { click_button('Search' } # try to click the 'Search' button upto 10 seconds, try every 2 seconds
|
101
|
+
# try { click_button('Search' }
|
102
|
+
def try_until(timeout = @@default_timeout, polling_interval = @@default_polling_interval || 1, & block)
|
103
|
+
start_time = Time.now
|
104
|
+
|
105
|
+
last_error = nil
|
106
|
+
until (duration = Time.now - start_time) > timeout
|
107
|
+
begin
|
108
|
+
return if yield
|
109
|
+
last_error = nil
|
110
|
+
rescue => e
|
111
|
+
last_error = e
|
112
|
+
end
|
113
|
+
sleep polling_interval
|
114
|
+
end
|
115
|
+
|
116
|
+
raise "Timeout after #{duration.to_i} seconds with error: #{last_error}." if last_error
|
117
|
+
raise "Timeout after #{duration.to_i} seconds."
|
118
|
+
end
|
119
|
+
|
120
|
+
alias try_upto try_until
|
121
|
+
|
122
|
+
def try(timeout = @@default_timeout, polling_interval = @@default_polling_interval || 1, &block)
|
123
|
+
puts "Warning: method 'try' is deprecated (won't support in RWebSpec 3), use try_until instead."
|
124
|
+
try_until(timeout, polling_interval) {
|
125
|
+
yield
|
126
|
+
}
|
127
|
+
end
|
128
|
+
|
129
|
+
##
|
130
|
+
# Convert :first to 1, :second to 2, and so on...
|
131
|
+
def symbol_to_sequence(symb)
|
132
|
+
value = {:zero => 0,
|
133
|
+
:first => 1,
|
134
|
+
:second => 2,
|
135
|
+
:third => 3,
|
136
|
+
:fourth => 4,
|
137
|
+
:fifth => 5,
|
138
|
+
:sixth => 6,
|
139
|
+
:seventh => 7,
|
140
|
+
:eighth => 8,
|
141
|
+
:ninth => 9,
|
142
|
+
:tenth => 10}[symb]
|
143
|
+
return value || symb.to_i
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
# use win32screenshot library to save curernt active window, which shall be IE
|
148
|
+
#
|
149
|
+
def take_screenshot
|
150
|
+
if $testwise_screenshot_supported && is_windows?
|
151
|
+
begin
|
152
|
+
screenshot_image_filename = "screenshot_" + Time.now.strftime("%m%d%H%M%S") + ".jpg"
|
153
|
+
the_dump_dir = default_dump_dir
|
154
|
+
FileUtils.mkdir_p(the_dump_dir) unless File.exists?(the_dump_dir)
|
155
|
+
screenshot_image_filepath = File.join(the_dump_dir, screenshot_image_filename)
|
156
|
+
screenshot_image_filepath.gsub!("/", "\\") if is_windows?
|
157
|
+
|
158
|
+
FileUtils.rm_f(screenshot_image_filepath) if File.exist?(screenshot_image_filepath)
|
159
|
+
|
160
|
+
case @web_browser.underlying_browser.browser
|
161
|
+
when :internet_explorer
|
162
|
+
Win32::Screenshot::Take.of(:window, :title => /internet\sexplorer/i).write(screenshot_image_filepath)
|
163
|
+
else
|
164
|
+
Win32::Screenshot::Take.of(:foreground).write(screenshot_image_filepath)
|
165
|
+
end
|
166
|
+
notify_screenshot_location(screenshot_image_filepath)
|
167
|
+
rescue => e
|
168
|
+
puts "error on taking screenshot: #{e}"
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
12
173
|
# default date format returned is 29/12/2007.
|
13
174
|
# if supplied parameter is not '%m/%d/%Y' -> 12/29/2007
|
14
175
|
# Otherwise, "2007-12-29", which is most approiate date format
|
@@ -35,7 +35,7 @@ module RWebSpec
|
|
35
35
|
initialize_celerity_browser(base_url, options)
|
36
36
|
when /mswin|windows|mingw/i
|
37
37
|
options[:browser] ||= "ie"
|
38
|
-
case options[:browser].to_s
|
38
|
+
case options[:browser].to_s.downcase
|
39
39
|
when "firefox"
|
40
40
|
initialize_firefox_browser(existing_browser, base_url, options)
|
41
41
|
when "chrome"
|
data/lib/rwebspec-webdriver.rb
CHANGED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Zhimin Zhan
|
@@ -14,7 +14,7 @@ autorequire: rwebspec-webdriver
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2012-01-19 00:00:00 +10:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|