rwebunit 0.9.4 → 1.0.3
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 +228 -168
- data/MIT-LICENSE +1 -1
- data/README +32 -29
- data/Rakefile +5 -4
- data/lib/rspec_extensions.rb +10 -2
- data/lib/rwebunit.rb +8 -3
- data/lib/rwebunit/assert.rb +25 -24
- data/lib/rwebunit/clickJSDialog.rb +15 -0
- data/lib/rwebunit/context.rb +24 -24
- data/lib/rwebunit/driver.rb +297 -33
- data/lib/rwebunit/itest_plugin.rb +47 -0
- data/lib/rwebunit/matchers/contains_text.rb +37 -0
- data/lib/rwebunit/rspec_helper.rb +140 -128
- data/lib/rwebunit/test_utils.rb +98 -88
- data/lib/rwebunit/{web_tester.rb → web_browser.rb} +433 -510
- data/lib/rwebunit/web_page.rb +96 -99
- data/lib/rwebunit/web_testcase.rb +36 -36
- data/lib/watir_extensions.rb +65 -0
- data/test/mock_page.rb +8 -0
- data/test/setup.rb +10 -0
- data/test/test.html +129 -0
- data/test/test_assert.rb +64 -0
- data/test/test_driver.rb +23 -5
- metadata +24 -14
- data/sample/README.txt +0 -21
- data/sample/kangxi_home_webtest.rb +0 -37
- data/sample/kangxi_httpcaller_webtest.rb +0 -33
- data/sample/kangxi_pages.rb +0 -62
- data/sample/kangxi_xml_formatter_webtest.rb +0 -44
- data/sample/rwebunit_home_testcase.rb +0 -22
- data/sample/sample_rwebunit_test.rb +0 -15
- data/sample/sample_rwebunit_testcase.rb +0 -22
- data/sample/sample_watir_test.rb +0 -17
data/lib/rwebunit/web_page.rb
CHANGED
@@ -1,99 +1,96 @@
|
|
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 RWebUnit
|
10
|
-
|
11
|
-
# WebPage (children of AbstractWebPage) encapsulates a real web page.
|
12
|
-
# For example,
|
13
|
-
# beginAt("/home")
|
14
|
-
# @
|
15
|
-
# @
|
16
|
-
# Can be rewritten to
|
17
|
-
# begin_at("/home")
|
18
|
-
# home_page = HomePage.new
|
19
|
-
# login_page = home_page.clickLoginLink
|
20
|
-
# login_page.enterUserName("sa")
|
21
|
-
#
|
22
|
-
# So you only need change in LoingPage class if UI changes, which happen quite often.
|
23
|
-
class AbstractWebPage
|
24
|
-
|
25
|
-
include RWebUnit::Assert
|
26
|
-
include RWebUnit::Driver
|
27
|
-
|
28
|
-
# browser: passed to do assertion within the page
|
29
|
-
# page_text: text used to identify the page, title will be the first candidate
|
30
|
-
attr_accessor :
|
31
|
-
|
32
|
-
def initialize(
|
33
|
-
@
|
34
|
-
@
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
end
|
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 RWebUnit
|
10
|
+
|
11
|
+
# WebPage (children of AbstractWebPage) encapsulates a real web page.
|
12
|
+
# For example,
|
13
|
+
# beginAt("/home")
|
14
|
+
# @web_browser.clickLinkWithText("/login")
|
15
|
+
# @web_browser.setFormElement("username", "sa")
|
16
|
+
# Can be rewritten to
|
17
|
+
# begin_at("/home")
|
18
|
+
# home_page = HomePage.new
|
19
|
+
# login_page = home_page.clickLoginLink
|
20
|
+
# login_page.enterUserName("sa")
|
21
|
+
#
|
22
|
+
# So you only need change in LoingPage class if UI changes, which happen quite often.
|
23
|
+
class AbstractWebPage
|
24
|
+
|
25
|
+
include RWebUnit::Assert
|
26
|
+
include RWebUnit::Driver
|
27
|
+
|
28
|
+
# browser: passed to do assertion within the page
|
29
|
+
# page_text: text used to identify the page, title will be the first candidate
|
30
|
+
attr_accessor :page_text
|
31
|
+
|
32
|
+
def initialize(the_browser, page_text=nil)
|
33
|
+
@web_browser = the_browser
|
34
|
+
@web_tester = the_browser
|
35
|
+
@page_text = page_text
|
36
|
+
begin
|
37
|
+
snapshot if $ITEST2_DUMP_PAGE
|
38
|
+
delay = $ITEST2_PAGE_DELAY
|
39
|
+
sleep(delay)
|
40
|
+
rescue => e
|
41
|
+
end
|
42
|
+
assert_on_page
|
43
|
+
end
|
44
|
+
|
45
|
+
def browser
|
46
|
+
@web_browser
|
47
|
+
end
|
48
|
+
|
49
|
+
def assert_on_page()
|
50
|
+
assert_text_present(@page_text) if @page_text
|
51
|
+
end
|
52
|
+
|
53
|
+
def assert_not_on_page()
|
54
|
+
assert_text_not_present(@page_text) if @page_text
|
55
|
+
end
|
56
|
+
|
57
|
+
def dump(stream = nil)
|
58
|
+
@web_browser.dump_response(stream)
|
59
|
+
end
|
60
|
+
|
61
|
+
def source
|
62
|
+
@web_browser.page_source
|
63
|
+
end
|
64
|
+
|
65
|
+
def title
|
66
|
+
@web_browser.page_title
|
67
|
+
end
|
68
|
+
|
69
|
+
# TO validate
|
70
|
+
def contains?(ary)
|
71
|
+
page_source = source
|
72
|
+
found = false
|
73
|
+
ary.each do |str|
|
74
|
+
found ||= page_source.include?(str)
|
75
|
+
end
|
76
|
+
return found
|
77
|
+
end
|
78
|
+
alias include contains?
|
79
|
+
|
80
|
+
|
81
|
+
def snapshot
|
82
|
+
if $ITEST2_DUMP_DIR
|
83
|
+
spec_run_id = $ITEST2_RUNNING_SPEC_ID || "unknown"
|
84
|
+
spec_run_dir_name = spec_run_id.to_s.rjust(4, "0") unless spec_run_id == "unknown"
|
85
|
+
spec_run_dir = File.join($ITEST2_DUMP_DIR, spec_run_dir_name)
|
86
|
+
Dir.mkdir(spec_run_dir) unless File.exists?(spec_run_dir)
|
87
|
+
file_name = Time.now.strftime("%m%d%H%M%S") + "_" + self.class.name.gsub("", "") + ".html"
|
88
|
+
file = File.join($ITEST2_DUMP_DIR, spec_run_dir_name, file_name)
|
89
|
+
page_source = browser.page_source
|
90
|
+
File.new(file, "w").puts source
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
@@ -1,36 +1,36 @@
|
|
1
|
-
#***********************************************************
|
2
|
-
#* Copyright (c) 2006, Zhimin Zhan.
|
3
|
-
#* Distributed open-source, see full license in MIT-LICENSE
|
4
|
-
#***********************************************************
|
5
|
-
|
6
|
-
require 'test/unit'
|
7
|
-
require File.join(File.dirname(__FILE__), 'assert')
|
8
|
-
require File.join(File.dirname(__FILE__), 'driver')
|
9
|
-
|
10
|
-
module RWebUnit
|
11
|
-
|
12
|
-
class WebTestCase < Test::Unit::TestCase
|
13
|
-
include RWebUnit::Driver
|
14
|
-
include RWebUnit::Assert
|
15
|
-
include RWebUnit::Utils
|
16
|
-
|
17
|
-
attr_reader :web_tester
|
18
|
-
|
19
|
-
def initialize(name=nil)
|
20
|
-
super(name) if name
|
21
|
-
@
|
22
|
-
end
|
23
|
-
|
24
|
-
def default_test
|
25
|
-
super unless (self.class == WebTestCase)
|
26
|
-
end
|
27
|
-
|
28
|
-
def open_browser(baseUrl, relativeUrl)
|
29
|
-
context.base_url = baseUrl
|
30
|
-
begin_at(relativeUrl)
|
31
|
-
end
|
32
|
-
alias open_ie open_browser
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
1
|
+
#***********************************************************
|
2
|
+
#* Copyright (c) 2006, Zhimin Zhan.
|
3
|
+
#* Distributed open-source, see full license in MIT-LICENSE
|
4
|
+
#***********************************************************
|
5
|
+
|
6
|
+
require 'test/unit'
|
7
|
+
require File.join(File.dirname(__FILE__), 'assert')
|
8
|
+
require File.join(File.dirname(__FILE__), 'driver')
|
9
|
+
|
10
|
+
module RWebUnit
|
11
|
+
|
12
|
+
class WebTestCase < Test::Unit::TestCase
|
13
|
+
include RWebUnit::Driver
|
14
|
+
include RWebUnit::Assert
|
15
|
+
include RWebUnit::Utils
|
16
|
+
|
17
|
+
attr_reader :web_tester
|
18
|
+
|
19
|
+
def initialize(name=nil)
|
20
|
+
super(name) if name
|
21
|
+
@web_browser = WebBrowser.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def default_test
|
25
|
+
super unless (self.class == WebTestCase)
|
26
|
+
end
|
27
|
+
|
28
|
+
def open_browser(baseUrl, relativeUrl)
|
29
|
+
context.base_url = baseUrl
|
30
|
+
begin_at(relativeUrl)
|
31
|
+
end
|
32
|
+
alias open_ie open_browser
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
|
2
|
+
module FireWatir
|
3
|
+
class Firefox
|
4
|
+
|
5
|
+
@@firefox_started = false
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
if(options.kind_of?(Integer))
|
9
|
+
options = {:waitTime => options}
|
10
|
+
end
|
11
|
+
|
12
|
+
if(options[:profile])
|
13
|
+
profile_opt = "-no-remote -P #{options[:profile]}"
|
14
|
+
else
|
15
|
+
profile_opt = ""
|
16
|
+
end
|
17
|
+
|
18
|
+
waitTime = options[:waitTime] || 2
|
19
|
+
|
20
|
+
case RUBY_PLATFORM
|
21
|
+
when /mswin/
|
22
|
+
# Get the path to Firefox.exe using Registry.
|
23
|
+
require 'win32/registry.rb'
|
24
|
+
path_to_bin = ""
|
25
|
+
Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Mozilla\Mozilla Firefox') do |reg|
|
26
|
+
keys = reg.keys
|
27
|
+
reg1 = Win32::Registry::HKEY_LOCAL_MACHINE.open("SOFTWARE\\Mozilla\\Mozilla Firefox\\#{keys[0]}\\Main")
|
28
|
+
reg1.each do |subkey, type, data|
|
29
|
+
if(subkey =~ /pathtoexe/i)
|
30
|
+
path_to_bin = data
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
when /linux/i
|
36
|
+
path_to_bin = `which firefox`.strip
|
37
|
+
when /darwin/i
|
38
|
+
path_to_bin = '/Applications/Firefox.app/Contents/MacOS/firefox'
|
39
|
+
when /java/
|
40
|
+
raise "Not implemented: Create a browser finder in JRuby"
|
41
|
+
end
|
42
|
+
|
43
|
+
@t = Thread.new { system("#{path_to_bin} -jssh #{profile_opt}")} unless @@firefox_started
|
44
|
+
|
45
|
+
sleep waitTime
|
46
|
+
begin
|
47
|
+
set_defaults()
|
48
|
+
rescue Watir::Exception::UnableToStartJSShException
|
49
|
+
if !@t # no new thread starting browser, try again
|
50
|
+
puts "Firefox with JSSH not detected after you indicated @@firefox_started"
|
51
|
+
@t = Thread.new { system("#{path_to_bin} -jssh #{profile_opt}")}
|
52
|
+
sleep waitTime
|
53
|
+
set_defaults
|
54
|
+
end
|
55
|
+
end
|
56
|
+
get_window_number()
|
57
|
+
set_browser_document()
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.firefox_started=(value)
|
61
|
+
@@firefox_started = value
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
data/test/mock_page.rb
ADDED
data/test/setup.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'firewatir'
|
2
|
+
|
3
|
+
$loaded = false
|
4
|
+
unless $loaded
|
5
|
+
sample_html = "file://" + File.expand_path(File.dirname(__FILE__) + "/test.html")
|
6
|
+
$firefox = FireWatir::Firefox.new
|
7
|
+
$firefox.goto(sample_html)
|
8
|
+
$web_browser = RWebUnit::WebBrowser.new("test", $firefox, :firefox => true)
|
9
|
+
$loaded = true
|
10
|
+
end
|
data/test/test.html
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>
|
5
|
+
For Testing Recorder
|
6
|
+
</title>
|
7
|
+
<style type="text/css">
|
8
|
+
body {
|
9
|
+
margin: 5px;
|
10
|
+
padding: 0;
|
11
|
+
font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Helvetica, Arial, sans-serif;
|
12
|
+
font-size: small;
|
13
|
+
background: #f4f4ed;
|
14
|
+
}
|
15
|
+
|
16
|
+
h1, h2, h3, h4, h5, h6 {
|
17
|
+
margin-top: 0;
|
18
|
+
color: black;
|
19
|
+
font-family: Georgia, "Times New Roman", Times, serif;
|
20
|
+
font-weight: normal
|
21
|
+
}
|
22
|
+
|
23
|
+
a:link {
|
24
|
+
color: #005f96
|
25
|
+
}
|
26
|
+
|
27
|
+
a:visited {
|
28
|
+
color: #484848
|
29
|
+
}
|
30
|
+
|
31
|
+
a:hover, a:active {
|
32
|
+
color: #c30
|
33
|
+
}
|
34
|
+
|
35
|
+
td {
|
36
|
+
font-size: small;
|
37
|
+
}
|
38
|
+
</style>
|
39
|
+
</head>
|
40
|
+
<body>
|
41
|
+
<form action="test">
|
42
|
+
<h1>
|
43
|
+
iTest2/Watir Recorder Test Page
|
44
|
+
</h1>
|
45
|
+
<h2>
|
46
|
+
Links
|
47
|
+
</h2>
|
48
|
+
<p>
|
49
|
+
<a href="http://www.itest2.com">iTest2</a> <a id="link_itest2" href="http://www.itest2.com" name="link_itest2">iTest2 with Id</a>
|
50
|
+
</p>
|
51
|
+
<h2>
|
52
|
+
Checkboxes
|
53
|
+
</h2>
|
54
|
+
<p>
|
55
|
+
<input name="checkbox1" type="checkbox"> No Value <input name="checkbox2" type="checkbox" value="true"> With value true <input id="checkbox3" type="checkbox"> Id but no name
|
56
|
+
</p>
|
57
|
+
<h2>
|
58
|
+
Buttons
|
59
|
+
</h2>
|
60
|
+
<p>
|
61
|
+
<input type="button" id="login-btn" value="Login"> <input type="button" value="Login"> <input type="submit" value="Submit without id">
|
62
|
+
</p>
|
63
|
+
<h2>
|
64
|
+
Radio buttons
|
65
|
+
</h2>
|
66
|
+
<p>
|
67
|
+
<input type="radio" checked="true" name="os" value="Apple"> Apple <input type="radio" name="os" value="Linux"> Linux
|
68
|
+
</p>
|
69
|
+
<h2>
|
70
|
+
Text fields
|
71
|
+
</h2>
|
72
|
+
<table>
|
73
|
+
<tr>
|
74
|
+
<td>
|
75
|
+
Text (single line):
|
76
|
+
</td>
|
77
|
+
<td>
|
78
|
+
<input type="text" name="text1" value="text already there"> <i>Right click to verify textfield</i>
|
79
|
+
</td>
|
80
|
+
</tr>
|
81
|
+
<tr>
|
82
|
+
<td>
|
83
|
+
Text (with name, just id):
|
84
|
+
</td>
|
85
|
+
<td>
|
86
|
+
<input type="text" id="text_without_id" value=""> <i>Right click to verify textfield</i>
|
87
|
+
</td>
|
88
|
+
</tr>
|
89
|
+
<tr>
|
90
|
+
<td>
|
91
|
+
Password:
|
92
|
+
</td>
|
93
|
+
<td>
|
94
|
+
<input type="password" name="password1">
|
95
|
+
</td>
|
96
|
+
</tr>
|
97
|
+
<tr>
|
98
|
+
<td valign="top">
|
99
|
+
TextArea:
|
100
|
+
</td>
|
101
|
+
<td>
|
102
|
+
<textarea name="textarea" cols="10" rows="2">
|
103
|
+
</textarea>
|
104
|
+
</td>
|
105
|
+
</tr>
|
106
|
+
</table>
|
107
|
+
<h2>
|
108
|
+
Select (combobox)
|
109
|
+
</h2>
|
110
|
+
<p>
|
111
|
+
By Name: <select name="testing_tool">
|
112
|
+
<option value="iTest2">
|
113
|
+
iTest2 display
|
114
|
+
</option>
|
115
|
+
<option value="Watir">
|
116
|
+
Watir
|
117
|
+
</option>
|
118
|
+
</select> By Id: <select id="methodology">
|
119
|
+
<option value="XP">
|
120
|
+
Agile way
|
121
|
+
</option>
|
122
|
+
<option value="Waterfall">
|
123
|
+
Water way
|
124
|
+
</option>
|
125
|
+
</select>
|
126
|
+
</p>
|
127
|
+
</form>
|
128
|
+
</body>
|
129
|
+
</html>
|