Friday, 4 August 2017

Code Example - Chrome Browser

package com.seleniumWebdriver;

import java.util.HashMap;
import java.util.Map;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.Test;

/**
 * @Blog Name : Selenium Code Example
 * @author Deepak Gupta
 * @Created Date 4-08-2017
 *
 */
public class ChromeBrowser {

WebDriver driver;

@Test
public void testChromeBrowser() {
try {

// Handle https - Your connection is not private
DesiredCapabilities dc = DesiredCapabilities.chrome();
dc.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

// Handle Set Chrome driver path and call
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "/drivers/chromedriver.exe");

// Handle - disable the invalid Extension
ChromeOptions options = new ChromeOptions();
options.addArguments("disable-infobars");

// Handle - disable the save password Extension
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("credentials_enable_service", false);
prefs.put("profile.password_manager_enabled", false);
options.setExperimentalOption("prefs", prefs);

// Handle - Call the Chrome browser
driver = new ChromeDriver(options);
driver.get("https://www.google.co.in");

} catch (Exception e) {
e.printStackTrace();
}
}

@AfterTest
public void tearDown() throws InterruptedException {

driver.quit();

}
}

No comments:

Post a Comment

Code Example - File Download By Robot Class In Firefox Browser

Exported from Notepad++ package com . practiceCode ; import java . awt . AWTException ; import java . awt . Robot ; import j...