Created
June 26, 2019 09:34
-
-
Save krishna-acondy/7495f720a5244bfcc764ef1fd4e8ae8c to your computer and use it in GitHub Desktop.
Automated UI Test Context
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
using System.IO; | |
using Gauge.CSharp.Lib.Attribute; | |
using Microsoft.Extensions.Configuration; | |
using OpenQA.Selenium; | |
namespace AutomatedUiTests | |
{ | |
public class TestContext | |
{ | |
public static IConfiguration Configuration { get; private set; } | |
public static IWebDriver WebDriver { get; private set; } | |
public static string ApplicationUrl => Configuration["ApplicationUrl"]; | |
[BeforeSuite] | |
public void Setup() | |
{ | |
Configuration = BuildConfiguration(); | |
WebDriver = CreateWebDriver(); | |
} | |
[AfterSuite] | |
public void TearDown() | |
{ | |
WebDriver.Quit(); | |
} | |
public static void GoToLandingPage() | |
{ | |
WebDriver.Navigate().GoToUrl(TestContext.ApplicationUrl); | |
} | |
public static IWebElement CurrentPage => WebDriver.FindElement(By.TagName("body")); | |
private static IConfigurationRoot BuildConfiguration() => | |
new ConfigurationBuilder() | |
.SetBasePath(Directory.GetCurrentDirectory()) | |
.AddJsonFile("appsettings.json") | |
.AddEnvironmentVariables() | |
.Build(); | |
private static IWebDriver CreateWebDriver() | |
{ | |
var chromeOptions = new ChromeOptions(); | |
var driverFolder = Path.Combine(Directory.GetCurrentDirectory(), "gauge_bin"); | |
return new ChromeDriver(driverFolder, chromeOptions); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment