Selenium Quick Guide

Selenium WebDriver Quick Guide
 

1) Introduction to Selenium WebDriver

2) Selenium WebDriver Environment Setup

3) Write outset Selenium Test Case

4) Web Elements together with Operations.

5) Element Locators

6) Selenium WebDriver Commands together with Operations

7) Handling Elements inwards Selenium

8) Cross Browser Testing

9) Writing Selenium Test Cases.

10) Writing Selenium Test Cases using User defined Methods
 Selenium WebDriver Commands together with Operations Selenium Quick Guide
--------------------------------------------------------------------
1) Introduction to Selenium WebDriver

• Selenium WebDriver was launched at Google In 2006.

• In 2008, the whole Selenium squad decided to merge Selenium Webdriver amongst Selenium RC inwards lodge to cast to a greater extent than powerful tool called Selenium 2.0.

Selenium 1.0 + Selenium WebDriver  = Selenium 2.0

Selenium 1.0

(Selenium IDE + Selenium RC + Selenium Grid)

Selenium 2.0

(Selenium IDE + Selenium RC + Selenium WebDriver + Selenium Grid)

Note: Now Selenium RC is solely for maintenance projects.


Selenium three (Latest Version released inwards Oct 2016)
----------------------------------------
Selenium WebDriver Features

• Selenium WebDriver supports diverse programming languages(Java, C#, Python, Ruby, Perl together with PHP) to write programs (Test Scripts)

• Selenium WebDriver supports diverse Browsers (Mozilla Firefox, Google Chrome, IE, Safari, Opera etc...) to exercise together with execute Test cases.

• Selenium WebDriver supports diverse operating environments(MS Windows, Linux, Macintosh etc...) to automate Web Applications.

• Selenium WebDriver supports Data Driven Testing together with Cross Browser Testing

• Selenium WebDriver supports Batch Testing amongst the assistance of either JUnit or TestNG framework.


• Using Element Locators together with WebDriver Methods /Commands nosotros tin give the sack exercise Test Cases.
----------------------------------------
Drawbacks of Selenium WebDriver

• Selenium WebDriver doesn't get got IDE (takes to a greater extent than fourth dimension together with to a greater extent than efforts to exercise Test cases)

• No built inwards Result Reporting facility.

• No other tool integration for Test Management.
---------------------------------------------------

2) Selenium WebDriver Environment Setup

Steps:

i) Download together with install Java (JDK) software. - To exercise together with execute programs (Test scripts)

ii) Set Environment variable path (Path Variable) - To usage Java from whatsoever directory.

iii) Download Eclipse IDE together with extract. - To write together with execute Java programs.

iv) Download Selenium WebDriver Java Language binding (from www.seleniumhq.org) together with add together WebDriver jounce files to Java projection inwards Eclipse IDE.
------------------------------------------------ 
Download Selenium WebDriver Java linguistic communication binding together with extract.

Add Selenium WebDriver jounce files to Java projection inwards Eclipse IDE.

Navigation to add together Selenium Webdriver jounce files to Java Project:

> Launch Eclipse IDE
> Create Java Project
> Select Java projection together with correct click
> Build path
> Configure Build path
> Select Libraries tab
> Click "external jars"
> Browse path of Selenium Webdriver jars.
> Add
--------------------------------------
Create Selenium WebDriver Test Case

> Create driver object past times importing WebDriver together with Firefox/IE/Chrome libraries(In The Test Case/Program).

> Using Element Locators together with WebDriver Commands/Methods write Test Steps.

> Insert Java programming statements to heighten Test cases.
---------------------------------------- 

3) Write First Selenium Test Case

Manual Test Case:

Test Case ID: gcrshop_admin_TC001

Test Case Name: Verify Admin Login inwards GCR Shop spider web portal

Test Steps:

i) Launch the Browser together with navigate to "www.gcrit.com/build3/admin"
ii) Enter User name
iii) Enter Password
iv) Click "Login" Button

Input Data / Test Data:

User refer =admin
Password = admin@123

Expected URL: "www.gcrit.com/build3/admin/index.php"

Actual URL: http://www.gcrit.com/build3/admin/index.php

Test Result: Pass
----------------------------------------
Selenium WebDriver Test Case:

