Selenium WebDriver – Running Tests On Various Browsers with Capabilities

In our automation journey we would have come across browser specific issues in Firefox and IE. Using below preferences and capabilities can help us avoid those

 

Lanching Firefox with desired capabilities

Below capabilities helps in handling untrusted certificates and downloads save window pop ups

System.out.println(“———-FIREFOX Browser——–“);
FirefoxProfile profile = new FirefoxProfile();
DesiredCapabilities caps = DesiredCapabilities.firefox();
profile.setAcceptUntrustedCertificates(false);
profile.setAssumeUntrustedCertificateIssuer(true);
profile.setPreference(“browser.download.folderList”, 2);
profile.setPreference(“browser.helperApps.alwaysAsk.force”, false);
profile.setPreference(“browser.download.manager.showWhenStarting”, false);
profile.setPreference(“browser.download.dir”, “C:\\Downloads”);
profile.setPreference(“browser.download.downloadDir”, “C:\\Downloads”);
profile.setPreference(“browser.download.defaultFolder”, “C:\\Downloads”);
profile.setPreference(“browser.helperApps.neverAsk.saveToDisk”,
“text/anytext ,text/plain,text/html,application/plain”);
caps = DesiredCapabilities.firefox();
browserType = caps.getBrowserName();
caps.setCapability(FirefoxDriver.PROFILE, profile);
driver = new FirefoxDriver(caps);

 

Lanching IE Explorer with desired capabilities

Below capabilities helps in handling a lot if IE browser issues. Also always use 32bit IE driver as its more stable even if you have a 64bit machine

System.out.println(“———-IE Browser——–“);
System.setProperty(“webdriver.ie.driver”, “path to IE driver.exe”);
DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
browserType = caps.getBrowserName();
caps.setCapability(InternetExplorerDriver.NATIVE_EVENTS, false);
caps.setCapability(InternetExplorerDriver.ENABLE_PERSISTENT_HOVERING, false);
caps.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, false);
caps.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
caps.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
driver = new InternetExplorerDriver(caps);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s