Mouse over using web driver

package pack;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class MouseOverDemo {

       public static void main(String[] args) throws InterruptedException {

              WebDriver driver = new FirefoxDriver();
              driver.get("http://www.rightstart.com");
              // Mouseover on Health adn Safety
              // create new action builder instance by passing WebDriver instance to
              // the class
              Actions builder = new Actions(driver);
              // WebElement and build it to generates a composite action containing
              // all actions so far, ready to be performed.
              // a is control tagname
              WebElement a = driver
                           .findElement(By.id("navigation-top-cat-label-336"));
              builder.moveToElement(a).build().perform();
              Thread.sleep(2000);
              // Mouseover on sleep safety
              builder = new Actions(driver);
              a = driver.findElement(By.id("navigation-top-cat-label-1060"));
              builder.moveToElement(a).build().perform();
              Thread.sleep(2000);
              // Mouseover on baby monitors and click on baby monitors

              builder = new Actions(driver);
              a = driver.findElement(By.id("navigation-top-cat-label-1312"));
              builder.moveToElement(a).click().build().perform();
       }

}

Right click in Selenium Web driver



package softwaretesting-guru;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;

public class RightClick {

       public static void main(String[] args) {
              //Launch the browser
              WebDriver driver=new FirefoxDriver();
              //Enter URL
              driver.get("http://www.gmail.com");
              //Enter the data in gmail username
              driver.findElement(By.id("Email")).sendKeys("Selenium");
              //rightclick on gmail username field
             
              //WebElement represents any HTML element.
              WebElement elementRC = driver.findElement(By.id("Email"));
              //Use this class rather than using the Keyboard or Mouse directly.
               Actions builder = new Actions(driver);
              // Performs a context-click at the current mouse location
               Action rClick = builder.contextClick(elementRC).build();
               //A convenience method for performing the actions without calling build() first.
               rClick.perform();

       }

}

Assertions in Selenium



package com.softwaretesting_guru.help;

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 Assertions extends SeleneseTestCase{

       @SuppressWarnings("deprecation")
       @Before
       public void setUp() throws Exception {
              //Starting the server
              SeleniumServer ss=new SeleniumServer();
              ss.start();
              selenium=new DefaultSelenium("localhost",4444,"firefox","http://www.gmail.com");
              selenium.start();
       }

       @After
       public void tearDown() throws Exception {
       }

       @SuppressWarnings("deprecation")
       @Test
       public void test() throws InterruptedException {
              selenium.open("/");
              selenium.waitForPageToLoad("70000");
              Thread.sleep(4000);
              selenium.windowMaximize();
              //Verifying the signin button
              assertTrue(selenium.isElementPresent("id=signIn"));
              //Click on the signin button
              //the below line will pause for 4000 seconds for each line from here
              selenium.setSpeed("4000");
             
              selenium.click("id=signIn");
              //Verifying the warning message displayed when username is not given.
              assertEquals("Enter your email address.",selenium.getText("id=errormsg_0_Email"));
              //Verifying whether the username control is present or not..
              assertTrue(selenium.isElementPresent("id=Email"));
              //Entering the username to username field
              selenium.type("id=Email","selenium");
              //verify whether entered username has been displayed or not by getting the username
              assertEquals("selenium",selenium.getValue("id=Email"));
              //Click on sigin button
              selenium.click("id=signIn");
              //Verifying the warning message displayed when password is not given.
              assertEquals("Enter your password.",selenium.getText("id=errormsg_0_Passwd"));
              //Verifying whether the password control is present or not..
              assertTrue(selenium.isElementPresent("id=Passwd"));
              //Entering the password to password field
              selenium.type("id=Passwd","selenium");
              //verify whether entered password has been displayed or not by getting the password
              assertEquals("selenium",selenium.getValue("id=Passwd"));
             
             
             
       }

      
       }