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?
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.
Related
I've run across an issue when running my Automation Tests. If i am debugging a test, it fails. If i after that stop the debugging, the browser is left open and the Chromedriver.exe task is left running in the background. its easy to close the chrome browser but the Chromedriver.exe is a bit more annoying as I could do a lot of debugging and have many of them left open. is there a correct way to close these in debugging and can I stop the test mid way? In my tests I use the
public void Dispose()
{
_driver.Quit();
}
and this works as long as I am not in debug mode and I stop the test in the middle. Any ideas on what should be the proper method to close these? Maybe a misunderstanding on my side to how im using Visual Studio. Any help is much appreciated.
Edit:
Im not sure thats related. When in debug mode, if you are running an automation test and if it fails. If you then stop the test at the fail point it leaves the browser open and the chromedriver running. my question is,
Is there a correct way to exit debug mode that closes the left open processes and browser. or is this a manual process or something that you use to do this outside of Visual Studio?
I do the same thing all the time. The problem is that you are stopping the test mid-run. When you do this, you leave the browser open. There are a couple options.
When you are done debugging, just hit Run. It will attempt to continue and fail and should close everything down properly.
Keep using it the way you currently do. You can kill processes using Task Manager, as needed. I have considered writing a batch file that kills all the chromedriver.exe processes, etc. You could do that and have it target IE and FF also to make cleaning up a lot of them easier.
I have the following situation, I have two test cases running in parallel that each open a selenium webdriver instance for Internet Explorer 11 and both navigate to the same login page and both try to login with a different username/password combo. The problem is that both webdrivers seem to get stuck during username input for some reason.
I should mention that running either test by themselves works without issue, running both tests sequentially is also ok, so the problem only occurs when both tests are ran at the same time.
Also of note is if I try the same thing with two instances of Chrome Driver instead of Internet Explorer, again there is no problem. So this is something related to the IE webdriver and only when there are multiple instances of it at the same time.
Does anyone have any solution/idea that could solve this?
It has already been documented here as a known issue, and currently the only way to reliably do this using IEDriver is by using separate vms.
Our Selenium tests were developed in C# and were running just fine for months but recently we noticed that a number of tests started failing when executed with Firefox WebDriver.
After investigating the test results and executing tests locally we noticed that from time to time clicks on random elements are executed (we can tell because the visual state of the button or the link changes to what looks like a clicked element)
Browser console does not indicated any errors. WebDriver logs show that click was executed.
Will be grateful for any help.
Edit:
Version of Selenium WebDriver - 2.53.0
Versions of Firefox - (tried few) 33.0.1, 43.0.1, 45.0, 46.0.1
Firefox scale 100%
tried with native events on and off
tried with additional implicit waiting before click
You question is not very specific, so I'll try to offer possible ways you can choose to resolving it.
You didn't indicate which driver and browser versions you used. If you didn't observe failures for months ant suddenly they appeared, my first guess would be that FF version you use on test machine(s) got updated (or driver version in tests was changed), and new combination can work differently. I had situation like this when tests behavior changed, updating driver version helped.
Another option would be to try and see which webelements get misclicked more often than others and insert instructions that check if they are displayed before executing actual click.
Also, try to do step-by-step debugging (if you haven't already) and see if you observe wrong clicks then
One thing we've seen in our testing is that if we're clicking around on the VM while a Selenium test is running on our VM, it can actually prevent clicks from going off.
But another thing we've encountered is that the clicks are often not working where they should be, so you can counter this by using JavaScript clicks instead of Selenium.
For elements that fail regularly, switch the element.Click() to a method utilizing the code below:
IJavaScriptExecutor executor = driver as IJavaScriptExecutor;
executor.ExecuteScript("arguments[0].click();", ElementToClick)
So the problem was that click does not work even when clicking manually so we'll be investigating in that direction.
I'm running Selenium Webdriver through a Visual Studio Unit Test and using the InternetExplorerDriver. This fires up IEDriverServer.exe in a console window.
This works great and the test executes. Once test execution finishes i'd like that cmd.exe window killed so that it's not hanging around for me to have to do manual cleanup. I have thousands of tests so you can imagine the headache of managing this.
Is there an elegant way to handle this without having to do post test execution and killing cmd.exe processes with kill.exe, etc? I've tried InternetExplorerDriverService.HideCommandPromptWindow = true, but that just runs cmd.exe in hidden mode and leaves the process running until it's manually killed. I've also tried InternetExplorerDriverService.SuppressInitialDiagnosticInformation and all that does is suppress some of the information written to the cmd.exe window.
To complement the awser, some informations about the subject. There are 3 main methods that that you can use as you need:
.Close(): - This method is used to close the current open window. It closes the current open window on which driver has focus on.
.Quit(): - This method is used to destroy the instance of WebDriver. It closes all Browser Windows associated with that driver and safely ends the session. Quit() calls Dispose method to achieve this.
.Dispose(): - This method closes all Browser windows and safely ends the session
emphasized text
In your case, as you need to kill the process, the best choice is use .Quit().
Sometimes you're unable to end the process when your selenium instance broke up, and the current and all next tests starts to fail, or even when you cancel a current debugging test suit. In this cases, you really need to kill the process.
As #Prateek saw, one of they is using Runtime.getRuntime(). In C#, the better way to do it is:
foreach (var proc in Process.GetProcessesByName("IEDriverServer"))
{
proc.Kill();
}
You can use it in the constructor where you start your WebDriver (but before to start it!) or, if you're using some lib as NUnit, you can create a global OneTimeSetUp. A kind of method that runs only one time before all test.
Also, if you don't like to put code or create new methods to do this job, you can configure in yout main .csproj the pre-build and post-build to execute your cmd command. Whenever you will run your tests or build your project, it will kill the opened webdriver instance.
To configure it you will need:
Right button in your .csproj and click in "Properties";
Navigate to "Build Events";
Paste the command taskkill /f /fi "pid gt 0" /im IEDriverServer.exe in pre-build textarea, post-build or in both.
There are two ways:
As suggested in comments driver.quit() will do the job.
But sometimes our test fails and the Driver keeps running. To avoid having multiple instances of drivers you can use: Runtime.getRuntime().exec("taskkill /T /F /IM IEDriverServer.exe");.
The benefit of using this command is that even if your script doesn't run completely it would still kill the driver.
You can use it in a number of places. For example:
If you are using frameworks such as TestNG you can override onTestFailure().
You can add it in the beginning of your test so that if there are any instances already open they'll be killed.
Or you can add in other places such as catch block.
I think you should try this:
InternetExplorerDriverService service = InternetExplorerDriverService.CreateDefaultService();
service.Start();
IWebDriver driver = new ThreadLocal<IWebDriver>(() => { return new InternetExplorerDriver(service); }).Value;
int pid = service.ProcessId;
// Do any automation you want with your driver...
driver.Quit(); // it calls Dispose
service.Dispose();
// And if you want to ensure... :-)
try { Process.GetProcessById(pid).Kill(); }
catch { }
Please, notice that it is suitable for Chrome, Firefox and other drives!
i am automating using selenium webdriver and C#. Is there a way to capture all urls that my browser navigates to while my Selenium automation tests run using an external tool such as Fiddler core / wireshark. I mean while my tests continue to run, I would like some of these tools to capture my urls parallely so that incase my tests fail, i could investigate further by using the final few urls(from the point of failure) to debug the issue.
Is this really possible. Do I need to use a separate thread to one of these tools(Fiddler/wireshark/any other tool) to capture the url?
Can this really be done
There are a few options.
Start wireshark (or fiddler) before your Selenium test kicks off. You can do this with a batch file that gets executed in your test setup.
You can utilize a browser plugin for fiddler. IE has one, I'm not sure if there is a comparible plugin for all browsers though. Then you can get Selenium to activate this through the browser...assuming fiddler keeps in the browser window and not open a separate non-browser window that Selenium can't see.UPDATE: Fiddler plugins don't stay in the browser window so this option won't work.
Write some wrapper code that does a driver.Url and stores it into a list. This wrapper code would check to see if the driver.Url is different from the last stored entry in the object and if it is different then it would add it to the list.
All have pros and cons. 3 would give you the most control as your test itself would gather the URL's and maintain a list in code that you can do what you want with. 1 of course would give you the most robust details, depending on how you setup wireshark, and you can profile the entire machine and network experience. 2 is a middle ground where your test still drives it, but the results are separate...but being part of the browser you would have to avoid cleanup after your tests...if you have more tests than one execute at a time this could cause alot of problems...