Created
February 14, 2021 09:56
-
-
Save ultimate-qa2/cc023a1d710a4c211381cbdf3982c94e to your computer and use it in GitHub Desktop.
DriverSetup for SpecFlow parallelization
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
[Binding] | |
public class DriverSetup | |
{ | |
private IObjectContainer _objectContainer; | |
public IWebDriver Driver; | |
public DriverSetup(IObjectContainer objectContainer) | |
{ | |
_objectContainer = objectContainer; | |
} | |
[BeforeScenario] | |
public void BeforeScenario() | |
{ | |
//TODO please supply your Sauce Labs user name in an environment variable | |
var sauceUserName = Environment.GetEnvironmentVariable("SAUCE_USERNAME", EnvironmentVariableTarget.User); | |
//TODO please supply your own Sauce Labs access Key in an environment variable | |
var sauceAccessKey = Environment.GetEnvironmentVariable("SAUCE_ACCESS_KEY", EnvironmentVariableTarget.User); | |
var sauceOptions = new Dictionary<string, object> | |
{ | |
["username"] = sauceUserName, | |
["accessKey"] = sauceAccessKey | |
}; | |
var chromeOptions = new ChromeOptions | |
{ | |
BrowserVersion = "latest", | |
PlatformName = "Windows 10" | |
}; | |
chromeOptions.AddAdditionalOption("sauce:options", sauceOptions); | |
Driver = new RemoteWebDriver(new Uri("https://ondemand.saucelabs.com/wd/hub"), | |
chromeOptions.ToCapabilities(), TimeSpan.FromSeconds(30)); | |
_objectContainer.RegisterInstanceAs(Driver); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment