watirloo 0.0.7 → 0.0.8
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/.gitignore +1 -0
- data/Rakefile +43 -18
- data/VERSION +1 -1
- data/_irbrc +37 -0
- data/lib/watirloo.rb +1 -2
- data/lib/watirloo/browsers.rb +9 -5
- data/lib/watirloo/extension/firewatir_ducktape.rb +66 -75
- data/lib/watirloo/extension/watir_ducktape.rb +0 -1
- data/lib/watirloo/locker.rb +15 -0
- data/lib/watirloo/screenshot.rb +50 -0
- data/spec/checkbox_group_spec.rb +9 -9
- data/spec/checkbox_groups_spec.rb +15 -16
- data/spec/ff.opts +14 -0
- data/spec/results/ff-failed.txt +0 -0
- data/spec/results/ff.html +409 -0
- data/spec/results/ff.txt +107 -0
- data/spec/{spec_results_failed.txt → results/ie-failed.txt} +0 -0
- data/spec/{spec_results.html → results/ie.html} +209 -229
- data/spec/{spec_results.txt → results/ie.txt} +64 -73
- data/spec/spec_helper.rb +4 -0
- data/watirloo.gemspec +11 -12
- metadata +11 -12
- data/spec/firewatir/attach_instance_test.rb +0 -38
- data/spec/firewatir/spec_results.html +0 -263
- data/spec/firewatir/spec_results.txt +0 -23
- data/spec/firewatir/spec_results_failed.txt +0 -3
- data/spec/label_spec.rb +0 -65
data/.gitignore
CHANGED
data/Rakefile
CHANGED
@@ -31,9 +31,9 @@ Spec::Rake::SpecTask.new do |spec|
|
|
31
31
|
"--color",
|
32
32
|
"--require spec/spec_helper_runner.rb", # slow execution expected. closes all browsers on desktop before :all
|
33
33
|
"--format specdoc",
|
34
|
-
"--format specdoc:spec/
|
35
|
-
"--format failing_examples:spec/
|
36
|
-
"--format html:spec/
|
34
|
+
"--format specdoc:spec/results/ie.txt",
|
35
|
+
"--format failing_examples:spec/results/ie-failed.txt",
|
36
|
+
"--format html:spec/results/ie.html",
|
37
37
|
#"--diff",
|
38
38
|
"--loadby mtime",
|
39
39
|
#"--dry-run", # will overwrite any previous spec_results
|
@@ -41,21 +41,6 @@ Spec::Rake::SpecTask.new do |spec|
|
|
41
41
|
]
|
42
42
|
end
|
43
43
|
|
44
|
-
# FIXME fix the spec FileList to only include those that execut for firefox. use taglog lib
|
45
|
-
desc "spec with ff browser"
|
46
|
-
Spec::Rake::SpecTask.new(:spec_ff) do |t|
|
47
|
-
t.spec_files = FileList['spec/*_spec.rb']
|
48
|
-
t.spec_opts = [
|
49
|
-
"--color",
|
50
|
-
"--require spec/spec_helper_ff.rb",
|
51
|
-
"--format specdoc",
|
52
|
-
"--format specdoc:spec/firewatir/spec_results.txt",
|
53
|
-
"--format failing_examples:spec/firewatir/spec_results_failed.txt",
|
54
|
-
"--format html:spec/firewatir/spec_results.html",
|
55
|
-
"--loadby mtime" ]
|
56
|
-
end
|
57
|
-
|
58
|
-
#task :default => :spec
|
59
44
|
|
60
45
|
require 'rake/rdoctask'
|
61
46
|
Rake::RDocTask.new do |rdoc|
|
@@ -65,4 +50,44 @@ Rake::RDocTask.new do |rdoc|
|
|
65
50
|
rdoc.title = "watirloo #{version}"
|
66
51
|
rdoc.rdoc_files.include('README*')
|
67
52
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
54
|
+
|
55
|
+
# FireFox
|
56
|
+
namespace :ff do
|
57
|
+
|
58
|
+
# FIXME fix the spec FileList to only include those that execut for firefox. use taglog lib
|
59
|
+
desc "spec with ff browser"
|
60
|
+
Spec::Rake::SpecTask.new do |spec|
|
61
|
+
spec.spec_files = ['spec/page_spec.rb']
|
62
|
+
#FIXME bug in SpecTask? when [] or spec_files omitted then it reads the default **/*_spec.rb list of files
|
63
|
+
#if I include at least one spec files above the rest of the files are added from spec.opts
|
64
|
+
spec.spec_opts = ["--options spec/ff.opts"]
|
65
|
+
end
|
66
|
+
|
67
|
+
desc "tasklist firefox.exe"
|
68
|
+
task :tasklist do
|
69
|
+
sh "tasklist /FI \"IMAGENAME eq firefox.exe\""
|
70
|
+
end
|
71
|
+
|
72
|
+
desc "taskkill firefox.exe tree"
|
73
|
+
task :taskkill do
|
74
|
+
sh "taskkill /f /t /im firefox.exe"
|
75
|
+
end
|
76
|
+
|
77
|
+
desc "start firefox with jssh"
|
78
|
+
task :start do
|
79
|
+
require 'firewatir'
|
80
|
+
FireWatir::Firefox.new
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
desc "start irb and load current lib/watirloo"
|
85
|
+
task :console do
|
86
|
+
puts "START IRB for current project"
|
87
|
+
this_dir = File.expand_path(File.join(File.dirname(__FILE__)))
|
88
|
+
this_irbrc = File.join(this_dir, '_irbrc')
|
89
|
+
this_lib = File.join(this_dir, 'lib')
|
90
|
+
sh "set IRBRC=#{this_irbrc} && irb -I #{this_lib}"
|
91
|
+
# do not read ~/.irbrc for other defaults
|
92
|
+
# see ./_irbrc for what's loaded into irb and modify to your liking
|
68
93
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.8
|
data/_irbrc
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# WINDOWS XP
|
2
|
+
puts "LOADING custom IRB console for current watirloo project"
|
3
|
+
require 'irb/completion'
|
4
|
+
require 'pp'
|
5
|
+
require 'irb/ext/save-history'
|
6
|
+
|
7
|
+
IRB.conf[:SAVE_HISTORY]=1000
|
8
|
+
IRB.conf[:HISTORY_FILE]="./_irb_history"
|
9
|
+
IRB.conf[:AUTO_INDENT]=true
|
10
|
+
IRB.conf[:PROMPT_MODE]=:SIMPLE
|
11
|
+
IRB.conf[:USE_READLINE]=true
|
12
|
+
|
13
|
+
class Object
|
14
|
+
# Return a list of methods defined locally for a particular object. Useful
|
15
|
+
# for seeing what it does whilst losing all the guff that's implemented
|
16
|
+
# by its parents (eg Object).
|
17
|
+
def local_methods(obj = self)
|
18
|
+
(obj.methods - obj.class.superclass.instance_methods).sort
|
19
|
+
end
|
20
|
+
def lm
|
21
|
+
local_methods
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
alias x exit
|
26
|
+
|
27
|
+
require 'watirloo' #should load the one in lib in current project
|
28
|
+
|
29
|
+
def _ie
|
30
|
+
Watirloo::Browsers.target=:ie
|
31
|
+
Watirloo::browser
|
32
|
+
end
|
33
|
+
|
34
|
+
def _ff
|
35
|
+
Watirloo::Browsers.target = :firefox
|
36
|
+
Watirloo::browser
|
37
|
+
end
|
data/lib/watirloo.rb
CHANGED
data/lib/watirloo/browsers.rb
CHANGED
@@ -53,20 +53,24 @@ module Watirloo
|
|
53
53
|
ie = Watir::IE.start
|
54
54
|
sleep 3
|
55
55
|
Locker.add(ie, key)
|
56
|
-
ie #return newly created browser for the test session and store it for
|
56
|
+
ie #return newly created browser for the test session and store it for later usage
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
60
|
def ff
|
61
|
-
require 'watirloo/firewatir_ducktape'
|
61
|
+
require 'watirloo/extension/firewatir_ducktape'
|
62
62
|
# this is a cruch for quick work with pages.
|
63
63
|
# in reality you want to create a browser and pass it as argument to initialize Page class
|
64
|
+
floc = FireLocker.instance
|
64
65
|
begin
|
65
|
-
|
66
|
+
floc.browser.url
|
67
|
+
floc.browser
|
66
68
|
rescue
|
67
|
-
|
69
|
+
floc.clear
|
70
|
+
::FireWatir::Firefox.new
|
71
|
+
sleep 2
|
72
|
+
floc.browser
|
68
73
|
end
|
69
|
-
|
70
74
|
end
|
71
75
|
end
|
72
76
|
end
|
@@ -1,80 +1,12 @@
|
|
1
|
-
gem 'firewatir', '>=1.6.2' # dependency
|
2
1
|
require 'firewatir'
|
3
2
|
|
4
3
|
module FireWatir
|
5
|
-
|
6
|
-
# duck punch and ducktape Firefox for Watirloo needs
|
7
|
-
# some of it is cosmetic surgery and some new methods with intention of
|
8
|
-
# sending a patch to Watir maintainers
|
9
|
-
class Firefox
|
10
|
-
|
11
|
-
# attach to the existing Firefox that was already started with JSSH option.
|
12
|
-
# this is a hack for Watirloo. it only attaches to the latest firefox.
|
13
|
-
# it assumes there is only one instance of FF window open on the desktop
|
14
|
-
def self.attach
|
15
|
-
Firefox.new :attach => true
|
16
|
-
end
|
17
|
-
|
18
|
-
# add option key :attach as a hack
|
19
|
-
# :attach => true to attach to topmost window in getWindows().lenght-1
|
20
|
-
# split up initialize to conditionally start FireFox
|
21
|
-
def initialize(options = {})
|
22
|
-
_start_firefox(options) unless options[:attach]
|
23
|
-
set_defaults()
|
24
|
-
get_window_number()
|
25
|
-
set_browser_document()
|
26
|
-
end
|
27
|
-
|
28
|
-
# refactor initialize method to move all starting of FF into its own method
|
29
|
-
def _start_firefox(options)
|
30
|
-
if(options.kind_of?(Integer))
|
31
|
-
options = {:waitTime => options}
|
32
|
-
end
|
33
|
-
|
34
|
-
if(options[:profile])
|
35
|
-
profile_opt = "-no-remote -P #{options[:profile]}"
|
36
|
-
else
|
37
|
-
profile_opt = ""
|
38
|
-
end
|
39
|
-
|
40
|
-
waitTime = options[:waitTime] || 2
|
41
|
-
|
42
|
-
case RUBY_PLATFORM
|
43
|
-
when /mswin/
|
44
|
-
# Get the path to Firefox.exe using Registry.
|
45
|
-
require 'win32/registry.rb'
|
46
|
-
path_to_bin = ""
|
47
|
-
Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Mozilla\Mozilla Firefox') do |reg|
|
48
|
-
keys = reg.keys
|
49
|
-
reg1 = Win32::Registry::HKEY_LOCAL_MACHINE.open("SOFTWARE\\Mozilla\\Mozilla Firefox\\#{keys[0]}\\Main")
|
50
|
-
reg1.each do |subkey, type, data|
|
51
|
-
if(subkey =~ /pathtoexe/i)
|
52
|
-
path_to_bin = data
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
when /linux/i
|
58
|
-
path_to_bin = `which firefox`.strip
|
59
|
-
when /darwin/i
|
60
|
-
path_to_bin = '/Applications/Firefox.app/Contents/MacOS/firefox'
|
61
|
-
when /java/
|
62
|
-
raise "Not implemented: Create a browser finder in JRuby"
|
63
|
-
end
|
64
|
-
|
65
|
-
@t = Thread.new { system("#{path_to_bin} -jssh #{profile_opt}")}
|
66
|
-
sleep waitTime
|
67
|
-
|
68
|
-
end
|
69
|
-
private :_start_firefox
|
70
|
-
|
71
|
-
end
|
72
|
-
|
4
|
+
|
73
5
|
class SelectList
|
74
6
|
|
75
7
|
include Watir::SelectListCommonWatir
|
76
|
-
|
77
|
-
|
8
|
+
|
9
|
+
# accepts one text item or array of text items. if array then sets one after another.
|
78
10
|
# For single select lists the last item in array wins
|
79
11
|
#
|
80
12
|
# examples
|
@@ -83,15 +15,35 @@ module FireWatir
|
|
83
15
|
# this is a single select list box it will set each value in turn
|
84
16
|
# select_list set 1 # => set the first option in a list
|
85
17
|
# select_list.set [1,3,5] => set the first, third and fith options
|
86
|
-
def
|
18
|
+
def select( item )
|
87
19
|
_set(:text, item)
|
88
20
|
end
|
89
21
|
|
90
22
|
# set item by the option value attribute. if array then set one after anohter.
|
91
23
|
# see examples in set method
|
92
|
-
def
|
24
|
+
def select_value( value )
|
93
25
|
_set(:value, value)
|
94
26
|
end
|
27
|
+
|
28
|
+
# set :value or :text
|
29
|
+
def _set(how, what)
|
30
|
+
if what.kind_of? Array
|
31
|
+
what.each { |item| _set(how,item)} # call self with individual item
|
32
|
+
else
|
33
|
+
if what.kind_of? Fixnum # if by position then translate to set by text
|
34
|
+
if (0..items.size).member? what
|
35
|
+
_set :text, items[what-1] #call self with found item
|
36
|
+
else
|
37
|
+
raise ::Watir::Exception::WatirException, "number #{item} is out of range of item count"
|
38
|
+
end
|
39
|
+
else
|
40
|
+
select_items_in_select_list(how, what) #finally as :value or :text
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
alias set select
|
46
|
+
alias set_value select_value
|
95
47
|
|
96
48
|
# returns array of value attributes
|
97
49
|
# each option usually has a value attribute
|
@@ -146,7 +98,11 @@ module FireWatir
|
|
146
98
|
end
|
147
99
|
end
|
148
100
|
end
|
149
|
-
|
101
|
+
|
102
|
+
def name
|
103
|
+
@name
|
104
|
+
end
|
105
|
+
|
150
106
|
# which values are selected?
|
151
107
|
def selected_values
|
152
108
|
values = []
|
@@ -156,7 +112,41 @@ module FireWatir
|
|
156
112
|
return values
|
157
113
|
end
|
158
114
|
end
|
159
|
-
|
115
|
+
|
116
|
+
class CheckboxGroups < ElementCollections
|
117
|
+
# def element_class; CheckboxGroup; end
|
118
|
+
|
119
|
+
def initialize(container)
|
120
|
+
@container = container
|
121
|
+
elements = locate_elements
|
122
|
+
@element_objects = []
|
123
|
+
# for each unique name create a checkbox_group
|
124
|
+
elements.each do |name|
|
125
|
+
@element_objects << CheckboxGroup.new(container, name)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def length
|
130
|
+
@element_objects.size
|
131
|
+
end
|
132
|
+
|
133
|
+
# return array of unique names for checkboxes in container
|
134
|
+
def locate_elements
|
135
|
+
names = []
|
136
|
+
@container.checkboxes.each do |cb|
|
137
|
+
names << cb.name
|
138
|
+
end
|
139
|
+
names.uniq #non repeating names
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
# allows access to a specific item in the collection. 1-based index
|
144
|
+
def [](n)
|
145
|
+
@element_objects[n-1]
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
|
160
150
|
class RadioGroup
|
161
151
|
|
162
152
|
include RadioCheckGroup
|
@@ -190,5 +180,6 @@ module FireWatir
|
|
190
180
|
def checkbox_group(name)
|
191
181
|
CheckboxGroup.new(self, name)
|
192
182
|
end
|
183
|
+
|
193
184
|
end
|
194
185
|
end
|
data/lib/watirloo/locker.rb
CHANGED
@@ -1,5 +1,20 @@
|
|
1
|
+
|
1
2
|
module Watirloo
|
2
3
|
|
4
|
+
require 'singleton'
|
5
|
+
|
6
|
+
class FireLocker
|
7
|
+
include Singleton
|
8
|
+
attr_accessor :browser
|
9
|
+
# reuse browser previously attached to.
|
10
|
+
# ISSUE: if browser is closed we are stuck holding reference to non existing browser
|
11
|
+
def browser
|
12
|
+
@firefox ||= ::FireWatir::Firefox.attach(:url, /.*/)
|
13
|
+
end
|
14
|
+
def clear
|
15
|
+
@firefox = nil
|
16
|
+
end
|
17
|
+
end
|
3
18
|
|
4
19
|
# manages references to browsers we care about to run tests agains.
|
5
20
|
# Saves references to window handles internall to yaml file so we can reuse the browser for tests by reattaching to it between tests.
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'Win32API'
|
2
|
+
|
3
|
+
module Watirloo
|
4
|
+
|
5
|
+
module ScreenCapture
|
6
|
+
|
7
|
+
KEYEVENTF_KEYUP = 0x2
|
8
|
+
VK_CONTROL = 0x11
|
9
|
+
VK_MENU = 0x12
|
10
|
+
VK_SHIFT = 0x10
|
11
|
+
VK_SNAPSHOT = 0x2C
|
12
|
+
|
13
|
+
# send key events Ctrl+PrintScreen using win32 to activate greenshot screencatpure program
|
14
|
+
# http://sourceforge.net/projects/greenshot/
|
15
|
+
# greenshot must be configured beforehand and running (best to just run it at win startup)
|
16
|
+
# output: save automatically to a location of your choice (best with png, smallest files)
|
17
|
+
# filepattern: recommended greenshot_%YYYY%-%MM%-%DD%_%hh%-%mm%-%ss%
|
18
|
+
# turn off open in editor option
|
19
|
+
# For reference see Watir::ScreenCapture.screen_capture method in watir gem
|
20
|
+
# by default it takes a screenshot of the desktop Ctrl+PrintScreen
|
21
|
+
# any other arg snaps the last region Shift+PrintScreen (call with :region arg)
|
22
|
+
def screenshot what=:desktop
|
23
|
+
# WIN32API.new(dllname, func, import, export = "0")
|
24
|
+
keybd_event = Win32API.new("user32", "keybd_event", ['I','I','L','L'], 'V')
|
25
|
+
#keybd_event(bVk, bScan, dwFlags, dwExtraInfo)
|
26
|
+
#Simulate a keyboard event
|
27
|
+
if what == :desktop
|
28
|
+
# Ctrl + PrintScreen keybd event
|
29
|
+
keybd_event.Call(VK_CONTROL, 1, 0, 0)
|
30
|
+
keybd_event.Call(VK_SNAPSHOT, 1, 0, 0)
|
31
|
+
keybd_event.Call(VK_SNAPSHOT, 1, KEYEVENTF_KEYUP, 0)
|
32
|
+
keybd_event.Call(VK_CONTROL, 1, KEYEVENTF_KEYUP, 0)
|
33
|
+
else
|
34
|
+
# Shift + PrintScreen keybd event
|
35
|
+
keybd_event.Call(VK_SHIFT, 1, 0, 0)
|
36
|
+
keybd_event.Call(VK_SNAPSHOT, 1, 0, 0)
|
37
|
+
keybd_event.Call(VK_SNAPSHOT, 1, KEYEVENTF_KEYUP, 0)
|
38
|
+
keybd_event.Call(VK_SHIFT, 1, KEYEVENTF_KEYUP, 0)
|
39
|
+
end
|
40
|
+
sleep 1 #give time to save
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
if $0 == __FILE__
|
46
|
+
# sample usage
|
47
|
+
include Watirloo::ScreenCapture
|
48
|
+
screenshot #takes full screen
|
49
|
+
screenshot :region # last set region. you must set region with PrintScreen first in greenshot
|
50
|
+
end
|
data/spec/checkbox_group_spec.rb
CHANGED
@@ -3,14 +3,14 @@ require File.dirname(__FILE__) + '/spec_helper'
|
|
3
3
|
describe 'browser checkbox_group accesses a group of checkboxes sharing the same name on a page' do
|
4
4
|
|
5
5
|
before :each do
|
6
|
-
@browser = Watirloo
|
6
|
+
@browser = Watirloo.browser
|
7
7
|
@browser.goto testfile('checkbox_group1.html')
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
it 'browser responds to checkbox_group' do
|
11
11
|
@browser.should respond_to(:checkbox_group)
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
it 'access by name as default returns CheckboxGroup' do
|
15
15
|
if @browser.kind_of?(FireWatir::Firefox)
|
16
16
|
@browser.checkbox_group('pets').should be_kind_of(FireWatir::CheckboxGroup)
|
@@ -20,9 +20,9 @@ describe 'browser checkbox_group accesses a group of checkboxes sharing the same
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'size retuns checkboxes as items count in a group' do
|
23
|
-
@browser.checkbox_group(
|
23
|
+
@browser.checkbox_group('pets').size.should == 5
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
it 'values returns array of value attributes for each checkbox in a group' do
|
27
27
|
@browser.checkbox_group('pets').values.should == ["cat", "dog", "zook", "zebra", "wumpa"]
|
28
28
|
end
|
@@ -32,7 +32,7 @@ end
|
|
32
32
|
describe "checkbox_group values when no checkbox is checked in a group" do
|
33
33
|
|
34
34
|
before :each do
|
35
|
-
@browser = Watirloo
|
35
|
+
@browser = Watirloo.browser
|
36
36
|
@browser.goto testfile('checkbox_group1.html')
|
37
37
|
end
|
38
38
|
|
@@ -50,13 +50,13 @@ describe "checkbox_group values when no checkbox is checked in a group" do
|
|
50
50
|
it "set? should return false when no checkbox is checked in a group" do
|
51
51
|
@browser.checkbox_group("pets").should_not be_set
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
end
|
55
55
|
|
56
56
|
describe "checkbox_group values when set string selecs one item only" do
|
57
57
|
|
58
58
|
before :each do
|
59
|
-
@browser = Watirloo
|
59
|
+
@browser = Watirloo.browser
|
60
60
|
@browser.goto testfile('checkbox_group1.html')
|
61
61
|
end
|
62
62
|
|
@@ -87,7 +87,7 @@ end
|
|
87
87
|
describe "checkbox_group set array of strings selects multiple values in a group" do
|
88
88
|
|
89
89
|
before :each do
|
90
|
-
@browser = Watirloo
|
90
|
+
@browser = Watirloo.browser
|
91
91
|
@browser.goto testfile('checkbox_group1.html')
|
92
92
|
end
|
93
93
|
|