rwebspec-webdriver 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,108 @@
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
+
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 = the_browser
34
+ @web_tester = the_browser
35
+ @page_specific_text = page_specific_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
+ # 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
@@ -0,0 +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
@@ -0,0 +1,9 @@
1
+ module Selenium
2
+ module WebDriver
3
+ class Element
4
+ def exists?
5
+ self.displayed?
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'watir'
3
+
4
+ # Used for calling javacript of VBScript
5
+ # Applies to IE only
6
+ #
7
+ # Ref: http://msdn.microsoft.com/en-us/library/aa741364%28VS.85%29.aspx
8
+ #
9
+ module Watir
10
+ class IE
11
+ def execute_script(scriptCode)
12
+ window.execScript(scriptCode)
13
+ end
14
+
15
+ def window
16
+ ie.Document.parentWindow
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rwebspec-webdriver
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - Zhimin Zhan
13
+ autorequire: rwebspec-webdriver
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-07-12 00:00:00 +10:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - "="
27
+ - !ruby/object:Gem::Version
28
+ hash: 11
29
+ segments:
30
+ - 1
31
+ - 1
32
+ - 12
33
+ version: 1.1.12
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: commonwatir
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 5
45
+ segments:
46
+ - 1
47
+ - 6
48
+ - 5
49
+ version: 1.6.5
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ description:
53
+ email: zhimin@agileway.net
54
+ executables: []
55
+
56
+ extensions: []
57
+
58
+ extra_rdoc_files: []
59
+
60
+ files:
61
+ - Rakefile
62
+ - README
63
+ - CHANGELOG
64
+ - MIT-LICENSE
65
+ - lib/rspec_extensions.rb
66
+ - lib/rwebspec/assert.rb
67
+ - lib/rwebspec/clickJSDialog.rb
68
+ - lib/rwebspec/context.rb
69
+ - lib/rwebspec/database_checker.rb
70
+ - lib/rwebspec/driver.rb
71
+ - lib/rwebspec/element_locator.rb
72
+ - lib/rwebspec/load_test_helper.rb
73
+ - lib/rwebspec/matchers/contains_text.rb
74
+ - lib/rwebspec/popup.rb
75
+ - lib/rwebspec/rspec_helper.rb
76
+ - lib/rwebspec/test_script.rb
77
+ - lib/rwebspec/test_utils.rb
78
+ - lib/rwebspec/testwise_plugin.rb
79
+ - lib/rwebspec/using_pages.rb
80
+ - lib/rwebspec/web_browser.rb
81
+ - lib/rwebspec/web_page.rb
82
+ - lib/rwebspec/web_testcase.rb
83
+ - lib/rwebspec-webdriver.rb
84
+ - lib/webdriver_extensions.rb
85
+ - lib/window_script_extensions.rb
86
+ has_rdoc: true
87
+ homepage: http://github.com/zhimin/rwebspec-webdriver/tree/master
88
+ licenses: []
89
+
90
+ post_install_message:
91
+ rdoc_options: []
92
+
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ requirements:
114
+ - none
115
+ rubyforge_project: rwebspec-webdrive
116
+ rubygems_version: 1.4.2
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: Executable functional specification for web applications in RSpec syntax and Selenium-WebDriver
120
+ test_files: []
121
+