mirror of
				https://github.com/teampoltergeist/poltergeist.git
				synced 2022-11-09 12:05:00 -05:00 
			
		
		
		
	Windows support
* Adding termination signal for Windows platform. * Fixing tests to run in Windows. * Updated README.
This commit is contained in:
		
							parent
							
								
									fe1a5170f8
								
							
						
					
					
						commit
						7b44965e41
					
				
					 7 changed files with 63 additions and 33 deletions
				
			
		
							
								
								
									
										10
									
								
								README.md
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								README.md
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -54,6 +54,9 @@ bit](http://code.google.com/p/phantomjs/downloads/detail?name=phantomjs-1.8.1-li
 | 
			
		|||
binary.
 | 
			
		||||
* Extract the tarball and copy `bin/phantomjs` into your `PATH`
 | 
			
		||||
 | 
			
		||||
### Windows ###
 | 
			
		||||
* Download the [precompiled binary](http://phantomjs.org/download.html) for Windows
 | 
			
		||||
 | 
			
		||||
### Manual compilation ###
 | 
			
		||||
 | 
			
		||||
Do this as a last resort if the binaries don't work for you. It will
 | 
			
		||||
| 
						 | 
				
			
			@ -68,13 +71,13 @@ guide](http://phantomjs.org/build.html).)
 | 
			
		|||
 | 
			
		||||
## Compatibility ##
 | 
			
		||||
 | 
			
		||||
Poltergeist runs on MRI 1.9, JRuby 1.9 and Rubinius 1.9.
 | 
			
		||||
Poltergeist runs on MRI 1.9, JRuby 1.9 and Rubinius 1.9. Poltergeist
 | 
			
		||||
and PhantomJS are currently supported on Mac OS X, Linux, and Windows
 | 
			
		||||
platforms.
 | 
			
		||||
 | 
			
		||||
Ruby 1.8 is no longer supported. The last release to support Ruby 1.8
 | 
			
		||||
was 1.0.2, so you should use that if you still need Ruby 1.8 support.
 | 
			
		||||
 | 
			
		||||
Poltergeist does not currently support the Windows operating system.
 | 
			
		||||
 | 
			
		||||
## Running on a CI ##
 | 
			
		||||
 | 
			
		||||
There are no special steps to take. You don't need Xvfb or any running X
 | 
			
		||||
| 
						 | 
				
			
			@ -313,6 +316,7 @@ Include as much information as possible. For example:
 | 
			
		|||
 | 
			
		||||
#### Features ####
 | 
			
		||||
 | 
			
		||||
*   Support for Windows hosted Poltergeist (Aaron Tull).
 | 
			
		||||
*   Add support for custom phantomjs loggers via `:phantomjs_logger` option.
 | 
			
		||||
    (Gabe Bell)
 | 
			
		||||
*   Add `page.driver.click(x, y)` to click precise coordinates.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,6 +7,7 @@ require 'capybara'
 | 
			
		|||
 | 
			
		||||
module Capybara
 | 
			
		||||
  module Poltergeist
 | 
			
		||||
    require 'capybara/poltergeist/utility'
 | 
			
		||||
    require 'capybara/poltergeist/driver'
 | 
			
		||||
    require 'capybara/poltergeist/browser'
 | 
			
		||||
    require 'capybara/poltergeist/node'
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,5 @@
 | 
			
		|||
require "timeout"
 | 
			
		||||
require "capybara/poltergeist/utility"
 | 
			
		||||
 | 
			
		||||
module Capybara::Poltergeist
 | 
			
		||||
  class Client
 | 
			
		||||
| 
						 | 
				
			
			@ -44,13 +45,16 @@ module Capybara::Poltergeist
 | 
			
		|||
    def stop
 | 
			
		||||
      if pid
 | 
			
		||||
        begin
 | 
			
		||||
          Process.kill('TERM', pid)
 | 
			
		||||
 | 
			
		||||
          begin
 | 
			
		||||
            Timeout.timeout(KILL_TIMEOUT) { Process.wait(pid) }
 | 
			
		||||
          rescue Timeout::Error
 | 
			
		||||
          if Capybara::Poltergeist.windows?
 | 
			
		||||
            Process.kill('KILL', pid)
 | 
			
		||||
            Process.wait(pid)
 | 
			
		||||
          else
 | 
			
		||||
            Process.kill('TERM', pid)
 | 
			
		||||
            begin
 | 
			
		||||
              Timeout.timeout(KILL_TIMEOUT) { Process.wait(pid) }
 | 
			
		||||
            rescue Timeout::Error
 | 
			
		||||
              Process.kill('KILL', pid)
 | 
			
		||||
              Process.wait(pid)
 | 
			
		||||
            end
 | 
			
		||||
          end
 | 
			
		||||
        rescue Errno::ESRCH, Errno::ECHILD
 | 
			
		||||
          # Zed's dead, baby
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										9
									
								
								lib/capybara/poltergeist/utility.rb
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								lib/capybara/poltergeist/utility.rb
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,9 @@
 | 
			
		|||
module Capybara
 | 
			
		||||
  module Poltergeist
 | 
			
		||||
    class << self
 | 
			
		||||
      def windows?
 | 
			
		||||
        RbConfig::CONFIG["host_os"] =~ /mingw|mswin|cygwin/
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			@ -84,7 +84,7 @@ module Capybara::Poltergeist
 | 
			
		|||
          )
 | 
			
		||||
        end
 | 
			
		||||
        driver = Capybara::Session.new(:poltergeist_with_custom_window_size, TestApp).driver
 | 
			
		||||
        driver.visit("/")
 | 
			
		||||
        driver.visit(session_url '/')
 | 
			
		||||
        driver.evaluate_script('[window.innerWidth, window.innerHeight]').should eq([800, 600])
 | 
			
		||||
      ensure
 | 
			
		||||
        driver.quit if driver
 | 
			
		||||
| 
						 | 
				
			
			@ -191,11 +191,19 @@ module Capybara::Poltergeist
 | 
			
		|||
      driver = Capybara::Poltergeist::Driver.new(nil)
 | 
			
		||||
      pid    = driver.client_pid
 | 
			
		||||
 | 
			
		||||
      Process.kill(0, pid).should == 1
 | 
			
		||||
      def terminate_process(pid)
 | 
			
		||||
        if Capybara::Poltergeist.windows?
 | 
			
		||||
          Process.kill('KILL', pid).should == 1
 | 
			
		||||
        else
 | 
			
		||||
          Process.kill('EXIT', pid).should == 1
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      terminate_process(pid)
 | 
			
		||||
      driver.quit
 | 
			
		||||
 | 
			
		||||
      begin
 | 
			
		||||
        Process.kill(0, pid)
 | 
			
		||||
        terminate_process(pid)
 | 
			
		||||
      rescue Errno::ESRCH
 | 
			
		||||
      else
 | 
			
		||||
        raise "process is still alive"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										2
									
								
								spec/support/custom_phantomjs.bat
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								spec/support/custom_phantomjs.bat
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,2 @@
 | 
			
		|||
@echo off > "%0%\..\custom_phantomjs_called"
 | 
			
		||||
phantomjs.exe %1
 | 
			
		||||
| 
						 | 
				
			
			@ -33,32 +33,34 @@ module Capybara::Poltergeist
 | 
			
		|||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it "forcibly kills the child if it doesn't respond to SIGTERM" do
 | 
			
		||||
      begin
 | 
			
		||||
        class << Process
 | 
			
		||||
          alias old_wait wait
 | 
			
		||||
        end
 | 
			
		||||
    unless Capybara::Poltergeist.windows?
 | 
			
		||||
      it "forcibly kills the child if it doesn't respond to SIGTERM" do
 | 
			
		||||
        begin
 | 
			
		||||
          class << Process
 | 
			
		||||
            alias old_wait wait
 | 
			
		||||
          end
 | 
			
		||||
 | 
			
		||||
        client = Client.new(server)
 | 
			
		||||
        Process.stub(spawn: 5678)
 | 
			
		||||
        client.start
 | 
			
		||||
          client = Client.new(server)
 | 
			
		||||
          Process.stub(spawn: 5678)
 | 
			
		||||
          client.start
 | 
			
		||||
 | 
			
		||||
        Process.should_receive(:kill).with('TERM', 5678).ordered
 | 
			
		||||
          Process.should_receive(:kill).with('TERM', 5678).ordered
 | 
			
		||||
 | 
			
		||||
        count = 0
 | 
			
		||||
        Process.singleton_class.send(:define_method, :wait) do |*args|
 | 
			
		||||
          count += 1
 | 
			
		||||
          count == 1 ? sleep(3) : 0
 | 
			
		||||
        end
 | 
			
		||||
          count = 0
 | 
			
		||||
          Process.singleton_class.send(:define_method, :wait) do |*args|
 | 
			
		||||
            count += 1
 | 
			
		||||
            count == 1 ? sleep(3) : 0
 | 
			
		||||
          end
 | 
			
		||||
 | 
			
		||||
        Process.should_receive(:kill).with('KILL', 5678).ordered
 | 
			
		||||
          Process.should_receive(:kill).with('KILL', 5678).ordered
 | 
			
		||||
 | 
			
		||||
        client.stop
 | 
			
		||||
      ensure
 | 
			
		||||
        class << Process
 | 
			
		||||
          undef wait
 | 
			
		||||
          alias wait old_wait
 | 
			
		||||
          undef old_wait
 | 
			
		||||
          client.stop
 | 
			
		||||
        ensure
 | 
			
		||||
          class << Process
 | 
			
		||||
            undef wait
 | 
			
		||||
            alias wait old_wait
 | 
			
		||||
            undef old_wait
 | 
			
		||||
          end
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue