Created
February 16, 2017 00:14
-
-
Save executeautomation/bac7500ffdd2402eb6a98e4f83e28047 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 Hooks : Base | |
{ | |
private BrowerType _browserType; | |
[SetUp] | |
public void InitializeTest() | |
{ | |
//Get the value from NUnit-console --params | |
//e.g. nunit3-console.exe --params:Browser=Firefox \SeleniumNUnitParam.dll | |
//If nothing specified, test will run in Chrome browser | |
var browserType = TestContext.Parameters.Get("Browser", "Chrome"); | |
//Parse the browser Type, since its Enum | |
_browserType = (BrowerType)Enum.Parse(typeof(BrowerType), browserType); | |
//Pass it to browser | |
ChooseDriverInstance(_browserType); | |
} | |
private void ChooseDriverInstance(BrowerType browserType) | |
{ | |
if (browserType == BrowerType.Chrome) | |
Driver = new ChromeDriver(); | |
else if (browserType == BrowerType.Firefox) | |
{ | |
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(); | |
service.FirefoxBinaryPath = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"; | |
service.HideCommandPromptWindow = true; | |
service.SuppressInitialDiagnosticInformation = true; | |
Driver = new FirefoxDriver(service); | |
} | |
else if(browserType == BrowerType.IE) | |
{ | |
Driver = new InternetExplorerDriver(); | |
} | |
} | |
[TearDown] | |
public void CloseBrowser() | |
{ | |
Driver.Quit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment