POM- Page Object Model.
This is also a kind of framework.
Framework is a set of guidelines like coding standards , test-data handling , object repository treatment etc.
Note- There is nothing like any specific framework. It is just like we are giving the name to framework on the basis what all things/approaches we have used in framework.
If you are driving some data from excel/database then that framework you can call it as data driven framework.
the below framework is also a data driven framework/ hybrid framework/ pom framework/ method driven framework/ function driven / module driven.
Main advantage of POM-
1- avoid to write the duplicate locators for same WebElement which is the big issue in other frameworks.
2- Maintenance of the test script which becomes very easy.
3- improves readability etc.
Important points about POM which we need to do-
1) In POM, create a class for each and every web page.
2) In those classes declare all the WebElements as private variable.
3) Write the public methods to perform operation on that page.
4) Rest all points mentioned in script as people won't like to read long history so lets start practical things.
Here We are going to test login functionality of linkedin.com
Manual testcases for linkedin login scenario which need to automate
1) Create a java project.
2) Create a folder with name Jars and copy all the jar files(downloaded selenium jar files from here also download apache jars files from here) inside the folder. Then add all the jar files to your project.
3) Add TestNG library.
4) Now create packages and corresponding classes under that.
a) com.LinkedIn.utilLibrary-> Inside this package create Generic class which will have generic methods means the methods which we can use in other projects as well like read and write data from excel file etc.
b) com.LinkedIn.objectPage -> Inside this create all the web page classes and BasePage class.
In BasePage class will declare all the WebElements which are same in all the Web pages like header level WebElements and Footer etc and also declare common methods.
c) com.LinkedIn.testScripts -> Here write the script of the test cases.
5) Create a excel file (BrowserAndURL.xlsx) which will have input feed data.
6) Now right click on your project and navigate to TestNG and Convert to TestNG.
7) Execute the testng.xml
8) That's all about this POM basics.
Project Structure-
GenericUtilLibrary
com.LinkedIn.objectPage
BasePage
LoginPage
com.LinkedIn.testScripts
AtLoginValid
AtLoginInvalidPassword
AtLoginInvalidBlank
AtLoginInvalidBlankPassword
AtLoginValidBack
SuperTestNG
This is how your project will look like after all set up done as above.
Output Console-
Exp msg 'Hmm, that's not the right password. Please try again or request a new one.' matched with act msg 'Hmm, that's not the right password. Please try again or request a new one.'.
Exp title 'false' matched with act title 'false'.
Exp title 'Welcome! | LinkedIn' matched with act title 'Welcome! | LinkedIn'.
Exp msg 'false' matched with act msg 'false'.
Exp title 'World's Largest Professional Network | LinkedIn' matched with act title 'World's Largest Professional Network | LinkedIn'.
===============================================
Suite
Total tests run: 5, Failures: 0, Skips: 0
===============================================
This is also a kind of framework.
Framework is a set of guidelines like coding standards , test-data handling , object repository treatment etc.
Note- There is nothing like any specific framework. It is just like we are giving the name to framework on the basis what all things/approaches we have used in framework.
If you are driving some data from excel/database then that framework you can call it as data driven framework.
the below framework is also a data driven framework/ hybrid framework/ pom framework/ method driven framework/ function driven / module driven.
Main advantage of POM-
1- avoid to write the duplicate locators for same WebElement which is the big issue in other frameworks.
2- Maintenance of the test script which becomes very easy.
3- improves readability etc.
Important points about POM which we need to do-
1) In POM, create a class for each and every web page.
2) In those classes declare all the WebElements as private variable.
3) Write the public methods to perform operation on that page.
4) Rest all points mentioned in script as people won't like to read long history so lets start practical things.
Here We are going to test login functionality of linkedin.com
Manual testcases for linkedin login scenario which need to automate
1) Create a java project.
2) Create a folder with name Jars and copy all the jar files(downloaded selenium jar files from here also download apache jars files from here) inside the folder. Then add all the jar files to your project.
3) Add TestNG library.
4) Now create packages and corresponding classes under that.
a) com.LinkedIn.utilLibrary-> Inside this package create Generic class which will have generic methods means the methods which we can use in other projects as well like read and write data from excel file etc.
b) com.LinkedIn.objectPage -> Inside this create all the web page classes and BasePage class.
In BasePage class will declare all the WebElements which are same in all the Web pages like header level WebElements and Footer etc and also declare common methods.
c) com.LinkedIn.testScripts -> Here write the script of the test cases.
5) Create a excel file (BrowserAndURL.xlsx) which will have input feed data.
6) Now right click on your project and navigate to TestNG and Convert to TestNG.
7) Execute the testng.xml
8) That's all about this POM basics.
Project Structure-
LinkedIN_Project_By_POM
src
com.LinkedIn.utilLibrary -src
GenericUtilLibrary
com.LinkedIn.objectPage
BasePage
LoginPage
com.LinkedIn.testScripts
AtLoginValid
AtLoginInvalidPassword
AtLoginInvalidBlank
AtLoginInvalidBlankPassword
AtLoginValidBack
SuperTestNG
This is how your project will look like after all set up done as above.
Output Console-
Exp msg 'Hmm, that's not the right password. Please try again or request a new one.' matched with act msg 'Hmm, that's not the right password. Please try again or request a new one.'.
Exp title 'false' matched with act title 'false'.
Exp title 'Welcome! | LinkedIn' matched with act title 'Welcome! | LinkedIn'.
Exp msg 'false' matched with act msg 'false'.
Exp title 'World's Largest Professional Network | LinkedIn' matched with act title 'World's Largest Professional Network | LinkedIn'.
===============================================
Suite
Total tests run: 5, Failures: 0, Skips: 0
===============================================