watir-webdriver 0.0.1.dev6 → 0.0.1.dev7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/Rakefile +1 -2
  2. data/VERSION +1 -1
  3. data/lib/watir-webdriver.rb +1 -4
  4. data/lib/watir-webdriver/base_element.rb +14 -7
  5. data/lib/watir-webdriver/browser.rb +3 -1
  6. data/lib/watir-webdriver/elements/button.rb +1 -0
  7. data/lib/watir-webdriver/elements/form.rb +1 -1
  8. data/lib/watir-webdriver/elements/frame.rb +77 -0
  9. data/lib/watir-webdriver/elements/generated.rb +536 -536
  10. data/lib/watir-webdriver/elements/option.rb +3 -0
  11. data/lib/watir-webdriver/elements/table_row.rb +1 -0
  12. data/lib/watir-webdriver/elements/text_field.rb +5 -1
  13. data/lib/watir-webdriver/xpath_support.rb +0 -1
  14. data/spec/base_element_spec.rb +16 -0
  15. data/spec/html/keylogger.html +15 -0
  16. data/spec/watirspec/area_spec.rb +78 -0
  17. data/spec/watirspec/areas_spec.rb +31 -0
  18. data/spec/watirspec/browser_spec.rb +274 -0
  19. data/spec/watirspec/button_spec.rb +242 -0
  20. data/spec/watirspec/buttons_spec.rb +48 -0
  21. data/spec/watirspec/checkbox_spec.rb +272 -0
  22. data/spec/watirspec/checkboxes_spec.rb +32 -0
  23. data/spec/watirspec/dd_spec.rb +123 -0
  24. data/spec/watirspec/dds_spec.rb +31 -0
  25. data/spec/watirspec/div_spec.rb +211 -0
  26. data/spec/watirspec/divs_spec.rb +31 -0
  27. data/spec/watirspec/dl_spec.rb +123 -0
  28. data/spec/watirspec/dls_spec.rb +32 -0
  29. data/spec/watirspec/dt_spec.rb +123 -0
  30. data/spec/watirspec/dts_spec.rb +31 -0
  31. data/spec/watirspec/element_spec.rb +89 -0
  32. data/spec/watirspec/em_spec.rb +97 -0
  33. data/spec/watirspec/ems_spec.rb +32 -0
  34. data/spec/watirspec/filefield_spec.rb +119 -0
  35. data/spec/watirspec/filefields_spec.rb +32 -0
  36. data/spec/watirspec/font_spec.rb +26 -0
  37. data/spec/watirspec/form_spec.rb +63 -0
  38. data/spec/watirspec/forms_spec.rb +33 -0
  39. data/spec/watirspec/frame_spec.rb +135 -0
  40. data/spec/watirspec/frames_spec.rb +62 -0
  41. data/spec/watirspec/hidden_spec.rb +102 -0
  42. data/spec/watirspec/hiddens_spec.rb +32 -0
  43. data/spec/watirspec/hn_spec.rb +93 -0
  44. data/spec/watirspec/hns_spec.rb +38 -0
  45. data/spec/watirspec/image_spec.rb +207 -0
  46. data/spec/watirspec/images_spec.rb +31 -0
  47. data/spec/watirspec/label_spec.rb +75 -0
  48. data/spec/watirspec/labels_spec.rb +31 -0
  49. data/spec/watirspec/li_spec.rb +112 -0
  50. data/spec/watirspec/lib/guards.rb +59 -0
  51. data/spec/watirspec/lib/server.rb +136 -0
  52. data/spec/watirspec/lib/spec_helper.rb +79 -0
  53. data/spec/watirspec/lib/watirspec.rb +72 -0
  54. data/spec/watirspec/link_spec.rb +168 -0
  55. data/spec/watirspec/links_spec.rb +35 -0
  56. data/spec/watirspec/lis_spec.rb +31 -0
  57. data/spec/watirspec/map_spec.rb +76 -0
  58. data/spec/watirspec/maps_spec.rb +32 -0
  59. data/spec/watirspec/meta_spec.rb +22 -0
  60. data/spec/watirspec/metas_spec.rb +30 -0
  61. data/spec/watirspec/ol_spec.rb +78 -0
  62. data/spec/watirspec/ols_spec.rb +31 -0
  63. data/spec/watirspec/option_spec.rb +173 -0
  64. data/spec/watirspec/p_spec.rb +128 -0
  65. data/spec/watirspec/pre_spec.rb +112 -0
  66. data/spec/watirspec/pres_spec.rb +31 -0
  67. data/spec/watirspec/ps_spec.rb +31 -0
  68. data/spec/watirspec/radio_spec.rb +255 -0
  69. data/spec/watirspec/radios_spec.rb +32 -0
  70. data/spec/watirspec/select_list_spec.rb +318 -0
  71. data/spec/watirspec/select_lists_spec.rb +35 -0
  72. data/spec/watirspec/span_spec.rb +142 -0
  73. data/spec/watirspec/spans_spec.rb +31 -0
  74. data/spec/watirspec/spec_helper.rb +17 -0
  75. data/spec/watirspec/strong_spec.rb +89 -0
  76. data/spec/watirspec/strongs_spec.rb +32 -0
  77. data/spec/watirspec/table_bodies_spec.rb +45 -0
  78. data/spec/watirspec/table_body_spec.rb +98 -0
  79. data/spec/watirspec/table_cell_spec.rb +68 -0
  80. data/spec/watirspec/table_cells_spec.rb +47 -0
  81. data/spec/watirspec/table_footer_spec.rb +85 -0
  82. data/spec/watirspec/table_footers_spec.rb +47 -0
  83. data/spec/watirspec/table_header_spec.rb +85 -0
  84. data/spec/watirspec/table_headers_spec.rb +45 -0
  85. data/spec/watirspec/table_row_spec.rb +87 -0
  86. data/spec/watirspec/table_rows_spec.rb +50 -0
  87. data/spec/watirspec/table_spec.rb +160 -0
  88. data/spec/watirspec/tables_spec.rb +33 -0
  89. data/spec/watirspec/text_field_spec.rb +276 -0
  90. data/spec/watirspec/text_fields_spec.rb +35 -0
  91. data/spec/watirspec/ul_spec.rb +76 -0
  92. data/spec/watirspec/uls_spec.rb +33 -0
  93. data/support/html5/html5.idl +1 -1
  94. metadata +181 -21
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe "Labels" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/forms_with_input_elements.html")
8
+ end
9
+
10
+ describe "#length" do
11
+ it "returns the number of labels" do
12
+ browser.labels.length.should == 26 # changed this from 25 - Jari
13
+ end
14
+ end
15
+
16
+ describe "#[]" do
17
+ it "returns the pre at the given index" do
18
+ browser.labels[0].id.should == "first_label"
19
+ end
20
+ end
21
+
22
+ describe "#each" do
23
+ it "iterates through labels correctly" do
24
+ browser.labels.each_with_index do |l, index|
25
+ l.id.should == browser.label(:index, index).id
26
+ l.value.should == browser.label(:index, index).value
27
+ end
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,112 @@
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe "Li" do
5
+
6
+ before :each do
7
+ browser.goto(WatirSpec.files + "/non_control_elements.html")
8
+ end
9
+
10
+ # Exists method
11
+ describe "#exist?" do
12
+ it "returns true if the 'li' exists" do
13
+ browser.li(:id, "non_link_1").should exist
14
+ browser.li(:id, /non_link_1/).should exist
15
+ browser.li(:text, "Non-link 3").should exist
16
+ browser.li(:text, /Non-link 3/).should exist
17
+ browser.li(:class, "nonlink").should exist
18
+ browser.li(:class, /nonlink/).should exist
19
+ browser.li(:index, 0).should exist
20
+ browser.li(:xpath, "//li[@id='non_link_1']").should exist
21
+ end
22
+
23
+ it "returns false if the 'li' doesn't exist" do
24
+ browser.li(:id, "no_such_id").should_not exist
25
+ browser.li(:id, /no_such_id/).should_not exist
26
+ browser.li(:text, "no_such_text").should_not exist
27
+ browser.li(:text, /no_such_text/).should_not exist
28
+ browser.li(:class, "no_such_class").should_not exist
29
+ browser.li(:class, /no_such_class/).should_not exist
30
+ browser.li(:index, 1337).should_not exist
31
+ browser.li(:xpath, "//li[@id='no_such_id']").should_not exist
32
+ end
33
+
34
+ it "raises TypeError when 'what' argument is invalid" do
35
+ lambda { browser.li(:id, 3.14).exists? }.should raise_error(TypeError)
36
+ end
37
+
38
+ it "raises MissingWayOfFindingObjectException when 'how' argument is invalid" do
39
+ lambda { browser.li(:no_such_how, 'some_value').exists? }.should raise_error(MissingWayOfFindingObjectException)
40
+ end
41
+ end
42
+
43
+ # Attribute methods
44
+ describe "#class_name" do
45
+ it "returns the class attribute" do
46
+ browser.li(:id, 'non_link_1').class_name.should == 'nonlink'
47
+ end
48
+
49
+ it "returns an empty string if the element exists and the attribute doesn't" do
50
+ browser.li(:index, 0).class_name.should == ''
51
+ end
52
+
53
+ it "raises UnknownObjectException if the li doesn't exist" do
54
+ lambda { browser.li(:id, 'no_such_id').class_name }.should raise_error(UnknownObjectException)
55
+ end
56
+ end
57
+
58
+ describe "#id" do
59
+ it "returns the id attribute" do
60
+ browser.li(:class, 'nonlink').id.should == "non_link_1"
61
+ end
62
+
63
+ it "returns an empty string if the element exists and the attribute doesn't" do
64
+ browser.li(:index, 0).id.should == ''
65
+ end
66
+
67
+ it "raises UnknownObjectException if the li doesn't exist" do
68
+ lambda { browser.li(:id, "no_such_id").id }.should raise_error(UnknownObjectException)
69
+ lambda { browser.li(:index, 1337).id }.should raise_error(UnknownObjectException)
70
+ end
71
+ end
72
+
73
+ describe "#title" do
74
+ it "returns the title attribute" do
75
+ browser.li(:id, 'non_link_1').title.should == 'This is not a link!'
76
+ end
77
+
78
+ it "returns an empty string if the element exists and the attribute doesn't" do
79
+ browser.li(:index, 0).title.should == ''
80
+ end
81
+
82
+ it "raises UnknownObjectException if the li doesn't exist" do
83
+ lambda { browser.li(:id, 'no_such_id').title }.should raise_error( UnknownObjectException)
84
+ lambda { browser.li(:xpath, "//li[@id='no_such_id']").title }.should raise_error( UnknownObjectException)
85
+ end
86
+ end
87
+
88
+ describe "#text" do
89
+ it "returns the text of the li" do
90
+ browser.li(:id, 'non_link_1').text.should == 'Non-link 1'
91
+ end
92
+
93
+ it "returns an empty string if the element doesn't contain any text" do
94
+ browser.li(:index, 0).text.should == ''
95
+ end
96
+
97
+ it "raises UnknownObjectException if the li doesn't exist" do
98
+ lambda { browser.li(:id, 'no_such_id').text }.should raise_error( UnknownObjectException)
99
+ lambda { browser.li(:xpath , "//li[@id='no_such_id']").text }.should raise_error( UnknownObjectException)
100
+ end
101
+ end
102
+
103
+ describe "#respond_to?" do
104
+ it "returns true for all attribute methods" do
105
+ browser.li(:index, 0).should respond_to(:class_name)
106
+ browser.li(:index, 0).should respond_to(:id)
107
+ browser.li(:index, 0).should respond_to(:text)
108
+ browser.li(:index, 0).should respond_to(:title)
109
+ end
110
+ end
111
+
112
+ end
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+ module WatirSpec
3
+ module Guards
4
+
5
+ class << self
6
+ def guards
7
+ @guards ||= Hash.new { |hash, key| hash[key] = [] }
8
+ end
9
+
10
+ def record(guard_name, impls, data)
11
+ impls.each do |impl|
12
+ guards[impl] << [guard_name, data]
13
+ end
14
+ end
15
+
16
+ def report
17
+ gs = guards[WatirSpec.implementation]
18
+ print "\n\nWatirSpec guards for this implementation: "
19
+
20
+ if gs.empty?
21
+ puts "none."
22
+ else
23
+ puts
24
+ gs.each do |guard_name, data|
25
+ puts "\t#{guard_name.to_s.ljust(20)}: #{data.inspect}"
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ def deviates_on(*impls)
32
+ Guards.record :deviates, impls, :file => caller.first
33
+ return yield if WatirSpec.unguarded?
34
+ yield if impls.include? WatirSpec.implementation
35
+ end
36
+
37
+ def not_compliant_on(*impls)
38
+ Guards.record :not_compliant, impls, :file => caller.first
39
+ return yield if WatirSpec.unguarded?
40
+ yield unless impls.include? WatirSpec.implementation
41
+ end
42
+
43
+ def compliant_on(*impls)
44
+ Guards.record :compliant, impls, :file => caller.first
45
+ return yield if WatirSpec.unguarded?
46
+ yield if impls.include? WatirSpec.implementation
47
+ end
48
+
49
+ def bug(key, *impls)
50
+ Guards.record :bug, impls, :file => caller.first, :key => key
51
+ return yield if WatirSpec.unguarded?
52
+ yield unless impls.include? WatirSpec.implementation
53
+ end
54
+ end
55
+ end
56
+
57
+ class Object
58
+ include WatirSpec::Guards
59
+ end
@@ -0,0 +1,136 @@
1
+ # encoding: utf-8
2
+ module WatirSpec
3
+ class Server < Sinatra::Base
4
+ class << self
5
+ attr_accessor :autorun
6
+
7
+ def run_async
8
+ case WatirSpec.platform
9
+ when :java
10
+ Thread.new { run! }
11
+ sleep 0.1 until WatirSpec::Server.running?
12
+ when :windows
13
+ require "win32/process"
14
+ pid = Process.create(
15
+ :app_name => "#{WatirSpec.ruby} #{File.dirname(__FILE__)}/../spec_helper.rb",
16
+ :process_inherit => true,
17
+ :thread_inherit => true,
18
+ :inherit => true
19
+ ).process_id
20
+ else
21
+ pid = fork { run! }
22
+ sleep 0.5 until listening?
23
+ end
24
+
25
+ if pid
26
+ # is this really necessary?
27
+ at_exit {
28
+ begin
29
+ Process.kill 0, pid
30
+ alive = true
31
+ rescue Errno::ESRCH
32
+ alive = false
33
+ end
34
+
35
+ Process.kill(9, pid) if alive
36
+ }
37
+ end
38
+ end
39
+
40
+ def run!
41
+ handler = detect_rack_handler
42
+ handler.run(self, :Host => bind, :Port => port) { @running = true }
43
+ end
44
+
45
+ def listening?
46
+ $stderr.puts "trying #{bind}:#{port}..."
47
+
48
+ TCPSocket.new(bind, port).close
49
+ true
50
+ rescue
51
+ false
52
+ end
53
+
54
+ def autorun
55
+ @autorun ||= true
56
+ end
57
+
58
+ def should_run?
59
+ autorun && !running?
60
+ end
61
+
62
+ def running?
63
+ defined?(@running) && @running
64
+ end
65
+ end # class << Server
66
+
67
+ set :public, WatirSpec.html
68
+ set :static, true
69
+ set :run, false
70
+ set :environment, :production
71
+ set :bind, "localhost" if WatirSpec.platform == :windows
72
+ set :port, 2000
73
+ set :server, %w[mongrel webrick]
74
+
75
+ get '/' do
76
+ self.class.name
77
+ end
78
+
79
+ post '/post_to_me' do
80
+ "You posted the following content:\n#{ env['rack.input'].read }"
81
+ end
82
+
83
+ get '/plain_text' do
84
+ content_type 'text/plain'
85
+ 'This is text/plain'
86
+ end
87
+
88
+ get '/ajax' do
89
+ sleep 10
90
+ "A slooow ajax response"
91
+ end
92
+
93
+ get '/charset_mismatch' do
94
+ content_type 'text/html; charset=UTF-8'
95
+ <<-HTML
96
+ <html>
97
+ <head>
98
+ <meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />
99
+ </head>
100
+ <body>
101
+ <h1>ø</h1>
102
+ </body>
103
+ </html>
104
+ HTML
105
+ end
106
+
107
+ get '/octet_stream' do
108
+ content_type 'application/octet-stream'
109
+ 'This is application/octet-stream'
110
+ end
111
+
112
+ get '/set_cookie' do
113
+ content_type 'text/plain'
114
+ headers 'Set-Cookie' => "monster=/"
115
+
116
+ "C is for cookie, it's good enough for me"
117
+ end
118
+
119
+ get '/header_echo' do
120
+ content_type 'text/plain'
121
+ env.inspect
122
+ end
123
+
124
+ get '/authentication' do
125
+ auth = Rack::Auth::Basic::Request.new(env)
126
+
127
+ unless auth.provided? && auth.credentials == %w[foo bar]
128
+ headers 'WWW-Authenticate' => %(Basic realm="localhost")
129
+ halt 401, 'Authorization Required'
130
+ end
131
+
132
+ "ok"
133
+ end
134
+
135
+ end # Server
136
+ end # WatirSpec
@@ -0,0 +1,79 @@
1
+ # encoding: utf-8
2
+ module WatirSpec
3
+ module SpecHelper
4
+
5
+ module BrowserHelper
6
+ def browser; @browser; end
7
+ end
8
+
9
+ module PersistentBrowserHelper
10
+ def browser; $browser; end
11
+ end
12
+
13
+ module MessagesHelper
14
+ def messages
15
+ browser.div(:id, 'messages').divs.map { |d| d.text }
16
+ end
17
+ end
18
+
19
+ module_function
20
+
21
+ def execute
22
+ load_requires
23
+ configure
24
+ start_server
25
+ add_guard_hook
26
+ end
27
+
28
+ def configure
29
+ Thread.abort_on_exception = true
30
+
31
+ Spec::Runner.configure do |config|
32
+ config.include(MessagesHelper)
33
+
34
+ if WatirSpec.persistent_browser == false
35
+ config.include(BrowserHelper)
36
+
37
+ config.before(:all) { @browser = WatirSpec.new_browser }
38
+ config.after(:all) { @browser.close if @browser }
39
+ else
40
+ config.include(PersistentBrowserHelper)
41
+ $browser = WatirSpec.new_browser
42
+ at_exit { $browser.close }
43
+ end
44
+ end
45
+ end
46
+
47
+ def load_requires
48
+ # load spec_helper from containing folder, if it exists
49
+ hook = File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper.rb")
50
+ raise(Errno::ENOENT, hook) unless File.exist?(hook)
51
+
52
+ load hook
53
+ require "fileutils"
54
+ require "spec"
55
+
56
+ begin
57
+ require "ruby-debug"
58
+ Debugger.start
59
+ Debugger.settings[:autoeval] = true
60
+ Debugger.settings[:autolist] = 1
61
+ rescue LoadError
62
+ end
63
+ end
64
+
65
+ def start_server
66
+ if WatirSpec::Server.should_run?
67
+ WatirSpec::Server.run_async
68
+ else
69
+ $stderr.puts "not running WatirSpec::Server"
70
+ end
71
+ end
72
+
73
+ def add_guard_hook
74
+ return if WatirSpec.unguarded?
75
+ at_exit { WatirSpec::Guards.report }
76
+ end
77
+
78
+ end # SpecHelper
79
+ end # WatirSpec
@@ -0,0 +1,72 @@
1
+ # encoding: utf-8
2
+ module WatirSpec
3
+ class << self
4
+ attr_accessor :browser_args, :persistent_browser, :unguarded, :implementation
5
+
6
+ def html
7
+ File.expand_path("#{File.dirname(__FILE__)}/../html")
8
+ end
9
+
10
+ def files
11
+ "file://#{html}"
12
+ end
13
+
14
+ def host
15
+ "http://#{Server.bind}:#{Server.port}"
16
+ end
17
+
18
+ def unguarded?
19
+ @unguarded ||= false
20
+ end
21
+
22
+ def platform
23
+ @platform ||= case RUBY_PLATFORM
24
+ when /java/
25
+ :java
26
+ when /mswin|msys|mingw32/
27
+ :windows
28
+ when /darwin/
29
+ :macosx
30
+ when /linux/
31
+ :linux
32
+ else
33
+ RUBY_PLATFORM
34
+ end
35
+ end
36
+
37
+ def implementation
38
+ @implementation ||= case Browser.name
39
+ when "Watir::IE"
40
+ :watir
41
+ when "Watir::Firefox", "FireWatir::Firefox"
42
+ :firewatir
43
+ when "Celerity::Browser"
44
+ :celerity
45
+ else
46
+ :unknown
47
+ end
48
+ end
49
+
50
+ def new_browser
51
+ args = WatirSpec.browser_args
52
+ args ? Browser.new(*args) : Browser.new
53
+ end
54
+
55
+ def ruby
56
+ if @ruby.nil?
57
+ if defined?(Gem)
58
+ @ruby = Gem.ruby
59
+ else
60
+ require "rbconfig"
61
+ rb = File.join(RbConfig::CONFIG.values_at('BINDIR', 'RUBY_INSTALL_NAME').compact)
62
+ ext = RbConfig::CONFIG['EXEEXT']
63
+
64
+ @ruby = "#{rb}#{ext}"
65
+ end
66
+ end
67
+
68
+ @ruby
69
+ end
70
+
71
+ end # class << WatirSpec
72
+ end # WatirSpec