0

I am implementing Page Object Model in Selenium using Python and pytest as testing framework. I have a page that has many elements so my page file is getting bigger. It is currently ~100 lines of code with all the locators that have their webdriverwaits associated with them. My question is should I add more locators to the same file or create a separate file for other locators. The locators that I am going to add now belong to a bit different type of tests then the ones I have added already. So I was thinking may be add further tests that are slightly different category to a new page and test files but don't want to deviate from POM best practices. I looked up the internet to find best practices guide but couldn't get a direct answer.

nd23
  • 83
  • 1
  • 8
  • 1
    sometimes adhering to "best practices" is counter-productive. DWMS. (I just invented this acronym... it stands for "Do What Makes Sense".) – pcalkins Jun 20 '19 at 21:37
  • 1
    Remember a Page Object does not have to represent an entire page (it's badly named). it just needs to represent a block of reusable functionality. Have a read of this from Martin Fowler (the person who came up with the term) https://martinfowler.com/bliki/PageObject.html – Ardesco Jun 21 '19 at 11:05
  • Thank you _pcalkins_ and _Ardesco_ for your insights. This definitely helps me to decide how to design my page objects. I will be defining a new page object now and will use the existing test file/object. – nd23 Jun 21 '19 at 14:45
  • btw, if you find yourself re-typing exepected conditions text and try/catch stuff, you might want to consider implementing your own MYActions class and extending it for each type of action... (all clicks to their own, typing, etc... then pass in XPATH or whatever variable is unique.... you could have by name, by id, etc... I would build XPATH's inside the methods in most cases... override the main "RunAction" method of myaction class.) – pcalkins Jun 21 '19 at 18:25
  • I've never worked with Python so I'm not sure about abstract classes there... from my short google of it, it does seem possible, though. – pcalkins Jun 21 '19 at 18:32

0 Answers0