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();





What have you tried, have you tried the class signature 'public class'
– Daniel Loudon
Sep 3 at 6:11





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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)