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?


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.

| improve this answer | |
  • 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. – Vishal Aggarwal Jan 5 '18 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 Jan 5 '18 at 12:32

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


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.

| improve this answer | |
  • 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? – Vishal Aggarwal Dec 30 '17 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 Jan 1 '18 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? – Vishal Aggarwal Jan 5 '18 at 8:16
  • yes, thats correct, as @Kate pointed it out,Use what works with the application under – the_coder Jan 8 '18 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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