Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top