Skip to content

Instantly share code, notes, and snippets.

@angelovstanton
Created July 9, 2015 11:27
Show Gist options
  • Save angelovstanton/d1ea3d49c19bc3ca318b to your computer and use it in GitHub Desktop.
Save angelovstanton/d1ea3d49c19bc3ca318b to your computer and use it in GitHub Desktop.
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