selenium-webdriver 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -54,6 +54,7 @@ module Selenium
54
54
  def quit
55
55
  @launcher.kill # FIXME: let chrome extension take care of this
56
56
  execute :request => 'quit'
57
+ @executor.close
57
58
  end
58
59
 
59
60
  def close
@@ -28,6 +28,11 @@ module Selenium
28
28
  JSON.parse read_response(@queue.pop)
29
29
  end
30
30
 
31
+ def close
32
+ @server.close
33
+ rescue IOError
34
+ end
35
+
31
36
  private
32
37
 
33
38
  def start_run_loop
@@ -42,6 +47,8 @@ module Selenium
42
47
 
43
48
  @accepted_any ||= true
44
49
  end
50
+ rescue IOError => e
51
+ raise e unless @server.closed?
45
52
  end
46
53
 
47
54
  def read_response(socket)
@@ -50,6 +50,7 @@ module Selenium
50
50
  end
51
51
 
52
52
  def create_profile
53
+ touch "#{tmp_profile_dir}/First Run"
53
54
  touch "#{tmp_profile_dir}/First Run Dev"
54
55
  end
55
56
 
@@ -6,6 +6,8 @@ module Selenium
6
6
  #
7
7
 
8
8
  class ChildProcess
9
+ attr_reader :pid
10
+
9
11
  def initialize(*args)
10
12
  @args = args
11
13
 
@@ -16,14 +18,15 @@ module Selenium
16
18
  end
17
19
  end
18
20
 
19
- def alive?
20
- return false unless @pid
21
+ def ugly_death?
22
+ code = exit_value()
23
+ # if exit_val is nil, the process is still alive
24
+ code && code != 0
25
+ end
21
26
 
22
- # TODO: check if this works on windows
23
- Process.kill 0, @pid
24
- true
25
- rescue Errno::ESRCH
26
- false
27
+ def exit_value
28
+ pid, status = Process.waitpid2(@pid, Process::WNOHANG)
29
+ status.exitstatus if pid
27
30
  end
28
31
 
29
32
  def start
@@ -34,7 +37,7 @@ module Selenium
34
37
 
35
38
  def wait
36
39
  raise "called wait with no pid" unless @pid
37
- Process.waitpid @pid
40
+ Process.waitpid2 @pid
38
41
  end
39
42
 
40
43
  def kill
@@ -78,6 +81,12 @@ module Selenium
78
81
  def wait
79
82
  @process.waitFor
80
83
  end
84
+
85
+ def exit_value
86
+ @process.exitValue
87
+ rescue java.lang.IllegalThreadStateException
88
+ nil
89
+ end
81
90
  end
82
91
 
83
92
  end # ChildProcess
@@ -59,6 +59,10 @@ module Selenium
59
59
  os == :windows
60
60
  end
61
61
 
62
+ def mac?
63
+ os == :macosx
64
+ end
65
+
62
66
  def wrap_in_quotes_if_necessary(str)
63
67
  win? ? %{"#{str}"} : str
64
68
  end
@@ -2,6 +2,7 @@ module Selenium
2
2
  module WebDriver
3
3
  module Firefox
4
4
  class Binary
5
+
5
6
  def initialize
6
7
  ENV['MOZ_NO_REMOTE'] = '1' # able to launch multiple instances
7
8
  check_binary_exists
@@ -9,10 +10,14 @@ module Selenium
9
10
 
10
11
  def create_base_profile(name)
11
12
  execute("-CreateProfile", name)
12
- Timeout.timeout(15, Error::TimeOutError) { wait }
13
13
 
14
- unless $?.success?
15
- raise Error::WebDriverError, "could not create base profile: (#{$?.exitstatus})"
14
+ status = nil
15
+ Timeout.timeout(15, Error::TimeOutError) do
16
+ _, status = wait
17
+ end
18
+
19
+ if status && !status.success?
20
+ raise Error::WebDriverError, "could not create base profile: (exit status: #{status.exitstatus})"
16
21
  end
17
22
  end
18
23
 
@@ -25,6 +30,7 @@ module Selenium
25
30
  # end
26
31
 
27
32
  execute(*args)
33
+ cope_with_mac_strangeness(args) if Platform.mac?
28
34
  end
29
35
 
30
36
  def execute(*extra_args)
@@ -32,6 +38,22 @@ module Selenium
32
38
  @process = ChildProcess.new(*args).start
33
39
  end
34
40
 
41
+ def cope_with_mac_strangeness(args)
42
+ sleep 0.3
43
+
44
+ if @process.ugly_death?
45
+ # process crashed, trying a restart. sleeping 5 seconds shorter than the java driver
46
+ sleep 5
47
+ execute(*args)
48
+ end
49
+
50
+ # ensure we're ok
51
+ sleep 0.3
52
+ if @process.ugly_death?
53
+ raise Error::WebDriverError, "Unable to start Firefox cleanly, args: #{args.inspect}, status: #{status.inspect}"
54
+ end
55
+ end
56
+
35
57
  def kill
36
58
  @process.kill if @process
37
59
  end
@@ -40,6 +62,10 @@ module Selenium
40
62
  @process.wait if @process
41
63
  end
42
64
 
65
+ def pid
66
+ @process.pid if @process
67
+ end
68
+
43
69
  private
44
70
 
45
71
  def path
@@ -15,7 +15,7 @@ module Selenium
15
15
  return new_socket
16
16
  rescue Errno::ECONNREFUSED, Errno::ENOTCONN => e
17
17
  $stderr.puts "#{self} caught #{e.message}" if $DEBUG
18
- sleep 0.250
18
+ sleep 0.25
19
19
  end
20
20
  end
21
21
  }
@@ -94,6 +94,7 @@ module Selenium
94
94
  connect
95
95
  return
96
96
  rescue Timeout::Error => e
97
+ puts "#{self} caught #{e.message}" if $DEBUG
97
98
  # ok
98
99
  end
99
100
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selenium-webdriver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jari Bakken
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-16 00:00:00 +01:00
12
+ date: 2009-11-17 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency