Selenium WebDriver Tutorial


Selenium WebDriver

> It is a virtually of import tool inwards Selenium Suite(Others are Selenium IDE, Selenium RC too Selenium Grid).

> It is an Interface (Programming Interface) allows us to execute tests
against dissimilar browsers (ex: Firefox, IE, Chrome etc...)

> WebDriver enables us to endure dissimilar programming languages to practise tests.

Java
.NET
PHP
Perl
Python
Ruby
---------------------------
WebDriver Environment Setup:

> Download too Install Java (on OS(Ex: Microsoft Windows))

> laid upwards path Environment variable

> Download too unzip Eclipse software

> Download WebDriver Java linguistic communication binding too Add webDriver appall files (in EClipse)

> Install Firebug plug-in for Firefox Browser (Install on FireFox) to inspect Web elements.
---------------------------------------------------
Navigation to Add WebDriver Jar files inwards eclipse:
Create Java Project
> Select src too correct click
> Build Path
> Configure Build Path
> Select Libraries tab
> Click on "Add External JARs
> Browse path of the webDriver jars
> Add
-----------------------------------
Pre-requisites to practise Automated Tests:
-----------------------------------------
> Import WebDriver Libraries too Firefox driver library
    
> Create driver object

> Using spider web chemical gene (Object) locaters(properties) too Methods, write object telephone phone statements.

> Insert coffee programmatic statements to lift tests.
---------------------------------------------------------- 

WebDriver Sample Programs:
1) Launch Firefox Browser, Navigate to Google home, Capture the Title too Display.
package WebDriverSample;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public cast GetBrowserTitle {
    populace static void main(String [] args){
    WebDriver driver = novel FirefoxDriver(); // Launches Firefox Browser amongst blank url
    driver.get("https://www.google.com"); // Navigates to the specified URL
    String Title = driver.getTitle();
    System.out.println(Title);
    driver.close(); // Closes the Browser
}
}
-------------------------------------------

2) Launch Firefox Browser, Navigate to Google home, Capture the Title too verify amongst expected:

package WebDriverSample;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public cast GetBrowserTitle {
    populace static void main(String [] args){
    WebDriver driver = novel FirefoxDriver(); // Launches Firefox Browser amongst blank url
    driver.get("https://www.google.com"); // Navigates to the specified URL
    String actual = driver.getTitle();
   
    if (actual.contentEquals("Google")){
        System.out.println("Test Passed");
    }
    else {
        System.out.println("Test Failed");
    }
    driver.close(); // Closes the Browser
}
}
----------------------------------------
3) Launch Google Home page too click on Gmail link
package WebDriverSample;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public cast GetBrowserTitle {
    populace static void main(String [] args){
    WebDriver driver = novel FirefoxDriver(); // Launches Firefox Browser amongst blank url
    driver.get("https://www.google.com");
    driver.findElement(By.linkText("Gmail")).click();
    //driver.close(); // Closes the Browser
}
}
--------------------------------------------------------
4) Gmail Login

/* Gmail Login
 * Steps:
 * i) Launch the Browser
 * ii) Navigate to Gmail Home page
 * iii) Enter Email
 * iv) Enter Password
 * v) Click on Sign in
 */
//---------------------------------------------
package WebDriverSample;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public cast GmailLogin{
    populace static void principal (String []args){
        WebDriver abcd = novel FirefoxDriver(); //i) Launch the Browser
        abcd.get("http:/www.gmail.com"); //ii) Navigate to Gmail Home page
        abcd.findElement(By.id("Email")).sendKeys("gcreddy123"); //Locating Email edit box too entering a value
        abcd.findElement(By.name("Passwd")).sendKeys("selenium123");//Locating Password edit box too entering a value
        abcd.findElement(By.id("signIn")).click(); //Click on Sign in
            }
}
------------------------------------------------
Selenium     UFT
Element -    Object
Locater        Property
--------------------------
// Close Browser

UFT:
'Close the Bower
Browser("title:=Google").Close

'Enter a Value into Edit box
Browser("title:=Google").Page("title:=Google").WebEdit("name:Email").Set "gcrindia"
-------------------------------------------
Selenium:

driver.close();
driver.findElement(By.id("Email")).sendKeys("gcrindia");

abcd.findElement(By.id("signIn")).click();
-------------------------------------------

Sumber http://www.gcreddy.com/
Post a Comment (0)
Previous Post Next Post