safariwatir 0.3.3 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,50 @@
1
+ "There's something eerily tingly about seeing a browser run by itself."
2
+ http://twitter.com/swombat/status/1280692921
3
+
4
+ = SafariWatir
5
+
6
+ * http://github.com/redsquirrel/safariwatir
7
+ * http://safariwatir.rubyforge.org
8
+ * http://rubyforge.org/mailman/listinfo/safariwatir-general
9
+ * http://twitter.com/SafariWatir
10
+
11
+ == DESCRIPTION:
12
+
13
+ We are putting Watir on Safari.
14
+ The original Watir (Web Application Testing in Ruby) project supports only IE on Windows.
15
+ This project aims at adding Watir support for Safari on the Mac.
16
+
17
+ == Requirements
18
+
19
+ Mac OS X running Safari. Some features require you to turn on "Enable access for assistive devices" in System Preferences > Universal Access.
20
+
21
+
22
+ == SYNOPSIS:
23
+
24
+ require 'rubygems'
25
+ require 'safariwatir'
26
+
27
+ browser = Watir::Safari.new
28
+ browser.goto("http://google.com")
29
+ browser.text_field(:name, "q").set("obtiva")
30
+ browser.button(:name, "btnI").click
31
+ puts "FAILURE" unless browser.contains_text("software")
32
+
33
+ == INSTALL:
34
+
35
+ [sudo] gem install safariwatir
36
+
37
+ or
38
+
39
+ git clone git://github.com/redsquirrel/safariwatir.git
40
+ cd safariwatir
41
+ rake install
42
+
43
+ == RUNNING SAFARIWATIR AGAINST WATIR'S CORE TESTS
44
+
45
+ # First, install the SafariWatir gem (see above)
46
+ svn checkout https://svn.openqa.org/svn/watir/trunk
47
+ cd trunk/watir
48
+ cp unittests/options.yml.example unittests/options.yml
49
+ # Edit unittests/options.yml and set browser: safari
50
+ ruby unittests/core_tests.rb
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('safariwatir', '0.3.5') do | config |
6
+ config.summary = %q{Automated testing tool for web applications.}
7
+ config.description = %q{WATIR stands for "Web Application Testing in Ruby". See WATIR project for more information. This is a Safari-version of the original IE-only WATIR.}
8
+ config.url = 'http://safariwatir.rubyforge.org/'
9
+ config.author = 'Dave Hoover'
10
+ config.email = 'dave@obtiva.com'
11
+ config.ignore_pattern = ['tmp/*', 'script/*']
12
+ config.development_dependencies = ["rb-appscript"]
13
+ end
@@ -35,8 +35,8 @@ module Watir
35
35
 
36
36
  def speed=(how_fast)
37
37
  case how_fast
38
- when :fast : set_fast_speed
39
- when :slow : set_slow_speed
38
+ when :fast then set_fast_speed
39
+ when :slow then set_slow_speed
40
40
  else
41
41
  raise ArgumentError, "Invalid speed: #{how_fast}"
42
42
  end
@@ -119,6 +119,10 @@ module Watir
119
119
  self.class.name.split("::").last
120
120
  end
121
121
 
122
+ def attr name
123
+ @scripter.get_attribute(name, self)
124
+ end
125
+
122
126
  def operate(&block)
123
127
  scripter_suffix = OPERATIONS[how]
124
128
  if scripter_suffix.kind_of? Hash
@@ -132,14 +136,19 @@ module Watir
132
136
 
133
137
  OPERATIONS = {
134
138
  :id => "by_id",
139
+ :alt => "by_alt",
140
+ :action => "by_action",
135
141
  :index => "by_index",
136
142
  :class => "by_class",
137
143
  :name => "by_name",
138
- :text => { "Link" => "on_link", "Label" => "by_text" },
144
+ :text => { "Link" => "on_link",
145
+ "Label" => "by_text",
146
+ "Span" => "by_text" },
139
147
  :url => "on_link",
140
148
  :value => "by_input_value",
141
149
  :caption => "by_input_value",
142
150
  :src => "by_src",
151
+ :xpath => "by_xpath",
143
152
  }
144
153
  end
145
154
 
@@ -159,6 +168,10 @@ module Watir
159
168
  def speak
160
169
  @scripter.speak_value_of(self)
