Webdriver Script015 : Handling Ajax Elements

/*********************************************************************

Script Summary

Title  : Webdriver Script015 : Handling Ajax Elements
Author : Gaurav Khanna

1. Set the Base URL to "http://www.google.com".
2. Type word 'Testing'
3. Pause for 5 seconds.
4. Print list of names suggested in Ajax Auto Suggested List

 *********************************************************************/

package com.gaurav.webdriver;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class s015_HandlingAjaxElements {

    // Declaring variable 'webDriver' of WebDriver Type
    WebDriver webDriver;

    // Declaring baseURL variable of String Type
    String baseUrl;

    @BeforeMethod
    public void startUp() {

        // Initializing FireFox Driver
        webDriver = new FirefoxDriver();

        // Assigning URL to variable 'baseUrl'
        baseUrl = "http://www.google.com";
    }

    @Test
    public void tests015_HandlingAjaxElements() throws InterruptedException {

        //
        webDriver.get(baseUrl);

        //
        webDriver.manage().window().maximize();

        //
        webDriver.findElement(By.id("gbqfq")).sendKeys("testing");

        //
        Thread.sleep(5000L);

        int i = 1;

        try {
            while (true) {
                String val = webDriver
                        .findElement(
                                By.xpath("//html/body/table/tbody/tr/td[2]/table/tbody/tr["
                                        + i + "]/td/div/table/tbody/tr/td/span"))
                        .getText();
                System.out.println(val);
                i++;
            }
        } catch (Exception e) {
            System.out.println("Exception at Element No. " + i);
        }
    }

    @AfterMethod
    public void shutDown() {

        // This will close the browser
        webDriver.quit();
    }

}

Using IsSelected() Method

/*
 *
 * @Author : Gaurav Khanna
 * 
 */

package webdriverScripts;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.Test;

public class IsSelectedMethod {

    // Declaring variable 'webDriver' of WebDriver Type
    WebDriver webDriver;

    // Declaring baseURL variable of String Type
    String baseUrl;

    @Test
    public void testisSelectedMethod() {

        // Initializing FireFox Driver
        webDriver = new FirefoxDriver();

        // Assigning URL to variable 'baseUrl'
        baseUrl = "http://book.theautomatedtester.co.uk/chapter1";

        // Open the link
        webDriver.get(baseUrl);

        // Click on the radio button
        webDriver.findElement(By.id("radiobutton")).click();

        // Verify that isSelected method returns true or false
        Assert.assertTrue(webDriver.findElement(By.id("radiobutton"))
                .isSelected());

        // This will close browser
        webDriver.quit();

    }

}

Using IsDisplayed() Method

/*
 *
 * @Author : Gaurav Khanna
 * 
 */

package webdriverScripts;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.Test;

public class IsDisplayedMethod {

    // Declaring variable 'webDriver' of WebDriver Type
    WebDriver webDriver;

    // Declaring baseURL variable of String Type
    String baseUrl;

    @Test
    public void testisDisplayedMethod() {

        // Initializing FireFox Driver
        webDriver = new FirefoxDriver();

        // Assigning URL to variable 'baseUrl'
        baseUrl = "http://book.theautomatedtester.co.uk/chapter1";

        // Open the link
        webDriver.get(baseUrl);

        // Validate that response of 'isDisplayed()' returns true
        Assert.assertTrue(webDriver.findElement(By.id("verifybutton"))
                .isDisplayed());

        // This will close the browser
        webDriver.quit();

    }

}

Webdriver Script012 : getAttribute() Method

/*********************************************************************

 Title  : Webdriver Script012 : getAttribute() Method
 Author : Gaurav Khanna

 *********************************************************************/

package com.gaurav.webdriver;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class s012_getAttributeMethod {

    // Declaring variable 'webDriver' of WebDriver Type
    WebDriver webDriver;

    // Declaring baseURL variable of String Type
    String baseUrl;

    // Declaring attributeValue variable of String Type
    String attributeValue;

    @BeforeMethod
    public void startUp() {

        // Initializing FireFox Driver
        webDriver = new FirefoxDriver();

        // Assigning URL to variable 'baseUrl'
        baseUrl = "http://book.theautomatedtester.co.uk/chapter1";
    }

    @Test
    public void testscript012() {

        // Open the link
        webDriver.get(baseUrl);

        // Locate Button and Store the value of button to 'attributeValue'
        // variable
        attributeValue = webDriver.findElement(By.id("verifybutton"))
                .getAttribute("value");

        // Printing value of 'attributeValue'
        System.out.println("Attribute Value : " + attributeValue);
    }

    @AfterMethod
    public void shutDown() {

        // This will close the browser
        webDriver.quit();
    }
}

Using Google Chrome Browser

/*
 *
 * @Author : Gaurav Khanna
 *
 */

package webdriverScripts;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

public class GoogleChromeBrowser {

    // Declaring variable 'webDriver' of WebDriver Type
    WebDriver webDriver;

    // Declaring baseURL variable of String Type
    String baseUrl;

    @Test
    public void testusingGoogleChromeBrowser() {

        // Setting Chrome Driver Path
        System.setProperty("webdriver.chrome.driver",
                "C:\\gaurav\\selenium\\lib\\chromedriver.exe");

        // Initializing Google Chrome Driver
        webDriver = new ChromeDriver();

        // Assigning URL to variable baseUrl
        baseUrl = "http://not-just-a-tester.blogspot.in";

        // Open the link
        webDriver.get(baseUrl);

        // Maximize the window
        webDriver.manage().window().maximize();

        // Click on Selenium link
        webDriver.findElement(By.linkText("Selenium")).click();

        // This will close the browser
        webDriver.quit();
    }

}

Using Internet Explorer Browser

/*
 *
 * @Author : Gaurav Khanna
 * 
 */

package webdriverScripts;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.Test;

public class InternetExplorerBrowser {

    // Declaring variable 'webDriver' of WebDriver Type
    WebDriver webDriver;

    // Declaring baseURL variable of String Type
    String baseUrl;

    @Test
    public void testusingInternetExplorerBrowser() {

        // Setting IE Driver Path
        System.setProperty("webdriver.ie.driver",
                "C:\\gaurav\\selenium\\lib\\IEDriverServer.exe");

        // Initializing IE Browser
        webDriver = new InternetExplorerDriver();

        // Assigning URL to variable baseUrl
        baseUrl = "http://not-just-a-tester.blogspot.in";

        // Open the link
        webDriver.get(baseUrl);

        // Maximize the window
        webDriver.manage().window().maximize();

        // Click on Selenium link
        webDriver.findElement(By.linkText("Selenium")).click();

        // This will close the browser
        webDriver.quit();

    }

}

Webdriver Script : Printing Page Source

/*
 *
 * @Author : Gaurav Khanna
 *
 */

package com.gaurav.webdriver;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.Test;

public class PrintingPageSource {

// Declaring variable 'webDriver' of WebDriver Type
WebDriver webDriver;

// Declaring baseURL variable of String Type
String baseUrl;

// Declaring pageSource variable of String Type
String pageSource;

@Test
public void testprintingPageSource() {

// Initializing FireFox Driver
webDriver = new FirefoxDriver();

// Assigning URL to variable 'baseUrl'
baseUrl = "http://not-just-a-tester.blogspot.in/";

// Open the link
webDriver.get(baseUrl);

// Maximize browser window
webDriver.manage().window().maximize();

// Assigning Page Source content to variable 'pageSource'
pageSource = webDriver.getPageSource();

// Print Current Page Source
System.out.println("Page Source is - " + pageSource);

// Verify that page source contains text 'Gaurav Khanna'
Assert.assertTrue(pageSource.contains("Gaurav Khanna"));

// This will close the browser
webDriver.quit();
}

}

Webdriver Script : Printing Current Page URL

/*
 *
 * @Author : Gaurav Khanna
 *
 */

package com.gaurav.webdriver;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class PrintingCurrentPageURL {

// Declaring variable 'webDriver' of WebDriver Type
WebDriver webDriver;

// Declaring baseURL variable of String Type
String baseUrl;

@Test
public void testprintingCurrentPageURL() {

// Initializing FireFox Driver
webDriver = new FirefoxDriver();

// Assigning URL to variable 'baseUrl'
baseUrl = "http://not-just-a-tester.blogspot.in";

// Open the link
webDriver.get(baseUrl);

// Maximize browser window
webDriver.manage().window().maximize();

// Click on Selenium link
webDriver.findElement(By.linkText("Selenium")).click();

// Print Current Page URL
System.out.println("Current URL -- " + webDriver.getCurrentUrl());

// This will close the browser
webDriver.quit();
}

}

