rwebspec-mechanize 0.2.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
+ 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 || $LOADWISE_DUMP_PAGE
38
+ delay = $TESTWISE_PAGE_DELAY || $LOADWISE_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,8 @@
1
+ require 'rubygems'
2
+ require 'mechanize'
3
+
4
+ require File.join(File.dirname(__FILE__), "rwebspec-mechanize", "context.rb")
5
+ require File.join(File.dirname(__FILE__), "rwebspec-mechanize", "web_browser.rb")
6
+ require File.join(File.dirname(__FILE__), "rwebspec-mechanize", "assert.rb")
7
+ require File.join(File.dirname(__FILE__), "rwebspec-mechanize", "test_utils.rb")
8
+ require File.join(File.dirname(__FILE__), "rwebspec-mechanize", "load_test_helper.rb")
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rwebspec-mechanize
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Zhimin Zhan
9
+ autorequire: rwebspec-mechanize
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.10.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.10.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: mechanize
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '2.5'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '2.5'
46
+ - !ruby/object:Gem::Dependency
47
+ name: nokogiri
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Load test specification for web applications in RSpec syntax and Watir
63
+ email: zhimin@agileway.com.au
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - Rakefile
69
+ - README
70
+ - CHANGELOG
71
+ - MIT-LICENSE
72
+ - lib/rwebspec-mechanize/assert.rb
73
+ - lib/rwebspec-mechanize/context.rb
74
+ - lib/rwebspec-mechanize/extensions/firewatir_extensions.rb
75
+ - lib/rwebspec-mechanize/extensions/rspec_extensions.rb
76
+ - lib/rwebspec-mechanize/extensions/watir_extensions.rb
77
+ - lib/rwebspec-mechanize/extensions/window_script_extensions.rb
78
+ - lib/rwebspec-mechanize/load_test_helper.rb
79
+ - lib/rwebspec-mechanize/plugins/loadwise_plugin.rb
80
+ - lib/rwebspec-mechanize/rspec_helper.rb
81
+ - lib/rwebspec-mechanize/test_utils.rb
82
+ - lib/rwebspec-mechanize/web_browser.rb
83
+ - lib/rwebspec-mechanize/web_page.rb
84
+ - lib/rwebspec-mechanize.rb
85
+ homepage: http://github.com/zhimin/rwebspec-mechanize/tree/master
86
+ licenses: []
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements:
104
+ - none
105
+ rubyforge_project: rwebspec-mechanize
106
+ rubygems_version: 1.8.24
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: Web application load testing specification in Ruby
110
+ test_files: []