User Tag List

Results 1 to 2 of 2
  1. #1
    New Member
    Join Date
    Oct 2013
    Post Thanks / Like
    0 Post(s)
    0 Thread(s)

    Question Page Object Model - passing in parameters

    Hi there,

    A number of page object model examples show something similar to the following type of login scenario:

    LoginPage.validLoginWithCredentials("test@test.com ", "myPassword")

    However, I am creating TestData classes. e.g. UserTestData. So given this I was wondering which people think is the better method:

    1. Pass individual parameters into the page:

    LoginPage.validLoginWithCredentials(userTestData.e mail, userTestData.password)

    2. Pass the user into the page and let the page split off the properties:


    The big benefit with 1 is that you are really keeping the LoginPage as a page object that simply simulates the actual LoginPage functions. However, the potentially bigger benefit of 2 is that if suddenly you need a 3rd parameter to login (other than email/password) then you only need to update UserTestData to include the new property (and set a default value in the contructor) and then update the LoginPage.validLoginWithCredentials method to deal with the new 3rd property. (i.e. 2 changes as opposed to having to update every single Test Case that uses the Login functionality?

    I am thinking option 2, but keen to know what other POM people thought as most examples usually show option 1?



  2. #2
    SQA Knight
    Join Date
    May 2006
    Playa Del Rey, California, United States
    Post Thanks / Like
    17 Post(s)
    1 Thread(s)
    I tend to use individual parameters, probably more because it's easy to do quickly, but also most flexible once you add a layer above it that your tests call.

    But I also have a level of abstraction above it called 'flows'. So my test might look like:

    public void testUserCanCreateProjects() {
      WebDriver driver = WebDriverFactory.create();
      flows.AdminFlows.login(driver, TestAccountSettings.getAdminCredentials());
      ... //do testing
    Problem I see with passing in entire objects into page objects is, although it's nice to refactor. You may find yourself having to do it more often because yourself using it at a larger scope. Usually when you have a larger object like that, you might have say a "UserObject" that contains more than just username password, first and last name, email, account keys, etc... I like to handle all the larger level logic within flows, because within the flows package, you use these building blocks to build larger multipage pieces.

    In the test itself, I am essentially following your approach, using object wrappers around information I am consuming. However, I don't like to have any references to those inside the Test themselves. I think of it as too high level to want to bother with the details. The test should read almost like the business story. I avoid putting data (although I do specify the data source) in the tests. I handle how data maps to page object parameters within the flow objects.

    BTW.. most examples are online are over simplified for the point of demonstration (I do this a lot myself). I do encourage you to challenge assumptions and practices in the code examples. Most examples you'll see out there lack any level of abstraction. For example, most examples will say, "driver = new FirefoxDriver()", however in practice, no one instantiates the FirefoxDriver() directly. They'll use a Factory method to make their tests configurable. So in reality, most people will do "driver = SomeWebDriverFactory.createDriverFromConfig()". Then separately specify the settings in their environment variables or a config file, have a specification of the driver's connection strings, test profile, etc...
    Last edited by dlai; 12-02-2013 at 08:28 AM.
    David Lai
    SDET / Consultant
    LinkedIn profile



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.0.9 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Questions / Answers Form provided by vBAnswers (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominatevBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 03:53 AM.

Copyright BetaSoft Inc.