May 24, 2011

Selenium 2.0

May 24, 2011 1
Selenium 2.0
This is my First post on Selenium 2.0 ....

Yesterday i downloaded Selenium 2.0 and configured setup in Eclipse...

Great news is i am able to run my first program using Juint...from now on words i will try to run my tests using TestNG and WebDriver..........

i will keep posted...

May 23, 2011

Installing Selenium IDE on Mozilla Firefox 4

May 23, 2011 36
Installing Selenium IDE on Mozilla Firefox 4



Installing selenium is simple, all you need is to install Selenium IDE addon to Mozilla Firefox.


Download Selenium IDE from Selenium site and the latest version is 1.0.10
Download FF latest version.


If you want to install Selenium IDE on Mozilla 4 you will need one extra steep. You will have to install compatibility addon to Firefox 4.
Can be downloaded from Mozilla Firefox Compatibility addon


Download that add on and install in FF....Then Selenium IDE will support...FF 4.0.1.

May 21, 2011

Setting up Selenium RC & TestNG using Eclipse - 1

May 21, 2011 7
I found that it is not easy for the beginners to setup Selenium RC and run the GoogleTest.java example after downloading it from www.openqa.org . The purpose of this post is to help beginners (new users to Selenium RC) help setting up Selenium RC with TestNG using Eclipse.


You need eclipse and TestNg Jar files..


Below are the steps to SetUp TestNG in eclipse.


Step1:


Open Eclipse.
Click on Help form Menubar  and select "Install new software".


Step2:


A new window will be opened. Click Add button.
 A new window is opened. and Enter Name as TESTNG and enter site "http://beust.com/eclipse"








Step3:
Select TestNG and Click Next

Step4:

In the next step click finish




Thats it You installed TESTNG in eclipse...

to verify that you need to click on Project -->new -->Other--?>Yoou can see TESTNG foler and expand that folder you cna see TESTNG Class..

See below screen shot..



Then go to second part of the post....it is post regarding 

Setting up Selenium RC & TestNG using Eclipse-II




May 19, 2011

Working with Multiple windows

May 19, 2011 1
Working with Multiple windows
I saw many posts on identifying window Name, ID and Title or Attribute....but all are giving Syntax...We can find that syntax in Selenium document. In this post, I would like to give an example how to identify window Name, ID and Title or Attribute...


Below is the code is to identify the new window....By using TITLE 


package test;


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


public class NewWindow extends SeleneseTestCase {
public SeleniumServer ss;
@Before
public void setUp() throws Exception {
ss= new SeleniumServer();
ss.start();
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.truepanel.com/");
selenium.start();
}


@Test
public void testNewWindow() throws Exception {
selenium.open("/");
   selenium.windowMaximize();
   selenium.setSpeed("2000");
   selenium.click("//div[@id='right']/div[2]/a[1]");
   selenium.setSpeed("2000");
   //Click on Facebook icon
   selenium.click("//div[@id='right']/div[2]/a[2]");
   selenium.setSpeed("2000");
   //Click on Linkedin icon
   selenium.click("//div[@id='right']/div[2]/a[3]");
   selenium.setSpeed("2000");
      String[] winNames = selenium.getAllWindowTitles();
 //All window names should be displayed in console
      for (int i = 0; i < winNames.length; i++) 
   {
    System.out.println("Window Titles are "+winNames[i]);
}
             
   /*selenium.selectWindow("Twitter");
   verifyEquals("Truepanel (Truepanel) on Twitter", selenium.getTitle());*/
   //Selects the new window with Title Truepanel | Facebook
   selenium.selectWindow("TruePanel | Facebook");
   selenium.setSpeed("2000");
   selenium.windowFocus();
   selenium.setSpeed("2000");
   selenium.windowMaximize();
   selenium.setSpeed("2000");
   if(selenium.isElementPresent("//div[@id='globalContainer']/div[2]/div/a/span"))
   {
    selenium.click("//div[@id='globalContainer']/div[2]/div/a/span");
selenium.waitForPageToLoad("30000");
selenium.type("firstname", "test");
selenium.type("lastname", "test");
selenium.type("reg_email__", "tets");
selenium.type("reg_email_confirmation__", "test");
selenium.selectWindow("null");
       selenium.windowFocus();
       verifyEquals("Welcome to Truepanel | Online Video Focus Groups", selenium.getTitle());
       selenium.click("//div[@id='navBtns']/a[2]");
selenium.waitForPageToLoad("30000");
       Thread.sleep(1000);
   }
   
     else
     {
    //this command will select the parent window
       selenium.selectWindow("null");
       selenium.windowFocus();
       verifyEquals("Welcome to Truepanel | Online Video Focus Groups", selenium.getTitle());
       Thread.sleep(1000);
   }
}
@After
public void tearDown() throws Exception {
selenium.stop();
ss.stop();
}
}