public static void main(String[] args) {
WebDriver driver = novel FirefoxDriver();//Launches Firefox Browser amongst blank url.
driver.get("http://www.gcrit.com/build3/admin/login.php");//Naviage to Admin domicile page
driver.findElement(By.name("username")).sendKeys("admin");
driver.findElement(By.name("password")).sendKeys("admin@123");
driver.findElement(By.id("tdb1")).click();

String url = driver.getCurrentUrl();

if (url.equals("http://www.gcrit.com/build3/admin/index.php")){
System.out.println("Login Successful - Passed");   
}
else {
System.out.println("Login Unsuccessful - Failed");
}
driver.close();//Closes the Browser
}
}
------------------------------------------------

4) Web Elements together with Operations

Browser
Page
-----------
Edit box, Link, Button, Image, Image link, Image button, Text Area, Check box, Radio Button, Drop downwards box, List box, Combo box, Web Table /HTML Table together with Frame.
------------------------------
i) Operations on Browser

Launch Browser, Navigate to specified URL, Close focused Browser together with Close all opened Browsers.

Navigate from i URL to another, Navigate back, Navigate forward, Refresh the Browser together with Maximize the Browser etc...
------------------------------
ii) Operations on Web Page

Get Page Title, Get Page root together with and Get Page URL etc...
------------------------------
iii) Operations on Edit box

Enter roughly value, Clear the value, Check the Edit box existence, Check enabled condition together with Get the Value etc...
------------------------------
iv) Operations on Link

Click, Check the Link existence, Check enabled condition together with Return Link refer etc...
------------------------------
v) Operations on Image

a) General Image

b) Image Button (Submits)

c) Image Link (Click, Redirects to roughly other page/location)
------------------------------
vi) Operations on Check box

Select, Unselect, Check if the banking concern jibe box is displayed or not? together with Check if the banking concern jibe box is enabled or not? etc...
------------------------------
vii) Operations on Button

Click, Check the Button enabled statues together with Check Displayed condition etc...
------------------------------
viii) Operations on Text Area

Return or Capture Text Area
------------------------------
ix) Operations on Radio Button

Select Radio Button, Check the Radio Button existence, Check the enabled condition together with Verify if the Radio push is Selected or not?
------------------------------
x) Operations on Drop downwards box

Select an Item, Check the Drop downwards box existence, Check the enabled condition together with Return Items Count.
------------------------------
xi) Operations List Box

Select i to a greater extent than items, Return Items count, Check the List box beingness together with Check the enabled status.
-------------------------------
xii) Operations on Combo box

Select an item, Enter an item, Check the Combo box beingness together with Check the enabled status.
--------------------------------------
xiii) Operations on Web Table /HTML Table

Get Cell value, Rows count together with Cells count etc...
--------------------------------
xiv) Operations on Frame

Switch from Top window to a frame together with Switch from a frame to Top window.
-------------------------------------------------- 

5) Element Locators
 

> Element Locator is an address that identifies a Web Element uniquely inside the spider web page.

> Selenium supports 8 Element locators to recognize Elements, they are id, name, className, tagName, linkText, partialLinkText, cssSelecotor together with xpath to detect elements on Web Pages.

> We tin give the sack usage anyone unique Locator to recgnize an Element.

i) id

Syntax:

By.id("id value")

Example:

driver.findElement(By.id(("Email"))
------------------------------
driver - is Object, findElement is Webdriver Method/command, By is Class, id is Locator together with Email is value.
--------------------------------
ii) name

Syntax:

By.name("value")

Example

driver.findElement(By.name("Email"))
--------------------------
iii) className

Syntax:

By.className("value")

Example:

driver.findElement(By.className("textboxcolor")).sendKeys("India");
-------------------------------------------
iv) tagName

Syntax:

By.tagName("value")

Example:

driver.findElement(By.tagName("input")).sendKeys("India");
------------------------------------
v) linkText

Syntax:

By.linkText("value")

driver.findElement(By.linkText("Gmail")).click();
----------------------------------
vi) partialLinkText

Syntax:

By.partialLinkText("value")

driver.findElement(By.partialLinkText("Gma")).click();
---------------------------
vii) cssSelector

Syntax:

By.cssSelector("value")

Example:

driver.findElement(By.cssSelector(".gb_P")).click();
---------------------------------------
viii) xpath

Syntax:

By.xpath("value")

Example:

driver.findElement(By.xpath(".//*[@id='gbw']/div/div/div[1]/div[1]/a")).click();
------------------------------------------------------

6) Selenium WebDriver Commands together with Operations

> Selenium WebDriver Methods/Commands are used to perform operations on Web Elements.

> Using Element Locators together with WebDriver Methods/Commands nosotros exercise Test Cases.

Element Locators - for recognizing Elements

WebDriver Methods - for performing operations on Elements.
-----------------------------------
i) get()

Description: Opens a specified URL inwards the Browser window.

Syntax:

driverObject.get("URL");

Example:

driver.get("https://www.google.co.in");
------------------------------------
ii) getTitle()

Returns Title of the Browser.

Syntax:

String variable = driver.getTitle();

Example:

driver.get("https://www.google.co.in");
String Title = driver.getTitle();
System.out.println(Title);
--------------------------------------------
iii) getPageSource()

Returns HTML page source.

Syntax:

String stringName = driver.getPageSource();

Example:

driver.get("https://www.google.co.in");
String pageSource = driver.getPageSource();
System.out.println(pageSource);
----------------------------------
iv) getCurrentUrl()

Returns Current URL of the Browser.

Syntax:

String stringName = driver.getCurrentUrl();

Example:
driver.get("https://www.google.co.in");
String URL = driver.getCurrentUrl();
System.out.println(URL);
-------------------------------
Browser Navigation Methods

v) navigate().to()

Loads a novel spider web page inwards the electrical current browser window.

Syntax:
driverObject.navigate().to("URL");

Example:

driver.get("https://www.google.co.in");
String URL = driver.getCurrentUrl();
System.out.println(URL);
driver.navigate().to("https://login.yahoo.com/");
URL = driver.getCurrentUrl();
System.out.println(URL);
-------------------------------------
vi) navigate().back()

It moves a unmarried exceptional dorsum inwards the Browser history.

Syntax:

driver.navigate().back();

Example:

driver.get("https://www.google.co.in");
String URL = driver.getCurrentUrl();
System.out.println(URL);
driver.navigate().to("https://login.yahoo.com/");
URL = driver.getCurrentUrl();
System.out.println(URL);
driver.navigate().back();
URL = driver.getCurrentUrl();
System.out.println(URL);
-----------------------------------
vii) navigate().forward()

It moves unmarried exceptional frontwards inwards the Browser history.

Syntax:

driver.navigate().forward();

Example:

driver.get("https://www.google.co.in");
String URL = driver.getCurrentUrl();
System.out.println(URL);

driver.navigate().to("https://login.yahoo.com/");
URL = driver.getCurrentUrl();
System.out.println(URL);

driver.navigate().back();
URL = driver.getCurrentUrl();
System.out.println(URL);

driver.navigate().forward();
URL = driver.getCurrentUrl();
System.out.println(URL);
-----------------------------------
viii) navigate().refresh()

Refresh the electrical current spider web page

Syntax:

driver.navigate().refresh()

WebDriver driver = novel FirefoxDriver();
driver.get("https://www.google.co.in");
String URL = driver.getCurrentUrl();
System.out.println(URL);
driver.navigate().refresh();
URL = driver.getCurrentUrl();
System.out.println(URL);
------------------------------------
ix) close()

It closes the focused Browser.

Syntax:

driverObject.close();

Example:

driver.get("https://www.google.co.in");
driver.close();
-----------------------------------
x) quit()

It closes all browser that opened past times WebDriver during execution.

Syntax:

driverObject.quit();

Example:

driver.get("file:///C:/Users/gcreddy/Desktop/HTMLExamples/LoginPage.html");
driver.findElement(By.linkText("Sign In")).click();
driver.quit();
-----------------------------------
xi) findElement()

It finds the outset chemical constituent inside the electrical current page using the give locator.

driver.findElement(By.ElementLocator("Value"))

Syntax:
WebDriver driver = novel FirefoxDriver();
driver.get("file:///C:/Users/gcreddy/Desktop/HTMLExamples/LoginPage.html");
driver.findElement(By.tagName("input")).sendKeys("abcd");

Or

WebElement Email = driver.findElement(By.id("Email"));
Email.sendKeys("India");
-----------------------------------
xii) sendkeys()

Enters a value into Edit box/Text box

Syntax:
driver.findElement(By.ElementLocator("value").sendkeys("input data");

Example:

driver.get("https://www.gmail.com");
driver.findElement(By.id("Email")).sendKeys("India");
}
-----------------------------------
xiii) clear()

It clears the value

Syntax:
driver.findElement(By.ElementLocator("value").clear();

Example:
driver.get("https://www.gmail.com");
driver.findElement(By.id("Email")).sendKeys("India");
Thread.sleep(5000);
driver.findElement(By.id("Email")).clear();
-----------------------------------
xiv) click()

Clicks an Element (Buttons, Links)

Syntax:

