This section contains Selenium notes

This section is to give you some idea and tools that will help your Selenium code provide flexability so that your automation efforts in Selenium give you the maximum return on your investment. I will here give code with the idea's that link into the Gherkin Directory. Code is in blue. Comments in green.

[Given(@"I open the tool")]
//10-11-201X Lots of comments please.
//This is the function to open the tool
//We wait up to 20 seconds for the first page to load, waiting for the text 'Text to be found'
//The 20 seconds is set in context scenario so that it can be globally configured as 'waitPeriod'
//along with driver that is also set in context scenario
//The url for the tool is pulled out of the application.xml file using linq
This prevents hard coding, as they can add or change the url at any time without the need to compile. The automated tests can be run against a number of different URL's. Your production URL, test URL, Each developer could have an ip address for local testing. I have a separate document that explains how the xml file works and can be updates by users.(To follow)
//10-11-201X Console date and time added for problem investigation and supportCode is in blue
string appLocation = AppDomain.CurrentDomain.BaseDirectory;No hard coding. In Visual Studio we store the application.xml in the \Support sub directory and copy and replace when build.
XElement mmXML = XElement.Load(appLocation + @"\Support\application.xml"); This is linq getting the xml file details
var baseURL = mmXML.Element("BaseURL").Value; This is the URL of the application. Thus developers etc can edit the XML file to point to a test system.
Console.WriteLine(DateTime.Now.ToString()); This helps with problem investigation and support
IWebDriver driver = new InternetExplorerDriver(); This is hard coded in this example but we could use XML and make this flexible.
int waitPeriod = 20; Again this could go into the xml file. We will use ScenarioContext to pass this value around all functions. Aways wait and check items are in the DOM before you use them with Selenium.
ScenarioContext.Current["waitPeriod"] = waitPeriod; I need to look into context injection but we will set ScenarioContext throught the Features. Notes I use the same variable name for context name.(Just make it easier later)
WebDriverWait wait = new WebDriverWait(driver,TimeSpan.FromSeconds(WaitPeriod));
driver.Navigate().GoToUrl(@"" + baseURL + "");
wait.Until(ExpectedConditions.ElemenExists(By.Xpath("//label[Ccontains(text(),'Text to be found')]"))); Never assume always check
ScenarioContext.Current[@"driver@"] = driver; This will be used by all other Dictionary lines.
driver.Manage().Window.Maximize(); IE opens at the size it was last closed. This ensures easy viewing of the tests

Edge WebDriver notes

Microsoft document that you update the OS System Path to ensure it contains the Microsoft Edge Driver. In many large corporates, this is locked down and you do not want to make the deployment and use of your automation tests to be any more complicated and laborious than needed. My suggested is to store the driver within your tests.

Microsoft Edge WebDriver The Microsoft Edge WebDriver can be stored in with your tests. In this example I have put it in the Support folder.

Microsoft Edge WebDriver Properties For the properties of the driver select 'Copy to Output Directory' option of 'Copy if newer'. This will ensure your drivers goes with your code when you deploy the tests to the business. Now all we have to do is dynamically reference the driver when we need to use it.

//10-11-2016 this snipit is to give you the idea and get you up and runningCode is in blue
string appLocation = AppDomain.CurrentDomain.BaseDirectory;No hard coding. In Visual Studio we store the MicrosoftWebDriver.exe in the \Support sub directory
RemoteWebDriver driver = null;
driver = new EdgeDriver(appLocation + @"\Support"); This is linq getting the xml file details
driver.Url = ""; This is the URL of the application. Move it to an XML file.
if (driver != null)
{ driver.Quit(); }