Monday, 25 February 2013

Switching between Windows using Selenium RC

Purpose: Script to swithc b/w windows using Selenium RC

We come across to handle switching b/w windows while accessing different webpages. Inroder to automate switching b/w windows, following steps will help you to write Selenium RC Script with the help of Java

The major command that will help to switch b/w windows is selectWindow(). Using thisSelenium Rc command we achive the desired automation script.

Following is the Selenium RC with Java script to handle popup windows:

// Code for JUnit

package com.seleniurc;
import com.thoughtworks.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 static org.junit.Assert.*;

public class MultiWindows {
 private Selenium selenium;
 private SeleniumServer seleniumserver;
 private RemoteControlConfiguration rc;

 @Before
 public void setUp() throws Exception {
  rc = new RemoteControlConfiguration();
  seleniumserver = new SeleniumServer(rc);
  selenium = new DefaultSelenium("localhost", 4444, "*firefox","http://");
  seleniumserver.start();
  selenium.start();
 }

 @Test
 public void testMultiWindows() throws Exception {
  //To open targeted webpage
  selenium.open("
http://www.quackit.com/html/codes/");
  // To hold the executing script for 5000 ms
  Thread.sleep(5000);
  selenium.click("link=Pop up windows");
  selenium.waitForPageToLoad("30000");
  // Perform click operation to open popup window
  selenium.click("link=Open a popup window");
  // waiting for popup window
  selenium.waitForPopUp("popUpWindow", "30000");
  // To switch b/w main window to popup window
  selenium.selectWindow("name=popUpWindow");
  Thread.sleep(3000);
  // executing text present command on popup window
  assertTrue(selenium.isTextPresent("Copy/Paste HTML Codes"));
  // closing popup window
  selenium.close();
  // Switching control to main window
  selenium.selectWindow(null);
  // executing text present command on popup window
  assertTrue(selenium.isTextPresent("Open a popup window"));
 }

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


// Code for TestNG
package com.seleniurc;
import org.openqa.selenium.server.RemoteControlConfiguration;
import org.openqa.selenium.server.SeleniumServer;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;

import com.thoughtworks.selenium.DefaultSelenium;
public class SwitchWindows {
 private DefaultSelenium selenium;
 private SeleniumServer server;
 private RemoteControlConfiguration rcc;
   @Test
   public void testSwitchWindows() throws InterruptedException {
    selenium.open("
http://www.quackit.com/html/codes/");
    assert(selenium.isTextPresent("HTML Codes - Free"));
    selenium.click("link=Pop up windows");
    //selenium.waitForPageToLoad("30000");
    assert(selenium.isTextPresent("HTML Popup Window Code"));
    Thread.sleep(3000);
    selenium.click("link=Open a popup window");
    selenium.waitForPopUp("popUpWindow", "30000");
    selenium.selectWindow("name=popUpWindow");
    assert(selenium.isTextPresent("Copy/Paste HTML Codes"));
    selenium.close();
    selenium.selectWindow(null);
    assert(selenium.isTextPresent("HTML Popup Window Code"));
    Thread.sleep(3000);
   }
   @BeforeClass
   public void beforeClass() throws Exception {
    rcc = new RemoteControlConfiguration();
    server = new SeleniumServer(rcc);
    selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://");
    server.start();
    selenium.start();
    selenium.windowMaximize();
   }

   @AfterClass
   public void afterClass() {
    selenium.stop();
    server.stop();
   }

}

Saturday, 25 February 2012

Creating Firefox Profile Template

Purpose: To overcome Certificate Verification, Application Dependent Certificates, Security Notifications

When ever we are working with Selenium Server (RC), every time the server starts Firefox browser it starts in separate profile. This may lead to fail the test case because of Digital Certificate Verification etc instead of AUT .



To resolve this issue we can create a Firefox Profile, add that certificate and pass the profile path to Server while starting the server.

Steps to Create Firefox Profile Template

1. Open Run and type "firefox.exe -p" and press enter.


2. This will leads to "Firefox - Choose User Profile" prompt.


3. Now click on Create Profile button, Click Next, provide profile name, location and press Finish button


4. Add the required Security Certificates digital certificates etc.

5. Now we need to provide additional parameter while starting the server as follows:

>java -jar <selenium server>.jar -firefoxProfileTemplate "path of newly created profile"

6. Now you can run the application without fail.






Friday, 24 February 2012

Steps to Setup Selenium IDE

I have tried the following steps, and it works smoothly to Setup Selenium IDE, hope this little contribution can help who want to start learning Automation Testing using Selenium. Following are the steps:

1. Go to  http://seleniumhq.org/download/ and click on Download Version 1.6.0 or latest and allow the pop-up.







2. Install the Selenium IDE Add-on



3. Once the Add-on installation is successfully completed restart the browser and start using Selenium IDE which is available in Tools menu (short cut - Ctrl+Alt+S)

Note: Selenium IDE will be useful for Record and Playback only. If we want to add dynamism we need to go for Selenium Server or RC / Web Driver.