driver.findElement(By.ElementLocator("value").click;

Example:

driver.get("https://www.gmail.com");
driver.findElement(By.id("next")).click();
-----------------------------------
xv) isEnabled()

It checks conditions the Element is inwards enabled nation or not?

Syntax:

boolean variableName = driver.findElement(By.ElementLocator("value").isEnabled();

Example:

driver.get("https://www.gmail.com");
boolean a = driver.findElement(By.id("next")).isEnabled();
System.out.println(a);
-----------------------------------
xvi) isDisplayed()

Checks if the Element is displayed or not? inwards the electrical current spider web page.

Syntax:

boolean variableName = driver.findElement(By.ElementLocator("value").isDisplayed();

driver.get("https://www.gmail.com");
boolean a = driver.findElement(By.id("next")).isDisplayed();
System.out.println(a);
-----------------------------------
xvii) isSelected()

checks if the Element is Selected or not? inwards the electrical current spider web page.

Syntax:

boolean variableName = driver.findElement(By.ElementLocator("value").isSelected();

example:

driver.get("file:///C:/Users/gcreddy/Desktop/HTMLExamples/MultipleCheckbox.html");
boolean a = driver.findElement(By.xpath("html/body/input[2]")).isSelected();
System.out.println(a);//false
driver.findElement(By.xpath("html/body/input[2]")).click();
a = driver.findElement(By.xpath("html/body/input[2]")).isSelected();
System.out.println(a);//true
-----------------------------------
xviii) manage().window().maximize()

Syntax:

driverObject.manage().window().maximize()

Example:

driver.get("file:///C:/Users/gcreddy/Desktop/HTMLExamples/MultipleCheckbox.html");
Thread.sleep(5000);
driver.manage().window().maximize();
------------------------------------------- 

8) Cross Browser Testing

> Cross Browser Testing is a type of Test to banking concern jibe that our Web Application plant equally expected inwards dissimilar Browsers.

> Influenza A virus subtype H5N1 spider web application tin give the sack last opened inwards whatsoever spider web browser past times the destination user, So nosotros require to ensure that the spider web application volition piece of occupation equally expected inwards all pop browsers.


Note: Selenium WebDriver Test Case is mutual for all Browsers, browser driver only varies from i Browser to another

 
a) Create Browser Drivers

(For Google Chrome, IE together with Other Browsers, download Browser drivers together with railroad train path inwards Selenium Test Scripts)

i) Mozilla Firefox Browser:

WebDriver driverName = novel FirefoxDriver();

ii) Google Chrome

//Instantiate Chrome Browser driver

System.setproperty("webdriver.chrome.driver", "driver .exe file path");
WebDriver driverName = novel ChromeDriver();

iii) IE Browser driver

System.setproperty("webdriver.ie.driver", "driver .exe file path");
WebDriver driverName = novel InternetExplorerDriver();
------------------------------------------------------
b) Create a Test Case together with Execute using Mozilla Firefox, Chrome together with IE Browsers.

Test Case: Verify Launch Application (Google) functionality inwards Firefox, Chrome together with IE Browsers.

Steps:
i) Launch the Browser
ii) Navigate to https://www.google.com url

Verification point:
Capture the page Title (Actual) together with Compare amongst Expected.

Expected Page Title:
--------------------------------
i) Test Case for Mozilla Firefox Browser

WebDriver driver = novel FirefoxDriver();
driver.get("https://www.google.com");

String PageTitle = driver.getTitle();

if (PageTitle.equals("Google")){
System.out.println("Google Application Launched - Passed");
}
else {
System.out.println("Google Application Not Launched -Failed");   
}
driver.close();
------------------------------
ii) Test Case for Google Chrome Browser

System.setProperty("webdriver.chrome.driver", "E:\\chromedriver.exe");
WebDriver driver = novel ChromeDriver();
driver.get("https://www.google.com");

String PageTitle = driver.getTitle();

if (PageTitle.equals("Google")){
System.out.println("Google Application Launched - Passed");
}
else {
System.out.println("Google Application Not Launched -Failed");   
}
driver.close();
------------------------------
iii) Test Case for meshing Explorer Browser

System.setProperty("webdriver.ie.driver", "E:\\IEDriverServer.exe");
WebDriver driver = novel InternetExplorerDriver();
driver.get("https://www.google.com");

String PageTitle = driver.getTitle();

if (PageTitle.equals("Google")){
System.out.println("Google Application Launched - Passed");
}
else {
System.out.println("Google Application Not Launched -Failed");   
}
driver.close();
--------------------------------------

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