1.

What are the different network protocols that Selenium supports?

Answer»

The TWO most commonly used network protocols are HTTP and HTTPS. There are multiple ways to handle both protocols in Selenium.

HTTP protocol -

No Authentication - When a website is using HTTP protocol and does not require any authentication, it is easy to handle

WebDriver driver = new ChromeDriver();

driver.get("http://destination-url/");

Basic authentication - Many WEBSITES apply basic authentication scheme before allowing access to the home page. You can handle basic authentication in three ways-

i) Using WebDriverWait and Alert classes to implement basic authentication for HTTP.

WebDriverWait testwait = new WebDriverWait(driver, 10);  Alert testalert = testwait.until(ExpectedConditions.alertIsPresent());  testalert.authenticateUsing(new UserAndPassword(**user**, **pass**));

ii) pass user/pass pair within the HTTP URL as a parameter to WebDriver's Get method.

String target = “http://user:pass@host”; public void LOGIN(String username, String password){     WebDriver driver = new ChromeDriver();     String URL = "http:// + username + ":" + password + "@" + "website link";     driver.get(URL);     driver.manage().window().maximize(); }

iii) Setting up browser preferences using the Selenium's profile classes.

FirefoxProfile FF = new FirefoxProfile(); FF.setPreference("network.http.phishy-userpass-length", 255); driver = new FirefoxDriver(FF); driver.get("http://user:pass@www.targetsite.com/");

HTTPS protocol - HTTPS is a secured protocol of HTTP and it encrypts communication exchanged between the web server and the browser. HTTPS protocol uses an SSL certificate that downloads onto the browser on initiating the first request. SSL certificate has a public key for encrypting the data transfer from client to server.

In short, we need to handle the SSL certificates in Selenium. To manage SSL in different browsers you need to use different approaches.

Handle SSL in Firefox - In firefox SSL is enabled using Selenium Profile APIs.

First load the profile of RUNNING browser instance.

ProfilesIni pf = new ProfilesIni(); FirefoxProfile ff = pf.getProfile ("myProfile");

Set the following properties to avoid security exception while opening the HTTPS site 

ff.setAcceptUntrustedCertificates(true); ff.setAssumeUntrustedCertificateIssuer(false);

Now create Firefox driver instance using profile object.

WebDriver driver = new FirefoxDriver (ffProfile);

Handle SSL in Chrome - Chrome need to set SSL options via desired capabilities of selenium WebDriver.

First prepare DesiredCapabilities instance

DesiredCapabilities set_ssl = DesiredCapabilities.chrome(); set_ssl.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true); WebDriver driver = new ChromeDriver (set_ssl);

Handle SSL in IE - In IE SSL is managed with two different methods.

i) Native JavaScript CODE -

driver.navigate ().to ("javascript:document.getElementById('overridelink').click()");
ii) DesiredCapabilities Class -

DesiredCapabilities ssl = new DesiredCapabilities(); ssl.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); System.setProperty("WebDriver.ie.driver","IEDriverServer.exe"); WebDriver driver = new InternetExplorerDriver(ssl);


Discussion

No Comment Found