I would really appreciate a guide on how to connect to an already open browser using Selenium Webdriver via C#.
This issue eats around 30% of my script development t
You can run your tests in parallel, but that is a just a good idea when you're ready to run all of your tests. Below is an idea that you can use while you're developing and running newly compiled code.
Serialize your WebDriver {browser} instance object into a file (or in memory in a Windows service if you prefer), and then retrieve (de-serialize) that file into an object each time you launch WebDriver. It takes a little massaging though, of the WebDriver source code.
When I get some time, I will update my answer here. I hope Stack Overflow will allow me to paste as much code changes as it took. Plus, I should still give credit to Erik in his answer and comments. Although it was my idea to begin with (for making WebDriver faster).
.NET: Serializing object to a file from a 3rd party assembly (to make Selenium WebDriver faster)
==========
Simple logic:
if serialized object file doesn't exist ==> open browser instance as normal, and create the file
if serialized object file exists ==> deserialize file into object ==> set browser instance equal to deserialized object (casted correctly of course)
==========
The other requirement is that you put in a condition into your method decorated with the [TearDown] attribute so your browser doesn't close when the script (test) finishes. The first time through, it'll take time to open it up. But once that browser window is open, you're good to go.
[TearDown]
public void TeardownTest()
{
try
{
if (Config.CLOSE_BROWSER_AFTER_TEST_CASE)
{
driver.Quit();
}
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}