Tuesday 27 January 2015

Handling Multiple Tabs in Selenium Webdriver

Hi, In this post I'm gonna explain you how to handle multiple tabs in selenium webdriver, well it is quite easy to handle it but remember selenium webdriver will open new window instead of new tab.

For Handling multiple tabs I'm going to use URL:http://irctc.co.in/, kindly execute below mentioned code.

Code:

package NewTabtest;

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

import java.util.ArrayList;

public class NewTab {

    public static void main(String[] args) {
        try{
           
            WebDriver driver = new FirefoxDriver();
            driver.get("https://www.irctc.co.in");
           
            driver.manage().window().maximize();
           
            driver.findElement(By.xpath(".//*[@id='bluemenu']/ul/li[4]/a")).click();
           
            ArrayList<String> tabs2 = new ArrayList<String> (driver.getWindowHandles());
    

          //Switching to new tab 'Tourist Trains'.
            driver.switchTo().window(tabs2.get(1));
           
            String me = "Tourist Trains";
           
            String mee = driver.findElement(By.xpath(".//*[@id='mainpannel']/div/h1")).getText();
           
            if(mee.equals(me))
            {
                System.out.println("Matches");
            }
           
            else
            {
                System.out.println("Doesn't matches");
            }

           //Closing the second tab 'Tourist Trains'
            driver.close();

          //Switching back to Home Tab
            driver.switchTo().window(tabs2.get(0));
           
            String se = "View All";
           
            String see = driver.findElement(By.xpath("html/body/div[1]/div/div[10]/div/div/div[1]/span/a")).getText();
           
           
            if(see.equals(se))
            {
                System.out.println("Matches");
            }
           
            else
            {
                System.out.println("Doesn't matches");
            }
           
            driver.close();
        }
   
    catch (Exception e)
    {
    }
    }
}


So this is how we handle multiple tabs, i hope you guys understood this post..:)

Monday 26 January 2015

Database Performance Testing Using Jmeter

Hi friends, this is my second post in Jmeter and in this post I'm gonna explain you how to test database using Jmeter and for that i will be using MySql database.

Step 1: Download MySql Java Connector 5.1.34 from the URL:http://mvnrepository.com/artifact/mysql/mysql-connector-java/5.1.34.

Step 2: Once download is complete then copy mysql-connector-java-5.1.34.jar into lib folder of Apache jmeter.


Step 3: Start Jmeter and right click on Test Plan and add Thread Group and give any value you want to give, I'm going to give value as 20.


Step 4 : Right click on Thread Group and add 'JDBC Connection Configuration' element and your element should look like this.


in the above image if you could see database URL:jdbc:mysql://localhost:3306:/forjmeter so here 3306 is port number of mysql and 'forjmeter' is the name of the database and make sure you have created 'forjmeter' database and also created table and inserted some values into table and you can change these things accordingly.

Step 5: Right click on Thread Group and add 'JDBC Request' and after adding write a query to fetch data from database as shown below and please make sure that Variable name is same in JDBC Request and JDBC Connection Configuration elements.


Step 6: Right click on Thread Group and add few listeners and I'm going to add three listeners.


Step 7: Now save the script and click on Start symbol to run the script.


So see 'View Result Tree' all are in green color it means it's a pass and also see 'Graph Results' in that Throughput is quite high so it means database is responding well.:)

Well, This is how you can test database performance using Jmeter and please write different scripts by changing elements to test your database.cheers


Sunday 25 January 2015

Selecting a date from DatePicker

Hi Friends, in this post I'm gonna explain you how to select a date from datepicker using selenium webdriver, well it sounds easy but it is not yet easy as you think because mostly datepicker has dynamically changing IDs so coding is not straight forward here.

Just visit the URL:http://demos.telerik.com/kendo-ui/datetimepicker/index and you will see the datepicker as shown below


Now suppose you want to select a date and time like: 8/8/2016 5.00 PM then follow the below code and you will be able to select that value..:)

Code:

package NewTabtest;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;




//Select date 8/August/2016 5.00 PM
public class DatePickerProgram {

   
    public static void main(String[] args) {
       
        try{
           
//Just Put value into variable and Print for the name sake
            String tobeenterdate = "8/8/2016 5:00 PM";
           
            System.out.println(tobeenterdate);
           
            WebDriver driver = new FirefoxDriver();
           
            driver.get("http://demos.telerik.com/kendo-ui/datetimepicker/index");
           
            driver.manage().window().maximize();


//Applying Explicit wait

            WebDriverWait wait = new WebDriverWait(driver, 300);
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[@id='to-do']/span/span/span/span[1]")));
           
            driver.findElement(By.xpath(".//*[@id='to-do']/span/span/span/span[1]")).click();
           
            Thread.sleep(2000);
           
            driver.findElement(By.xpath(" //a[text()='January 2015']")).click();
           
            Thread.sleep(3000);
           
            driver.findElement(By.xpath(" //a[text()='2015']")).click();
           
            Thread.sleep(3000);
           
            driver.findElement(By.xpath(" //td/a[text()='2016']")).click();
           
            Thread.sleep(3000);
           
            driver.findElement(By.xpath(" //td/a[text()='Aug']")).click();
           
            Thread.sleep(3000);
           
            driver.findElement(By.xpath(" //td/a[text()='8']")).click();
           
            Thread.sleep(3000);
           
            driver.findElement(By.xpath(".//*[@id='to-do']/span/span/span/span[2]")).click();
           
            Thread.sleep(3000);
           
            driver.findElement(By.xpath(" //li[text()='5:00 PM']")).click();
           
            Thread.sleep(3000);
           
//Fetching the value selected from datepicker for comparison.
            String getdatepicker = driver.findElement(By.xpath(".//*[@id='datetimepicker']")).getAttribute("value");
           
            System.out.println(getdatepicker);
           
//Comparing actual value with expected value
            if (tobeenterdate.equals(getdatepicker))
            {
                System.out.println("DatePicker value is correct");
            }
            else
            {
                System.out.println("DatePicker value is incorrect");
            }
           
            driver.close();
        }
        catch (Exception e)
        {
           
        }
                
        }
}

Well, Execute the above code and it will run perfectly and moreover you can modify the values mentioned in the code according to your requirements..cheers..:)

Boundary Value Analysis and Equivalence Partitioning

Hi, This is my first post in Manual Testing and I'm gonna explain you how Boundary Value Analysis and Equivalence Partitioning work.

 Boundary Value Analysis: Basically BVA is a test case desgin technique and also blackbox technique used to test boundary values of the input data and using this technuique we can derive test cases for particluar input data.

example: Consider a textbox which accepts numbers 10-100 then using BVA technique we can take boundry values of data as follows.
 9,10,11,99,100,101 so we can write six test cases for that textbox.

Testcase1: Enter number '9' in the textbox.
Testcase2: Enter number '10' in the textbox.
Testcase3: Enter number '11' in the textbox.
Testcase4: Enter number '99' in the textbox.
Testcase5: Enter number '100' in the textbox.
Testcase6: Enter number '101' in the textbox.

Equivalence Partitioning: This is also test case design technique which divides inputs into different classes and takes one value from each class and basically this technique is used when we know the input range.

example: I'm taking same example of BVA here too, consider a textbox which accepts numbers 10-100 then using this technique we can divide the input as shown below.

                 less than 10   |   10 - 100  | more than 100
                     Class1             Class2            Class3

As you can see i have divided inputs in three different classes and I'm gonna take one value from each of these 3 classes so my test cases are as follows.

Testcase1: Enter any number less than 10.
Testcase2: Enter number between 10-100.
Testcase3:Enter any number more than 100.

So this is how BVA and EP work, i hope this post will clear your doubts about BVA and EP..:)


Simple Jmeter Test Plan

Hi, this is my first post in jmeter hence like to start with preparing a simple jmeter test plan.

Now Consider a scenario where you asked to do performance testing of your website with 25 users.? the answer is to use Jmeter which is open source tool for doing performance testing and i hope you guys know how to install jmeter and how to start running simple test. assuming that you guys have basic knowledge in jmeter i will start showing how to write test script which will test website using 25 users, for that i will be using 'Rediff.com'.

Step 1: Once you open Jmeter you will see two things 1) test plan 2) Workbench now right click on Test Plan and add 'Thread Group'. Throup group is an element where you define number of users and your Thread Group should look like this.


Step 2: Right click on ThreadGroup and add 'HTTP request default', once done then in 'HTTP request default' add 'www.rediff.com' in 'Server name or IP' textbox.


Step 3: Again right click on ThreadGroup and add 'HTTP Request' and in Path mention the page name where you want to navigate.(See screenshot).


Step 4: You can add as many as HTTP Request you want and specify only path name in each HTTP request, in my case i have added one more HTTP request as shown below.


Step 5: Now add some listeners to view Test Execution report, I'm going to add three Listeners.


Step 6: Now Test script is ready to run but save it first by pressing 'Ctrl+s' on keyboard and it will pop up one window and give the appropriate name.



Step 7: Now you are ready to run your Test so click on 'Start' symbol and view the result by clicking on Listeners.