May 13, 2011

Handling Alerts...

May 13, 2011 12
Handling Alerts...
How to handle alerts in Registration page..

Below is the command used for handling Alerts...




getAlert()


Returns:
The message of the most recent JavaScript alert
Retrieves the message of a JavaScript alert generated during the previous action, or fail if there were no alerts. Getting an alert has the same effect as manually clicking OK. If an alert is generated but you do not consume it with getAlert, the next Selenium action will fail.


Under Selenium, JavaScript alerts will NOT pop up a visible alert dialog.

Selenium does NOT support JavaScript alerts that are generated in a page's onload() event handler. In this case a visible dialog WILL be generated and Selenium will hang until someone manually clicks OK.




Below is the script to handle Alert.....



package reporting;


import com.thoughtworks.selenium.*;


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


public class Alert extends SeleneseTestCase  {
public SeleniumServer ss;


@Before
public void setUp() throws Exception {
ss =new SeleniumServer();
ss.start();
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.rediff.com/");
selenium.start();
}


@Test
public void testAlert() throws Exception {
selenium.open("/");
selenium.windowMaximize();
selenium.click("link=Create a Rediffmail account");
selenium.waitForPageToLoad("30000");


selenium.type("name", "tester");
selenium.click("login");
//Enter Name here
selenium.type("login", "Tester1");
selenium.type("passwd", "selenium");
selenium.select("DOB_Day", "label=04");
selenium.select("DOB_Month", "label=APR");
selenium.select("DOB_Year", "label=1912");
//Click Register button
selenium.click("Register");
//Will get an alert..to handle this alert we will use below command
selenium.getAlert();
Thread.sleep(10000);
//After handling alert enter user name
selenium.type("login", "nagaraju");
Thread.sleep(10000);
}


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



Send a Mail to Friend from Gmail

May 13, 2011 1
Send a Mail to Friend from Gmail
Send mail to any one from Gmail..using the below script..

Gmail is one of the complicated stuff..Record and play back will not work here..because IDs and Names of the elements are changing randomly..Here we need to use ClickAt instead of Click...and we need to use Xpaths...

Below is the script to send mail to one mail ID...

Please change your mail and password  to execute this program...



package reporting;

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

public class Gmail extends SeleneseTestCase {
public SeleniumServer ss;
@Before
public void setUp() throws Exception {
ss=new SeleniumServer();
ss.start();
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "https://www.google.com/");
selenium.start();
}

@Test
public void testGmail() throws Exception {
selenium.open("/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fui%3Dhtml%26zy%3Dl&bsv=llya694le36z&scc=1&ltmpl=default&ltmplcache=2");
selenium.windowMaximize();
selenium.type("Email", "nagaqtt");
selenium.type("Passwd", "xxxx");
selenium.click("signIn");
selenium.waitForPageToLoad("30000");
//Click the compose button
selenium.clickAt("//div[3]/div[1]/div[1]/div[1]/div/div", "");
//Enter Email ID in To field
Thread.sleep(10000);
selenium.type("to", "nagaselenium@gmail.com");
//Subject of the mail
selenium.type("subject", "testing");
Thread.sleep(1000);
selenium.selectWindow("null");
//Content in the mail
Thread.sleep(1000);
selenium.typeKeys("//html/body[@class='editable  LW-yrriRe']", "nagaraju sending mail to his friend");
//Clicking the send button
selenium.clickAt("//div[@role='button']/b", "");
Thread.sleep(10000);
//Clicking the logout
if(selenium.isElementPresent("gbi4m1"))
{
selenium.click("gbi4m1");
}

selenium.click("link=Sign out");
Thread.sleep(10000);
}

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




How to Scroll the page

May 13, 2011 5
How to Scroll the page
We can scroll the page by using FOCUS command...


focus(locator)
Arguments:
Move the focus to the specified element; for example, if the element is an input field, move the cursor to that field.
Basically there is no specific command for scrolling the page down. I tried keyPress and all other options, but i felt Focus is the best for scrolling the page down. We need to select a element and set focus on that element.

Below is the example...


package reporting;

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

public class Focus extends SeleneseTestCase {
public SeleniumServer aa;
@Before
public void setUp() throws Exception {
aa= new SeleniumServer();
aa.start();
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.google.com/");
selenium.start();
}

@Test
public void testFocus() throws Exception {
selenium.open("/");
selenium.windowMaximize();
selenium.type("q", "selenium wiki");
selenium.click("btnG");
//Waiting for an element
for (int second = 0;; second++) {
if (second >= 60) fail("timeout");
try { if (selenium.isElementPresent("link=Selenium Overview - Wiki - Liferay.com")) break; } catch (Exception e) {}
Thread.sleep(1000);
}
//Set focus on element --then page will scroll down --focus will be on that element
selenium.focus("link=Selenium Overview - Wiki - Liferay.com");
//To capture a screenshot
selenium.captureScreenshot("c:/naga/screenshot.png");
Thread.sleep(10000);
}



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




May 3, 2011

Run Selenium RC using Command Prompt

May 03, 2011 55
Downloading and Installing Selenium RC:
  • Go to http://seleniumhq.org/download/.
  • Under Selenium Server (formerly the Selenium RC Server) section you    can see the selenium server latest version.
  • Click on download, it will be redirected to selenium server download page.
  • Selenium server is a JAR file. Download selenium-server-standalone-2.ob3.jar.
  • Create a Folder selenium in “C” drive.
  • Paste the selenium-server-standalone-2.ob3.jar file in that folder.

Start  and Stop Selenium Server:

