Class SeleniumDriver
Driver class for Selenium WebDriver.
Inheritance
Implements
Inherited Members
Namespace: TestingDriver
Assembly: TestingDriver.dll
Syntax
public class SeleniumDriver : ITestingDriver
Constructors
| Improve this Doc View SourceSeleniumDriver(String, Int32, String, String, String, Int32, String, String, String, Boolean, Boolean, IWebDriver, String, Int32)
Initializes a new instance of the SeleniumDriver class.
Declaration
public SeleniumDriver(string browser = "chrome", int timeOut = 5, string environment = "", string url = "", string screenshotSaveLocation = "./", int actualTimeout = 60, string loadingSpinner = "", string errorContainer = "", string remoteHost = "", bool headless = true, bool incogMode = true, IWebDriver webDriver = null, string browserSize = "max", int localTimeout = 30)
Parameters
Type | Name | Description |
---|---|---|
System.String | browser | The browser to use. |
System.Int32 | timeOut | The time out in seconds. |
System.String | environment | The environment of the test. |
System.String | url | Default url to naivgate to. |
System.String | screenshotSaveLocation | Location to save screenshots. |
System.Int32 | actualTimeout | Time out limit in minutes. |
System.String | loadingSpinner | The xpath for any loading spinners. |
System.String | errorContainer | The xpath for any error containers. |
System.String | remoteHost | The address of the remote host. |
System.Boolean | headless | Indicate whether to run the browser in headless mode. |
System.Boolean | incogMode | Indicate whether to run the browser in incognito mode. |
OpenQA.Selenium.IWebDriver | webDriver | Any Web driver to be passed in. |
System.String | browserSize | The execution type which indicates how the test will be executed in. |
System.Int32 | localTimeout | The timeout indicating how long to wait to find individual elements. |
Properties
| Improve this Doc View SourceCurrentURL
Gets the url of the page the webdriver is focued on.
Declaration
public string CurrentURL { get; }
Property Value
Type | Description |
---|---|
System.String |
ErrorContainer
Gets or sets the error container to check if any errors are shown on the UI.
Declaration
public string ErrorContainer { get; set; }
Property Value
Type | Description |
---|---|
System.String |
LoadingSpinner
Gets or sets the loadiong spinner that appears on the website.
Declaration
public string LoadingSpinner { get; set; }
Property Value
Type | Description |
---|---|
System.String |
LocalTimeout
Gets or sets the local timeout to attempt to find and wait for elements.
Declaration
public int LocalTimeout { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Name
Gets the name of the testing driver.
Declaration
public ITestingDriver.TestingDriverType Name { get; }
Property Value
Type | Description |
---|---|
ITestingDriver.TestingDriverType |
WebDriver
Gets the web driver in use.
Declaration
public IWebDriver WebDriver { get; }
Property Value
Type | Description |
---|---|
OpenQA.Selenium.IWebDriver |
Methods
| Improve this Doc View SourceAcceptAlert()
Accepts the alert provided that there is an alert.
Declaration
public void AcceptAlert()
Back()
Goes back a page.
Declaration
public void Back()
Check(String, Boolean, String)
Sets the check box's value to ON.
Declaration
public void Check(string xPath, bool byJS = false, string jsCommand = "")
Parameters
Type | Name | Description |
---|---|---|
System.String | xPath | The xpath to find the specified element. |
System.Boolean | byJS | Whether to use JS to perform the click / not. |
System.String | jsCommand | Any js command needed. |
CheckErrorContainer()
Checks if there are any errors in the error container.
Declaration
public void CheckErrorContainer()
CheckForElementState(String, ITestingDriver.ElementState, String)
Checks for an element state.
Declaration
public bool CheckForElementState(string xPath, ITestingDriver.ElementState state, string jsCommand = "")
Parameters
Type | Name | Description |
---|---|---|
System.String | xPath | The xpath to find the web element. |
ITestingDriver.ElementState | state | The state of the web element to wait for. |
System.String | jsCommand | Any JS command to use when finding the element. |
Returns
Type | Description |
---|---|
System.Boolean | If the element state is as wanted. |
ClickElement(String, Boolean, String)
Performs the actions of clicking the specified element. Uses Selenium binding by default.
Declaration
public void ClickElement(string xPath, bool byJS = false, string jsCommand = "")
Parameters
Type | Name | Description |
---|---|---|
System.String | xPath | The xpath to find the specified element. |
System.Boolean | byJS | Whether to use JS to perform the click / not. |
System.String | jsCommand | Any js command needed. |
CloseBrowser(Boolean)
Closes the current window. It will quit the browser if it is the last window opened.
Declaration
public void CloseBrowser(bool closeAll)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | closeAll |
DismissAlert()
Dismisses the alert provided taht there is an alert.
Declaration
public void DismissAlert()
ExecuteJS(String)
Executes JS command.
Declaration
public void ExecuteJS(string jsCommand)
Parameters
Type | Name | Description |
---|---|---|
System.String | jsCommand | command. |
ForceKillWebDriver()
Force kill web driver.
Declaration
public void ForceKillWebDriver()
Forward()
Goes Fowards a page.
Declaration
public void Forward()
GenerateAODAResults(String)
Generates the AODA results.
Declaration
public void GenerateAODAResults(string folderLocation)
Parameters
Type | Name | Description |
---|---|---|
System.String | folderLocation | The folder to generate AODA results in. |
GetAlertText()
Gets the text inside the alert.
Declaration
public string GetAlertText()
Returns
Type | Description |
---|---|
System.String | Alert Text. |
GetAllLinksURL()
The GetAllLinksURL.
Declaration
public List<string> GetAllLinksURL()
Returns
Type | Description |
---|---|
System.Collections.Generic.List<System.String> | The List{string}. |
GetElementAttribute(String, String, String)
Returns the given attribute for the element given.
Declaration
public string GetElementAttribute(string attribute, string xPath, string jsCommand = "")
Parameters
Type | Name | Description |
---|---|---|
System.String | attribute | |
System.String | xPath | xpath to find the attribute. |
System.String | jsCommand | any js command to use. |
Returns
Type | Description |
---|---|
System.String | the value of the attribute. |
GetElementText(String, String)
Returns the given text for the element given.
Declaration
public string GetElementText(string xPath, string jsCommand = "")
Parameters
Type | Name | Description |
---|---|---|
System.String | xPath | xpath to find the attribute. |
System.String | jsCommand | any js command to use. |
Returns
Type | Description |
---|---|
System.String | the value of the attribute. |
GetWebElement(String, String)
Returns the webElement at the given xPath.
Declaration
public IWebElement GetWebElement(string xPath, string jsCommand = "")
Parameters
Type | Name | Description |
---|---|---|
System.String | xPath | The xpath to find the element at. |
System.String | jsCommand | any Js Command To use. |
Returns
Type | Description |
---|---|
OpenQA.Selenium.IWebElement | The web element. |
LaunchNewTab(String, Boolean)
Tells the browser to launch a new tab.
Declaration
public bool LaunchNewTab(string url = "", bool instantiateNewDriver = false)
Parameters
Type | Name | Description |
---|---|---|
System.String | url | URL for the browser to navigate to. |
System.Boolean | instantiateNewDriver | Instantiates a new selenium driver. |
Returns
Type | Description |
---|---|
System.Boolean | if the navigation was successful.
|
Maximize()
Maximizes the browser.
Declaration
public void Maximize()
NavigateToURL(String, Boolean)
Tells the browser to navigate to the provided url.
Declaration
public bool NavigateToURL(string url = "", bool instantiateNewDriver = true)
Parameters
Type | Name | Description |
---|---|---|
System.String | url | URL for the browser to navigate to. |
System.Boolean | instantiateNewDriver | Instantiates a new selenium driver. |
Returns
Type | Description |
---|---|
System.Boolean | if the navigation was successful.
|
PopulateElement(String, String, String)
Performs the action of populating a value.
Declaration
public void PopulateElement(string xPath, string value, string jsCommand = "")
Parameters
Type | Name | Description |
---|---|---|
System.String | xPath | The xpath to use to identify the element. |
System.String | value | The value to populate. |
System.String | jsCommand | Any js command needed. |
Quit()
Quits the webdriver. Call this when you want the driver to be closed.
Declaration
public void Quit()
RefreshWebPage()
Refreshes the webpage.
Declaration
public void RefreshWebPage()
RunAODA(String)
Method to run aoda on the current web page.
Declaration
public void RunAODA(string providedPageTitle)
Parameters
Type | Name | Description |
---|---|---|
System.String | providedPageTitle | Title of the web page the user provides. |
SelectValueInElement(String, String, String)
Performs the action of selecting a value in an element.
Declaration
public void SelectValueInElement(string xPath, string value, string jsCommand)
Parameters
Type | Name | Description |
---|---|---|
System.String | xPath | The xpath to use to identify the element. |
System.String | value | The value to select in the element. |
System.String | jsCommand | Any js command needed. |
SendKeys(String)
The SendKeys.
Declaration
public void SendKeys(string keystroke)
Parameters
Type | Name | Description |
---|---|---|
System.String | keystroke | The keystrokeSystem.String. |
SetTimeOutThreshold(String)
Sets the global timeout in seconds.
Declaration
public void SetTimeOutThreshold(string seconds)
Parameters
Type | Name | Description |
---|---|---|
System.String | seconds | maximum duration of timeout. |
SwitchToIFrame(String, String)
Switches to appropriate IFrame. Use root in xpath to leave the iframe.
Declaration
public void SwitchToIFrame(string xPath, string jsCommand)
Parameters
Type | Name | Description |
---|---|---|
System.String | xPath | xPath to find the iFrame. use "root" to leave iframe. |
System.String | jsCommand | Any js command needed. |
SwitchToTab(Int32)
The SwitchToTab.
Declaration
public void SwitchToTab(int tab)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | tab | The tabSystem.Int32. |
TakeEntireScreenshot(String, Boolean)
Takes a screenshot of the browser. Screenshot will have the datestamp as its name. Year Month Date Hour Minutes Seconds (AM/PM).
Declaration
public bool TakeEntireScreenshot(string fileName, bool isMobile = false)
Parameters
Type | Name | Description |
---|---|---|
System.String | fileName | The fileName of the testing driver. |
System.Boolean | isMobile | Whether it is a mobile device. |
Returns
Type | Description |
---|---|
System.Boolean | if screenshot was successfully taken.
|
TakeScreenShot(String)
Takes a screenshot of the browser. Screenshot will have the datestamp as its name. Year Month Date Hour Minutes Seconds (AM/PM).
Declaration
public void TakeScreenShot(string fileName)
Parameters
Type | Name | Description |
---|---|---|
System.String | fileName | The fileName of the testing driver. |
Uncheck(String, Boolean, String)
Sets the check box's value to OFF.
Declaration
public void Uncheck(string xPath, bool byJS = false, string jsCommand = "")
Parameters
Type | Name | Description |
---|---|---|
System.String | xPath | The xpath to find the specified element. |
System.Boolean | byJS | Whether to use JS to perform the click / not. |
System.String | jsCommand | Any js command needed. |
VerifyAttribute(String, String, String, String)
Returns whether or not the actual attribute value of the check box matches with the expected value, given a verification attribute string to check.
Declaration
public bool VerifyAttribute(string attribute, string expectedValue, string xPath, string jsCommand = "")
Parameters
Type | Name | Description |
---|---|---|
System.String | attribute | Verification attribute string to check. |
System.String | expectedValue | Expected value to compare with. |
System.String | xPath | The xpath of the element. |
System.String | jsCommand | Any js command needed. |
Returns
Type | Description |
---|---|
System.Boolean | if actual attribute value matches with the expected value.
|
VerifyDropDownContent(List<String>, String, String)
Returns whether or not the drop down list contains all the given strings.
Declaration
public bool VerifyDropDownContent(List<string> expected, string xPath, string jsCommand = "")
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.List<System.String> | expected | The list of expected strings. |
System.String | xPath | The xpath of the element. |
System.String | jsCommand | Any js command needed. |
Returns
Type | Description |
---|---|
System.Boolean | the drop down contains all the given strings.
|
VerifyElementSelected(String, String)
Returns whether or not the element is selected or not.
Declaration
public bool VerifyElementSelected(string xPath, string jsCommand = "")
Parameters
Type | Name | Description |
---|---|---|
System.String | xPath | The xpath of the element. |
System.String | jsCommand | Any js command needed. |
Returns
Type | Description |
---|---|
System.Boolean | the element is current selected.
|
VerifyElementText(String, String, String)
Returns whether or not the element's text is the same as the expected value.
Declaration
public bool VerifyElementText(string expected, string xPath, string jsCommand = "")
Parameters
Type | Name | Description |
---|---|---|
System.String | expected | What the value is expected to be. |
System.String | xPath | The xpath of the element. |
System.String | jsCommand | Any js command needed. |
Returns
Type | Description |
---|---|
System.Boolean | if it is the same.
|
VerifyFieldValue(String, String, String)
Returns whether or not the element's value attribute is the same as the expected value. Usually for form-like elements.
Declaration
public bool VerifyFieldValue(string expected, string xPath, string jsCommand = "")
Parameters
Type | Name | Description |
---|---|---|
System.String | expected | What the value is expected to be. |
System.String | xPath | The xpath of the element. |
System.String | jsCommand | Any js command needed. |
Returns
Type | Description |
---|---|
System.Boolean | if it is the same.
|
Wait(Int32)
Sets implicit wait timeout in seconds.
Declaration
public void Wait(int seconds)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | seconds | Maximum timeout duration in seconds. |
WaitForElementState(String, ITestingDriver.ElementState, String)
Waits for an element state.
Declaration
public void WaitForElementState(string xPath, ITestingDriver.ElementState state, string jsCommand = "")
Parameters
Type | Name | Description |
---|---|---|
System.String | xPath | The xpath to find the web element. |
ITestingDriver.ElementState | state | The state of the web element to wait for. |
System.String | jsCommand | Any js command needed. |
WaitForLoadingSpinner()
Waits until the loading spinner disappears.
Declaration
public void WaitForLoadingSpinner()