Step 8: If you see in 'View Results tree' listener all request marked in Green so it means it's a pass.:) and if any request is marked in Red then it's a fail.

Step 9: Now see the 'Graph results' you will see 'No of Samples' , 'Average', 'Deviation' and 'ThroughPut' and most important of these is 'Throughput'.
Throughput - Number of request processed by server in one minute and larger the Throughput the good is the performance of the server but in my case Throughput is very less but it is because of my slow Internet and Throughput depends on Internet speed too and if you run same test at your side then Throughput will be different.

Step 10: So this is how you can create simple Jmeter Script and now can add or remove elements based on your requirements.

I hope you are able to run the test plan..:)



Friday 9 January 2015

Gmail Login Program using data driven framework

Hi Friends, in my last post i explained how to write simple Gmail login program, in this post I'm going to explain you how to write Gmail login program using Data Driven framework, in short I'm gonna read Gmail login values from Excel file(.xls), please follow the below steps carefully.

1) In Eclipse, Create a new project, then package then one class.

2) Add respective jar files.

3) Then download jxl jar files from the website:http://www.java2s.com/Code/Jar/j/Downloadjxljar.htm

4) In the above mentioned website download zip file with a name "jxl/jxl.jar.zip( 672 k)".

5) Once you download then extract zip file at an appropriate place, and after extracting then you will see one folder with a name "jxl.jar", now open that you will see one jar file with a name "jxl.jar".

6) Now you need to add 'jxl.jar' into your project , please see below steps.
    a) Right click on your project then select properties.
    b)Properties window will open now click on 'Java Build Path' then on 'libraries'.
    c) In Libraries click 'Add External JARs' and select 'jxl.jar' from appropriate place and click ok, this is how you have to add 'jxl.jar' into your project.

7) Create .xls file and place it at an appropriate place so that you can use that in your program, below I'm attaching screenshot and this is how you need to enter values in excel file.





8) Once you are done with all above steps, then start writing program, below I'm pasting the code.

package GmailLoginExcel;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.io.FileInputStream;






// Please include these two
import jxl.Sheet;
import jxl.Workbook;

public class GmailLogin {
   
    public static void main(String[] args) {
        try{
           
                                                                           //eg: ("D:\\Gmail\\GmailLogin.xls")
            FileInputStream fi=new FileInputStream("Enter path of excel file");
            Workbook w=Workbook.getWorkbook(fi);
            Sheet s=w.getSheet(0);
           
            WebDriver driver = new FirefoxDriver();
            driver.get("https://www.gmail.com");
           
            driver.manage().window().maximize();
            //Wait
            WebDriverWait wait = new WebDriverWait(driver, 300);
           
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[@id='Email']")));
           
          
            //Read data from excel sheet
            String s1 = s.getCell(0,0).getContents();
            String s2 = s.getCell(0,1).getContents();
           
         
           
           
            driver.findElement(By.xpath(".//*[@id='Email']")).sendKeys(s1);
           
           
            driver.findElement(By.xpath(".//*[@id='Passwd']")).sendKeys(s2);
           
           
            driver.findElement(By.xpath(".//*[@id='signIn']")).click();   
           
            Thread.sleep(19000);
           
            driver.findElement(By.xpath(".//*[@id='gb']/div[1]/div[1]/div[2]/div[5]/div[1]/a/span")).click();
           
            Thread.sleep(3000);
           
            driver.findElement(By.xpath(".//*[@id='gb_71']")).click();
           
            System.out.println("Success");
           
            Thread.sleep(3000);
           
            driver.close();
           
       
        }
        catch (Exception e)
        {
        }
        }

}

9) Above code will run perfectly, now modify above code according to your requirements..cheers..:)




Simple gmail login program

Hi All,

If you are new to selenium webdriver and want to execute simple program then below i'm writing code for simple Gmail login.please see

//Name of the package
Package GmailLogin

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Gmail {

    public static void main (String[] args)
    {
        try{

WebDriver driver = new FirefoxDriver();
driver.get("https://www.gmail.com");
        driver.manage().window().maximize();

WebDriverWait wait = new WebDriverWait(driver, 300);
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[@id='Email']")));

driver.findElement(By.xpath(".//*[@id='Email']")).sendKeys("Enter email id");

driver.findElement(By.xpath(".//*[@id='Passwd']")).sendKeys("Enter password");
       
        driver.findElement(By.xpath(".//*[@id='signIn']")).click();

//Applying sleep in order to wait till Gmail mail page appears
Thread.sleep(19000);

driver.close();

}
            catch(Exception e)
        {
            System.out.println(e);
        }
    }
   
}


Please execute above mentioned program, it will run perfectly.:)