P3selenium Framework Configuration Steps

Here we will see the Configuration Steps of P3selenium.

 

Precondition:
Java should be installed in the system
TestNG and Maven should be installed in eclipse

NOTE: We are using “Eclipse Juno” in this example

Configuration Steps:
You can get P3selenium framework from Github, use the following URL to download the zip
https://github.com/AbhishekAggarwal/p3selenium

Step 1: Extract the zip file and put it in your workspace
Step 2: Open Eclipse IDE.
Step 3: Go to File > Import
Step 4: Import window will open, select Existing Projects into Workspace under General category

Import

Step 5: Now to run different tests you have to make an entry in testng.xml file. Below is the testng.xml file used in p3selenium framework

Step 6: To run the test, right click on the project go to “Run As” > Maven test.
NOTE: When you run the project first time it may take time because it will download some required jar files.

Step 7: Now, we have to see the reports.
Reports will get generated at the end of the test execution and to see the reports you have to open the index.html file which is under target>surefire-reports>html>index.html

How to Start Scripting using P3selenium Framework

Before see how to Start Scripting using P3selenium Framework let’s first see the structure of the p3selenium framework, it will give the better understanding in scripting.

Project Structure:

p3selenium folder structure

P3selenium built with robust folder structure. We have attached a info file with each folder which tells you the use of that folder.

Now let’s start with the scripting.
P3selenium framework has WebDriverFactory class that contains all methods that selenium framework contains. These methods are redefine so that they can be used easily and also this class has given additional methods other than methods provided by selenium webdriver, those methods will be explained later in the post or post series.
To use WebDriverFactory we need to first create the object of WebDriverFactory class.

then to use methods of the WebDriverFactory follow the below syntax:

element_name and element_type are string type.

element_type can be anything like name, css, link, class, id, name, value, label, xpath, tag and partialLinkText.

WebDriverFactory class have below methods:

WebDriverFactory Outline

WebDriverFactory class act as addon while scripting, suppose you want to move over an element then you can use mouseOver method by using following code:

these methods can be called in the same way by creating wdf object. Like for click method you have to write the following code:

 

One great advantage of using this framework is the *robust exception handling mechanism*. For example, during searching of element on the page if an exception occurs then the framework itself handles it and tells you the exact line where the error occurs rather then saying no such element.

Other methods like:

  • findElement
  • get
  • getCurrentUrl
  • getPageSource
  • getTitle
  • getWindowHandle
  • getWindowHandles
  • manage
  • navigate
  • quit

can be used by writing getDriver().method_name(); or driver.method_name(); in your scripts.

You can use findElement() in two ways:
1. either way you write the code by directly calling the method on driver object driver.findElement(By by)
2. or by creating object of WebDriverFactory, for example –

Special features:
Ready to Use Functions
There are some methods that you might need while scripting

Consider a situation where you want to find an element(s) in a table:
Sometimes you may encounter with the table on a web page.
Like

heading1 heading2
value1 value2
value1 value2
end1 end2

structure, where you may face difficulty to write the generic code to locate an element. We have made it possible, call below function to locate the element in the table

We are developing a demo site where you can test all the functionality of this framework, Stay Tuned :)