Webdriver Script : Printing Page Title

/*********************************

Title  : Printing Page Title
Author : Gaurav Khanna

 *********************************/

package com.gaurav.webdriver;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class PrintingPageTitle {

// Declaring variable 'webDriver' of WebDriver Type
WebDriver webDriver;

// Declaring baseURL variable of String Type
String baseUrl;

@Test
public void testprintingPageTitle() {

// Initializing FireFox Driver
webDriver = new FirefoxDriver();

// Assigning URL to variable 'baseUrl'
baseUrl = "http://not-just-a-tester.blogspot.in/";

// Open the link
webDriver.get(baseUrl);

// Maximize browser window
webDriver.manage().window().maximize();

// Print Page Title
System.out.println("Title is - " + webDriver.getTitle());

// This will close the browser
webDriver.quit();
}
}

LoadRunner Vs Jmeter

In current industry, LoadRunner(Paid) and Jmeter(Open Source) are two well known tools for performance testing. I got this image from net comparing both tools on various basis. Hope it will help to understand the difference.







Performance Testing Life Cycle

Following are the different phases of performance testing :

1. Requirements Analysis:

This is the phase where business and technical requirements are identified and gathered. Here the team sends the Requirements gathering questionnaire to the client for asking test requirements, H/w and S/w requirements.

Following are the some of the requirements gathered:
1. SLAs (Service level Agreements).
2. Workload
3. Volume of data
4. H/w
5. Application Architecture and components
6. Test tool details
7. Test types
8. Test Duration
Here a document is provided as a template for this.

2. Test plan/Design :

In this phase the test is planned and designed. Planning is mostly about the Test environment setup as per application, work load profile and H/W.
Test design is mostly about types of tests to be conducted, Number of Users, schedule, Execution plan, Scripts to recorded, Data, Scripts enhancements, metrics to be measured.
In Most of the organizations they follow a single document as Test plan/design. Below mentioned are the sections to be included.
1 introduction
2 application overview
3 performance test goals and objectives
4 performance test approach
5 in scope and out of scope
6 testing procedure (entry& exit criteria, transaction traversal details, test data requirements, schedule, deliverables, workload criteria)
7 test environment (tool, environment setup, test environment setup)
8 communication & reporting
9 test metrics (client, resource, server)
10 roles and responsibilities
11 risks & mitigations
12 abbreviations
13 test plan approval/ signoff
Here a document is provided as a template for this.

3. Test Development:

Before going for performance testing, the test environment (S/W & H/W) should be ready and the scripts should be developed. The test scripts are developed based on the protocol and base scripts are scripted.
Once base scripts are captured, they should be enhanced by performing Correlation (For dynamic value handling), Parameterization (Substitution of values), function and custom functions to meet the requirement.
Once they are enhanced they should be validated against 1 user (Perform single user run) and reviewed and should be base lined. The base lined scripts should be used for test execution.
The output of this phase should be scripts and the performance test isolated environment.

4. Test Execution:

This is the phase where test executions occur as per the mentioned in the plan for meeting client requirements. Here the sequence of steps to follow:
1. Decide the test (Load/stress/endurance) and number of users.
2. Ramp up, duration and Ramp down pattern.
3. Workload profile, run time settings and upload scripts.
4. Apply the details and set the monitors to measure the metrics.
5. Start run and perform online monitoring.
Outputs of this phase are Test results and Test logs.

5. Test Results Analysis:

During this phase the test results and logs are analyzed for identifying bottlenecks and performance issues. Results are compared with SLAs for all types of metrics and verify whether results met SLAs or not.
If results are not met SLAs, raise performance defects and analysis what is causing that problem and report.
Preliminary test report is prepared shared across. A template is provided here as attachment. For the reported performance bottlenecks /issues engineering team acts and tunes the application and reengineers it wherever required.
For the tuned application Step 4 Test execution is performed until application meets expected SLAs.

6. Test Reporting:

For the analyzed results an executive summary report is prepared with the following and sent across respective stake holders.
1. Client metrics (Response times, throughput, hits/sec, pages/sec e.t.c) statistics and graphs.
2. Server and resource metrics statistics and graphs (RAM Disk, Processor, NW and App, Web, DB server metrics).
3. Performed tests
4. Test results and report paths,
5. Suggestions and Recommendations.
6. Test logs of various tests
7. Comparisons of results for various tests.