161
170
  end
171
+
172
+ def enabled?
173
+ !@scripter.element_disabled?(self)
174
+ end
162
175
 
163
176
  def tag; "INPUT"; end
164
177
 
@@ -214,6 +227,10 @@ module Watir
214
227
  class Div < ContentElement
215
228
  def tag; "DIV"; end
216
229
  end
230
+
231
+ class P < ContentElement
232
+ def tag; "P"; end
233
+ end
217
234
 
218
235
  class Label < ContentElement
219
236
  def tag; "LABEL"; end
@@ -226,6 +243,12 @@ module Watir
226
243
  end
227
244
  end
228
245
 
246
+ def click_jquery
247
+ @scripter.highlight(self) do
248
+ click_link_jquery
249
+ end
250
+ end
251
+
229
252
  def tag; "A"; end
230
253
  end
231
254
 
@@ -399,6 +422,13 @@ module Watir
399
422
  class Password < TextField
400
423
  end
401
424
 
425
+ class Ul < ContentElement
426
+ def tag; "UL"; end
427
+ end
428
+
429
+ class Li < ContentElement
430
+ def tag; "LI"; end
431
+ end
402
432
 
403
433
  # Elements
404
434
 
@@ -417,6 +447,10 @@ module Watir
417
447
  def div(how, what)
418
448
  Div.new(scripter, how, what)
419
449
  end
450
+
451
+ def p(how, what)
452
+ P.new(scripter, how, what)
453
+ end
420
454
 
421
455
  def form(how, what)
422
456
  Form.new(scripter, how, what)
@@ -433,6 +467,10 @@ module Watir
433
467
  def label(how, what)
434
468
  Label.new(scripter, how, what)
435
469
  end
470
+
471
+ def li(how, what)
472
+ Li.new(scripter, how, what)
473
+ end
436
474
 
437
475
  def link(how, what)
438
476
  Link.new(scripter, how, what)
@@ -465,12 +503,16 @@ module Watir
465
503
  def text_field(how, what)
466
504
  TextField.new(scripter, how, what)
467
505
  end
506
+
507
+ def ul(how, what)
508
+ Ul.new(scripter, how, what)
509
+ end
468
510
 
469
511
  def contains_text(what)
470
512
  case what
471
- when Regexp:
513
+ when Regexp
472
514
  text =~ what
473
- when String:
515
+ when String
474
516
  text.index(what)
475
517
  else
476
518
  raise MissingWayOfFindingObjectException
@@ -489,11 +531,21 @@ module Watir
489
531
  end
490
532
 
491
533
  def initialize
492
- @scripter = AppleScripter.new
534
+ @scripter = AppleScripter.new(JavaScripter.new)
493
535
  @scripter.ensure_window_ready
494
536
  set_slow_speed
495
537
  end
496
538
 
539
+ # URL of page
540
+ def url
541
+ scripter.url
542
+ end
543
+
544
+ # Hide's Safari
545
+ def hide
546
+ scripter.hide
547
+ end
548
+
497
549
  def close
498
550
  scripter.close
499
551
  end
@@ -501,7 +553,7 @@ module Watir
501
553
  def quit
502
554
  scripter.quit
503
555
  end
504
-
556
+
505
557
  def alert
506
558
  AlertWindow.new(scripter)
507
559
  end
@@ -517,5 +569,21 @@ module Watir
517
569
  def goto(url)
518
570
  scripter.navigate_to(url)
519
571
  end
572
+
573
+ # Reloads the page
574
+ def reload
575
+ scripter.reload
576
+ end
577
+ alias :refresh :reload
520
578
  end # class Safari
579
+
580
+
581
+ class WebKit < Safari
582
+ def initialize
583
+ @scripter = AppleScripter.new(JavaScripter.new, :appname => "WebKit")
584
+ @scripter.ensure_window_ready
585
+ set_slow_speed
586
+ end
587
+ end # class WebKit
588
+
521
589
  end
File without changes
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/core_ext'
2
2
  require File.dirname(__FILE__) + '/../watir/exceptions'
3
3
  require 'appscript'
4
4
 
5
- module Watir
5
+ module Watir # :nodoc:
6
6
  ELEMENT_NOT_FOUND = "__safari_watir_element_unfound__"
7
7
  FRAME_NOT_FOUND = "__safari_watir_frame_unfound__"
