rwebunit 0.1.1 → 0.2.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 +2 -3
- data/lib/rwebunit/test_context.rb +10 -10
- data/lib/rwebunit/test_utils.rb +73 -73
- data/lib/rwebunit/web_page.rb +78 -54
- data/lib/rwebunit/web_testcase.rb +203 -204
- data/lib/rwebunit/web_tester.rb +398 -381
- data/lib/rwebunit.rb +0 -2
- data/sample/kangxi_home_webtest.rb +9 -9
- data/sample/kangxi_httpcaller_webtest.rb +4 -4
- data/sample/kangxi_xml_formatter_webtest.rb +9 -9
- data/sample/sample_rwebunit_test.rb +1 -1
- data/sample/sample_rwebunit_testcase.rb +1 -1
- data/sample/sample_watir_test.rb +12 -12
- data/test/test_test_utils.rb +58 -58
- metadata +10 -9
data/CHANGELOG
CHANGED
data/Rakefile
CHANGED
@@ -5,12 +5,11 @@ require 'rake/rdoctask'
|
|
5
5
|
Gem::manage_gems
|
6
6
|
require 'rake/gempackagetask'
|
7
7
|
|
8
|
-
|
9
8
|
$:.unshift(File.dirname(__FILE__) + "/lib")
|
10
9
|
require 'rwebunit'
|
11
10
|
|
12
11
|
desc "Default task"
|
13
|
-
task :default => [ :clean, :test ]
|
12
|
+
task :default => [ :clean, :test , :gem]
|
14
13
|
|
15
14
|
desc "Clean generated files"
|
16
15
|
task :clean do
|
@@ -37,7 +36,7 @@ Rake::RDocTask.new { |rdoc|
|
|
37
36
|
spec = Gem::Specification.new do |s|
|
38
37
|
s.platform= Gem::Platform::RUBY
|
39
38
|
s.name = "rwebunit"
|
40
|
-
s.version = "0.
|
39
|
+
s.version = "0.2.0"
|
41
40
|
s.summary = "An wrap of WATIR for functional testing of web applications"
|
42
41
|
# s.description = ""
|
43
42
|
|
@@ -5,15 +5,15 @@
|
|
5
5
|
|
6
6
|
module RWebUnit
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
##
|
9
|
+
# Store test optionns
|
10
|
+
#
|
11
|
+
class TestContext
|
12
|
+
attr_accessor :base_url
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def setBaseUrl(baseUrl)
|
15
|
+
@base_url = baseUrl
|
16
|
+
end
|
17
|
+
end
|
18
18
|
|
19
|
-
end
|
19
|
+
end
|
data/lib/rwebunit/test_utils.rb
CHANGED
@@ -4,77 +4,77 @@
|
|
4
4
|
#***********************************************************
|
5
5
|
|
6
6
|
module RWebUnit
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
private
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
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
80
|
end
|
data/lib/rwebunit/web_page.rb
CHANGED
@@ -5,58 +5,82 @@
|
|
5
5
|
|
6
6
|
module RWebUnit
|
7
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
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
|
61
43
|
|
62
|
-
|
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
|
+
# Wait for specific seconds for an Ajax update finish.
|
61
|
+
# Trick: In your Rails application,
|
62
|
+
# :loading => "Element.show('search_indicator');
|
63
|
+
# :complete => "Element.hide('search_indicator');
|
64
|
+
#
|
65
|
+
# <%= image_tag("indicator.gif", :id => 'search_indicator', :style => 'display:none') %>
|
66
|
+
#
|
67
|
+
# In your test case:
|
68
|
+
# wait_ajax_update("search_indicator", "30)
|
69
|
+
#
|
70
|
+
# Warning: this method has not been fully tested, if you are not using Rails, change your parameter accordingly.
|
71
|
+
#
|
72
|
+
def wait_ajax_update(element_id, seconds)
|
73
|
+
count = 0
|
74
|
+
while count < (seconds / 2) do
|
75
|
+
search_indicator = @browser.getElementById(element_id)
|
76
|
+
search_indicator_outer_html = search_indicator.outerHtml if search_indicator
|
77
|
+
return true if search_indicator_outer_html && search_indicator_outer_html.include?('style="DISPLAY: none"')
|
78
|
+
sleep 2;
|
79
|
+
count = count + 1
|
80
|
+
end
|
81
|
+
return false
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|