January 15, 2011

How to verify the TOOLTIP

Hi All,

Here is the interesting post to verify the tool tip.

ToolTip: The tooltip or infotip is a common graphical user interface element. It is used in conjunction with a cursor, usually a mouse pointer. The user hovers the cursor over an item, without clicking it, and a tooltip may appear—a small "hover box" with information about the item being hovered over.

Below is the sample code to verify the tooltip.

-----------------------------------------------------------------------------------------


import org.junit.*;

import org.openqa.selenium.server.*;

import com.thoughtworks.selenium.*;

public class Tooltip extends SeleneseTestCase{

public Selenium selenium;

public SeleniumServer seleniumserver;


@BeforeClass
public void setUp() throws Exception {

RemoteControlConfiguration rc = new RemoteControlConfiguration();
//rc.setSingleWindow(true);
seleniumserver = new SeleniumServer(rc);
selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://");
seleniumserver.start();
selenium.start();
}

@Test
public void testTooltip() throws Exception
{
selenium.open("http://in.yahoo.com/?p=us");
selenium.waitForPageToLoad("30000");
assertTrue(selenium.isTextPresent("the web"));
String tooltip = selenium.getAttribute("p@title");
System.out.println("Tootltip is "+tooltip);
selenium.click("//li[2]/a/span");
//selenium.waitForPageToLoad("30000");
verifyTrue(selenium.isTextPresent("Image Search"));
String tooltip1 = selenium.getAttribute("p@title");
System.out.println("Tootltip is "+tooltip1);
selenium.click("//li[3]/a/span");
//selenium.waitForPageToLoad("30000");
assertTrue(selenium.isTextPresent("News Search"));
String tooltip2 = selenium.getAttribute("p@title");
System.out.println("Tootltip is "+tooltip2);
selenium.click("//li[4]/a/span");
//selenium.waitForPageToLoad("30000");
assertTrue(selenium.isTextPresent("Local Search"));
String tooltip3 = selenium.getAttribute("p_13838465-p@title");
System.out.println("Tootltip is "+tooltip3);
}
@AfterClass
public void tearDown() throws InterruptedException{
selenium.stop();
seleniumserver.stop();
}
}

-----------------------------------------------------------------------------------------
Hope this post is useful for all.

2 comments:

  1. What will be code if attribute is visible only when hover over the link text ?

    ReplyDelete
  2. can we take screenshot of tool-tip title.

    ReplyDelete