8
8
  NO_RESPONSE = "__safari_watir_no_response__"
@@ -16,7 +16,7 @@ function dispatchOnChange(element) {
16
16
  element.dispatchEvent(event);
17
17
  }|
18
18
 
19
- class JavaScripter
19
+ class JavaScripter # :nodoc:
20
20
  def operate(locator, operation)
21
21
  %|#{locator}
22
22
  if (element) {
@@ -45,13 +45,13 @@ if (element) {
45
45
 
46
46
  finder =
47
47
  case cell.row.how
48
- when :id:
48
+ when :id
49
49
  %|getElementById('#{cell.row.what}')|
50
- when :index:
50
+ when :index
51
51
  case cell.row.table.how
52
52
  when :id
53
53
  %|getElementById('#{cell.row.table.what}').rows[#{cell.row.what-1}]|
54
- when :index:
54
+ when :index
55
55
  %|getElementsByTagName('TABLE')[#{cell.row.table.what-1}].rows[#{cell.row.what-1}]|
56
56
  else
57
57
  raise MissingWayOfFindingObjectException, "Table element does not support #{cell.row.table.how}"
@@ -64,7 +64,7 @@ if (element) {
64
64
  end
65
65
  end
66
66
 
67
- class FrameJavaScripter < JavaScripter
67
+ class FrameJavaScripter < JavaScripter # :nodoc:
68
68
  def initialize(frame)
69
69
  @page_container = "parent.#{frame.name}"
70
70
  end
@@ -77,7 +77,7 @@ if (element) {
77
77
  end
78
78
  end
79
79
 
80
- class TableJavaScripter < JavaScripter
80
+ class TableJavaScripter < JavaScripter # :nodoc:
81
81
  def_init :cell
82
82
 
83
83
  def wrap(script)
@@ -86,7 +86,7 @@ if (element) {
86
86
  end
87
87
  end
88
88
 
89
- class AppleScripter
89
+ class AppleScripter # :nodoc:
90
90
  include Watir::Exception
91
91
 
92
92
  attr_reader :js
@@ -95,9 +95,10 @@ if (element) {
95
95
 
96
96
  TIMEOUT = 10
97
97
 
98
- def initialize(scripter = JavaScripter.new)
98
+ def initialize(scripter = JavaScripter.new, opts={})
99
99
  @js = scripter
100
- @app = Appscript.app("Safari")
100
+ @appname = opts[:appname] || "Safari"
101
+ @app = Appscript.app(@appname)
101
102
  @document = @app.documents[1]
102
103
  end
103
104
 
@@ -106,7 +107,23 @@ if (element) {
106
107
  @app.make(:new => :document) if @app.documents.get.size == 0
107
108
  @document = @app.documents[1]
108
109
  end
109
-
110
+
111
+ def url
112
+ @document.URL.get
113
+ end
114
+
115
+ def hide
116
+ # because applescript is stupid and annoying you have
117
+ # to get all the processes from System Events, grab
118
+ # the right one for this instance and then set visible
119
+ # of it to false.
120
+ se = Appscript.app("System Events")
121
+ safari = se.processes.get.select do |app|
122
+ app.name.get == @appname
123
+ end.first
124
+ safari.visible.set(false)
125
+ end
126
+
110
127
  def close
111
128
  @app.quit
112
129
  end
@@ -116,6 +133,10 @@ if (element) {
116
133
  @document.URL.set(url)
117
134
  end
118
135
  end
136
+
137
+ def reload
138
+ execute(%|window.location.reload()|)
139
+ end
119
140
 
120
141
  def get_text_for(element = @element)
121
142
  execute(element.operate { %|return element.innerText| }, element)
@@ -136,6 +157,11 @@ if (element == undefined) {
136
157
  def get_value_for(element = @element)
137
158
  execute(element.operate { %|return element.value;| }, element)
138
159
  end
160
+
161
+ def get_attribute(name, element = @element)
162
+ execute(element.operate { %|return element.getAttribute('#{name}')| }, element)
163
+ end
164
+
139
165
 
140
166
  def document_text
141
167
  execute(%|return document.getElementsByTagName('BODY').item(0).innerText;|)
@@ -181,7 +207,7 @@ element.style.backgroundColor = 'yellow';|
181
207
  def select_option(element = @element)
182
208
  execute(element.operate do
183
209
  %|var selected = -1;
184
- var previous_selection = 0;
210
+ var previous_selection = -2;
185
211
  for (var i = 0; i < element.options.length; i++) {
186
212
  if (element.options[i].selected) {
187
213
  previous_selection = i;
@@ -307,13 +333,23 @@ if (element.onclick) {
307
333
  end
308
334
  end
309
335
 
336
+ def click_link_jquery(element = @element)
337
+ click = %/
338
+ $(element).trigger('click');
339
+ /
340
+ page_load do
341
+ execute(js.operate(find_link(element), click))
342
+ end
343
+ end
344
+
310
345
  def operate_on_link(element)
311
346
  js.operate(find_link(element), yield)
312
347
  end
313
348
 
349
+ # This needs to take XPath into account now?
314
350
  def find_link(element)
315
351
  case element.how
316
- when :index:
352
+ when :index
317
353
  %|var element = document.getElementsByTagName('A')[#{element.what-1}];|
318
354
  else
319
355
  %|var element = undefined;
@@ -330,9 +366,9 @@ for (var i = 0; i < document.links.length; i++) {
330
366
  def handle_match(element, how = nil)
331
367
  how = {:text => "text", :url => "href"}[element.how] unless how
332
368
  case element.what
333
- when Regexp:
369
+ when Regexp
334
370
  %|#{how}.match(/#{element.what.source}/#{element.what.casefold? ? "i":nil})|
335
- when String:
371
+ when String
336
372
  %|#{how} == '#{element.what}'|
337
373
  else
338
374
  raise RuntimeError, "Unable to locate #{element.name} with #{element.how}"
@@ -344,6 +380,10 @@ for (var i = 0; i < document.links.length; i++) {
344
380
  def checkbox_is_checked?(element = @element)
345
381
  execute(element.operate { %|return element.checked;| }, element)
346
382
  end
383
+
384
+ def element_disabled?(element = @element)
385
+ execute(element.operate { %|return element.disabled;| }, element)
386
+ end
347
387
 
348
388
  def operate_by_input_value(element)
349
389
  js.operate(%|
@@ -399,10 +439,25 @@ var element = elements[0];|, yield)
399
439
  operate_by(element, 'src', &block)
400
440
  end
401
441
 
442
+ def operate_by_alt(element, &block)
443
+ operate_by(element, 'alt', &block)
444
+ end
445
+
446
+ def operate_by_action(element, &block)
447
+ operate_by(element, 'action', &block)
448
+ end
449
+
402
450
  def operate_by_text(element, &block)
403
451
  operate_by(element, 'innerText', &block)
404
452
  end
405
453
 
454
+ def operate_by_xpath(element)
455
+ js.operate(%|
456
+ var result = document.evaluate('#{element.what}', document.documentElement, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
457
+ var element = result ? result.singleNodeValue : null;
458
+ |, yield)
459
+ end
460
+
406
461
  def operate_by(element, attribute)
407
462
  js.operate(%|var elements = document.getElementsByTagName('#{element.tag}');
408
463
  var element = undefined;
@@ -490,13 +545,13 @@ SCRIPT`
490
545
  def execute(script, element = nil)
491
546
  response = eval_js(script)
492
547
  case response
493
- when NO_RESPONSE:
548
+ when NO_RESPONSE
494
549
  nil
495
- when ELEMENT_NOT_FOUND:
550
+ when ELEMENT_NOT_FOUND
496
551
  raise UnknownObjectException, "Unable to locate #{element.name} element with #{element.how} of #{element.what}"
497
- when TABLE_CELL_NOT_FOUND:
552
+ when TABLE_CELL_NOT_FOUND
498
553
  raise UnknownCellException, "Unable to locate a table cell with #{element.how} of #{element.what}"
499
- when FRAME_NOT_FOUND:
554
+ when FRAME_NOT_FOUND
500
555
  raise UnknownFrameException, "Unable to locate a frame with name #{element.name}"
501
556
  else
502
557
  response
@@ -561,4 +616,4 @@ return "#{no_redirect_flag}"|)
561
616
  @app.do_JavaScript(js.wrap(script), :in => @document)
562
617
  end
563
618
  end # class AppleScripter
564
- end
619
+ end
File without changes
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{safariwatir}
5
+ s.version = "0.3.7"
6
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
7
+ s.authors = ["Dave Hoover", "Tom Copeland"]
8
+ s.date = %q{2009-10-20}
9
+ s.description = %q{WATIR stands for "Web Application Testing in Ruby". See WATIR project for more information. This is a Safari-version of the original IE-only WATIR.}
10
+ s.email = %q{dave@obtiva.com}
11
+ s.extra_rdoc_files = ["lib/safariwatir/core_ext.rb", "lib/safariwatir/scripter.rb", "lib/safariwatir.rb", "lib/watir/exceptions.rb", "README.rdoc"]
12
+ s.files = ["lib/safariwatir/core_ext.rb", "lib/safariwatir/scripter.rb", "lib/safariwatir.rb", "lib/watir/exceptions.rb", "Rakefile", "README.rdoc", "safariwatir.gemspec", "safariwatir_example.rb"]
13
+ s.has_rdoc = true
14
+ s.homepage = %q{http://safariwatir.rubyforge.org/}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Safariwatir", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{safariwatir}
18
+ s.rubygems_version = %q{1.3.1}
19
+ s.summary = %q{Automated testing tool for web applications.}
20
+ if s.respond_to? :specification_version then
21
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
22
+ s.specification_version = 2
23
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
24
+ s.add_development_dependency(%q<rb-appscript>, [">= 0"])
25
+ else
26
+ s.add_dependency(%q<rb-appscript>, [">= 0"])
27
+ end
28
+ else
29
+ s.add_dependency(%q<rb-appscript>, [">= 0"])
30
+ end
31
+ end
File without changes
metadata CHANGED
@@ -1,19 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: safariwatir
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Hoover
8
+ - Tom Copeland
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2008-10-31 00:00:00 -05:00
13
+ date: 2009-10-20 00:00:00 -04:00
13
14
  default_executable:
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: rb-appscript
18
+ type: :development
17
19
  version_requirement:
18
20
  version_requirements: !ruby/object:Gem::Requirement
19
21
  requirements:
@@ -27,21 +29,35 @@ executables: []
27
29
 
28
30
  extensions: []
29
31
 
30
- extra_rdoc_files: []
31
-
32
+ extra_rdoc_files:
33
+ - lib/safariwatir/core_ext.rb
34
+ - lib/safariwatir/scripter.rb
35
+ - lib/safariwatir.rb
36
+ - lib/watir/exceptions.rb
37
+ - README.rdoc
32
38
  files:
33
- - safariwatir.rb
34
- - safariwatir_script.rb
35
- - safariwatir/core_ext.rb
36
- - safariwatir/scripter.rb
37
- - watir/exceptions.rb
39
+ - lib/safariwatir/core_ext.rb
40
+ - lib/safariwatir/scripter.rb
41
+ - lib/safariwatir.rb
42
+ - lib/watir/exceptions.rb
43
+ - Rakefile
44
+ - README.rdoc
45
+ - safariwatir.gemspec
46
+ - safariwatir_example.rb
38
47
  has_rdoc: true
39
48
  homepage: http://safariwatir.rubyforge.org/
40
- post_install_message:
41
- rdoc_options: []
49
+ licenses: []
42
50
 
51
+ post_install_message:
52
+ rdoc_options:
53
+ - --line-numbers
54
+ - --inline-source
55
+ - --title
56
+ - Safariwatir
57
+ - --main
58
+ - README.rdoc
43
59
  require_paths:
44
- - .
60
+ - lib
45
61
  required_ruby_version: !ruby/object:Gem::Requirement
46
62
  requirements:
47
63
  - - ">="
@@ -52,13 +68,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
68
  requirements:
53
69
  - - ">="
54
70
  - !ruby/object:Gem::Version
55
- version: "0"
71
+ version: "1.2"
56
72
  version:
57
- requirements:
58
- - Mac OS X running Safari
59
- - Some features require you to turn on "Enable access for assistive devices" in System Preferences > Universal Access
73
+ requirements: []
74
+
60
75
  rubyforge_project: safariwatir
61
- rubygems_version: 1.1.1
76
+ rubygems_version: 1.3.4
62
77
  signing_key:
63
78
  specification_version: 2
64
79
  summary: Automated testing tool for web applications.