popup 0.0.5
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/README.md +45 -0
- data/Rakefile +19 -0
- data/lib/popup.rb +7 -0
- data/lib/popup/alert_popup.rb +13 -0
- data/lib/popup/confirm_popup.rb +26 -0
- data/lib/popup/constants/file_popup.yml +13 -0
- data/lib/popup/exceptions.rb +9 -0
- data/lib/popup/ext/rautomation_ext.rb +6 -0
- data/lib/popup/file_ext.rb +19 -0
- data/lib/popup/file_popup.rb +48 -0
- data/lib/popup/popup.rb +109 -0
- data/lib/popup/popup_window.rb +53 -0
- data/lib/popup/save_popup.rb +18 -0
- data/lib/popup/version.rb +5 -0
- data/lib/popup/window_factory.rb +67 -0
- data/spec/alert_popup_spec.rb +24 -0
- data/spec/confirm_popup_spec.rb +49 -0
- data/spec/file_popup_spec.rb +38 -0
- data/spec/popup_spec.rb +37 -0
- data/spec/popup_window_spec.rb +26 -0
- data/spec/spec_helper.rb +28 -0
- data/spec/webserver.rb +52 -0
- data/support/file_popup/test.txt +1 -0
- data/support/file_popup/test1.txt +1 -0
- data/support/html_popup/file.html +13 -0
- metadata +115 -0
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
Popup
|
2
|
+
===========
|
3
|
+
|
4
|
+
Are you using watir for TA(testingautomation) ?
|
5
|
+
Do you test with complicat codes ?
|
6
|
+
Yes, Popup is designed for you.
|
7
|
+
It can do all type of popups, and is complicat with different windows platfrom, XP,2003,vista,win7 (en and chinese version)
|
8
|
+
It also has a very simple interface.
|
9
|
+
|
10
|
+
Requirements
|
11
|
+
------------
|
12
|
+
* Ruby
|
13
|
+
|
14
|
+
Compatibility
|
15
|
+
-------------
|
16
|
+
Ruby1.8.6
|
17
|
+
Ruby1.8.7
|
18
|
+
Ruby1.9.2
|
19
|
+
|
20
|
+
support XP,2003,vista,win7( If not work, please tell me, I will fix it immediately )
|
21
|
+
|
22
|
+
|
23
|
+
Installation
|
24
|
+
------------
|
25
|
+
gem install popup
|
26
|
+
|
27
|
+
Usage
|
28
|
+
-----
|
29
|
+
require 'rubygems'
|
30
|
+
require 'popup'
|
31
|
+
ATT::AlertPopup.find_when { button.click }.click
|
32
|
+
----------------------
|
33
|
+
|
34
|
+
How to test
|
35
|
+
----
|
36
|
+
1. run spec/*.spec:
|
37
|
+
rspec .
|
38
|
+
|
39
|
+
How to push my fix code
|
40
|
+
--------
|
41
|
+
|
42
|
+
* fork it
|
43
|
+
* read the code and modify it and commit
|
44
|
+
* add spec test.( important, if there is no testing, I will reject your push request. )
|
45
|
+
* Then push your request.
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
task :default=> "spec:popup"
|
5
|
+
|
6
|
+
namespace :spec do
|
7
|
+
#~ require 'rspec/core/rake_task'
|
8
|
+
#~ RSpec::Core::RakeTask.new(:spec)
|
9
|
+
|
10
|
+
desc "Run specs against ie adapter"
|
11
|
+
task "popup" do
|
12
|
+
#task = Rake::Task["spec:spec"]
|
13
|
+
#task.reenable
|
14
|
+
#task.invoke
|
15
|
+
Dir.chdir(File.dirname(__FILE__)) do
|
16
|
+
puts `rspec`
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/popup.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module ATT
|
2
|
+
class ConfirmPopup < Popup
|
3
|
+
# Click
|
4
|
+
def click
|
5
|
+
confirm_button.click
|
6
|
+
end
|
7
|
+
|
8
|
+
alias set click
|
9
|
+
|
10
|
+
def cancel
|
11
|
+
cancel_button.click
|
12
|
+
end
|
13
|
+
|
14
|
+
alias clear cancel
|
15
|
+
|
16
|
+
# @private
|
17
|
+
def confirm_button
|
18
|
+
@window.button(:instance=>1)
|
19
|
+
end
|
20
|
+
|
21
|
+
# @private
|
22
|
+
def cancel_button
|
23
|
+
@window.button(:instance=>2)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module ATT
|
2
|
+
class RootException < RuntimeError ; end
|
3
|
+
class RootNotSetError < RootException ; end
|
4
|
+
class WindowNotFoundError < RootException ; end
|
5
|
+
class FileNotFoundError < RootException ; end
|
6
|
+
class NotImplementError < RootException ; end
|
7
|
+
class NotRecordError < RootException; end
|
8
|
+
class MutliWindowsMatchError < RootException; end
|
9
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ATT
|
2
|
+
module FileExt
|
3
|
+
private
|
4
|
+
def check_file_exist?(file_path)
|
5
|
+
raise FileNotFoundError,"#{file_path} not exist" unless File.file?( window_full_path(file_path) )
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
def window_full_path(file_path)
|
10
|
+
path = file_path
|
11
|
+
unless Pathname.new(file_path).absolute?
|
12
|
+
path = File.expand_path(File.join(Config.root,file_path))
|
13
|
+
else
|
14
|
+
path = File.expand_path(file_path)
|
15
|
+
end
|
16
|
+
path.gsub("/","\\")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
module ATT
|
3
|
+
class FilePopup < Popup
|
4
|
+
include FileExt
|
5
|
+
CONFIRM_TEXT = [ "OPEN", "打开", "Open" ]
|
6
|
+
# Set File Popup with file_path, then click confirm button.
|
7
|
+
# @param file_path
|
8
|
+
# @return: none
|
9
|
+
# Will raise FileNotFoundError when file_path is valid path
|
10
|
+
# Raise RootNotSetError when ATT::Config.root not set and path is not an absolute path
|
11
|
+
def set(file_path)
|
12
|
+
check_file_exist?(file_path)
|
13
|
+
set_text(file_path)
|
14
|
+
click_confirm
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_text(file_path)
|
18
|
+
#@text_field = WindowFactory.make_other(@window, config["edit"] )
|
19
|
+
text_field.set(window_full_path(file_path))
|
20
|
+
end
|
21
|
+
|
22
|
+
def text_field
|
23
|
+
@window.text_field(:instance=>1)
|
24
|
+
end
|
25
|
+
|
26
|
+
def click_confirm
|
27
|
+
#@window.button( config("open_button") ).click
|
28
|
+
#WindowFactory.make_other( @window,config["confirm"] ).click
|
29
|
+
confirm_button.click
|
30
|
+
end
|
31
|
+
|
32
|
+
def confirm_button
|
33
|
+
most_like = @window.button(:index=>1)
|
34
|
+
CONFIRM_TEXT.each do |text|
|
35
|
+
most_like.value.include?(text) && ( return most_like )
|
36
|
+
end
|
37
|
+
# Warning:at the most time it should be the button index is 1, if not,
|
38
|
+
# Now we try find one matched button with CONFIRM_TEXT.
|
39
|
+
@window.buttons.find do |button|
|
40
|
+
CONFIRM_TEXT.each do |text|
|
41
|
+
button.value.include?(text) && ( break true ) || false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
data/lib/popup/popup.rb
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'popup/ext/rautomation_ext'
|
2
|
+
require 'popup/popup_window'
|
3
|
+
module ATT
|
4
|
+
module Config
|
5
|
+
module_function
|
6
|
+
def root
|
7
|
+
@root || ( raise ATT::RootNotSetError,'please use ATT::Config.root=(path) to set.' )
|
8
|
+
end
|
9
|
+
|
10
|
+
module_function
|
11
|
+
def root=(root)
|
12
|
+
@root=root
|
13
|
+
end
|
14
|
+
|
15
|
+
module_function
|
16
|
+
def timeout=(timeout)
|
17
|
+
@timeout = timeout
|
18
|
+
end
|
19
|
+
|
20
|
+
module_function
|
21
|
+
def timeout
|
22
|
+
@timeout || 60
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Popup
|
27
|
+
@@windows = nil
|
28
|
+
RAutomation::Window.wait_timeout = Config::timeout
|
29
|
+
ENV["RAUTOMATION_ADAPTER"] = "autoit"
|
30
|
+
def initialize(window) # :nodoc:
|
31
|
+
@window = window
|
32
|
+
end
|
33
|
+
|
34
|
+
# Get a popup between record() and find(),
|
35
|
+
# * If not found, it will raise +WindowNotFoundError
|
36
|
+
# * Else, if found more than one windows, it will raise MutliWindowsMatchError
|
37
|
+
# * +ATTEND+: must call record() before use it.
|
38
|
+
# @Return: Popup object that is found.
|
39
|
+
def self.find
|
40
|
+
raise NotRecordError,"please call record() before use me." unless @@windows
|
41
|
+
windows_new = []
|
42
|
+
begin
|
43
|
+
RAutomation::WaitHelper.wait_until(Config::timeout) do
|
44
|
+
sleep 0.5
|
45
|
+
windows_now = collect_windows
|
46
|
+
windows_new = windows_now - @@windows
|
47
|
+
windows_new.size > 0 && windows_new.reject! { |h| RAutomation::Window.new(:hwnd=>h).text.chomp == "" }
|
48
|
+
windows_new.size > 0
|
49
|
+
end
|
50
|
+
rescue RAutomation::WaitHelper::TimeoutError
|
51
|
+
raise WindowNotFoundError,"can not found new window in time #{Config::timeout} seconds"
|
52
|
+
end
|
53
|
+
#~ puts "new = " + (windows_new.collect do |hwnd| RAutomation::Window.new(:hwnd=>hwnd,:adapter=>"autoit").text end).join(",")
|
54
|
+
# TODO: next week we should guess one window, but not raise a big exception
|
55
|
+
raise MutliWindowsMatchError,"more than one windows opened between record() and find()" if windows_new.size > 1
|
56
|
+
window = RAutomation::Window.new(:hwnd => windows_new[0] ) if windows_new.size == 1
|
57
|
+
return self.new(window)
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.find_all
|
61
|
+
windows_now = collect_windows
|
62
|
+
windows_new = windows_now - @@windows
|
63
|
+
windows_new.collect { |hwnd| self.new( RAutomation::Window.new(:hwnd => hwnd ) ) }
|
64
|
+
end
|
65
|
+
|
66
|
+
# Record all the windows availed now.
|
67
|
+
# @return: Array that contains all the hwnd of visble windows.
|
68
|
+
def self.record
|
69
|
+
@@windows = collect_windows
|
70
|
+
end
|
71
|
+
# :nodoc:
|
72
|
+
def self.collect_windows
|
73
|
+
RAutomation::Window.windows.collect { |w| w.hwnd }.find_all { |hwnd| PopupWindow.is_popup?(hwnd) }
|
74
|
+
end
|
75
|
+
|
76
|
+
# Find a new popup when execute the block you have given.
|
77
|
+
#
|
78
|
+
def self.find_when # :yields:
|
79
|
+
record
|
80
|
+
begin
|
81
|
+
thread = Thread.new {
|
82
|
+
yield
|
83
|
+
}
|
84
|
+
find
|
85
|
+
ensure
|
86
|
+
thread.kill
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# Close the window
|
91
|
+
# It behave as click x button at the right postion above.
|
92
|
+
def close
|
93
|
+
@window.close
|
94
|
+
end
|
95
|
+
# @return: true if window exist
|
96
|
+
# false if not
|
97
|
+
def assert_exist?
|
98
|
+
@window.exist?
|
99
|
+
end
|
100
|
+
|
101
|
+
alias exist? assert_exist?
|
102
|
+
|
103
|
+
private
|
104
|
+
def config
|
105
|
+
@config ||= WindowFactory.config(self.class)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
module ATT
|
3
|
+
class PopupWindow
|
4
|
+
extend FFI::Library
|
5
|
+
ffi_lib 'user32'
|
6
|
+
attach_function :GetWindow, [ :long, :uint ], :long
|
7
|
+
attach_function :GetParent, [ :long ], :long
|
8
|
+
|
9
|
+
# check the window of hwnd whether a popup window
|
10
|
+
def self.is_popup?(hwnd)
|
11
|
+
GetWindow( hwnd, 4 ) != 0
|
12
|
+
end
|
13
|
+
|
14
|
+
@@listen_threads = []
|
15
|
+
|
16
|
+
def self.listen(interval=5) # :yields: popup
|
17
|
+
th = Thread.new do
|
18
|
+
Popup.record
|
19
|
+
begin
|
20
|
+
loop do
|
21
|
+
sleep interval
|
22
|
+
news = Popup.find_all
|
23
|
+
news.each do |popup|
|
24
|
+
yield popup
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
@@listen_threads << th
|
30
|
+
th
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.stop_listen(thread = 'all')
|
34
|
+
if thread == 'all'
|
35
|
+
@@listen_threads.each do |thread|
|
36
|
+
begin
|
37
|
+
thread.kill
|
38
|
+
rescue Exception
|
39
|
+
puts $!
|
40
|
+
end
|
41
|
+
end
|
42
|
+
@@listen_threads =[]
|
43
|
+
elsif @@listen_threads.delete(thread)
|
44
|
+
thread.kill
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.listen_threads
|
49
|
+
@@listen_threads
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module ATT
|
2
|
+
class SavePopup < Popup
|
3
|
+
include FileExt
|
4
|
+
# TODO:
|
5
|
+
# Save diaglog as a file
|
6
|
+
# if +file_path+ is relative path, it will be expand to abosulte path join with ATT::Config.root
|
7
|
+
# @param: file_path
|
8
|
+
def saveas(file_path)
|
9
|
+
confirm_button.click
|
10
|
+
end
|
11
|
+
|
12
|
+
alias set click
|
13
|
+
|
14
|
+
def confirm_button # :nodoc:
|
15
|
+
@window.button(:instance=>1)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'popup/ext/rautomation_ext'
|
2
|
+
require 'active_support'
|
3
|
+
module ATT
|
4
|
+
class WindowFactory
|
5
|
+
@@config_root = File.join(__FILE__,'..','constants')
|
6
|
+
class << self
|
7
|
+
def config(klass)
|
8
|
+
klass = klass.class unless klass.kind_of?(Class)
|
9
|
+
_config(klass.to_s.split('::')[-1].underscore + '.yml')
|
10
|
+
end
|
11
|
+
def _config(file_name)
|
12
|
+
YAML.load_file(File.join(@@config_root,file_name))
|
13
|
+
end
|
14
|
+
|
15
|
+
def make(klass)
|
16
|
+
raise NotImplementError,"this feature no implement yeat."
|
17
|
+
end
|
18
|
+
|
19
|
+
def make_other(container,e)
|
20
|
+
type = e["type"]
|
21
|
+
locators = e["default_locators"]
|
22
|
+
_make_other(container,type,locators)
|
23
|
+
end
|
24
|
+
|
25
|
+
def _make_other(container,type,locators)
|
26
|
+
container.send(type,locators)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class RegFactory < WindowFactory
|
32
|
+
$KCODE="u"
|
33
|
+
class << self
|
34
|
+
def make(klass)
|
35
|
+
RAutomation::Window.new(:title=> reg_title(klass), :adapter=>"autoit" )
|
36
|
+
end
|
37
|
+
|
38
|
+
def reg_title(klass)
|
39
|
+
reg(config(klass)["title"])
|
40
|
+
end
|
41
|
+
|
42
|
+
def reg(hash_or_array)
|
43
|
+
if hash_or_array.kind_of?(Array)
|
44
|
+
ach = "each"
|
45
|
+
else
|
46
|
+
ach = "each_value"
|
47
|
+
end
|
48
|
+
reg_str = ""
|
49
|
+
hash_or_array.send(ach) do |v|
|
50
|
+
next if v == ""
|
51
|
+
reg_str += ( Regexp.escape(v) + "|" )
|
52
|
+
end
|
53
|
+
Regexp.new(reg_str.chop)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class ArrayFactory
|
59
|
+
class <<self
|
60
|
+
def make(type)
|
61
|
+
end
|
62
|
+
|
63
|
+
def platform
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
gem "watir","1.6.5"
|
3
|
+
require 'watir'
|
4
|
+
|
5
|
+
describe ATT::AlertPopup do
|
6
|
+
before(:each) do
|
7
|
+
@b = TestBrowser.get
|
8
|
+
end
|
9
|
+
|
10
|
+
it "#set" do
|
11
|
+
file = @b.button(:id,"alert_popup")
|
12
|
+
ATT::AlertPopup.record
|
13
|
+
file.click_no_wait
|
14
|
+
o = ATT::AlertPopup.find
|
15
|
+
o.click
|
16
|
+
sleep 1
|
17
|
+
o.should_not be_exist
|
18
|
+
end
|
19
|
+
|
20
|
+
it "#find_when test" do
|
21
|
+
alert = @b.button(:id,"alert_popup")
|
22
|
+
ATT::AlertPopup.find_when { alert.click_no_wait }.click
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
gem "watir","1.6.5"
|
3
|
+
require 'watir'
|
4
|
+
|
5
|
+
describe ATT::ConfirmPopup do
|
6
|
+
before(:each) do
|
7
|
+
@b = TestBrowser.get
|
8
|
+
end
|
9
|
+
|
10
|
+
it "#click" do
|
11
|
+
confirm_button = @b.button(:id,"confirm_popup")
|
12
|
+
ATT::ConfirmPopup.record
|
13
|
+
confirm_button.click_no_wait
|
14
|
+
o = ATT::ConfirmPopup.find
|
15
|
+
o.click
|
16
|
+
o.should_not be_exist
|
17
|
+
end
|
18
|
+
it "#set" do
|
19
|
+
confirm_button = @b.button(:id,"confirm_popup")
|
20
|
+
ATT::ConfirmPopup.record
|
21
|
+
confirm_button.click_no_wait
|
22
|
+
o = ATT::ConfirmPopup.find
|
23
|
+
o.set
|
24
|
+
o.should_not be_exist
|
25
|
+
confirm_button.value.should == "true"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "#clear" do
|
29
|
+
confirm_button = @b.button(:id,"confirm_popup")
|
30
|
+
ATT::ConfirmPopup.record
|
31
|
+
confirm_button.click_no_wait
|
32
|
+
o = ATT::ConfirmPopup.find
|
33
|
+
o.clear
|
34
|
+
o.should_not be_exist
|
35
|
+
sleep 2
|
36
|
+
confirm_button.value.should == "false"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "#click but not found" do
|
40
|
+
confirm_button = @b.button(:id,"confirm_popup")
|
41
|
+
begin
|
42
|
+
ATT::Config.timeout=5
|
43
|
+
ATT::ConfirmPopup.record
|
44
|
+
lambda {ATT::ConfirmPopup.find }.should raise_error
|
45
|
+
ensure
|
46
|
+
ATT::Config.timeout=60
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
gem "watir","1.6.5"
|
3
|
+
require 'watir'
|
4
|
+
|
5
|
+
describe ATT::FilePopup do
|
6
|
+
before(:each) do
|
7
|
+
@b = TestBrowser.get
|
8
|
+
end
|
9
|
+
|
10
|
+
it "#exist?" do
|
11
|
+
window = RAutomation::Window.new(:title=>"notexist")
|
12
|
+
o = ATT::FilePopup.new(window)
|
13
|
+
o.should respond_to("exist?")
|
14
|
+
o.should respond_to("assert_exist?")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "#set" do
|
18
|
+
file = @b.file_field(:id,"file_popup")
|
19
|
+
ATT::FilePopup.record
|
20
|
+
file.click_no_wait
|
21
|
+
o = ATT::FilePopup.find
|
22
|
+
o.set("file_popup/test.txt")
|
23
|
+
o.should_not be_exist
|
24
|
+
file.value.should =~ /test.txt$/
|
25
|
+
end
|
26
|
+
|
27
|
+
it "#set absolute path" do
|
28
|
+
file = @b.file_field(:id,"file_popup")
|
29
|
+
ATT::FilePopup.record
|
30
|
+
file.click_no_wait
|
31
|
+
o = ATT::FilePopup.find
|
32
|
+
lambda { o.set("file_popup/no_exist.txt") }.should raise_error
|
33
|
+
absolute_path = Pathname.new(File.join(ATT::Config.root,"file_popup/test1.txt")).realpath
|
34
|
+
o.set(absolute_path)
|
35
|
+
o.should_not be_exist
|
36
|
+
file.value.should =~ /test1.txt$/
|
37
|
+
end
|
38
|
+
end
|
data/spec/popup_spec.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
gem "watir","1.6.5"
|
3
|
+
require 'watir'
|
4
|
+
|
5
|
+
describe ATT::Popup do
|
6
|
+
|
7
|
+
it "#exist?" do
|
8
|
+
window = RAutomation::Window.new(:title=>"not exist")
|
9
|
+
o = ATT::Popup.new(window)
|
10
|
+
o.should respond_to("exist?")
|
11
|
+
o.should respond_to("assert_exist?")
|
12
|
+
o.should_not be_exist
|
13
|
+
end
|
14
|
+
|
15
|
+
it "#record" do
|
16
|
+
ATT::Popup.should be_respond_to("record")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "#find" do
|
20
|
+
b = TestBrowser.get
|
21
|
+
ATT::Popup.record
|
22
|
+
b.file_field(:id,"file_popup").click_no_wait
|
23
|
+
o = ATT::Popup.find
|
24
|
+
o.should_not be_nil
|
25
|
+
o.close
|
26
|
+
end
|
27
|
+
it "#find multi" do
|
28
|
+
b = TestBrowser.get
|
29
|
+
ATT::Popup.record
|
30
|
+
b.file_field(:id,"file_popup").click_no_wait
|
31
|
+
c = Watir::IE.new
|
32
|
+
o = ATT::Popup.find
|
33
|
+
o.should_not be_nil
|
34
|
+
o.close
|
35
|
+
c.close
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
gem "watir","1.6.5"
|
3
|
+
require 'watir'
|
4
|
+
describe ATT::PopupWindow do
|
5
|
+
it '#listen' do
|
6
|
+
b = TestBrowser.get
|
7
|
+
th = ATT::PopupWindow.listen do |popup|
|
8
|
+
popup.close
|
9
|
+
end
|
10
|
+
b.file_field(:id,"file_popup").click_no_wait
|
11
|
+
sleep 10
|
12
|
+
ATT::Popup.find_all.should == []
|
13
|
+
ATT::PopupWindow.stop_listen(th)
|
14
|
+
b.close
|
15
|
+
end
|
16
|
+
|
17
|
+
it '#stop_listen all' do
|
18
|
+
th = ATT::PopupWindow.listen do |p|
|
19
|
+
puts 'ok'
|
20
|
+
end
|
21
|
+
#sleep 20
|
22
|
+
ATT::PopupWindow.stop_listen('all')
|
23
|
+
ATT::PopupWindow.listen_threads.should == []
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
$LOAD_PATH.unshift File.join(__FILE__,'..','..','lib')
|
2
|
+
require 'popup'
|
3
|
+
require 'rspec'
|
4
|
+
ATT::Config.root = File.join(__FILE__,'..','..','support')
|
5
|
+
|
6
|
+
require 'webserver'
|
7
|
+
|
8
|
+
class TestBrowser
|
9
|
+
def self.get(type= :ie)
|
10
|
+
@server || start_server
|
11
|
+
if @browser.nil?
|
12
|
+
@browser = Watir::Browser.new()
|
13
|
+
@browser.goto("http://localhost:#{@port}/file.html")
|
14
|
+
end
|
15
|
+
at_exit { close }
|
16
|
+
@browser
|
17
|
+
end
|
18
|
+
def self.start_server
|
19
|
+
@server = PopupServer.new
|
20
|
+
@port = @server.port
|
21
|
+
@server.start
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.close
|
25
|
+
@browser.close
|
26
|
+
@server.stop
|
27
|
+
end
|
28
|
+
end
|
data/spec/webserver.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'webrick'
|
2
|
+
require 'timeout'
|
3
|
+
|
4
|
+
class PopupServer
|
5
|
+
|
6
|
+
attr_reader :port,:run
|
7
|
+
def initialize(port=12345)
|
8
|
+
@run = false
|
9
|
+
@port = port
|
10
|
+
@s = WEBrick::HTTPServer.new(
|
11
|
+
:Port=> @port,
|
12
|
+
:DocumentRoot => File.join(File.join(__FILE__,'..','..','support'),"html_popup")
|
13
|
+
)
|
14
|
+
@s.mount("/html_popup",WEBrick::HTTPServlet::FileHandler,"/file.html")
|
15
|
+
end
|
16
|
+
|
17
|
+
def start(wait_forever = false)
|
18
|
+
raise "popup server is running,can NOT run again" if @run
|
19
|
+
@run = true
|
20
|
+
@s_thread = Thread.new do
|
21
|
+
@s.start
|
22
|
+
end
|
23
|
+
wait
|
24
|
+
@s_thread.join if wait_forever
|
25
|
+
end
|
26
|
+
|
27
|
+
def wait(timeout=10)
|
28
|
+
Timeout.timeout(timeout,"after #{timeout} popup server still can NOT start") do
|
29
|
+
loop do
|
30
|
+
begin
|
31
|
+
TCPSocket.new("127.0.0.1",@port)
|
32
|
+
return true
|
33
|
+
rescue
|
34
|
+
sleep 0.5
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def stop
|
41
|
+
@s.shutdown
|
42
|
+
@run = false
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
if $0 == __FILE__
|
48
|
+
a = PopupServer.new
|
49
|
+
a.start(true)
|
50
|
+
#sleep 100
|
51
|
+
#a.stop
|
52
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
111
|
@@ -0,0 +1 @@
|
|
1
|
+
111
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<html>
|
2
|
+
<title>
|
3
|
+
popup test
|
4
|
+
</title>
|
5
|
+
<script type="text/javascript">
|
6
|
+
|
7
|
+
</script>
|
8
|
+
<body>
|
9
|
+
<button onclick="alert('1')" id="alert_popup">alert_popup</button>
|
10
|
+
<button onclick="ret = confirm('yes/no'); document.getElementById('confirm_popup').innerHTML=ret;" id="confirm_popup">confirm</button>
|
11
|
+
<input type="file" id="file_popup" value="file_popup"></input>
|
12
|
+
</body>
|
13
|
+
</html>
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: popup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 5
|
9
|
+
version: 0.0.5
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- yafei Li
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-09-08 00:00:00 +08:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rautomation
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: ffi
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :runtime
|
45
|
+
version_requirements: *id002
|
46
|
+
description: popup operation for all windows version.
|
47
|
+
email: lyfi2003@gmail.com
|
48
|
+
executables: []
|
49
|
+
|
50
|
+
extensions: []
|
51
|
+
|
52
|
+
extra_rdoc_files: []
|
53
|
+
|
54
|
+
files:
|
55
|
+
- lib/popup/alert_popup.rb
|
56
|
+
- lib/popup/confirm_popup.rb
|
57
|
+
- lib/popup/constants/file_popup.yml
|
58
|
+
- lib/popup/exceptions.rb
|
59
|
+
- lib/popup/ext/rautomation_ext.rb
|
60
|
+
- lib/popup/file_ext.rb
|
61
|
+
- lib/popup/file_popup.rb
|
62
|
+
- lib/popup/popup.rb
|
63
|
+
- lib/popup/popup_window.rb
|
64
|
+
- lib/popup/save_popup.rb
|
65
|
+
- lib/popup/version.rb
|
66
|
+
- lib/popup/window_factory.rb
|
67
|
+
- lib/popup.rb
|
68
|
+
- spec/alert_popup_spec.rb
|
69
|
+
- spec/confirm_popup_spec.rb
|
70
|
+
- spec/file_popup_spec.rb
|
71
|
+
- spec/popup_spec.rb
|
72
|
+
- spec/popup_window_spec.rb
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
- spec/webserver.rb
|
75
|
+
- support/file_popup/test.txt
|
76
|
+
- support/file_popup/test1.txt
|
77
|
+
- support/html_popup/file.html
|
78
|
+
- Rakefile
|
79
|
+
- README.md
|
80
|
+
has_rdoc: true
|
81
|
+
homepage: http://200.200.0.35:81/svn/popup
|
82
|
+
licenses: []
|
83
|
+
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
version: "0"
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
segments:
|
103
|
+
- 1
|
104
|
+
- 3
|
105
|
+
- 5
|
106
|
+
version: 1.3.5
|
107
|
+
requirements: []
|
108
|
+
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 1.3.7
|
111
|
+
signing_key:
|
112
|
+
specification_version: 3
|
113
|
+
summary: popup operation for all windows version.
|
114
|
+
test_files: []
|
115
|
+
|