Showing posts with label HTTPS sites. Show all posts
Showing posts with label HTTPS sites. Show all posts

August 28, 2013

Handling HTTPS sites Or Handling Security Certificate Errors using Selenium WebDriver

August 28, 2013 1
Selenium webdriver is used to automate web applications. Web applications generally starts with http://www.example.com......But some websites like internal websites or banking or secured web sites will starts with https://www.example.com. 

Below is one of the approach to handle https site while you are running from InternetExplorer.




Here we need to click the second option to go in to website.

Here we are taking help of Java script to click the second link 


Below is the code for handling https site..


===============================================
package scripts;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class HttpsTest {
WebDriver driver;
@Test
public void httpsTest() throws Exception {
driver.get("https://esupport.satyam.com/main.aspx");
                //Java script to click the link
driver.navigate().to("javascript:document.getElementById('overridelink').click()");
Thread.sleep(5000);
              //assert the title of the page
Assert.assertEquals(driver.getTitle(), "Welcome to Tech Mahindra Universe");
System.out.println("asssert successfull");
Thread.sleep(5000);
}
@BeforeTest
public void beforeTest() {
//launch Internet explorer
System.setProperty("webdriver.ie.driver", "F:\\Jar\\IEDriverServer.exe");
driver=new InternetExplorerDriver();
driver.manage().window().maximize();

driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}

@AfterTest
public void afterTest() {
driver.close();
driver.quit();
}

}
==============================================================
Hope this post will be useful......

December 29, 2011

Handling HTTPS sites using Selenium

December 29, 2011 58
As all we know selenium is used for automating web application. We will not have any difficulty in automating HTTP site...We face some of the below issues while automating HTTPS sites..

HTTPS sites will show some security notifications below are some:

Firefox:



Internet Explorer:





To over come this issue we need to add certification

1. Need to add remote control configuration
RemoteControlConfiguration rcc = new RemoteControlConfiguration ();

2. Set TrustAllSSLCertificates flag to TRUE
rcc.setTrustAllSSLCertificates(true);


3. Pass the rcc Instance to Selenium Server
SeleniumServer server = new SeleniumServer(rcc);


If the above steps also doesnt work you need to install cyber villian certificate to automate HTTPS sites (Especially for IE)


1. Extract selenium-server.jar
2. In selenium server folder Open sslSupport folder
3. It contains cybervillainsCA.cer please install that certificate

Now you can run your selenium rc  scripts with out any problem for HTTPS sites.


Below is the code with out the Above steps:


====================================

package selenium;


import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.SeleneseTestCase;

@SuppressWarnings("deprecation")
public class HTTPs extends SeleneseTestCase{

public SeleniumServer ss;
@Before
public void setUp() throws Exception
{
ss=new SeleniumServer();
ss.start();
selenium=new DefaultSelenium("localhost", 4444, "*firefox", "https://www.dibbs.bsm.dla.mil/");
selenium.start();
}

@Test
public void testSelenium() throws Exception
{
selenium.open("/");
selenium.windowMaximize();

Thread.sleep(5000);

}
@After
public void tearDown() throws Exception
{
selenium.stop();
ss.stop();
}

}
=============================================
If you run the above script it will give you an error..see the below image


To avoid that error please use below code:

================================================

package selenium;


import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.server.RemoteControlConfiguration;
import org.openqa.selenium.server.SeleniumServer;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.SeleneseTestCase;

@SuppressWarnings("deprecation")
public class HTTPs extends SeleneseTestCase{

public SeleniumServer ss;
@Before
public void setUp() throws Exception 
{
RemoteControlConfiguration rcc=new RemoteControlConfiguration();
//trust all ssl certificates
rcc.setTrustAllSSLCertificates(true);

ss=new SeleniumServer(rcc);
ss.start();
selenium=new DefaultSelenium("localhost", 4444, "*firefox", "https://www.dibbs.bsm.dla.mil/");
selenium.start();
}

@Test
public void testSelenium() throws Exception
{
selenium.open("/");
selenium.windowMaximize();

Thread.sleep(5000);

}
@After
public void tearDown() throws Exception 
{
selenium.stop();
ss.stop();
}

}


========================================================
The three lines which are in blue will make your browser to trust all SSL certificates..

Hope this post will be useful..