Here we will see the Configuration Steps of P3selenium.
Java should be installed in the system
TestNG and Maven should be installed in eclipse
NOTE: We are using “Eclipse Juno” in this example
You can get P3selenium framework from Github, use the following URL to download the zip
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
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
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite> is kind of root tag in testng.xml file. All test are defined in suite using <test> tag
We can define parameters under suite. Parameter defined here passes with every class defined in the test
<parameter name="browser"value="chrome" />
<parameter name="excel_name"value="none" />
We have given name to our test that is P3testing. There can be multiple <test> tags in a suite
These are our classes. Each class represent one testcase
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
In this post we will see Selenium webdriver and Grid Integration, you will get the answers of the following questions:
What is Selenium Grid?
How it is useful?
Requirements of Selenium Grid
How to Setup Selenium Grid?
Selenium grid is a way using which we can run our automated script on other system (prerequisite: they should be in LAN).
You need the selenium standalone server on both the machines i.e. on hub machine and on node machine.
Machine on which the selenium framework or script is actually present is the hub machine and the other machine on which we are intended to execute the script are the node machine.
Step – 1: open command prompt on the hub machine or on the machine which you want to make hub.
Step – 2: Goto the folder where you put the selenium standalone server, then execute the following command: java -jar selenium-server-standalone-2.41.0.jar -role hub
once this command executed your hub is ready to for the node to connect.
Step – 3: You can check hub is running by clicking the view config of the URL: http://localhost:4444/grid/console
Now go to another system which you want to make node, you just need the selenium standalone server and browser specific driver on this machine but not the complete framework as like you have on hub machine.
Put both the jars in same folder.
Open command prompt and go to the respective folder and execute the following command (By using below command we are registering chrome driver)
once you executed the node command, open the http://localhost:4444/grid/console
you will see node details, see below image
Now you have to tell selenium framework on hub machine to run the test script on the registered node.
Below is the code snippet:
NOTE: p3selenium framework already grid enabled you just have to set use_grid=true in config.properties (https://github.com/AbhishekAggarwal/p3selenium/blob/master/src/test/resources/config.properties) and p3selenium framework works in grid mode.
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.
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 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:
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 –
In this article we will talk about the Use and Benefits of p3selenium.
Use of P3selenium framework and benefits:
First thing first, before proceeding we would like to see the benefits of using this framework. Some of the benefits of the P3selenium framework are listed below:
Scalable: This framework allows you to add new features can easily
Maintainable: This framework follows a robust package structure that allows you to maintain and manage your automated scripts in an easy way. It helps you to keep your scripts in a manageable way. You can manage and run as many scripts as needed.
Boilerplate code: P3selenium can be used as a boilerplate code, you do not have to write the code to create a framework for automation testing, just pick the P3selenium and start scripting your application scenarios from day one.You can keep your scripts under com.p3selenium.scripts.pname.testcase
Centralized exception handling: Besides stack trace information, the framework assists you by letting you know the which line of code throws an error. We have built a robust framework by using a centralized exception handling mechanism. Any one using P3selenium framework can take advantage of this.Suppose an exception occurs while script execution then it this framework handles the exception and gives you a useful message that let you quickly identify the exception occurred.
Database Testing: Adding this feature to the framework, this feature will be added in second release i.e. p3selenium_v1.0
Grid Enabled: P3selenium framework is grid enabled, it contains all the settings that is required to run the framework as a grid.