Showing posts with label Frameworks. Show all posts
Showing posts with label Frameworks. Show all posts

Tuesday, June 3, 2014

Page Object Model (POM) with realtime project.

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-


LinkedIN_Project_By_POM
        src
            com.LinkedIn.utilLibrary -
                  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
===============================================




Monday, June 2, 2014

Why framework is needed and what are the uses ?


Ans - Framework is a set of guidelines like coding standards , test-data handling , object repository treatment etc... which when followed during automation scripting produce beneficial outcomes like increase code re-usage , higher portability , reduced script maintenance cost etc. Mind you these are just guidelines and not rules; they are not mandatory and you can still script without following the guidelines. But you will miss out on the advantages of having a Framework. So its always best practice to have good framework.

For more details about framework, please refer below link-


Sunday, June 1, 2014

How to explain the framework to the interviewer.

In our project Your_Project_Name (ex- CustomerCentre) , we are using Hybrid Framework(why framework required) which is the combination of Data Driven, Method Driven and Modular Driven Framework. Basically this involves 3 stages-

1) Designing the framework,
2) Implementing the framework,
3) Execution of the framework.


1) Designing the framework-

 

a) while designing the fw in anyone of the local drive create a folder by name HybridFramework. Launch the eclipse, set the workspace to HybridFramework.
b) in eclipse create a java project by name CustomerCentre.
c) in eclipse under CustomerCentre proj create a folder Jars & to that Jars folder include all the jar files related to the project such WebDriver jar, poi jar etc.
d) in eclipse under CustomerCentre proj create another folder by name Drivers to this folder copy all the executable files or driver such as Chrome Driver, IE driver and so on.
When designing the framework there are methods which can be used in more than one project such methods we call it as Generic method. And there are methods which are related to only one single project those methods are called as project specific method.
Naming convention for package- com.projectname.packagename (com.CustomerCentre.Library)
All the methods related to Generic, we write them under GenericLibrary class which is present in the Libraries package. And all the project specific methods are written under ProjectSpecificLibrary class which is present under libraries package.
All the GenericLibrary method should be public as well as static. Like – getLastRowNum, getCellValue, setCellValue, etc.
In the application there are certain types of steps which has to be used again & again such as open browser, open application & so on. In order to handle these types of steps we create ConfigLibrary (SuperTestNG) class in which we have written the methods by using Selenium annotations like @BeforeMethod, @AfterMethod etc. so that we need not to write the code for repeating steps each time. Inharit this class from all other classes to use these class methods.
We create an excel file by name Config, in which we wrote all the input data for the testing and then copy the entire excel file, and paste it under the CustomerCentre project.
To confirm everything working fine or not, we create a dummy package with dummy @Test method. If browser is getting launched, app is getting launched & browser is getting closed i.e. whatever we have developed till is correct. Then delete the dummy package.
To perform the validation, we create one more class Assertion. Whenever we need to perform validation we need to call assertText() or assertTitle() present under the Assertion class. (Assert.assertEquals())
 

2)- Implementing the ProjectSpecificLibrary- 

 

This is where actual implementation of the framework start. While going thru the manual testcases we note down the common repeated steps and make those steps as a project specific methods. Even if one step is repeating , may be in same testcase or other testcase make it as a method. Then write the test script for all the manual test cases.

 

3)- Execution-

 

 Right click on the project, navigate to TestNG → convert to TestNG → give the proper suite name and test name and click on finish. Then execute this xml file (ctrl+f11) or right click and run as TestNG Suite. Or to run thru cmd → navigate till project then give this commnd-

java -cp bin;jars/* org.testng.TestNG testng.xml


Explain with the below diagram that will be more impressive.


Sunday, May 11, 2014

What are the advantages of POM (page object model) frame work in selenium ?

Main advantage-
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.