0

I'm trying to make my tests run faster on a dedicated server. I've noticed, that normally the tests run sluggishly, but when I increase firefox priority (which by default is lower than normal), they run much faster.

I was looking for a setting in FirefoxDriver which would let me choose process priority, but I can't find one.

Can anyone point me to how to set web driver priorities in selenium?

Arsen Zahray
  • 24,367
  • 48
  • 131
  • 224
  • "***when I increase firefox priority***" do you mean changing the capabilities before initiating the any browser specific Driver??? – Anuragh27crony Jan 07 '13 at 06:04
  • no, i mean, in ProcessExplorer – Arsen Zahray Jan 07 '13 at 08:45
  • You can't do this in Selenium. You should instead be asking "_How does ProcessExplorer set the priority of a process?_", and then using that Windows API yourself. – Ross Patterson Jan 07 '13 at 12:11
  • If speed is your only concern you can use htmldriver instead, as that is supposed to be quite a bit faster. However, you'll lose the benefit of actually testing against a real Firefox browser. – grumpasaurus Jan 07 '13 at 15:24

1 Answers1

2

I disagree with why you are doing this, and I think simply changing the priority is not the way to solve your issue.

There is no API exposed to do this, so you could send a request off to the Selenium developers for this (http://code.google.com/selenium).

Due to this, you will have to change the priority process after Selenium has created a browser session.

You will need to find the process:

var fireFoxProcesses = Process.GetProcessesByName("firefox");

This will return an array of Process objects, however, if you are running one test after another, there should only be one firefox.exe process open. This is my assumption. Therefore, we get the actual process object:

// should only be one, unless you are opening a few tests in concurrently.
var actualFirefoxProcess = fireFoxProcesses.First();

Finally, change it's priority class:

actualFirefoxProcess.PriorityClass = ProcessPriorityClass.High;

I would guess this can get a little unreliable though.

Edit

As for differentiation of a 'user created' Firefox, and one run by Selenium, you can look at the parent process of the firefox processes. That is, what process launched the Firefox process?

No point in copying code, but this solution worked well for me: How can I get the PID of the parent process of my application ...this then gets tricky because a user can launch Firefox multiple ways, but if they are using a shortcut/start menu list item, the parent process will be explorer.

You've not mentioned what solution you are using for running the tests. Whether it's through Visual Studio's Test Runner, NUnit's own GUI, TeamCity, CruiseControl, Jenkins, TFS or some other CI solution, but you'll need to check what launched the Firefox process in order to determine whether it was a "user created" Firefox instance or one from Selenium tests.

Community
  • 1
  • 1
Arran
  • 24,648
  • 6
  • 68
  • 78
  • +1 I agree with disagreeing. Hooking into system processes is a bad idea. Better solution is to increase cpu/memory on that machine. – asgoth Jan 07 '13 at 10:27
  • actually, selenium starts a separate firefox process for each driver it uses. You can use 2 webdrivers at the same time, and you get 2 firefox processes. Your solution won't work in this case. Also, if run on a non-dedicated machine, this sometimes will change the priority of the user's firefox – Arsen Zahray Jan 07 '13 at 10:43
  • To determine between a user created process and one created by Selenium/your testing solution, you'll need to look at the 'parent' process: http://stackoverflow.com/questions/2531837/how-can-i-get-the-pid-of-the-parent-process-of-my-application (I don't believe there is any difference between the processes, other than what launched it)....again, perhaps the tests are running slowly due to hardware issues, or how your tests are structured. Do they run slowly on both your own machine and dedicated server? – Arran Jan 07 '13 at 11:18
  • Don't bother requesting such a feature of the Selenium developers. It would almost certainly be rejected as not germane and nearly impossible to implement in Remote WebDriver. – Ross Patterson Jan 07 '13 at 12:09