3

I wonder how people take a call in deciding the right level of function abstraction in Page objects, I sometimes find myself either on a very high level like "CreateOrder" or sometimes very low level like "clickSubmitButton"..

Is there any rule of thumb or best practices to break down user operations on a page in easily manageable,readable, reusable Page object methods?

0

2 Answers 2

1

It depends

The rule of thumb I use is that if I find myself coding essentially the same thing three times, I wrap the coding into an appropriate object and call it.

So if your submit button is used in multiple different tests, then a CommonModules.ClickSubmitButton(); might be appropriate. If it's only ever used to create an order, and you're calling the order creation with set parameters, then it makes sense to use OrderModule.CreateOrder(orderDataObject);

Use what works with the application in test, and keep both DRY (Don't Repeat Yourself) and YAGNI (You Ain't Gonna Need It) in mind, and your code should be fine.

2
  • Thanks Kate for detailed answer however an order can be created in multiple ways from different application paths if I encapsulate all cases as parameters then the test would like a simple one liner with one function call to 'createOrder' but function itself will be very large & complex covering lot of conditions based on parameters.It would fulfill both DRY and YAGNI but function complexity will be very high. Commented Jan 5, 2018 at 8:29
  • In that case, each path has a test: CreateOrderFromCustomerScreen(), CreateOrderFromOrderScreen() and so forth - and within the test you're calling the appropriate helper functions.
    – Kate Paulk
    Commented Jan 5, 2018 at 12:32
0

I think the Functional Implementation & Structural Implementation sections in the following article may clarify your doubt:

https://www.3pillarglobal.com/insights/abstracting-selenium-tests-using-page-object-model

But, personally I think though we start to write very low level methods like 'clickSumbitButton' eventually we would convert our test scripts into using highlevel methods like 'createOrder' which themselves call the low level methods.

4
  • Thanks for the answer however as per your answer what function will be called in test script/spec file? If we call the createOrder() function then there might be a single function call(a single line) in the test script.Is it what you intended in your answer? Commented Dec 30, 2017 at 16:10
  • yes, at first we may start using the clickSubmit button in multiple test scripts but eventually we may need to use 'create order' functionality multiple times than rather than going through the individual process(clicking of submit button) every time, we may call the highlevel method of (createOrder).
    – the_coder
    Commented Jan 1, 2018 at 4:48
  • Ok, so if a test case is to create a order then you will first write the test script in multiple steps using 'clickSubmitButton' but eventually update the script with direct one function call to ' createOrder', is that correct? Commented Jan 5, 2018 at 8:16
  • yes, thats correct, as @Kate pointed it out,Use what works with the application under
    – the_coder
    Commented Jan 8, 2018 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.