Hi Devendra, following feature-file shows the scenario for gmail login functionality test:
Feature: Login Feature File
@selenium
Scenario: Login scenario test for Gmail
Given navigate to Gmail page
When user logged in using username as “username” and password as “password”
Then home page should be displayed
Now from this feature file, you can write Selenium test file using Webdriver:
public class stepDefinition {
WebDriver dr;
@Given("^navigate to gmail page$")
public void navigate(){
dr=new FirefoxDriver();
dr.get("http://www.gmail.com");
}
@When ("^user logged in using username as \"(.*)\" and password as \"(.*)\"$")
public void login(String username,String password){
dr.findElement(By.xpath("//*[@id='Email']")).sendKeys(username);
dr.findElement(By.xpath("//*[@id='Passwd']")).sendKeys(password);
dr.findElement(By.xpath("//*[@id='signIn']")).click();
dr.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}
@Then("^home page should be displayed$")
public void verifySuccessful(){
String expectedText="Gmail";
String actualText= dr.findElement(By.xpath("//*[@id='gbq1']/div/a/span")).getText();
Assert.assertTrue("Login not successful",expectedText.equals(actualText));
}
}