zhimin-rwebspec 1.4.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.
@@ -0,0 +1,92 @@
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_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
+
62
+ def source
63
+ @web_browser.page_source
64
+ end
65
+
66
+ # return current page title
67
+ def title
68
+ @web_browser.page_title
69
+ end
70
+
71
+ # return current page text
72
+ def text
73
+ @web_browser.text
74
+ end
75
+
76
+ # TO validate
77
+ def contains?(ary)
78
+ the_page_source = source
79
+ found = false
80
+ ary.each do |str|
81
+ found ||= the_page_source.include?(str)
82
+ end
83
+ return found
84
+ end
85
+
86
+ def snapshot(replace_css = false)
87
+ save_current_page(:filename => Time.now.strftime("%m%d%H%M%S") + "_" + self.class.name.gsub(" ", "") + ".html" )
88
+ end
89
+
90
+ end
91
+
92
+ end
@@ -0,0 +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 RWebSpec
11
+
12
+ class WebTestCase < Test::Unit::TestCase
13
+ include RWebSpec::Driver
14
+ include RWebSpec::Assert
15
+ include RWebSpec::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
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zhimin-rwebspec
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Zhimin Zhan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-08 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - "="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.1.12
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: commonwatir
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.6.2
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: test-unit
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.0.2
44
+ version:
45
+ description:
46
+ email: zhimin@agileway.net
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files: []
52
+
53
+ files:
54
+ - Rakefile
55
+ - README
56
+ - CHANGELOG
57
+ - MIT-LICENSE
58
+ - lib/rspec_extensions.rb
59
+ - lib/rwebspec
60
+ - lib/rwebspec/assert.rb
61
+ - lib/rwebspec/clickJSDialog.rb
62
+ - lib/rwebspec/context.rb
63
+ - lib/rwebspec/driver.rb
64
+ - lib/rwebspec/itest_plugin.rb
65
+ - lib/rwebspec/matchers
66
+ - lib/rwebspec/matchers/contains_text.rb
67
+ - lib/rwebspec/popup.rb
68
+ - lib/rwebspec/rspec_helper.rb
69
+ - lib/rwebspec/test_script.rb
70
+ - lib/rwebspec/test_utils.rb
71
+ - lib/rwebspec/using_pages.rb
72
+ - lib/rwebspec/web_browser.rb
73
+ - lib/rwebspec/web_page.rb
74
+ - lib/rwebspec/web_testcase.rb
75
+ - lib/rwebspec.rb
76
+ - lib/watir_extensions.rb
77
+ has_rdoc: true
78
+ homepage: http://github.com/zhimin/rwebspec/tree/master
79
+ licenses:
80
+ post_install_message:
81
+ rdoc_options: []
82
+
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
90
+ version:
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: "0"
96
+ version:
97
+ requirements:
98
+ - none
99
+ rubyforge_project: rwebspec
100
+ rubygems_version: 1.3.5
101
+ signing_key:
102
+ specification_version: 2
103
+ summary: Executable functional specification for web applications in RSpec syntax and Watir
104
+ test_files: []
105
+