0

I am using WebDriver with C# for automated testing of gmail. I fill the form, and click the button to enter. How can I verify the pass or fail of login?

[FindsBy(How = How.Id, Using = "Email")]
public IWebElement username;

[FindsBy(How = How.Id, Using = "Passwd")]
public IWebElement password;

[FindsBy(How = How.Id, Using = "signIn")]
public IWebElement loginButton;

public LoginForm()
{
    PageFactory.InitElements(Driver.driver, this);
}

public GmailPage Login(String username, String password)
{
    this.username.SendKeys(username);
    this.password.SendKeys(password);
    this.loginButton.Click();
    GmailPage result = new GmailPage();
    return result;
}
Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
user1590561
  • 583
  • 2
  • 6
  • 17

3 Answers3

0

I would use Nunit, since your using C# and look through there Assertion docs: NUNIT

I would assert on something unique that shows on the page after login is successful or assert that you dont see gmail asking to reenter credentials.

Assert.IsTrue( true, "your name here" );

or Assert.False( false, "The username or password you entered is incorrect" );

tebel
  • 23
  • 1
  • 8
  • I understand that. But after submitting the form there are the loading page. how to skip this page and start looking for element in email page? – user1590561 Aug 10 '12 at 15:52
  • Are you talking about putting a wait command for webelement to show ? – tebel Aug 10 '12 at 15:54
  • yes. thread.sleep() isn't right and I want to ask you: where I can read about the expectations in webdriver. – user1590561 Aug 11 '12 at 12:17
  • http://stackoverflow.com/questions/6992993/selenium-c-sharp-webdriver-wait-until-element-is-present. I think this is what you want. Let me know... – tebel Aug 11 '12 at 20:38
0

When Username or Password is wrong, there is shown a message after clicking Sign in button in gmail. So, you can verify text present as:

assertTrue(driver.getPageSource().contains("The username or password you entered is incorrect."), "Username or password is not correct");

If you are able to log in successfully, you can do assertion as:

assertFalse(driver.getPageSource().contains("The username or password you entered is incorrect."), "some message");

The above example is based on WebDriver (Selenium 2) using TestNG as framework. assertTrue contains 2 parameters: i) boolean ii) message. You can consider the same concept using NUnit.

The above code is similar to isTextPresent() of Selenium RC

Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
0

try below code, it's working for me, I got it by inspecting the fields using chrome , and hence right click on the field and copy XPath fields and use them in selenium

driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20)); 
driver.FindElement(By.XPath("//div[@class='sign-in-dialog-provider']")).Click(); 
driver.FindElement(By.Id("identifierId")).SendKeys("YOUR Email\n");

Thread.Sleep(10);


driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20));

Actions builder = new Actions(driver);

builder.MoveToElement(driver.FindElement(By.XPath("//*[@id='password']/div[1]/div/div[1]/input"))).Build().Perform();

var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));

IWebElement checkOut = wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//*[@id='password']/div[1]/div/div[1]/input")));

checkOut.SendKeys("Your Password");

driver.FindElement(By.XPath("//*[@id='passwordNext']/content")).Click();
kingbode
  • 131
  • 2
  • 8
  • If you want to make your input really helpful - consider fixing the indenting and removing all the commented code. Either code is of use, then it is there, or it is useless - then you throw it out. – GhostCat Sep 01 '17 at 18:47