Site icon TestingDocs.com

Learning Selenium WebDriver

Introduction

Selenium Webdriver is a set of API’s that automates browsers. Primarily, it is used for automating web applications for Functional Testing purposes. Learning Selenium is easy.

In this post we will set up java, eclipse, and selenium to run a sample program in Selenium.

Prerequisites: Windows or Linux Machine

 

 

Java JDK Installation:

https://www.testingdocs.com/download-and-installing-java-jdk/

Eclipse Installation:

https://www.testingdocs.com/downloading-and-extracting-eclipse-ide/

Create a Maven project.

Setup and Configuration of Selenium in Eclipse is very easy using Maven. New to Maven?

Please have a look at: What is Maven ?

How to create a new maven project.

File -> New -> Maven Project.

Create a simple project, choose skip archetype selection. Enter the project name and hit Finish.

Now we will add Selenium dependency to Our project. Add the below dependencies to pom.xml.

Eclipse would automatically download the dependencies and builds the workspace automatically.

Tip: Hit Ctrl+S keyboard combination to save.

 

<dependencies>
  	<dependency>
  		<groupId>org.seleniumhq.selenium</groupId>
  		<artifactId>selenium-server</artifactId>
  		<version>2.53.1</version>
  	</dependency>
  
  	<dependency>
  		<groupId>org.seleniumhq.selenium</groupId>
  		<artifactId>selenium-api</artifactId>
  		<version>2.53.1</version>
  	</dependency>

  	<dependency>
  		<groupId>org.seleniumhq.selenium</groupId>
  		<artifactId>selenium-java</artifactId>
  		<version>2.53.1</version>
  	</dependency>

        <dependency>
  		<groupId>org.seleniumhq.selenium</groupId>
  		<artifactId>selenium-remote-driver</artifactId>
  		<version>2.53.1</version>
  	</dependency>

  <dependency>
  		<groupId>org.seleniumhq.selenium</groupId>
  		<artifactId>selenium-firefox-driver</artifactId>
  		<version>2.53.1</version>
  	</dependency>
  	
  </dependencies>

 

You can check the added dependencies and any conflicts, also as shown below.

Expand the project and right-click pom.xml and open it with Maven POM editor as shown in the picture.

 

Switch to the dependencies tab and click on Add.. button to add a dependency.

Type selenium in the textbox and hit enter, choose the dependencies you want, and add them to the project. To practice different programs using Selenium choose all the dependencies.

After adding the dependencies save them.For example, IE Driver maven dependency :

<dependency>
  <groupId>org.seleniumhq.selenium</groupId>
  <artifactId>selenium-ie-driver</artifactId>
  <version>2.53.1</version>
</dependency>

Create a sample Selenium first program

Create a new class and choose the main method while creating as shown in below figure.

 

Now type the following program code :

package demo;
 
import org.openqa.selenium.firefox.FirefoxDriver;
 
public class FirstProgram {
 
  public static void main(String[] args) {
    
  FirefoxDriver fox = new FirefoxDriver(); 
  fox.get("http://www.google.com"); 
    fox.close();
 
  }
 
}

 

Run the program to see Firefox open, Browse Google search engine page and close.

 

Selenium WebDriver Tutorials on this website can be found at:

https://www.testingdocs.com/selenium-webdriver-tutorial

For more details on the Selenium, visit the official website at:

https://www.selenium.dev/

Save

Exit mobile version