Showing posts with label Maven. Show all posts
Showing posts with label Maven. Show all posts

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.
  1. Launch the Eclipse IDE.
  2. Create a new project by selecting [File -> New -> Other] from Eclipse Main Menu.
  3. On the New dialog, select [Maven -> Maven Project] as shown in the following screenshot:

  1. 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: 

  1. 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:


  1. 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.       
  1. 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.
  2. 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>

  1. 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!

Tuesday, 4 February 2014

Working with Selenium WebDriver and Cucumber without Maven

Download jar files

List of jar file needed to configure Cucumber is as follows -
1.       cucumber-core-1.1.5.jar
2.       cucumber-html-0.2.3.jar
3.       cucumber-java-1.1.5.jar
4.       cucumber-junit-1.1.5.jar
5.       cucumber-jvm-deps-1.0.3.jar
6.       gherkin-2.12.2.jar
7.       hamcrest-core-1.3.jar
8.       jchronic-0.2.6.jar
9.       Junit-4.11.jar
10.     Selenium-server-standalone-2.39.0.jar


Create Cucumber Project in Eclipse

1. Go to [File -> New -> Java Project]

2. Enter project name in [Project Name] field

3. Click on [Finish] button

4. Delete [src ] folder of this project

5. [Right click on Project folder] & select [Source Folder]

6. Enter value [src/test/resources] in [Folder Name] field

7. Click on [Finish] button

8. [Right click on Project folder] & select [Source Folder]

9. Enter value [src/test/java] in [Folder Name] field

10. Click on [Finish] button

11. [Right click on Project folder] & select [Source Folder]

12. Enter value [src/main/java] in [Folder Name] field

13. Click on [Finish] button


14.  Add above downloaded jar file into Build path of your Selenium Project.