Skip to content

Instantly share code, notes, and snippets.

@angelovstanton
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angelovstanton/ba444fb1a8ae266cdac6 to your computer and use it in GitHub Desktop.
Save angelovstanton/ba444fb1a8ae266cdac6 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