Created
March 24, 2021 14:52
-
-
Save johnmmoss/17d3138462a611eba81f7f0d033f37a0 to your computer and use it in GitHub Desktop.
Setup Selenium tests using new Context Injection
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
using Microsoft.Extensions.Configuration; | |
[Binding] | |
public class Setup | |
{ | |
[BeforeFeature] | |
public static void BeforeFeature(FeatureContext featureContext) | |
{ | |
// Read settings from testSettings.Development file | |
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development" ; | |
var config = new ConfigurationBuilder() | |
.AddJsonFile($"testSettings.{environment}.json") | |
.Build(); | |
var url = config["testWebUrl"]; | |
var chromeOptions = new ChromeOptions(); | |
chromeOptions.AddArgument("headless"); | |
var webDriver = new ChromeDriver(chromeOptions); | |
featureContext.Add(typeof(IWebDriver).ToString(), webDriver); | |
featureContext.Add("baseUrl", url); | |
} | |
[AfterFeature] | |
public static void AfterFeature(FeatureContext featureContext) | |
{ | |
var webDriver = featureContext.Get<IWebDriver>(); | |
webDriver.Quit(); | |
webDriver.Dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment