2

I have this in ruby mine on a windows computer:

require 'watir-webdriver'

Before do
  @browser = Watir::Browser.new :ie
end

I need to change @browser to run at a higher priority because of some time out issues that I get that are caused when other programs are running at the same time. I know how to increase the amount of time allowed for time out, but after some testing I found I would have to set time out higher than I find to be acceptable.

Box Box Box Box
  • 5,094
  • 10
  • 49
  • 67
Trev
  • 23
  • 2

2 Answers2

1

I have found that you can actually find the webdriven browser's PID from deep inside the @browser object (reading all protected and private components), and then renice it with a negative number to increase priority, which might require sudo to be allowed by a non-root user.

I've explored exporting this object to an ASCII form for storage, which actually works, though importing it back was the subject of another question. Try this (I do it just for fun every time my code fires up a new Watir::Browser):

require "yaml" 
File.open("browserObj.yaml", 'w').write YAML::dump($browser)

Then when you peek inside this file browserObj.yaml, it gives you all sorts of interesting info, like:

    server_url: !ruby/object:URI::HTTP 
      fragment: 
      host: 127.0.0.1
      opaque: 
      parser: 
      password: 
      path: /hub/
      port: 7055
      query: 
      registry: 
      scheme: http
      user: 
    timeout: 
  launcher: !ruby/object:Selenium::WebDriver::Firefox::Launcher 
    binary: !ruby/object:Selenium::WebDriver::Firefox::Binary 
      process: !ruby/object:ChildProcess::Unix::ForkExecProcess 
        args: 
        - ./firefox.sh
        - -no-remote
        - -foreground
        detach: false
        duplex: false
        environment: {}

        exit_code: 
        io: 
        pid: 6114
        started: true

Notice the PID in the 2nd last line, which your code can easily detect and do whatever with at this point.

That is even safer than simply parsing the hierarchical process tree with eg. pstree -panu $PPID to find child browser processes.

In my own stuff I actually don't bother (eg. when I need to kill the proper Firefox process and not others) because I go by DISPLAY. All my desktop/interactive user stuff happens on DISPLAY :0, while my Watir Webdriver stuff happens on DISPLAY :99 hosted by Xvfb or Xephyr, which I can more selectively kill/xkill with the help of tools like xprop and xwininfo.

EDIT For completeness, here's the Unix/Cygwin command I use to send a kill command to the watir-webdriver browser's pid if I need to:

awk '/pid:/ {print $2;}' browserObj.yaml |xargs -rt kill
Community
  • 1
  • 1
Marcos
  • 4,796
  • 5
  • 40
  • 64
  • 1
    Oh wait you use Windows. Nevermind the bit about `sudo`. `renice` does come with Cygwin if you use that, otherwise maybe someone can fill in more native methods to give processes higher priority from scripts/cli. I've used short .vbs scripts to do that in the past, maybe Sysinternals has something too. – Marcos Apr 28 '12 at 21:23
0

Browsing the docs and code I didn't see any ready way to find the process id of the IE that the driver uses. You might try using system tools to discover what process is listening on the webdriver port (default 5555) and nicing that process. On posix you could try lsof or netstat to find processes using a specific port, I have no idea how to help you on windows.

Of course if this is a resource competition issue, why don't you just give your watir tests a better controlled environment which doesn't have other stuff preventing it from running at the speeds you desire.

dbenhur
  • 20,008
  • 4
  • 48
  • 45