Hi,
In module 14, you have discussed about Options classes (ChromeOptions, FirefoxOptions, InternetExplorerOptions) and its useage. affer that you have created one program called LoadingOptions, in this program you have created different functions to call them based on browser selection in test cases.
But I am not able to figure out how exactly we will be using this LoadingOptions program or functions written under this program into other test case. so that there is no need to write code everytime for disabling log\ pageload stratergy etc... ( which all come under options class.
Can you please help in this matter? I have gone through all videos of module 14 but did not get usage of this program anywhere. I think this is something very important but I am missing something.
Thank you.
I think I got it. this program is incomplete and you want this to be complete by ourself in such a way that we can use it in other test cases to call different browser. Please correct me if I am wrong.
I have created a function of this class and used it in my test cases to.
PFA function created by me and used same in other test case.
package testCases;
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.ProfilesIni;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.ie.InternetExplorerDriverService;
import org.openqa.selenium.ie.InternetExplorerOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;
public class LoadingOptions {
@Test
public WebDriver executeTest(String browser){
//String browser = "Chrome";// xls, xml
WebDriver driver = null;
// script
if(browser.equals("Mozilla")){
driver = new FirefoxDriver(loadFirefoxOptions());
}else if(browser.equals("Chrome")){
driver = new ChromeDriver(loadChromeOptions());
}else if(browser.equals("IE")){
driver = new InternetExplorerDriver(loadInternetExplorerOptions());
}else if(browser.equals("Edge")){
driver = new EdgeDriver();
}
return driver;
}
public FirefoxOptions loadFirefoxOptions(){
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "null");
FirefoxOptions options = new FirefoxOptions();
options.setPageLoadStrategy(PageLoadStrategy.EAGER);
ProfilesIni allProf = new ProfilesIni();// all profiles on pc
FirefoxProfile prof = allProf.getProfile("Mod11");
prof.setPreference("dom.webnotifications.enabled", false);// turn off
prof.setAcceptUntrustedCertificates(true);
prof.setAssumeUntrustedCertificateIssuer(false);
options.setProfile(prof);
return options;
}
public ChromeOptions loadChromeOptions(){
System.setProperty(ChromeDriverService.CHROME_DRIVER_LOG_PROPERTY, "null");
System.setProperty(ChromeDriverService.CHROME_DRIVER_SILENT_OUTPUT_PROPERTY, "true");
ChromeOptions ops = new ChromeOptions();
ops.addArguments("--disable-notifications");
ops.addArguments("disable-infobars");
ops.addArguments("--start-maximized");
return ops;
}
public InternetExplorerOptions loadInternetExplorerOptions() {
System.setProperty(InternetExplorerDriverService.IE_DRIVER_LOGLEVEL_PROPERTY,"INFO");
System.setProperty(InternetExplorerDriverService.IE_DRIVER_LOGFILE_PROPERTY, "null");
DesiredCapabilities cap = new DesiredCapabilities();
InternetExplorerOptions ieops = new InternetExplorerOptions();
return ieops;
}
}
---------------------------------------------------------------------------------------
package testCases;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.Test;
public class SalesLogin {
//static String browser = "Chrome";
static WebDriver driver;
@Test(dataProviderClass=LogInTestDataProvider.class,dataProvider="Salsman_login_data_provider")
public void loginSales(String username,String password,String Browser) {
String browser = Browser;
LoadingOptions loading = new LoadingOptions();
driver = loading.executeTest(browser);
driver.get("url of my application");
Boolean present = driver.findElement(By.id("userName")).isDisplayed();
System.out.println(present);
driver.findElement(By.id("userName")).sendKeys(username);
driver.findElement(By.id("password")).sendKeys(password);
driver.findElement(By.xpath("//button[@class ='btn btn-block btn-lg btn-success']")).click();
}
}
Instructor
Ashish Thakur Replied on 20/03/2019
Yes, you can implement this method
Thank you.