Created
July 9, 2015 11:27
-
-
Save angelovstanton/d1ea3d49c19bc3ca318b to your computer and use it in GitHub Desktop.
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 class BrowserLaunchTestBehaviorObserver : BaseTestBehaviorObserver | |
{ | |
protected override void PreTestInit(object sender, TestExecutionEventArgs e) | |
{ | |
var browserType = this.GetExecutionBrowser(e.MemberInfo); | |
Driver.StartBrowser(browserType); | |
} | |
protected override void PostTestCleanup(object sender, TestExecutionEventArgs e) | |
{ | |
Driver.StopBrowser(); | |
} | |
private BrowserTypes GetExecutionBrowser(MemberInfo memberInfo) | |
{ | |
BrowserTypes result = BrowserTypes.Firefox; | |
BrowserTypes classBrowserType = this.GetExecutionBrowserClassLevel(memberInfo.DeclaringType); | |
BrowserTypes methodBrowserType = this.GetExecutionBrowserMethodLevel(memberInfo); | |
if (methodBrowserType != BrowserTypes.NotSet) | |
{ | |
result = methodBrowserType; | |
} | |
else if (classBrowserType != BrowserTypes.NotSet) | |
{ | |
result = classBrowserType; | |
} | |
return result; | |
} | |
private BrowserTypes GetExecutionBrowserMethodLevel(MemberInfo memberInfo) | |
{ | |
var executionBrowserAttribute = memberInfo.GetCustomAttribute<ExecutionBrowserAttribute>(true); | |
if (executionBrowserAttribute != null) | |
{ | |
return executionBrowserAttribute.BrowserType; | |
} | |
return BrowserTypes.NotSet; | |
} | |
private BrowserTypes GetExecutionBrowserClassLevel(Type type) | |
{ | |
var executionBrowserAttribute = type.GetCustomAttribute<ExecutionBrowserAttribute>(true); | |
if (executionBrowserAttribute != null) | |
{ | |
return executionBrowserAttribute.BrowserType; | |
} | |
return BrowserTypes.NotSet; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment