I had been using Selenium Webdriver for quiet long but every time I saw that the time required to maintain my test scripts were quiet high.Hence created a @BeforeSuite for initialising your webdriver, your testURL, your webelements etc.
Here is the code snapshot as below:

@BeforeSuite
public void steup() {

if(driver==null) {

// FileInputStream is a java library that accepts a constructor and reading the file Config.properties from the said location
try {
fis= new FileInputStream(“.\\src\\test\\resources\\properties\\Config.properties”);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

try {
config.load(fis);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

// FileInputStream is a java library that accepts a constructor and reading the file OR.properties from the said location
try {
fis = new FileInputStream(“.\\src\\test\\resources\\properties\\OR.properties”);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

//Loading the OR file for reading the values
try {
OR.load(fis);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

if (config.getProperty(“browser”).equals(“firefox”)) {
//System.setProperty(“webDriver.gecko.driver”, System.getProperty(“user.dir”)+”src\\test\\resources\\executables\\geckodriver.exe”);
System.setProperty(“webdriver.gecko.driver”,”.\\src\\test\\resources\\executables\\geckodriver.exe”);
driver = new FirefoxDriver();

}else if (config.getProperty(“browser”).equals(“chrome”)) {
System.setProperty(“webdriver.chrome.driver”, System.getProperty(“user.dir”)+”src\\test\\resources\\executables\\chromedriver.exe”);

driver = new ChromeDriver();

}

driver.get(config.getProperty(“testsiteurl”));
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(Integer.parseInt(config.getProperty(“implicit.wait”)), TimeUnit.SECONDS);
}

}

Use it and just make use of in your project.

Are you looking to automate your testing project in your organization, email us at contacts@bitsenze.com.

//www.bitsenze.com/wp-content/uploads/2020/01/BS-Infoedgelogo-final-update.png