Selenium Web Driver 2.0 Setup and Create First Project

For Quick View visit my you tube video –Setup and Create First Project

Introduction

  • Selenium 2 (Selenium WebDriver) = Selenium 1.0 + WebDriver
  • I will not go in detail to explain selenium 1.0. It just include selenium IDE + Selenium RC and Selenium Grid
  • Selenium 2 has included selenium 1.0 + WebDriver
  • Selenium WebDriver is designed in a simpler and more concise programming interface along with addressing some limitations in the Selenium-RC API
  • Support various programing language to write Test Script (ex. Java, Paython, C#,Ruby,Php..)
  • Support various browsers to Test (ex. Chrome, FireFox, IE, Safari)
  • Support on various OS (ex. Windows, Linux, Mac)
  • Selenium-WebDriver was developed to better support dynamic web pages where elements of a page may change without the page itself being reloaded.
  • WebDriver’s goal is to supply a well-designed object-oriented API that provides improved support for modern advanced web-app testing problems.

Setup

Create First Selenium Project

  • Launch the Eclipse IDE
  • Create new project or Open project
  • Configure Build Path (Right click on Project > Build Path > Configure Build Path or Go to Project Properties)
  • Open Libraries tab under Java Build Path
  • Add External Jars ( Selenium xx all Jars)
  • Write Test Script for each Test Step

Test Scenario – Successful Login with valid credential in http://phptravels.net

Test Case – Login with valid username and password

Test Steps :

  1. Open Firefox driver
  2. Open Login page url – http://phptravels.net/login
  3. Enter valid email id – user@phptravels.com
  4. Enter valid password – demouser
  5. Press Login button
  6. Verify that user successfully login into the site and display user name on left top corner – John Smith
  7. Close the browser

Scripts:

package SmokTest;

 

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.Assert;

public class Login {

public static void main(String[] args) throws InterruptedException {

// TODO Auto-generated method stub

System.setProperty(“webdriver.chrome.driver”, “C:\\chromedriver_win32\\chromedriver.exe”);

WebDriver driver = new ChromeDriver(); // Step 1 – Open Firefox Browser

//WebDriver driver = new FirefoxDriver();

driver.get(“http://phptravels.net/login”); // Step 2 – Open Web app URL

System.out.println(“Launches Chrome browser successfully”);

driver.findElement(By.name(“username”)).sendKeys(“user@phptravels.com”); //step 3

driver.findElement(By.name(“password”)).sendKeys(“demouser”); //step 4

driver.findElement(By.xpath(“.//*[@id=’loginfrm’]/div/div[5]/div/div/div[1]/button”)).click(); //step 5

Thread.sleep(5000);

String WelcomeMsg = driver.findElement(By.xpath(“.//*[@id=’top’]/div[5]/div[1]/div[1]/h3”)).getText();

System.out.println(“Welcome :”+WelcomeMsg);

Assert.assertEquals(“Hi, John Smith”, WelcomeMsg, “Not matched Login msg”);

driver.close(); // Close the browser

}

}

Advertisements

About samp79

Professional Automation Tester
This entry was posted in Selenium, Set up. Bookmark the permalink.

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