So, i am building a pagefactory testng framework with selenium webdriver for an application which is having login page, registration, settings etc. I have as of now kept my project structure as separate page classes for each screen like Homepage for login, Registration for registration ,setting for setting functionality. For test cases Homepage functionalities are under 1 package , and other module test cases are in their respective packages. My question is more around Navigation conditions which are many . how should i organise navigation conditions. As of now i am writing all navigations from Login screen under same package of homepage, similarly navigations from other screen in their respective packages. I want to understand what is the best way of folder structure to organize in selenium framework.
-
You can use maven project structure – Ankur Singh May 12 '18 at 17:24
-
Could you clarify the question, please. What do you mean by navigation conditions? – anonygoose May 12 '18 at 17:39
-
I am using the same Maven project structure but my application is like Registration screen can be navigated from multiple other screens like login screen,setting screen .As i am structuring my test cases under one module.Foe example login related test scripts under one package. Now Navigation to Registration ,as this can be achieved by multiple screens i have written a single code for navigation to registration screen with if else .Now my question is where ,in which package i should place this navigation code i.e in login package or registration or other package ? – shashank shekhar May 12 '18 at 23:34
1 Answers
I think you have POMs package that has all your pages objects and functions right? If so, you can use aggregation and composition in OOP. Create new new package called components, this package should include all page components. What does it mean? you can create your pages as parts(components). If your homepage has 1 top menu and 1 side menu and main list of elements, you can create it as parts, 1 class for top menu, and 2 more classes for the others. Your homepage class as POM should use all 3 classes functions using OOP aggregation or composition. Make independent navigation in your tests steps, the test steps must include the clicks on your pages.
For instance: create login page instance login do login now you are in homepage create homepage instance homepage navigate to settings page . . etc.
Did you mean above? If not please elaborate your question.

- 1,030
- 1
- 13
- 32
-
Hi .Thanks for this. I needed something like this. My only concern is if i create multiple classes for parts then wouldnt it make the project bulky in terms of lot of classes. – shashank shekhar May 14 '18 at 23:30
-
@shashankshekhar, This is how Page Object Model works, never mind about your classes number. You can work in really good way while implementing your POMs, have a look to Factory Design Pattern https://www.tutorialspoint.com/design_pattern/factory_pattern.htm. – Nael Marwan May 15 '18 at 09:59
-
Ok thanks .Also need one more valuable feedback.So one of my application page is such as it has vehicle model list which has around 9 car models and i have separate test cases for each car models form fill in one class. Everytime i fill the form completely i click next button to check validation. Now as my all test cases are in one class with annotation @Test ,how should i arrange the test case so that after completion of one test case run it resets to starting point for next @ Test ?Please advice – shashank shekhar May 17 '18 at 02:44
-
You can use Test dependency https://www.tutorialspoint.com/testng/testng_dependency_test.htm. OR Use priorities with values. – Nael Marwan May 17 '18 at 07:54
-
Hi @Nael,I followed your instruction for creating separate components for the main page like for homepage I created one class for registration ,one help and one main form.now I am not able to figure out how to make independent navigation on each page.like on login page on clicking registration link it navigates to registration page.how can I pass the driver instance from login to registration in same method.please advice. – shashank shekhar Jun 08 '18 at 11:03
-
Hi, Create abstract class that all page objects classes extend this abstract class. In the abstract class add a static driver field and initialize it with driver creation function that return the object. Let all the pages extend the abstract class, then you will have shared static driver for all classes. OR When you create an object of a page you can pass the driver to the constructor, then you have the driver in your page class and you will be able to use the selenium functions. Please accept my answer if it's clear. – Nael Marwan Jun 09 '18 at 16:34