rwebspec 3.1.4 → 4.0

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -1,108 +1,107 @@
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 RWebSpec
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 RWebSpec::Assert
26
- include RWebSpec::Driver
27
- include RWebSpec::Utils
28
-
29
- # browser: passed to do assertion within the page
30
- # page_text: text used to identify the page, title will be the first candidate
31
- attr_accessor :page_specific_text
32
-
33
- def initialize(the_browser, page_specific_text = nil)
34
- @web_browser = @browser = @web_tester = the_browser
35
- @page_specific_text = page_specific_text
36
- begin
37
- snapshot if $TESTWISE_DUMP_PAGE || $TESTWISE_DUMP_PAGE
38
- delay = $TESTWISE_PAGE_DELAY || $TESTWISE_PAGE_DELAY
39
- sleep(delay)
40
- rescue => e
41
- end
42
- assert_on_page
43
- end
44
-
45
- # return the browser instance in page objects
46
- def browser
47
- @web_browser
48
- end
49
-
50
- # Assert is on current page
51
- # Example
52
- # home_page = HomePage.new("Welcome to iTest2")
53
- # ....
54
- # home_page.assert_on_page # will check the text 'Welcome to iTest2' still present on the page
55
- def assert_on_page()
56
- assert_text_present(@page_specific_text) if @page_specific_text
57
- end
58
-
59
- def assert_not_on_page()
60
- assert_text_not_present(@page_specific_text) if @page_specific_text
61
- end
62
-
63
- def dump(stream = nil)
64
- @web_browser.dump_response(stream)
65
- end
66
-
67
- # Page source (html)
68
- def source
69
- @web_browser.page_source
70
- end
71
- alias html source
72
-
73
- # return current page title
74
- def title
75
- @web_browser.page_title
76
- end
77
-
78
- # return current page text
79
- def text
80
- @web_browser.text
81
- end
82
-
83
- def url
84
- @web_browser.url
85
- end
86
-
87
- # TO validate
88
- def contains?(ary)
89
- return true if ary.nil?
90
- the_page_source = source
91
- found = false
92
- ary.each_line do |str|
93
- found ||= the_page_source.include?(str)
94
- end
95
- return found
96
- end
97
-
98
- # Will save current page source to a file
99
- # home_page = HomePage.new("Welcome to iTest2")
100
- # ...
101
- # home_page.snapshot() # => save to 20090830100102_HomePage.html
102
- def snapshot(replace_css = false)
103
- save_current_page(:filename => Time.now.strftime("%m%d%H%M%S") + "_" + self.class.name.gsub(" ", "") + ".html" )
104
- end
105
-
106
- end
107
-
108
- 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 'fileutils'
7
+
8
+ module RWebSpec
9
+
10
+ # WebPage (children of AbstractWebPage) encapsulates a real web page.
11
+ # For example,
12
+ # beginAt("/home")
13
+ # @web_browser.clickLinkWithText("/login")
14
+ # @web_browser.setFormElement("username", "sa")
15
+ # Can be rewritten to
16
+ # begin_at("/home")
17
+ # home_page = HomePage.new
18
+ # login_page = home_page.clickLoginLink
19
+ # login_page.enterUserName("sa")
20
+ #
21
+ # So you only need change in LoingPage class if UI changes, which happen quite often.
22
+ class AbstractWebPage
23
+
24
+ include RWebSpec::Assert
25
+ include RWebSpec::Driver
26
+ include RWebSpec::Utils
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_specific_text
31
+
32
+ def initialize(the_browser, page_specific_text = nil)
33
+ @web_browser = @browser = @web_tester = the_browser
34
+ @page_specific_text = page_specific_text
35
+ begin
36
+ snapshot if $TESTWISE_DUMP_PAGE || $TESTWISE_DUMP_PAGE
37
+ delay = $TESTWISE_PAGE_DELAY || $TESTWISE_PAGE_DELAY
38
+ sleep(delay)
39
+ rescue => e
40
+ end
41
+ assert_on_page
42
+ end
43
+
44
+ # return the browser instance in page objects
45
+ def browser
46
+ @web_browser
47
+ end
48
+
49
+ # Assert is on current page
50
+ # Example
51
+ # home_page = HomePage.new("Welcome to iTest2")
52
+ # ....
53
+ # home_page.assert_on_page # will check the text 'Welcome to iTest2' still present on the page
54
+ def assert_on_page()
55
+ assert_text_present(@page_specific_text) if @page_specific_text
56
+ end
57
+
58
+ def assert_not_on_page()
59
+ assert_text_not_present(@page_specific_text) if @page_specific_text
60
+ end
61
+
62
+ def dump(stream = nil)
63
+ @web_browser.dump_response(stream)
64
+ end
65
+
66
+ # Page source (html)
67
+ def source
68
+ @web_browser.page_source
69
+ end
70
+ alias html source
71
+
72
+ # return current page title
73
+ def title
74
+ @web_browser.page_title
75
+ end
76
+
77
+ # return current page text
78
+ def text
79
+ @web_browser.text
80
+ end
81
+
82
+ def url
83
+ @web_browser.url
84
+ end
85
+
86
+ # TO validate
87
+ def contains?(ary)
88
+ return true if ary.nil?
89
+ the_page_source = source
90
+ found = false
91
+ ary.each_line do |str|
92
+ found ||= the_page_source.include?(str)
93
+ end
94
+ return found
95
+ end
96
+
97
+ # Will save current page source to a file
98
+ # home_page = HomePage.new("Welcome to iTest2")
99
+ # ...
100
+ # home_page.snapshot() # => save to 20090830100102_HomePage.html
101
+ def snapshot(replace_css = false)
102
+ save_current_page(:filename => Time.now.strftime("%m%d%H%M%S") + "_" + self.class.name.gsub(" ", "") + ".html" )
103
+ end
104
+
105
+ end
106
+
107
+ end
@@ -1,38 +1,38 @@
1
- #***********************************************************
2
- #* Copyright (c) 2006, Zhimin Zhan.
3
- #* Distributed open-source, see full license in MIT-LICENSE
4
- #***********************************************************
5
-
6
- # Deprecated, use RSpec syntax instead
7
-
8
- require 'test/unit'
9
- require File.join(File.dirname(__FILE__), 'assert')
10
- require File.join(File.dirname(__FILE__), 'driver')
11
-
12
- module RWebSpec
13
-
14
- class WebTestCase < Test::Unit::TestCase
15
- include RWebSpec::Driver
16
- include RWebSpec::Assert
17
- include RWebSpec::Utils
18
-
19
- attr_reader :web_tester
20
-
21
- def initialize(name=nil)
22
- super(name) if name
23
- @web_browser = WebBrowser.new
24
- end
25
-
26
- def default_test
27
- super unless (self.class == WebTestCase)
28
- end
29
-
30
- def open_browser(baseUrl, relativeUrl)
31
- context.base_url = baseUrl
32
- begin_at(relativeUrl)
33
- end
34
- alias open_ie open_browser
35
-
36
- end
37
-
38
- end
1
+ #***********************************************************
2
+ #* Copyright (c) 2006, Zhimin Zhan.
3
+ #* Distributed open-source, see full license in MIT-LICENSE
4
+ #***********************************************************
5
+
6
+ # Deprecated, use RSpec syntax instead
7
+
8
+ require 'test/unit'
9
+ require File.join(File.dirname(__FILE__), 'assert')
10
+ require File.join(File.dirname(__FILE__), 'driver')
11
+
12
+ module RWebSpec
13
+
14
+ class WebTestCase < Test::Unit::TestCase
15
+ include RWebSpec::Driver
16
+ include RWebSpec::Assert
17
+ include RWebSpec::Utils
18
+
19
+ attr_reader :web_tester
20
+
21
+ def initialize(name=nil)
22
+ super(name) if name
23
+ @web_browser = WebBrowser.new
24
+ end
25
+
26
+ def default_test
27
+ super unless (self.class == WebTestCase)
28
+ end
29
+
30
+ def open_browser(baseUrl, relativeUrl)
31
+ context.base_url = baseUrl
32
+ begin_at(relativeUrl)
33
+ end
34
+ alias open_ie open_browser
35
+
36
+ end
37
+
38
+ end