safariwatir 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/safariwatir.rb +21 -3
  2. data/safariwatir/scripter.rb +16 -8
  3. metadata +2 -2
data/safariwatir.rb CHANGED
@@ -59,14 +59,28 @@ module Watir
59
59
  end
60
60
 
61
61
  class SecurityWarningWindow
62
- def_init :scripter
62
+ def initialize(scripter, url)
63
+ @scripter = scripter
64
+ @url = url
65
+ end
63
66
 
64
67
  def continue
65
- @scripter.click_security_warning("Continue")
68
+ handle_click("Continue")
66
69
  end
67
70
 
68
71
  def cancel
69
- @scripter.click_security_warning("Cancel")
72
+ handle_click("Cancel")
73
+ end
74
+
75
+ private
76
+ def handle_click(button)
77
+ if @url
78
+ @scripter.navigate_to(@url) do
79
+ @scripter.click_security_warning(button)
80
+ end
81
+ else
82
+ @scripter.click_security_warning(button)
83
+ end
70
84
  end
71
85
  end
72
86
 
@@ -495,6 +509,10 @@ module Watir
495
509
  def security_warning
496
510
  SecurityWarningWindow.new(scripter)
497
511
  end
512
+
513
+ def security_warning_at(url)
514
+ SecurityWarningWindow.new(scripter, url)
515
+ end
498
516
 
499
517
  def goto(url)
500
518
  scripter.navigate_to(url)
@@ -7,7 +7,8 @@ module Watir
7
7
  FRAME_NOT_FOUND = "__safari_watir_frame_unfound__"
8
8
  NO_RESPONSE = "__safari_watir_no_response__"
9
9
  TABLE_CELL_NOT_FOUND = "__safari_watir_cell_unfound__"
10
-
10
+ EXTRA_ACTION_SUCCESS = "__safari_watir_extra_action__"
11
+
11
12
  JS_LIBRARY = %|
12
13
  function dispatchOnChange(element) {
13
14
  var event = document.createEvent('HTMLEvents');
@@ -110,8 +111,8 @@ if (element) {
110
111
  @app.quit
111
112
  end
112
113
 
113
- def navigate_to(url)
114
- page_load do
114
+ def navigate_to(url, &extra_action)
115
+ page_load(extra_action) do
115
116
  @document.URL.set(url)
116
117
  end
117
118
  end
@@ -435,10 +436,11 @@ tell window 1
435
436
  tell group 2
436
437
  if button named "#{label}" exists then
437
438
  click button named "#{label}"
439
+ return "#{EXTRA_ACTION_SUCCESS}"
438
440
  end if
439
441
  end tell
440
442
  end tell
441
- end tell|)
443
+ end tell|, true)
442
444
  end
443
445
 
444
446
  def for_table(element)
@@ -507,16 +509,19 @@ SCRIPT`
507
509
  end
508
510
 
509
511
  # Must have "Enable access for assistive devices" checked in System Preferences > Universal Access
510
- def execute_system_events(script)
511
- `osascript <<SCRIPT
512
+ def execute_system_events(script, capture_result = false)
513
+ result = `osascript <<SCRIPT
512
514
  tell application "System Events" to tell process "Safari"
513
515
  #{script}
514
516
  end tell
515
517
  SCRIPT`
516
- nil
518
+
519
+ if capture_result && result
520
+ return result.chomp
521
+ end
517
522
  end
518
523
 
519
- def page_load
524
+ def page_load(extra_action = nil)
520
525
  yield
521
526
  sleep 1
522
527
 
@@ -526,6 +531,9 @@ SCRIPT`
526
531
  sleep 0.4
527
532
  handle_client_redirect
528
533
  break
534
+ elsif extra_action
535
+ result = extra_action.call
536
+ break if result == EXTRA_ACTION_SUCCESS
529
537
  else
530
538
  sleep 1
531
539
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: safariwatir
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Hoover
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-10-28 00:00:00 -05:00
12
+ date: 2008-10-31 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency