Data Driven testing using cvs file

I am facing an issue where I can not do a data driven testing using page object model. and help ..

Train Asked on August 21, 2014 in Selenium WebDriver.
Add Comment
  • 2 Answer(s)

    Hi biswajit,

    You can visit http://www.toolsqa.com/selenium-webdriver/page-object-pattern-model-page-factory/
    for brief explanation.

    Regards,
    Vaidy

    Doctor Answered on August 21, 2014.
    Add Comment
    Best answer

    Hi biswajit,

    Check this example. I hope this will help.

    publicclassLoginPage{
    privatefinalWebDriver driver;

    publicLoginPage(WebDriver driver){
    this.driver = driver;

    // Check that we’re on the right page.
    if(!“Login”.equals(driver.getTitle())){
    // Alternatively, we could navigate to the login page, perhaps logging out first
    thrownewIllegalStateException(“This is not the login page”);
    }
    }

    // The login page contains several HTML elements that will be represented as WebElements.
    // The locators for these elements should only be defined once.
    By usernameLocator =By.id(“username”);
    By passwordLocator =By.id(“passwd”);
    By loginButtonLocator =By.id(“login”);

    // The login page allows the user to type their username into the username field
    publicLoginPage typeUsername(String username){
    // This is the only place that “knows” how to enter a username
    driver
    .findElement(usernameLocator).sendKeys(username);

    // Return the current page object as this action doesn’t navigate to a page represented by another PageObject
    returnthis;
    }

    // The login page allows the user to type their password into the password field
    publicLoginPage typePassword(String password){
    // This is the only place that “knows” how to enter a password
    driver
    .findElement(passwordLocator).sendKeys(password);

    // Return the current page object as this action doesn’t navigate to a page represented by another PageObject
    returnthis;
    }

    // The login page allows the user to submit the login form
    publicHomePage submitLogin(){
    // This is the only place that submits the login form and expects the destination to be the home page.
    // A seperate method should be created for the instance of clicking login whilst expecting a login failure.
    driver
    .findElement(loginButtonLocator).submit();

    // Return a new page object representing the destination. Should the login page ever
    // go somewhere else (for example, a legal disclaimer) then changing the method signature
    // for this method will mean that all tests that rely on this behaviour won’t compile.
    returnnewHomePage(driver);
    }

    // The login page allows the user to submit the login form knowing that an invalid username and / or password were entered
    publicLoginPage submitLoginExpectingFailure(){
    // This is the only place that submits the login form and expects the destination to be the login page due to login failure.
    driver
    .findElement(loginButtonLocator).submit();

    // Return a new page object representing the destination. Should the user ever be navigated to the home page after submiting a login with credentials
    // expected to fail login, the script will fail when it attempts to instantiate the LoginPage PageObject.
    returnnewLoginPage(driver);
    }

    // Conceptually, the login page offers the user the service of being able to “log into”
    // the application using a user name and password.
    publicHomePage loginAs(String username,String password){
    // The PageObject methods that enter username, password & submit login have already defined and should not be repeated here.
    typeUsername
    (username);
    typePassword
    (password);
    return submitLogin();
    }
    }

    Regards,
    Vaidy

    Doctor Answered on August 21, 2014.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.