Setup Environment For Selenium

Goals/Requirements

Before starting to setup things lets lets clearify our requirements for the setup and the course

  • We want to be able to write Selenium scripts but not individual scripts, but with a more organized and robust structure
  • We will be using Java as the main programming language for writing the scripts, so the latest jdk will be required
  • A build/testing tool, so we will be using Maven for the purpose with ofcourse Junit
  • Based on the target web browser we might need to download different WebDriver executables(Firefox does not need any WebDriver)

Setup

After installing Java and Maven just follow these steps:

  • Create a folder and inside that create a pom.xml file which can have the following content:
  • <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>org.learning.asl</groupId>
    <artifactId>selasl</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    
    <name>selasl</name>
    <url>http://maven.apache.org</url>
    
    <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    
    <dependencies>
    <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.11</version>
    <scope>test</scope>
    </dependency>
    <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>2.45.0</version>
    </dependency>
    </dependencies>
    </project>
    
  • From the command prompt simply go to the same directory where the pom.xml file is and run the following command: mvn clean install
    It will read the pom.xml file and download all the dependencies for you
  • After finishing you can see the traget directory created
  • Create the following directory structure right next to the target directory, notice that the structure should be similar to the groupId specified in the pom.xml
         src
         |--main
         |  |----java
         |  |--------org
         |  |-----------learning
         |  |-------------------asl
         |  |----------------------selasl
         |
         |--test
            |----java
            |--------org
            |-----------learning
            |-------------------asl
            |----------------------selasl
  • The main directory is where we will put our non-script files like PageObjects, helper classes and other utils.
  • In the test directory we will put our test scripts

Now everything is setup up and good to go next we will write a simple selenium script and try to understand its working. We will start with a Simple Selenium Webdriver Example.

Advertisements

2 thoughts on “Setup Environment For Selenium

  1. Pingback: Selenium Components-Selenium IDE and Webdriver | cubcode
  2. Pingback: Simple Selenium Webdriver Example in Java | cubcode

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s