Skip to content

Instantly share code, notes, and snippets.

@johnmmoss
Created March 24, 2021 14:52
Show Gist options
  • Save johnmmoss/17d3138462a611eba81f7f0d033f37a0 to your computer and use it in GitHub Desktop.
Save johnmmoss/17d3138462a611eba81f7f0d033f37a0 to your computer and use it in GitHub Desktop.
Setup Selenium tests using new Context Injection
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