Last active
December 23, 2015 04:29
-
-
Save djfr/6581061 to your computer and use it in GitHub Desktop.
Finds a browser that is ready to record a Web Performance Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class CodedUIExtensions | |
{ | |
#if !DO_NOT_FIND_WEBRECORD | |
private static bool _recording; | |
private static WinButton _recordButton; | |
private static WinButton _pauseButton; | |
#endif | |
public static BrowserWindow Launch(bool pauseRecording = false) | |
{ | |
return Launch("main.aspx", pauseRecording); | |
} | |
public static BrowserWindow Launch(string path, bool pauseRecording = false) | |
{ | |
#if !DO_NOT_FIND_WEBRECORD | |
// Try to find an open browser that is recording to do a web performance recording session | |
try | |
{ | |
var recordingBrowser = new BrowserWindow(); | |
recordingBrowser.SearchProperties[UITestControl.PropertyNames.Name] = "Blank Page"; | |
recordingBrowser.SearchProperties[UITestControl.PropertyNames.ClassName] = "IEFrame"; | |
recordingBrowser.Find(); | |
var recordWindow = new WinWindow(recordingBrowser); | |
recordWindow.SearchProperties[WinControl.PropertyNames.ControlName] = "toolStrip1"; | |
recordWindow.Find(); | |
var toolbar = new WinToolBar(recordWindow); | |
toolbar.SearchProperties[UITestControl.PropertyNames.Name] = "toolStrip1"; | |
toolbar.Find(); | |
_recordButton = new WinButton(toolbar); | |
_recordButton.SearchProperties[UITestControl.PropertyNames.Name] = "Record"; | |
_recordButton.Find(); | |
_pauseButton = new WinButton(toolbar); | |
_pauseButton.SearchProperties[UITestControl.PropertyNames.Name] = "Pause"; | |
_pauseButton.Find(); | |
if (pauseRecording) | |
{ | |
Mouse.Click(_pauseButton); | |
recordingBrowser.WaitForControlReady(); | |
} | |
recordingBrowser.NavigateToUrl(new Uri(path)); | |
_recording = true; | |
return recordingBrowser; | |
} | |
catch | |
{ | |
} | |
#endif | |
// A browser with a session ready to record couldn't be found, so open a new one | |
var browserWindow = BrowserWindow.Launch(path); | |
browserWindow.WaitForControlReady(); | |
return browserWindow; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment