vendredi 20 mars 2015

HOw do I pass an instance of my browser Window class from a [ClassInitialize] method to another class that is not static

While working on my first big program for coded ui I found out that i had messed up the way i was moving across the application. This manifested its self in making my program really slow, i mean turtle slow lol. I figured this out after coding most of the program and being very disappointed by the performance.


The issue is i was not passing an instance of my browser between my classes and was strictly relying i should say on my U.I maps i created(I can go into details about this if anyone wants to know). When i started out the project I knew i had to do that but since i created a [ClassInitialize] to kick off browser for all of my test methods. The area that i kicked off my browser i wasn't able to pass it since it was static and this cause me to do alot of un-needed consequences in how i built the U.I maps and such.


Currently i'm thinking that I either need to change it to a test initialize and kick off the launching of my browser in one my test methods or the other way i was thinking of is to pass the instance of my browser object by calling my first class that i use. Here is the code below of what i currently have i'd like some opinions on the best way to go about it.



[ClassInitialize]
public static void GoToHomePage(TestContext context)
{
Playback.Initialize();

MyCodedUITests.StartTest();
//Playback.PlaybackSettings.MatchExactHierarchy = true;
// //dev
//VyguideWindow = BrowserWindow.Launch(new Uri(@"http://ThesiteIlaunch"));
//prod
VyguideWindow = BrowserWindow.Launch(new Uri(@"http://ThesiteILauch"));
proc = VyguideWindow.Process;
VyguideWindow.CloseOnPlaybackCleanup = false;
VyguideWindow.Maximized = true;
HomePage passWnd = new HomePage();
passWnd.PassBrows(VyguideWindow);

}

public BrowserWindow PassBrows(BrowserWindow window)
{
BrowserWindow myBrowser = window;

return myBrowser;
}


Please give me some feedback on best practice or if i should use test initialize. The initial thinking was that i was going to use the classinitialize and all my other test methods was going to run from it, that was the reason i first did it, but i dont know if this is still doable. Thanks for any feedback.


Aucun commentaire:

Enregistrer un commentaire