Search code examples
coded-ui-tests

Browser Window in each method of test case? Using coded ui


I am new to coded UI, is it good practice to initialize Browser Window in each method of test case. For example i have two methods in my test case, I am trying to find control in each method, for that i write browser window in each method, can i write like that.


Solution

  • I don't see an issue with that approach.

    Are you trying to reduce code/setup statements?

    It really depends, you could have a test class with many test methods. however have a method attributed with ClassInitialize to launch the browser one time (and set the option to not destroy the window after each test) and keep reusing the same window. Then, possibly, have a method to close the window attributed with ClassCleanup.

    Then in a test, you should only potentially need to use the NavigateTo method at the start of your tests to be on the right page.

    Do you have test requirements dealing with sessions or saved data?

    You may need to actively close down a window after a test and programmatically empty caches. Then in this aspect, I would be using BrowserWindow.Launch typically and letting CodedUi automatically destroy the window if i forgot to call close on the window.