Re: [selenium-users] Best practice - Create a new driver instance per test, or instantiate the drivers and then run tests

429 views
Skip to first unread message

sirus tula

unread,
Sep 24, 2012, 10:15:56 PM9/24/12
to seleniu...@googlegroups.com
Well like other experts here said, there is NOT one approach or method that would be applicable to all.

It depends upon the project or the way your project manager wanted to use automation in the project.

Now regarding test runner application, why create ONE while there is already a standard GUI application called NUnit?

In my current project, I have implemented Page Object Model where i have differentiated every page of the application as an object or class.

Then I use properties as variables so i can call them whenever/wherever i want.

Then i call the class that i want to execute as per the needs of the test.

Hope that helps.

Sirus

On Mon, Sep 24, 2012 at 11:45 AM, Ben Houghton <bdhou...@gmail.com> wrote:
Hello,

In an attempt to learn C#, I'm creating a test runner application that will execute selenium tests written in C# against drivers specified by the user.  At the moment I'm creating the required IWebDriver instances, adding them to a list and then looping through said list and executing each test against it, thus giving me cross browser testing against each test.  However this approach does lead to potential issues as since the same browser instance is being used when looping though the tests, there could be things left behind from the last test that might affect the current one in the loop (session data, cookies etc).  As such I was thinking of refactoring to create a new instance of the required browsers for each test (essentially swapping the nested loops around).  This though means that a new instance of the respective drivers' server will be created each time as well (along with new server log files etc), which seems like a bit of overkill when all I want to do is ensure a clean browsers session is started for each test.

What are the best practices around this area, and is there a way I can ensure that the browser is reset each time it is passed to a test, without Quitting and reinitialising a new instance of the server?

Hope the above question makes sense,

Cheers,

Ben

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/jerv8Hgx5RUJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Oscar Rieken

unread,
Sep 25, 2012, 10:27:54 PM9/25/12
to seleniu...@googlegroups.com
we did something like this to play around with c#. asp.net mvc3, specflow, and webdriver
https://github.com/hammernight/Garcom  

I rather avoid the headache and always start each test with a fresh browser the time you lose is minimal and its easier to manage if you end up needing to run all your tests across the grid.



On Tue, Sep 25, 2012 at 5:08 AM, Ben Houghton <bdhou...@gmail.com> wrote:
Hi Sirus,

Thanks for the heads up, I'll be implementing the Page Object Model within the program in the next sprint (at this stage it's simply workign out what tests and browsers it needs to use based on the arguements passed).  I think I'll be exploring the resetting of the browser by removing cookies etc, as that way I get the best of both worlds.

As for why I'm doing this and not using NUnit, I'm doing this as a way of learning C#, and due to the nature of the subject, there is a requirement for looping through each test not only for each browser, but with different data sets as well.  Now perhaps it's my naievity with the language and tools availavble, but I couldn't find a way of doing dynamic nested looping of tests without writing my own test runner to do so.

Cheers,

Ben
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/QrQOxMnIB9oJ.

Oscar Rieken

unread,
Sep 26, 2012, 5:01:18 PM9/26/12
to seleniu...@googlegroups.com
It should just append to the old log

sometimes you can end up with stale chromedriver sessions if you dont quit before you close

On Wed, Sep 26, 2012 at 5:40 AM, Ben Houghton <bdhou...@gmail.com> wrote:
Do you not find though that when you create a new browser instance (presumably by calling IWebDriver driver = new ChromeDriver(); for example) then it loads a new instance of the driver's respective server and creates new log files etc?

Cheers,

Ben
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/9pJshHBWj24J.

jeremyweber

unread,
Sep 27, 2012, 8:17:34 AM9/27/12
to seleniu...@googlegroups.com
We created something similar where the browser to launch, the host system under test and some other stuff is read from an xml file.  We then hooked in to some of the JUnit annotations like BeforeClass and AfterClass that instantiate the driver before the run of the test class,and subsequently close the driver.  So the browser is only reopened when the next test class is run and not in every test in the test class.  Seems to work well enough.
Reply all
Reply to author
Forward
0 new messages