  • We need to be able to start and stop the Selenium Server.
  • We can do this at the command line:
  • Start:  (Command line)
  • java -jar selenium-server-standalone-2.0b3.jar
  • Stop: (Browser)
  • http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer
Getting Started with Selenium/ Selenium RC steps:

  • Record your test case using Selenium IDE
  • Play your test case using selenium IDE itself to make sure that your test case works.
  • Export your recording test case - as html file.
  • Create a test suite.
  • Run your exported html test case using selenium rc
Steps:

  • Record a program using IDE:
  • Create a folder in any drive – Ex: C:\tests
Create folders:
  • We need to create two folders.
  • 1.To save our test suite and test case. (tests)
  • 2.To save results (results)
  • Using Selenium IDE record a test case and save it as .html in a tests folder.
  • Make sure your test run correctly.
Create a Test suite:
  • Create a test suite and save it in C:\tests folder
Run your scripts using selenium RC:

  • We can run our tests in any browser by using selenium RC.


Syntax:
java -jar selenium-server-standalone-2.0b3.jar -htmlSuite "*browser" "http://www.example.com" "c:\naga\tests\run.html" "c:\naga\results\results1.html“

RUN THE ABOVE COMMAND FROM COMMAND PROMPT:

Run this command from selenium directory.
Example:
C:\selenium>java -jar selenium-server.jar -htmlSuite "*iexplore" "http://www.google.com" "c:\naga\tests\run.html“ "c:\naga\results\results1.html"

Selenium Test Runner:

Results: