-2

I have a simple question. I 'm sure many of us might have got into the same situation. I am using page object pattern. Below are the steps i do along the navigation.

  1. Login to my application as one type of user.
  2. Click some link to go form page.
  3. On form page , fills the fields and submit
  4. Logout

On 3) the form object page shows some different input fields depending on the type of the user, which i need to interact with. So how do i deal it within the same page object. Has anybody got into the same situation and have found some decent way of doing this ?

Saifur
  • 16,081
  • 6
  • 49
  • 73

2 Answers2

0

I know it a simple automation script not a Java project where we should be using all oops concepts but still I would go with the following:

  1. Create a parent page class containing the common WebElements and methods.

  2. Create child classes with elements and methods specific to that customer.

  3. In the test, pass a parameter which specifies the type of customer and call the appropriate child class.

If you don't want any of this inheritance stuff, you can also try the following.

  1. Create a page class with elements for all types of customers.

  2. Create generic methods which can take a parameter customerType and perform operations like if customerType==1 do these operations else do these.

Another solution which popped up in my mind, assuming that all fields for a particular customer are mandatory, is as follows.

  1. Create a common class for all elements.

  2. Create a generic method in the page class which follows the condition, if this element is present then enter value.

StrikerVillain
  • 3,719
  • 2
  • 24
  • 41
  • I like the inheritance part better. But i've got an issue there. Let's say if there are 25 groups(or more in future) , i will end up writing 25 sub classes for each group which i'm afraid of ;). I was thinking if we could provide elements locators dynamically for that particular page. – Ashish Mohindroo Dec 27 '14 at 20:47
  • I dont know how providing dynamic values to element locators is possible. But I have added another solution. – StrikerVillain Dec 27 '14 at 21:00
0

If you understand the concept of Page object model then this questions will be more clear to you. Yes, inheritance is a big factor here. I suggest you read through this to see how a real page object model should work. And, solution of #3 question is as simple as UI mapping. Something like

@FindBy(how = How.NAME, using = "q")
private WebElement searchBox;

for each elements or similar implementation.

For a complete page object you should map all the elements not depending on the users. The reason being, every time you call that class it will be instantiated and all the mapped elements as well. There is no need of dynamically load the elements If any elements are not used or hidden on the page those will be available and you will not be using them anyway

Saifur
  • 16,081
  • 6
  • 49
  • 73
  • I agree with you that when instantiating page objects it should not be dependant on the users but i think i probably need to still check it in my fillform function if the element is displayed or not , otherwise i will get element not found exception for the elements present for one user but not for another. – Ashish Mohindroo Dec 30 '14 at 22:04
  • You have completely missed my point! Say user `manager` should see `filedA` and `fieldB` and user `employee` should see `fieldA` only. You will still need to map both `filedA` and `filedB`. If you log in as manager and use both fields you will not get any exception wheres logging in as `employee` if you try to access `filedA` you will get exception. You don't need any additional check here. – Saifur Dec 30 '14 at 23:50