Like us on Facebook

LightBlog

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..


December 27, 2011

Pros and Cons of using Selenium Backed Web driver

December 27, 2011 1
Pros and Cons of using Selenium Backed Web driver

Pros
  1. Allows for the WebDriver and Selenium APIs to live side-by-side
  2. Provides a simple mechanism for a managed migration from the Selenium RC API to WebDriver’s
  3. Does not require the standalone Selenium RC server to be run



Cons
  1. Does not implement every method
  2. More advanced Selenium usage (using “browserbot” or other built-in JavaScript methods from Selenium Core) may not work
  3. Some methods may be slower due to underlying implementation differences.
Source:
http://seleniumhq.org/docs/03_webdriver.html#webdriver-backed-selenium-rc 

Web Driver Backed Selenium -- Sample script

December 27, 2011 66
Web Driver Backed Selenium -- Sample script
The Java version of WebDriver provides an implementation of the Selenium-RC API. These means that you can use the underlying WebDriver technology using the Selenium-RC API. This is primarily provided for backwards compatablity. It allows those who have existing test suites using the Selenium-RC API to use WebDriver under the covers. It’s provided to help ease the migration path to Selenium-Web driver.


Sample Backed web driver script looks like this:


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



package webone;


import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.firefox.FirefoxDriver;
import com.thoughtworks.selenium.SeleneseTestCase;
import com.thoughtworks.selenium.Selenium;
@SuppressWarnings("deprecation")
public class BackedSelenium extends SeleneseTestCase  {

//web driver --here we are declaring the browser
WebDriver driver = new FirefoxDriver();
@Before
public void setUp() throws Exception {

String baseUrl = "http://www.google.co.in/";
selenium = new WebDriverBackedSelenium(driver, baseUrl);
}


@Test
public void testBackedSelenium() throws Exception {
//This is using selenium
selenium.open("/");
selenium.click("id=gbi5");
selenium.click("id=gmlas");
selenium.waitForPageToLoad("30000");
selenium.type("name=as_q", "test");
//Here we are using Webdriver
driver.findElement(By.id("as_oq1")).sendKeys("naga");

driver.findElement(By.id("as_oq2")).sendKeys("Webdriver");
Thread.sleep(5000);

}


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

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

By using the above format you can use both the Selenium API and Web driver API...