Thursday, 16 May 2013

selenium webdriver example



Automation of Login Details:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class LoginTest {

   
    public static void main(String[] args) {
        //WebDriver driver=new FirefoxDriver();
      
 System.setProperty("webdriver.chrome.driver", "C:\\Selenuim_Automation\\ChromeDriver\\chromedriver.exe");
        WebDriver driver=new ChromeDriver();

        //Step 1- Opening Ellamoss site
        driver.get("http://www.ellamos.com/");

        //Step-2 Clicking on My account
        driver.findElement(By.xpath("html/body/form/div[6]/div[1]/div/ul/li[1]/a")).click();

        //Step-3 Entering Email address in the textbox
        driver.findElement(By.xpath("//*[@id='ContentPlaceHolder1_email']")).sendKeys("abc@gmail.com");

        //Step-4 Entering Password in the textbox
        driver.findElement(By.xpath("//*[@id='ContentPlaceHolder1_password']")).sendKeys("pass_123");

        //Step-5 Clicking on Signin button
        driver.findElement(By.xpath("//*[@id='login']")).click();
       
        //Verifications
        //Getting the text from application

        String actText=driver.findElement(By.xpath("html/body/form/div[6]/div[3]/table/tbody/tr[2]/td/span[1]/span")).getText();

        //Expected text
        String expText="abc@gmail.com";
        //actText, exptext Comparison
        if(actText.equals(expText)){
            System.out.println("Strings are equal");
        }else{
            System.out.println("Strings are not equal");
        }

        driver.close();
       
    }

}

No comments:

Post a Comment