Selenium IDE, Selenium RC and Webdriver
Learn testing with examples.
Tuesday, May 22, 2012
Error while running webdriver tests in IE
While running tests in webdriver using internet explorer i got the following error
org.openqa.selenium.WebDriverException: Unexpected error launching Internet Explorer. Protected Mode must be set to the same value (enabled or disabled) for all zones. (WARNING: The server did not provide any stacktrace information)
The reason for this is in Internet Explorer Protected Mode must be set to the same value (enabled or disabled) for all zones.
See the below image to understand this line.
Go to Tools----Options---Security Tab
Like this for all the zones...Local Intranet, Trusted sites and Restricted sites..we have to Update the security level to low.
Than u can easily run tests using internet explorer..
Thursday, December 29, 2011
Handling HTTPS sites using Selenium
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:
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();
}
}
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 ();
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..
Labels:
HTTPS sites,
selenium RC
Tuesday, December 27, 2011
Pros and Cons of using Selenium Backed Web driver
Pros
- Allows for the WebDriver and Selenium APIs to live side-by-side
- Provides a simple mechanism for a managed migration from the Selenium RC API to WebDriver’s
- Does not require the standalone Selenium RC server to be run
Cons
- Does not implement every method
- More advanced Selenium usage (using “browserbot” or other built-in JavaScript methods from Selenium Core) may not work
- Some methods may be slower due to underlying implementation differences.
http://seleniumhq.org/docs/03_webdriver.html#webdriver-backed-selenium-rc
Labels:
Selenium 2.0,
Webdriver
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...
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...
Labels:
Selenium 2.0,
selenium RC,
Webdriver
Tuesday, November 8, 2011
Screenshot Using Webdriver / Selenium 2.0
Hi All,
Here is a post which explains you how to capture a screenshot using Webdriver/Selenium 2.0
Its a little bit different from Selenium1/Selenium RC.
You can see the screen shot in the specified folder (D:\\screenshot)
Here is the CODE..........
package scripts;
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class ScreenShot {
WebDriver driver;
@Before
public void setUp() throws Exception {
driver= new FirefoxDriver();
}
@After
public void tearDown() throws Exception {
driver.close();
}
@Test
public void testTextBox() throws Exception {
//open google home page
driver.get("http://www.google.co.in/");
// click on options in top right corner
driver.findElement(By.id("gbi5")).click();
//click on Advanced Search link
driver.findElement(By.id("gmlas")).click();
// type "selenium" in all these words: text box
driver.findElement(By.name("as_q")).sendKeys("selenium");
// click on Advanced Search button
driver.findElement(By.xpath("//input[@type='submit' and @value='Advanced Search']")).click();
// click on first link from search results
driver.findElement(By.linkText("Selenium - Web Browser Automation")).click();
Thread.sleep(5000);
// below two lines code is to take screenshot
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("D:\\screenshot\\google.png"));
Thread.sleep(10000);
}
}
Hope it will help you in capturing screenshots....
Thanks,
Madhu
Here is a post which explains you how to capture a screenshot using Webdriver/Selenium 2.0
Its a little bit different from Selenium1/Selenium RC.
You can see the screen shot in the specified folder (D:\\screenshot)
Here is the CODE..........
package scripts;
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class ScreenShot {
WebDriver driver;
@Before
public void setUp() throws Exception {
driver= new FirefoxDriver();
}
@After
public void tearDown() throws Exception {
driver.close();
}
@Test
public void testTextBox() throws Exception {
//open google home page
driver.get("http://www.google.co.in/");
// click on options in top right corner
driver.findElement(By.id("gbi5")).click();
//click on Advanced Search link
driver.findElement(By.id("gmlas")).click();
// type "selenium" in all these words: text box
driver.findElement(By.name("as_q")).sendKeys("selenium");
// click on Advanced Search button
driver.findElement(By.xpath("//input[@type='submit' and @value='Advanced Search']")).click();
// click on first link from search results
driver.findElement(By.linkText("Selenium - Web Browser Automation")).click();
Thread.sleep(5000);
// below two lines code is to take screenshot
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("D:\\screenshot\\google.png"));
Thread.sleep(10000);
}
}
Hope it will help you in capturing screenshots....
Thanks,
Madhu
Labels:
Selenium 2.0,
Webdriver
Subscribe to:
Posts (Atom)



