A blog on Selenium WebDriver, Java, VB Script, Software Testing, SOAPUI, Groovy, SOA Testing, Mobile Testing, Appium etc.
Wednesday, 28 October 2015
Saturday, 3 October 2015
Create selenium WebDriver project in eclipse with Apache maven
The Problem
I often see Selenium practitioners ask that I have downloaded necessary resources to work on Selenium WebDriver. But, What should be project structure, how to manage dependencies, How to do build and test management etc.
A Solution
By leveraging Apache Maven in our test framework, we can manage entire life-cycle of a test project. It provides support to define project structure, download the project dependencies libraries automatically, build and test management etc. Maven allows us to get all the Selenium libraries files and their dependencies by configuring the pom.xml (POM – Project Object Model) file.
Let’s dig in with an example
An Example
We will use Eclipse IDE and Maven for building the Selenium WebDriver test framework.
- Launch the Eclipse IDE.
- Create a new project by selecting [File -> New -> Other] from Eclipse Main Menu.
- On the New dialog, select [Maven -> Maven Project] as shown in the following screenshot:
- Click on [Next], the New Maven Project dialog will be displayed. Select the [Create a simple project (skip archetype selection)] check-box and set everything to default and click on the Next button as shown in the following screenshot:
- On the New Maven Project dialog box, enter base package name (like com.myproject.app) in Group Id and project name (like myproject) in Artifact Id textboxes. You can also add a name and description but it is optional. Set everything to default and click on the [Finish] button as shown in the following screenshot:
- Eclipse will create the myproject project with a structure (in Package Explorer) similar to the one shown in the following screenshot:
7.
7. The JRE version might change based on the Java version installed on your machine.
Right-click on JRE System Library [J2SE-1.5] and select the Properties option from the
menu.
- Select pom.xml from Package Explorer. This will open the pom.xml file in the editor area with the Overview tab open. Select the pom.xml tab instead.
- Add the WebDriver and TestNG dependencies highlighted in the following code snippet, to pom.xml in the <project> node:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myproject.app</groupId>
<artifactId>myproject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>2.42.2</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.8</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
<testResource>
<directory>src/test/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
/project>
- Right click on pom.xml from Package Explorer & Select [Run As -> Maven Install]
Conclusion
If you'd like to see the code and example used in the above project, you can find them here.
Happy Testing!
Test Automation Framework using Jenkins, GitHub, Maven, Selenium Grid, and TestNG
The Problem
You’re looking to automation web application using Selenium WebDriver for a full end-to-end / UI automation testing, there could be many challenges -
Challenge 1 - Selenium tests take a long time to run, how to speed up test execution, How to run script across the browser
Challenge 2 - Your team is distributed across geography, how team members develop, debug & update would test scripts at a central repository.
Challenge 3 - How to make sure code is not broken & there is no build failure after last night script update?
Challenge 4 - Who will own the responsibility to run script & share execution result (success/failure) with team & stakeholder?
Challenge 5 - How to manage project dependency & make sure across the team same version of jar file is used.
A Solution
Solution 1 - By leveraging Selenium Grid, we could speed up test execution & reduce test execution time. It provides ability to run parallel execution of test cases on multiple browser and operating system. Setup a Selenium Grid hub and nodes to run a battery of Selenium tests quickly.
Solution 2 - By leveraging Git/GitHub (private/public code repository) we can maintain web-based code repository and source code management, where every team member can upload their test scripts. It also provides access control and collaboration features such as wikis, task management, and bug tracking and feature requests for every project.
Solution 3 & 4 – By leveraging Jenkins, once configured on a central machine, it runs Selenium tests automatically several times a day (or as scheduled), or even each time there is a code commit (It allows to schedule build with GitHub with the git-plugin to run job on each commit, success/failure report is shared with stakeholder via email upon completion of build job).
Solution 5 - By leveraging Apache Maven in our test framework, this is a software project management and comprehension tool. Based on the concept of a project object model (POM),Maven manages a project's resource, build, reporting and documentation from a central piece of information.
General workflow
Maintain two branches on GitHub – Master & Stable. All new development & changes happens in branch Master. Stable branch contains successfully executable test scripts.
- Push changes to a branch Master or Initiate a Script run by clicking on [Build Now] on Jenkins Project page
- Jenkins detects a change pushed to Master
- Jenkins pulls in the latest changes & begins to run Selenium tests
- Upon completion of test execution, Jenkins sends execution report via email to configured email ID
Let’s dig in with an example
An Example
Jenkins CI to manage test execution & nodes from single interface -
POM.xml which manages project dependency, goal & project lifecycle -
Test Java class which has tests for AUT
Test Execution Report
Conclusion
If you'd like to see the code of above mentioned project, please write to us.
Happy Testing!
Cucumber vs TestNG : Which is better?
I have been a long time user of TestNG. Few months back, I started exploring about Cucumber. It was a wish from my client to create automation framework using Cucumber. I searched on web & found many blogs on Cucumber & its implementation. I started with assumption that Cucumber will replace TestNG. After working for few months, I came to following conclusion they are as follows -
Cucumber
|
TestNG
|
|
|
Thursday, 1 October 2015
R code to get the column Name having null value
R Quick Solution:
Problem: What to know which columns have NULL value in dataset?
Solution:
Data set: r_data
> for(varr in names(r_data))
{
print(varr)
print(sum(is.na(r_ data[varr])))
}
Output:
[1] "SD_ID"
[1] 0
[1] "ZIP"
[1] 0
[1] "COUNTY"
[1] 0
[1] "LATITUDE"
[1] 20
[1] 0
[1] "ZIP"
[1] 0
[1] "COUNTY"
[1] 0
[1] "LATITUDE"
[1] 20
It
means variable Latitude has 20 missing values. So you to investigate it
and substitute the missing value based on your business requirement.
Subscribe to:
Posts (Atom)