Created
July 9, 2015 19:47
-
-
Save angelovstanton/5a26e96bdee83dad0bde to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
{ | |
public BrowserLaunchTestBehaviorObserver(ITestExecutionSubject testExecutionSubject) | |
: base(testExecutionSubject) | |
{ | |
} | |
public override void PreTestInit(TestContext context, MemberInfo memberInfo) | |
{ | |
var browserType = this.GetExecutionBrowser(memberInfo); | |
Driver.StartBrowser(browserType); | |
} | |
public override void PostTestCleanup(TestContext context, MemberInfo memberInfo) | |
{ | |
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