rwebunit 0.1
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 +6 -0
- data/MIT-LICENSE +21 -0
- data/README +30 -0
- data/Rakefile +68 -0
- data/docs/html/index.html +129 -0
- data/lib/rwebunit/test_context.rb +19 -0
- data/lib/rwebunit/test_utils.rb +80 -0
- data/lib/rwebunit/web_page.rb +62 -0
- data/lib/rwebunit/web_testcase.rb +160 -0
- data/lib/rwebunit/web_tester.rb +277 -0
- data/lib/rwebunit.rb +13 -0
- data/sample/kongming_pages.rb +63 -0
- data/sample/kongming_webtest.rb +79 -0
- data/sample/sample_rwebunit_test.rb +14 -0
- data/sample/sample_rwebunit_testcase.rb +22 -0
- data/sample/sample_watir_test.rb +16 -0
- data/test/test_test_utils.rb +73 -0
- metadata +71 -0
data/CHANGELOG
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2006 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,30 @@
|
|
1
|
+
rWebUnit is a ruby version of thoughtwork's open source jWebUnit, which 'facilitates creation of
|
2
|
+
acceptance tests for web applications'.
|
3
|
+
|
4
|
+
rWebUnit wraps the popular web testing framework: WATIR (jWebUnit depends on HttpUnit).
|
5
|
+
Because underlying technologies are different (HttpUnit simulates a browser, Watir drives IE), rWebUnit does
|
6
|
+
not support full jWebUnit API.
|
7
|
+
|
8
|
+
For example,
|
9
|
+
jWebUnit: checkCheckBox("name", "new_value") can set new value for a checkbox, but rWebUnit/Watir can't.
|
10
|
+
On the other hand, HttpUnit has limited support of Javascript, You don't need to worry about it in Watir.
|
11
|
+
|
12
|
+
Here are reasons you might want to try rWebUnit instead of using Watir directly.
|
13
|
+
|
14
|
+
* already familar with jWebUnit framework (arguably, more readable tests)
|
15
|
+
* want to use WebTest - Page framework to design your tests (look at sample\kongming_webtest.rb)
|
16
|
+
* want to use a high level of API beyond specific framework: WATIR
|
17
|
+
* utilize common test methods included in rWebUnit (like getToday ...)
|
18
|
+
|
19
|
+
TODO:
|
20
|
+
====
|
21
|
+
* file upload (waiting for Watir 2.0?)
|
22
|
+
* script to convert jWebUnit -> rWebUnit, and vice versa.
|
23
|
+
|
24
|
+
FAQ:
|
25
|
+
===
|
26
|
+
1. How can I run rWebUnit tests without showing IE window?
|
27
|
+
|
28
|
+
A: This is really a WATIR question. Append '-b' option your command.
|
29
|
+
Example: ruby hide_webtest.rb -b
|
30
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
Gem::manage_gems
|
6
|
+
require 'rake/gempackagetask'
|
7
|
+
|
8
|
+
|
9
|
+
$:.unshift(File.dirname(__FILE__) + "/lib")
|
10
|
+
require 'rwebunit'
|
11
|
+
|
12
|
+
desc "Default task"
|
13
|
+
task :default => [ :clean, :test ]
|
14
|
+
|
15
|
+
desc "Clean generated files"
|
16
|
+
task :clean do
|
17
|
+
rm_rf 'pkg'
|
18
|
+
rm_rf 'doc'
|
19
|
+
end
|
20
|
+
|
21
|
+
# run the unit tests
|
22
|
+
Rake::TestTask.new("test") { |t|
|
23
|
+
t.test_files = FileList['test/test*.rb']
|
24
|
+
t.verbose= true
|
25
|
+
}
|
26
|
+
|
27
|
+
# Generate the RDoc documentation
|
28
|
+
Rake::RDocTask.new { |rdoc|
|
29
|
+
rdoc.rdoc_dir = 'doc'
|
30
|
+
rdoc.title = 'rWebUnit'
|
31
|
+
rdoc.template = "#{ENV['template']}.rb" if ENV['template']
|
32
|
+
rdoc.rdoc_files.include('README')
|
33
|
+
rdoc.rdoc_files.include('lib/rwebunit.rb')
|
34
|
+
rdoc.rdoc_files.include('lib/rwebunit/*.rb')
|
35
|
+
}
|
36
|
+
|
37
|
+
spec = Gem::Specification.new do |s|
|
38
|
+
s.platform= Gem::Platform::RUBY
|
39
|
+
s.name = "rwebunit"
|
40
|
+
s.version = "0.1"
|
41
|
+
s.summary = "An wrap of WATIR for functional testing of web applications"
|
42
|
+
# s.description = ""
|
43
|
+
|
44
|
+
s.author = "Zhimin Zhan"
|
45
|
+
s.email = "zhimin@zhimin.com"
|
46
|
+
s.homepage= "http://www.zhimin.com/rWebUnit"
|
47
|
+
# s.rubyforge_project = ""
|
48
|
+
|
49
|
+
s.has_rdoc = true
|
50
|
+
s.requirements << 'none'
|
51
|
+
s.require_path = "lib"
|
52
|
+
s.autorequire = "rwebunit"
|
53
|
+
|
54
|
+
s.files = [ "Rakefile", "README", "CHANGELOG", "MIT-LICENSE" ]
|
55
|
+
# s.files = s.files + Dir.glob( "bin/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
|
56
|
+
s.files = s.files + Dir.glob( "lib/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
|
57
|
+
s.files = s.files + Dir.glob( "test/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
|
58
|
+
s.files = s.files + Dir.glob( "sample/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
|
59
|
+
s.files = s.files + Dir.glob( "docs/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
|
60
|
+
|
61
|
+
s.add_dependency("watir", ">= 1.4.1")
|
62
|
+
end
|
63
|
+
|
64
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
65
|
+
pkg.need_zip = true
|
66
|
+
end
|
67
|
+
|
68
|
+
|
@@ -0,0 +1,129 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>rWebUnit </title>
|
4
|
+
</head>
|
5
|
+
<body>
|
6
|
+
<p></p>
|
7
|
+
|
8
|
+
<table class="bodyTable">
|
9
|
+
<tr class="a">
|
10
|
+
<th>Watir Test</th>
|
11
|
+
<th>rWebUnit Test</th>
|
12
|
+
</tr>
|
13
|
+
<tr class="b">
|
14
|
+
<td valign="top" nowrap="nowrap">
|
15
|
+
<div class="source">
|
16
|
+
<pre>
|
17
|
+
require 'watir'
|
18
|
+
require 'test/unit'
|
19
|
+
|
20
|
+
class WatirSearchExample < Test::Unit::TestCase
|
21
|
+
|
22
|
+
def test_search
|
23
|
+
ie= Watir::IE.new
|
24
|
+
ie.goto("http://www.google.com")
|
25
|
+
ie.text_field( :name, " q"). set(" httpunit")
|
26
|
+
ie.button( :name, " btnG"). click
|
27
|
+
ie.link( :text, " HttpUnit Home"). click
|
28
|
+
assert_equal(" HttpUnit Home", ie.document.title)
|
29
|
+
assert( ie.contains_text(" User' s Manual"))
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
</pre>
|
34
|
+
</div>
|
35
|
+
</td>
|
36
|
+
<td valign="top" nowrap="nowrap">
|
37
|
+
<div class="source">
|
38
|
+
<pre>
|
39
|
+
|
40
|
+
require 'rwebunit'
|
41
|
+
|
42
|
+
class RWebUnitSearchExample < RWebUnit::WebTestCase
|
43
|
+
|
44
|
+
def test_search()
|
45
|
+
getTestContext().base_url="http://www.google.com"
|
46
|
+
beginAt("/")
|
47
|
+
setFormElement(" q", " httpunit")
|
48
|
+
clickButtonWithValue(" Google Search")
|
49
|
+
clickLinkWithText(" HttpUnit Home")
|
50
|
+
assertTitleEquals(" HttpUnit Home")
|
51
|
+
assertLinkPresentWithText(" User' s Manual")
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
</pre>
|
56
|
+
</div>
|
57
|
+
</td>
|
58
|
+
</tr>
|
59
|
+
</table>
|
60
|
+
<br/>
|
61
|
+
<table class="bodyTable">
|
62
|
+
<tr class="a">
|
63
|
+
<th>jWebUnit TestCase</th>
|
64
|
+
<th>rWebUnit TestCase</th>
|
65
|
+
</tr>
|
66
|
+
<tr class="b">
|
67
|
+
<td valign="top" nowrap="nowrap">
|
68
|
+
<div class="source">
|
69
|
+
<pre>
|
70
|
+
import net.sourceforge.jwebunit.WebTestCase;
|
71
|
+
|
72
|
+
public class JWebUnitSearchExample extends WebTestCase {
|
73
|
+
|
74
|
+
public JWebUnitSearchExample(String name) {
|
75
|
+
super(name);
|
76
|
+
}
|
77
|
+
|
78
|
+
public void setUp() {
|
79
|
+
getTestContext().setBaseUrl("http://www.google.com");
|
80
|
+
}
|
81
|
+
|
82
|
+
public void testSearch() {
|
83
|
+
beginAt("/");
|
84
|
+
setFormElement("q", "httpunit");
|
85
|
+
submit("btnG");
|
86
|
+
clickLinkWithText("HttpUnit");
|
87
|
+
assertTitleEquals("HttpUnit");
|
88
|
+
assertLinkPresentWithText("User's Manual");
|
89
|
+
}
|
90
|
+
}
|
91
|
+
</pre>
|
92
|
+
</div>
|
93
|
+
</td>
|
94
|
+
|
95
|
+
<td valign="top" nowrap="nowrap">
|
96
|
+
|
97
|
+
<div class="source">
|
98
|
+
<pre>
|
99
|
+
require 'rwebunit'
|
100
|
+
|
101
|
+
class RWebUnitSearchExample < RWebUnit::WebTestCase
|
102
|
+
|
103
|
+
def initialize( name)
|
104
|
+
super( name)
|
105
|
+
end
|
106
|
+
|
107
|
+
def setup
|
108
|
+
getTestContext(). setBaseUrl(" http:// www.google.com")
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_search
|
112
|
+
beginAt("/")
|
113
|
+
setFormElement(" q", " httpunit")
|
114
|
+
submit(" btnG")
|
115
|
+
clickLinkWithText(" HttpUnit Home")
|
116
|
+
assertTitleEquals(" HttpUnit Home")
|
117
|
+
assertLinkPresentWithText(" User' s Manual")
|
118
|
+
end
|
119
|
+
end
|
120
|
+
</pre>
|
121
|
+
</div>
|
122
|
+
|
123
|
+
</td>
|
124
|
+
</tr>
|
125
|
+
</table>
|
126
|
+
|
127
|
+
|
128
|
+
</body>
|
129
|
+
</html>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
#***********************************************************
|
2
|
+
#* Copyright (c) 2006, Zhimin Zhan.
|
3
|
+
#* Distributed open-source, see full license in MIT-LICENSE
|
4
|
+
#***********************************************************
|
5
|
+
|
6
|
+
module RWebUnit
|
7
|
+
|
8
|
+
##
|
9
|
+
# Store test optionns
|
10
|
+
#
|
11
|
+
class TestContext
|
12
|
+
attr_accessor :base_url
|
13
|
+
|
14
|
+
def setBaseUrl(baseUrl)
|
15
|
+
@base_url = baseUrl
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
#***********************************************************
|
2
|
+
#* Copyright (c) 2006, Zhimin Zhan.
|
3
|
+
#* Distributed open-source, see full license in MIT-LICENSE
|
4
|
+
#***********************************************************
|
5
|
+
|
6
|
+
module RWebUnit
|
7
|
+
module Utils
|
8
|
+
|
9
|
+
#useful methods for test data
|
10
|
+
def getToday_AU()
|
11
|
+
format_date(Time.now, "%02d/%02d/%04d")
|
12
|
+
end
|
13
|
+
alias getToday getToday_AU
|
14
|
+
|
15
|
+
def getToday_US()
|
16
|
+
sprintf("%02d/%02d/%04d", Time.now.month, Time.now.day, Time.now.year)
|
17
|
+
end
|
18
|
+
|
19
|
+
def getDaysBefore(days)
|
20
|
+
nil if !(days.instance_of?(Fixnum))
|
21
|
+
format_date(Time.now - days * 24 * 3600)
|
22
|
+
end
|
23
|
+
|
24
|
+
def getYesterday
|
25
|
+
getDaysBefore(1)
|
26
|
+
end
|
27
|
+
|
28
|
+
def getDaysAfter(days)
|
29
|
+
nil if !(days.instance_of?(Fixnum))
|
30
|
+
format_date(Time.now + days * 24 * 3600)
|
31
|
+
end
|
32
|
+
|
33
|
+
def getTomorrow
|
34
|
+
getDaysAfter(1)
|
35
|
+
end
|
36
|
+
|
37
|
+
#TODO: getDaysBefore, getDaysAfter, getYesterday, getTomorrow
|
38
|
+
|
39
|
+
# return a random number >= min, but <= max
|
40
|
+
def randomNumber(min, max)
|
41
|
+
rand(max-min+1)+min
|
42
|
+
end
|
43
|
+
|
44
|
+
def randomBoolean()
|
45
|
+
return randomNumber(0, 1) == 1
|
46
|
+
end
|
47
|
+
|
48
|
+
def randomChar(lowercase)
|
49
|
+
sprintf("%c", random_number(97, 122)) if lowercase
|
50
|
+
sprintf("%c", random_number(65, 90)) unless lowercase
|
51
|
+
end
|
52
|
+
|
53
|
+
def randomDigit()
|
54
|
+
sprintf("%c", randomNumber(48, 57))
|
55
|
+
end
|
56
|
+
|
57
|
+
def randomString(length, lowercase)
|
58
|
+
randomStr = ""
|
59
|
+
length.times {
|
60
|
+
randomStr += randomChar(lowercase)
|
61
|
+
}
|
62
|
+
randomStr
|
63
|
+
end
|
64
|
+
|
65
|
+
# Return a random string in a rangeof pre-defined strings
|
66
|
+
def randomStringInCollection(arr)
|
67
|
+
return nil if arr.empty?
|
68
|
+
index = random_number(0, arr.length-1)
|
69
|
+
arr[index]
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
def format_date(date, date_format = nil)
|
74
|
+
date_format ||= "%02d/%02d/%04d"
|
75
|
+
sprintf(date_format, date.day, date.month, date.year)
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#***********************************************************
|
2
|
+
#* Copyright (c) 2006, Zhimin Zhan.
|
3
|
+
#* Distributed open-source, see full license in MIT-LICENSE
|
4
|
+
#***********************************************************
|
5
|
+
|
6
|
+
module RWebUnit
|
7
|
+
|
8
|
+
# WebPage (children of AbstractWebPage) encapsulates a real web page.
|
9
|
+
# For example,
|
10
|
+
# beginAt("/home")
|
11
|
+
# @browser.clickLinkWithText("/login")
|
12
|
+
# @browser.setFormElement("username", "sa")
|
13
|
+
# Can be rewritten to
|
14
|
+
# beginAt("/home")
|
15
|
+
# home_page = HomePage.new
|
16
|
+
# login_page = home_page.clickLoginLink
|
17
|
+
# login_page.enterUserName("sa")
|
18
|
+
#
|
19
|
+
# So you only need change in LoingPage class if UI changes, which happen quite often.
|
20
|
+
class AbstractWebPage
|
21
|
+
|
22
|
+
# browser: passed to do assertion within the page
|
23
|
+
# page_text: text used to identify the page, title will be the first candidate
|
24
|
+
attr_accessor :browser, :page_text
|
25
|
+
|
26
|
+
def initialize(ie, page_text=nil)
|
27
|
+
@browser = ie
|
28
|
+
@page_text = page_text
|
29
|
+
assertOnPage
|
30
|
+
end
|
31
|
+
|
32
|
+
def assertTextPresent(text)
|
33
|
+
@browser.assertTextPresent(text)
|
34
|
+
end
|
35
|
+
|
36
|
+
def assertTextInElement(elementID, text)
|
37
|
+
@browser.assertTextInElement(elementID, text)
|
38
|
+
end
|
39
|
+
|
40
|
+
def assertOnPage()
|
41
|
+
assertTextPresent(@page_text) if @page_text
|
42
|
+
end
|
43
|
+
|
44
|
+
def assertNotOnPage()
|
45
|
+
assertTextNotPresent(@page_text) if @page_text
|
46
|
+
end
|
47
|
+
|
48
|
+
def submit
|
49
|
+
@browser.submit
|
50
|
+
end
|
51
|
+
|
52
|
+
def getElementValue(elementId)
|
53
|
+
@browser.getElemenValue(elementId)
|
54
|
+
end
|
55
|
+
|
56
|
+
def dumpResponse(stream = nil)
|
57
|
+
@browser.dumpResponse(stream)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
#***********************************************************
|
2
|
+
#* Copyright (c) 2006, Zhimin Zhan.
|
3
|
+
#* Distributed open-source, see full license in MIT-LICENSE
|
4
|
+
#***********************************************************
|
5
|
+
|
6
|
+
require 'test/unit'
|
7
|
+
|
8
|
+
module RWebUnit
|
9
|
+
|
10
|
+
class WebTestCase < Test::Unit::TestCase
|
11
|
+
include RWebUnit::Utils
|
12
|
+
|
13
|
+
attr_reader :web_tester
|
14
|
+
|
15
|
+
def initialize(name=nil)
|
16
|
+
super(name) if name
|
17
|
+
@web_tester = WebTester.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def default_test
|
21
|
+
super unless(self.class == WebTestCase)
|
22
|
+
end
|
23
|
+
|
24
|
+
def getTestContext
|
25
|
+
@web_tester.test_context
|
26
|
+
end
|
27
|
+
|
28
|
+
def beginAt(url)
|
29
|
+
@web_tester.beginAt(url)
|
30
|
+
end
|
31
|
+
|
32
|
+
def openBrowser(baseUrl, relativeUrl)
|
33
|
+
getTestContext().base_url = baseUrl
|
34
|
+
beginAt(relativeUrl)
|
35
|
+
end
|
36
|
+
|
37
|
+
def closeBrowser
|
38
|
+
@web_tester.closeBrowser
|
39
|
+
end
|
40
|
+
|
41
|
+
def goBack()
|
42
|
+
@web_tester.goBack
|
43
|
+
end
|
44
|
+
|
45
|
+
def goForward()
|
46
|
+
@web_tester.goForward
|
47
|
+
end
|
48
|
+
|
49
|
+
def gotoPage(page)
|
50
|
+
@web_tester.gotoPage(page)
|
51
|
+
end
|
52
|
+
|
53
|
+
# assertions
|
54
|
+
def assertTitleEquals(title)
|
55
|
+
@web_tester.assertTitleEquals(title)
|
56
|
+
end
|
57
|
+
|
58
|
+
def assertTextPresent(text)
|
59
|
+
@web_tester.assertTextPresent(text)
|
60
|
+
end
|
61
|
+
|
62
|
+
def assertTextNotPresent(text)
|
63
|
+
@web_tester.assertTextNotPresent(text)
|
64
|
+
end
|
65
|
+
|
66
|
+
# textfields
|
67
|
+
def setFormElement(elementName, elementValue)
|
68
|
+
@web_tester.setFormElement(elementName, elementValue)
|
69
|
+
end
|
70
|
+
|
71
|
+
def assertTextPresentInTextField(textfieldName, text, msg = nil)
|
72
|
+
@web_tester.assertTextPresentInTextField(textfieldName, text, msg)
|
73
|
+
end
|
74
|
+
|
75
|
+
#links
|
76
|
+
def clickLinkWithText(linkText)
|
77
|
+
@web_tester.clickLinkWithText(linkText)
|
78
|
+
end
|
79
|
+
|
80
|
+
def assertLinkPresentWithText(linkText)
|
81
|
+
@web_tester.assertLinkPresentWithText(linkText)
|
82
|
+
end
|
83
|
+
|
84
|
+
def assertLinkNotPresentWithText(linkText)
|
85
|
+
@web_tester.assertLinkNotPresentWithText(linkText)
|
86
|
+
end
|
87
|
+
|
88
|
+
##
|
89
|
+
# buttons
|
90
|
+
|
91
|
+
# submit the form using the first (index) submit button
|
92
|
+
def submit()
|
93
|
+
@web_tester.submit()
|
94
|
+
end
|
95
|
+
|
96
|
+
def submit(buttonId)
|
97
|
+
@web_tester.submit(buttonId)
|
98
|
+
end
|
99
|
+
|
100
|
+
def clickButton(buttonId)
|
101
|
+
@web_tester.clickButton(buttonId)
|
102
|
+
end
|
103
|
+
|
104
|
+
def clickButtonWithCaption(caption)
|
105
|
+
@web_tester.clickButtonWithCaption(caption)
|
106
|
+
end
|
107
|
+
|
108
|
+
def clickButtonWithValue(value)
|
109
|
+
@web_tester.clickButtonWithValue(value)
|
110
|
+
end
|
111
|
+
|
112
|
+
def assertButtonNotPresent(buttonID)
|
113
|
+
@web_tester.assertButtonNotPresent(buttonID)
|
114
|
+
end
|
115
|
+
|
116
|
+
def assertButtonNotPresentWithText(text)
|
117
|
+
@web_tester.assertButtonNotPresentWithText(text)
|
118
|
+
end
|
119
|
+
|
120
|
+
def assertButtonPresent(buttonID)
|
121
|
+
@web_tester.assertButtonPresent(buttonID)
|
122
|
+
end
|
123
|
+
|
124
|
+
def assertButtonPresentWithText(buttonID)
|
125
|
+
@web_tester.assertButtonPresentWithText(buttonID)
|
126
|
+
end
|
127
|
+
|
128
|
+
# checkbox
|
129
|
+
def checkCheckbox(checkBoxName)
|
130
|
+
@web_tester.checkCheckbox(checkBoxName)
|
131
|
+
end
|
132
|
+
|
133
|
+
def uncheckCheckbox(checkBoxName)
|
134
|
+
@web_tester.uncheckCheckbox(checkBoxName)
|
135
|
+
end
|
136
|
+
|
137
|
+
# combo box
|
138
|
+
def selectOption(selectName, option)
|
139
|
+
@web_tester.selectOption(selectName, option)
|
140
|
+
end
|
141
|
+
|
142
|
+
# dhtml related
|
143
|
+
def assertElementPresent(elementID)
|
144
|
+
@web_tester.assertElementPresent(elementID)
|
145
|
+
end
|
146
|
+
|
147
|
+
def assertElementNotPresent(elementID)
|
148
|
+
@web_tester.assertElementNotPresent(elementID)
|
149
|
+
end
|
150
|
+
|
151
|
+
# ---
|
152
|
+
# For deubgging
|
153
|
+
# ---
|
154
|
+
def dumpResponse(stream = nil)
|
155
|
+
@web_tester.dumpResponse(stream)
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
@@ -0,0 +1,277 @@
|
|
1
|
+
#***********************************************************
|
2
|
+
#* Copyright (c) 2006, Zhimin Zhan.
|
3
|
+
#* Distributed open-source, see full license in MIT-LICENSE
|
4
|
+
#***********************************************************
|
5
|
+
|
6
|
+
require 'watir/watir_simple.rb'
|
7
|
+
require 'runit/assert'
|
8
|
+
|
9
|
+
module RWebUnit
|
10
|
+
|
11
|
+
##
|
12
|
+
# Wrapping WATIR and provide assertions
|
13
|
+
#
|
14
|
+
class WebTester
|
15
|
+
include Watir::Simple
|
16
|
+
include RUNIT::Assert
|
17
|
+
|
18
|
+
attr_accessor :test_context
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@test_context = TestContext.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def beginAt(relativeURL)
|
25
|
+
url = @test_context.base_url + relativeURL
|
26
|
+
new_browser_at(url) # create @@browser
|
27
|
+
end
|
28
|
+
|
29
|
+
def closeBrowser
|
30
|
+
begin
|
31
|
+
close_browser
|
32
|
+
rescue
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
def goBack
|
38
|
+
go_back()
|
39
|
+
end
|
40
|
+
|
41
|
+
def goForward
|
42
|
+
go_forward()
|
43
|
+
end
|
44
|
+
|
45
|
+
def gotoPage(page)
|
46
|
+
navigate_to(page)
|
47
|
+
end
|
48
|
+
|
49
|
+
# assertions
|
50
|
+
def assertTitleEquals(title)
|
51
|
+
assert_equals(title, html_title())
|
52
|
+
end
|
53
|
+
|
54
|
+
# text fields
|
55
|
+
def setFormElement(elementName, elementValue)
|
56
|
+
enter_text_into_field_with_name(elementName, elementValue)
|
57
|
+
end
|
58
|
+
alias enterText setFormElement
|
59
|
+
|
60
|
+
def assertTextPresentInTextField(textfieldName, text, msg = nil)
|
61
|
+
assert_text_in_field(textfieldName, text, msg)
|
62
|
+
end
|
63
|
+
|
64
|
+
#links
|
65
|
+
def clickLink(linkId)
|
66
|
+
click_link_with_id(linkId)
|
67
|
+
end
|
68
|
+
|
69
|
+
def clickLinkWithText(linkText)
|
70
|
+
click_link_with_text(linkText)
|
71
|
+
end
|
72
|
+
|
73
|
+
def assertLinkPresentWithText(linkText)
|
74
|
+
html_links.each { |link|
|
75
|
+
return if linkText == link.text
|
76
|
+
}
|
77
|
+
assert(false, "can't find the link with text: #{linkText}")
|
78
|
+
end
|
79
|
+
|
80
|
+
def assertLinkNotPresentWithText(linkText)
|
81
|
+
html_links.each { |link|
|
82
|
+
assert(linkText != link.text, "unexpected link: #{linkText} found")
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
##
|
87
|
+
# buttons
|
88
|
+
|
89
|
+
# submit first submit button
|
90
|
+
def submit(buttonName = nil)
|
91
|
+
if (buttonName.nil?) then
|
92
|
+
html_buttons.each { |button|
|
93
|
+
next if button.type != 'submit'
|
94
|
+
button.click
|
95
|
+
return
|
96
|
+
}
|
97
|
+
else
|
98
|
+
click_button_with_name(buttonName)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def clickButton(buttonId)
|
103
|
+
click_button_with_id(buttonId)
|
104
|
+
end
|
105
|
+
|
106
|
+
def clickButtonWithCaption(caption)
|
107
|
+
click_button_with_caption(caption)
|
108
|
+
end
|
109
|
+
|
110
|
+
def clickButtonWithValue(value)
|
111
|
+
click_button_with_value(value)
|
112
|
+
end
|
113
|
+
|
114
|
+
def assertButtonNotPresent(buttonId)
|
115
|
+
html_buttons.each { |button|
|
116
|
+
assert(button.id != buttonId, "unexpected button id: #{buttonId} found")
|
117
|
+
}
|
118
|
+
end
|
119
|
+
|
120
|
+
def assertButtonNotPresentWithText(text)
|
121
|
+
html_buttons.each { |button|
|
122
|
+
assert(button.value != text, "unexpected button id: #{text} found")
|
123
|
+
}
|
124
|
+
end
|
125
|
+
|
126
|
+
def assertButtonPresent(buttonID)
|
127
|
+
html_buttons.each { |button|
|
128
|
+
return if buttonID == button.id
|
129
|
+
}
|
130
|
+
assert(false, "can't find the button with id: #{buttonID}")
|
131
|
+
end
|
132
|
+
|
133
|
+
def assertButtonPresentWithText(buttonText)
|
134
|
+
html_buttons.each { |button|
|
135
|
+
return if buttonText == button.value
|
136
|
+
}
|
137
|
+
assert(false, "can't find the button with text: #{buttonText}")
|
138
|
+
end
|
139
|
+
|
140
|
+
# checkbox
|
141
|
+
def checkCheckbox(checkBoxName)
|
142
|
+
@@browser.checkbox(:name, checkBoxName).set
|
143
|
+
end
|
144
|
+
|
145
|
+
def uncheckCheckbox(checkBoxName)
|
146
|
+
@@browser.checkbox(:name, checkBoxName).clear
|
147
|
+
end
|
148
|
+
|
149
|
+
def assertCheckboxNotSelected(checkBoxName)
|
150
|
+
rasie
|
151
|
+
end
|
152
|
+
|
153
|
+
def assertCheckboxSelected(checkBoxName)
|
154
|
+
raise
|
155
|
+
end
|
156
|
+
|
157
|
+
|
158
|
+
# combo box
|
159
|
+
def selectOption(selectName, option)
|
160
|
+
@@browser.select_from_combobox_with_name(selectName, option)
|
161
|
+
end
|
162
|
+
|
163
|
+
def assertOptionValueNotPresent(selectName, optionValue)
|
164
|
+
html_selects.each { |select|
|
165
|
+
select.o.each do |option| # items in the list
|
166
|
+
assert(!(select.name == selectName && option.value == optionValue), "unexpected select option: #{optionValue} for #{selectName} found")
|
167
|
+
end
|
168
|
+
}
|
169
|
+
end
|
170
|
+
|
171
|
+
def assertOptionNotPresent(selectName, optionLabel)
|
172
|
+
html_selects.each { |select|
|
173
|
+
select.o.each do |option| # items in the list
|
174
|
+
assert(!(select.name == selectName && option.text == optionLabel), "unexpected select option: #{optionLabel} for #{selectName} found")
|
175
|
+
end
|
176
|
+
}
|
177
|
+
end
|
178
|
+
|
179
|
+
def assertOptionValuePresent(selectName, optionValue)
|
180
|
+
html_selects.each { |select|
|
181
|
+
select.o.each do |option| # items in the list
|
182
|
+
return if (select.name == selectName && option.value == optionValue)
|
183
|
+
end
|
184
|
+
}
|
185
|
+
assert(false, "can't find the combob box with value: #{optionValue}")
|
186
|
+
end
|
187
|
+
|
188
|
+
def assertOptionPresent(selectName, optionLabel)
|
189
|
+
html_selects.each { |select|
|
190
|
+
select.o.each do |option| # items in the list
|
191
|
+
return if (select.name == selectName && option.text == optionLabel)
|
192
|
+
end
|
193
|
+
}
|
194
|
+
assert(false, "can't find the combob box: #{selectName} with value: #{optionLabel}")
|
195
|
+
end
|
196
|
+
|
197
|
+
#text
|
198
|
+
def assertTextPresent(text)
|
199
|
+
puts html_body() if $DEBUG
|
200
|
+
assert((html_body().include? text), 'expected text: ' + text + ' not found')
|
201
|
+
end
|
202
|
+
|
203
|
+
def assertTextNotPresent(text)
|
204
|
+
assert(!(html_body().include? text), 'expected text: ' + text + ' found')
|
205
|
+
end
|
206
|
+
|
207
|
+
def assertElementPresent(elementID)
|
208
|
+
elem = @@browser.document.getElementById(elementID)
|
209
|
+
assert_not_nil(elem)
|
210
|
+
end
|
211
|
+
|
212
|
+
def assertElementNotPresent(elementID)
|
213
|
+
elem = @@browser.document.getElementById(elementID)
|
214
|
+
assert_nil(elem)
|
215
|
+
end
|
216
|
+
|
217
|
+
def assertTextInElement(elementID, text)
|
218
|
+
elem = @@browser.document.getElementById(elementID)
|
219
|
+
assert_not_nil(elem.innerText)
|
220
|
+
assert(elem.innerText.include?(text))
|
221
|
+
end
|
222
|
+
|
223
|
+
def getElementValue(elementId)
|
224
|
+
elem = @@browser.document.getElementById(elementId)
|
225
|
+
return nil if elem == nil
|
226
|
+
elem_val = elem.invoke('innerText')
|
227
|
+
return elem_val
|
228
|
+
end
|
229
|
+
|
230
|
+
# ---
|
231
|
+
# For deubgging
|
232
|
+
# ---
|
233
|
+
def dumpResponse(stream = nil)
|
234
|
+
if stream.nil?
|
235
|
+
puts html_body # std out
|
236
|
+
else
|
237
|
+
stream.puts html_body
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
private
|
242
|
+
def html_body
|
243
|
+
@@browser.html()
|
244
|
+
end
|
245
|
+
|
246
|
+
def html_title
|
247
|
+
@@browser.document.title
|
248
|
+
end
|
249
|
+
|
250
|
+
def html_links
|
251
|
+
@@browser.links
|
252
|
+
end
|
253
|
+
|
254
|
+
def html_buttons
|
255
|
+
@@browser.buttons
|
256
|
+
end
|
257
|
+
|
258
|
+
def html_selects
|
259
|
+
@@browser.select_lists
|
260
|
+
end
|
261
|
+
|
262
|
+
def assert_equals(expected, actual, msg=nil)
|
263
|
+
assert(expected == actual, (msg.nil?) ? "Expected: #{expected} diff from actual: #{actual}" : msg)
|
264
|
+
end
|
265
|
+
alias assert_equal assert_equals
|
266
|
+
|
267
|
+
def assert_nil(actual, msg="")
|
268
|
+
assert(actual.nil?, msg)
|
269
|
+
end
|
270
|
+
|
271
|
+
def assert_not_nil(actual, msg="")
|
272
|
+
assert(!actual.nil?, msg)
|
273
|
+
end
|
274
|
+
|
275
|
+
end
|
276
|
+
|
277
|
+
end
|
data/lib/rwebunit.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#***********************************************************
|
2
|
+
#* Copyright (c) 2006, Zhimin Zhan.
|
3
|
+
#* Distributed open-source, see full license in MIT-LICENSE
|
4
|
+
#***********************************************************
|
5
|
+
|
6
|
+
# Extra full path to load libraries
|
7
|
+
require File.dirname(__FILE__) + "/rwebunit/test_utils"
|
8
|
+
require File.dirname(__FILE__) + "/rwebunit/web_page"
|
9
|
+
require File.dirname(__FILE__) + "/rwebunit/web_testcase"
|
10
|
+
require File.dirname(__FILE__) + "/rwebunit/web_tester"
|
11
|
+
require File.dirname(__FILE__) + "/rwebunit/test_context"
|
12
|
+
|
13
|
+
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "rwebunit"
|
2
|
+
|
3
|
+
class KongmingHomePage < RWebUnit::AbstractWebPage
|
4
|
+
|
5
|
+
def initialize(browser, title)
|
6
|
+
super(browser, title)
|
7
|
+
end
|
8
|
+
|
9
|
+
def assertTheListLinkPresent
|
10
|
+
@browser.assertLinkPresentWithText('The List')
|
11
|
+
end
|
12
|
+
|
13
|
+
def assertDashboardLinkPresent
|
14
|
+
@browser.assertLinkPresentWithText('Dashboard')
|
15
|
+
end
|
16
|
+
|
17
|
+
def assertTestCenterLinkPresent
|
18
|
+
@browser.assertLinkPresentWithText('Test center')
|
19
|
+
end
|
20
|
+
|
21
|
+
def assertTestWebServiceLinkPresent
|
22
|
+
@browser.assertLinkPresentWithText('Test web service')
|
23
|
+
end
|
24
|
+
|
25
|
+
def clickXMLFormatterLink
|
26
|
+
@browser.clickLinkWithText("XML Formatter")
|
27
|
+
KongmingXMLFormatterPage.new(@browser)
|
28
|
+
end
|
29
|
+
|
30
|
+
def clickHttpCallerLink
|
31
|
+
@browser.clickLinkWithText("Http Caller")
|
32
|
+
KongmingXMLFormatterPage.new(@browser)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
class KongmingXMLFormatterPage < RWebUnit::AbstractWebPage
|
38
|
+
|
39
|
+
def initialize(browser)
|
40
|
+
super(browser, "Format XML")
|
41
|
+
end
|
42
|
+
|
43
|
+
def clickFillExampleLink
|
44
|
+
@browser.clickLinkWithText("Fill example")
|
45
|
+
end
|
46
|
+
|
47
|
+
def enterXml(inputXml)
|
48
|
+
@browser.enterText("inputText", inputXml)
|
49
|
+
end
|
50
|
+
|
51
|
+
def clickFormat
|
52
|
+
@browser.clickButtonWithValue("Format")
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
class KongmingXMLFormatterPage < RWebUnit::AbstractWebPage
|
58
|
+
|
59
|
+
def initialize(browser)
|
60
|
+
super(browser, "Http Caller")
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require "rwebunit"
|
2
|
+
|
3
|
+
$:.unshift File.dirname(__FILE__)
|
4
|
+
require "kongming_pages.rb"
|
5
|
+
|
6
|
+
class TestWuning < RWebUnit::WebTestCase
|
7
|
+
|
8
|
+
def initialize(name)
|
9
|
+
super(name)
|
10
|
+
end
|
11
|
+
|
12
|
+
def setup
|
13
|
+
super
|
14
|
+
openBrowser("http://localhost:3721", "/home")
|
15
|
+
end
|
16
|
+
|
17
|
+
def teardown
|
18
|
+
super
|
19
|
+
closeBrowser()
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_homepage_exists()
|
23
|
+
kongming_homepage = KongmingHomePage.new(@web_tester, "Welcome")
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_all_links_exist
|
27
|
+
kongming_homepage = KongmingHomePage.new(@web_tester, "Welcome")
|
28
|
+
kongming_homepage.assertTheListLinkPresent()
|
29
|
+
kongming_homepage.assertDashboardLinkPresent
|
30
|
+
kongming_homepage.assertTestCenterLinkPresent
|
31
|
+
kongming_homepage.assertTestWebServiceLinkPresent
|
32
|
+
end
|
33
|
+
|
34
|
+
# enter text in a text field, then click a button
|
35
|
+
def test_format_xml
|
36
|
+
kongming_homepage = KongmingHomePage.new(@web_tester, "Welcome")
|
37
|
+
kongming_xmlformatter_page = kongming_homepage.clickXMLFormatterLink
|
38
|
+
kongming_xmlformatter_page.enterXml("<name><first>James</first><last>Bond</last></name>")
|
39
|
+
kongming_xmlformatter_page.clickFormat
|
40
|
+
end
|
41
|
+
|
42
|
+
# Invoke link to populate date using javascripts (clickFillExampleLink)
|
43
|
+
# Calling submit
|
44
|
+
# Check special text before and after submit
|
45
|
+
def test_format_xml_sample
|
46
|
+
kongming_homepage = KongmingHomePage.new(@web_tester, "Welcome")
|
47
|
+
kongming_xmlformatter_page = kongming_homepage.clickXMLFormatterLink
|
48
|
+
kongming_xmlformatter_page.clickFillExampleLink
|
49
|
+
@web_tester.assertElementNotPresent("formatted_xml")
|
50
|
+
kongming_xmlformatter_page.submit
|
51
|
+
@web_tester.assertElementPresent("formatted_xml")
|
52
|
+
end
|
53
|
+
|
54
|
+
# web testcase can utilize useful methods defined in test_utils
|
55
|
+
def test_can_call_utils
|
56
|
+
kongming_homepage = KongmingHomePage.new(@web_tester, "Welcome")
|
57
|
+
kongming_xmlformatter_page = kongming_homepage.clickXMLFormatterLink
|
58
|
+
kongming_xmlformatter_page.enterXml("<date><now>" + getToday + "</now></date>")
|
59
|
+
kongming_xmlformatter_page.clickFormat
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_combobox
|
63
|
+
kongming_homepage = KongmingHomePage.new(@web_tester, "Welcome")
|
64
|
+
kongming_httpcaller_page = kongming_homepage.clickHttpCallerLink
|
65
|
+
# html:
|
66
|
+
# <select name="method">
|
67
|
+
# <option value="POST">HTTP POST </option>
|
68
|
+
# <option value="GET"> HTTP GET </option>
|
69
|
+
# </select>
|
70
|
+
|
71
|
+
@web_tester.assertOptionPresent("method", "HTTP POST") # trimmed
|
72
|
+
@web_tester.assertOptionPresent("method", "HTTP GET")
|
73
|
+
@web_tester.assertOptionNotPresent("method", "PUT")
|
74
|
+
@web_tester.assertOptionValuePresent("method", "POST")
|
75
|
+
@web_tester.assertOptionValuePresent("method", "GET")
|
76
|
+
@web_tester.assertOptionValueNotPresent("method", "HEAD")
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rwebunit'
|
2
|
+
|
3
|
+
class RWebUnitSearchExample < RWebUnit::WebTestCase
|
4
|
+
|
5
|
+
def test_search()
|
6
|
+
getTestContext().base_url = "http://www.google.com"
|
7
|
+
beginAt("/")
|
8
|
+
setFormElement("q", "httpunit")
|
9
|
+
clickButtonWithCaption("Google Search")
|
10
|
+
clickLinkWithText("HttpUnit Home")
|
11
|
+
assertTitleEquals("HttpUnit Home")
|
12
|
+
assertLinkPresentWithText("User's Manual")
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# the same test used in jWebUnit home page written in rWebUnit
|
2
|
+
require 'rwebunit'
|
3
|
+
|
4
|
+
class RWebUnitSearchExample < RWebUnit::WebTestCase
|
5
|
+
|
6
|
+
def initialize(name)
|
7
|
+
super(name)
|
8
|
+
end
|
9
|
+
|
10
|
+
def setup
|
11
|
+
getTestContext().setBaseUrl("http://www.google.com")
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_search()
|
15
|
+
beginAt("/")
|
16
|
+
setFormElement("q", "httpunit")
|
17
|
+
submit("btnG")
|
18
|
+
clickLinkWithText("HttpUnit Home")
|
19
|
+
assertTitleEquals("HttpUnit Home")
|
20
|
+
assertLinkPresentWithText("User's Manual")
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'watir'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class WatirSearchExample < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_search
|
7
|
+
ie = Watir::IE.new
|
8
|
+
ie.goto("http://www.google.com")
|
9
|
+
ie.text_field(:name, "q").set("httpunit")
|
10
|
+
ie.button(:name, "btnG").click
|
11
|
+
ie.link(:text, "HttpUnit Home").click
|
12
|
+
assert_equal("HttpUnit Home", ie.document.title)
|
13
|
+
assert(ie.contains_text("User's Manual"))
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "lib/rwebunit")
|
2
|
+
$:.unshift File.dirname(__FILE__)
|
3
|
+
|
4
|
+
require "test_utils.rb"
|
5
|
+
require 'test/unit'
|
6
|
+
|
7
|
+
class TestWebTestCase < Test::Unit::TestCase
|
8
|
+
include RWebUnit::Utils
|
9
|
+
|
10
|
+
def setup
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_getToday
|
17
|
+
today_str = sprintf("%02d/%02d/%04d", Time.now.day, Time.now.month, Time.now.year)
|
18
|
+
assert_equal(today_str, getToday)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_getDaysBefore
|
22
|
+
yesterday = Time.now - 24 * 3600 * 1
|
23
|
+
yesterday_str = sprintf("%02d/%02d/%04d", yesterday.day, yesterday.month, yesterday.year)
|
24
|
+
assert_equal(yesterday_str, getDaysBefore(1))
|
25
|
+
assert_equal(yesterday_str, getYesterday)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_getDaysAfter
|
29
|
+
tomorrow = Time.now + 24 * 3600 * 1
|
30
|
+
tomorrow_str = sprintf("%02d/%02d/%04d", tomorrow.day, tomorrow.month, tomorrow.year)
|
31
|
+
assert_equal(tomorrow_str, getDaysAfter(1))
|
32
|
+
assert_equal(tomorrow_str, getTomorrow)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_randomBoolean
|
36
|
+
true_count = 0
|
37
|
+
false_count = 0
|
38
|
+
100.times {
|
39
|
+
obj = randomBoolean
|
40
|
+
assert(obj.instance_of?(TrueClass) || obj.instance_of?(FalseClass), "can only be true or false")
|
41
|
+
true_count += 1 if obj
|
42
|
+
false_count += 1 if !obj
|
43
|
+
}
|
44
|
+
assert(true_count > 0, "it is not random")
|
45
|
+
assert(false_count > 0, "it is not random")
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_randomNumber
|
49
|
+
tmp_array = []
|
50
|
+
1000.times {
|
51
|
+
num = randomNumber(1,10)
|
52
|
+
assert(num.instance_of?(Fixnum), "can only be number")
|
53
|
+
tmp_array << num
|
54
|
+
}
|
55
|
+
uniq_numbers = tmp_array.uniq.sort
|
56
|
+
assert_equal(10, uniq_numbers.length)
|
57
|
+
assert_equal(1, uniq_numbers[0])
|
58
|
+
assert_equal(10, uniq_numbers[9])
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_randomDigit
|
62
|
+
tmp_array = []
|
63
|
+
1000.times {
|
64
|
+
dc = randomDigit()
|
65
|
+
tmp_array << dc
|
66
|
+
}
|
67
|
+
uniq_digits = tmp_array.uniq.sort
|
68
|
+
assert_equal(10, uniq_digits.length)
|
69
|
+
assert_equal('0', uniq_digits[0])
|
70
|
+
assert_equal('9', uniq_digits[9])
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.11
|
3
|
+
specification_version: 1
|
4
|
+
name: rwebunit
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: "0.1"
|
7
|
+
date: 2006-04-11 00:00:00 +10:00
|
8
|
+
summary: An wrap of WATIR for functional testing of web applications
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: zhimin@zhimin.com
|
12
|
+
homepage: http://www.zhimin.com/rWebUnit
|
13
|
+
rubyforge_project:
|
14
|
+
description:
|
15
|
+
autorequire: rwebunit
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
authors:
|
29
|
+
- Zhimin Zhan
|
30
|
+
files:
|
31
|
+
- Rakefile
|
32
|
+
- README
|
33
|
+
- CHANGELOG
|
34
|
+
- MIT-LICENSE
|
35
|
+
- lib/rwebunit.rb
|
36
|
+
- lib/rwebunit
|
37
|
+
- lib/rwebunit/test_context.rb
|
38
|
+
- lib/rwebunit/test_utils.rb
|
39
|
+
- lib/rwebunit/web_page.rb
|
40
|
+
- lib/rwebunit/web_testcase.rb
|
41
|
+
- lib/rwebunit/web_tester.rb
|
42
|
+
- test/test_test_utils.rb
|
43
|
+
- sample/kongming_pages.rb
|
44
|
+
- sample/kongming_webtest.rb
|
45
|
+
- sample/sample_rwebunit_test.rb
|
46
|
+
- sample/sample_rwebunit_testcase.rb
|
47
|
+
- sample/sample_watir_test.rb
|
48
|
+
- docs/html
|
49
|
+
- docs/html/index.html
|
50
|
+
test_files: []
|
51
|
+
|
52
|
+
rdoc_options: []
|
53
|
+
|
54
|
+
extra_rdoc_files: []
|
55
|
+
|
56
|
+
executables: []
|
57
|
+
|
58
|
+
extensions: []
|
59
|
+
|
60
|
+
requirements:
|
61
|
+
- none
|
62
|
+
dependencies:
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: watir
|
65
|
+
version_requirement:
|
66
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 1.4.1
|
71
|
+
version:
|