Constant Class for Browser Driver
Constant Class for Browser Driver
Is there any method to make a global class for browser driver in selenium, so i can use this class to initialize driver in each test instead of repeating same method everytime ?
This method what i want to share between tests for once :
FirefoxOptions options = new FirefoxOptions();
options.SetPreference("dom.webnotifications.enabled", false);
options.AcceptInsecureCertificates = true;
driver = new FirefoxDriver(options);
driver.Manage().Window.Maximize();
2 Answers
2
You can create a method in the helper class as below.
public static class BrowserConfigurationHelper
public static IWebDriver GetDriver()
FirefoxOptions options = new FirefoxOptions();
options.SetPreference("dom.webnotifications.enabled", false);
options.AcceptInsecureCertificates = true;
var driver = new FirefoxDriver(options);
driver.Manage().Window.Maximize();
return driver;
In Each Test method, you can simply call the GetDriver method to do the driver initialization as below
var driver = BrowserConfigurationHelper.GetDriver();
To make a class available anywhere, use the method signature
public static class CommonTestFunctions
...
The public
access modifier will allow any object or class access to your class, just put your functions that you use many times in test methods into that class and use it like:
public
//CommonTestFunctions class
public FireFoxOptions InitFireFoxOptions();
FirefoxOptions options = new FirefoxOptions();
options.SetPreference("dom.webnotifications.enabled", false);
options.AcceptInsecureCertificates = true;
driver = new FirefoxDriver(options);
driver.Manage().Window.Maximize();
//test method
var fireFoxOptions = CommonTestFunctions.InitFoxFoxOptions();
check my method i don't think will work with you solution
– James Fallon
Sep 3 at 6:21
It should, make sure you add references to the project with your common functions if you have multiple projects
– Daniel Loudon
Sep 3 at 6:26
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
What have you tried, have you tried the class signature 'public class'
– Daniel Loudon
Sep 3 at 6:11