Saturday, 31 May 2014

How to create Object repository in Selenium and How to use in Selenium Webdriver

One of the interview questions asked 

Step 1- Open note pad

Step 2- Put key and value pairs for example

facebook.login.username.xpath=.//*[@id='email']
facebook.login.password.xpath=.//*[@id='pass']
facebook.login.Signup.xpath=.//*[@id='loginbutton']

Step 3- Save file as .properties file (I saved in project home diretory and inside Object_Repo folder and name of object repository is facebook.properties

Step 4- Write Selenium script and use the same in script

Lets implement the same

package ObjectRepoExample;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

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

public class TestFacebook {

@Test
public void TestOR() throws IOException{


File src=new File("./Object_Repo/facebook.properties");

FileInputStream fis=new FileInputStream(src);

Properties pro=new Properties();

pro.load(fis);

System.out.println("Property class loaded");

WebDriver driver=new FirefoxDriver();

driver.manage().window().maximize();

driver.get("http://www.facebook.com");

driver.findElement(By.xpath(pro.getProperty("facebook.login.username.xpath"))).sendKeys("Selenium@gmail.com");

driver.findElement(By.xpath(pro.getProperty("facebook.login.password.xpath"))).sendKeys("adsadasdas");

driver.findElement(By.xpath(pro.getProperty("facebook.login.Signup.xpath"))).click();


}



}

How to highlight elements in Selenium Webdriver

One of the interview questions asked is how to highlight the web elements in the page

Below is the answer 
In Selenium we can use JavascriptExecutor (interface) to execute Javascript code into webdriver

In this post we will execute Javascript which will highlight the element.

Lets implement the same this will highlight the user name field

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



public class Highlight {


public static void main(String []args){

WebDriver driver=new FirefoxDriver();

driver.manage().window().maximize();

driver.get("http://www.facebook.com");

               // Create the  JavascriptExecutor object
JavascriptExecutor js=(JavascriptExecutor)driver;

WebElement username= driver.findElement(By.id("email"));

               // call the executeScript method
js.executeScript("arguments[0].setAttribute('style,'border: solid 2px red'')", username); // this code creates a block of solid red color around the email id text box
}

}


if we want to just blink and go off as we have an option in QTP we can add one more line of code 

js.executeScript("arguments[0].setAttribute('style,'border: solid 2px red'')", username); // this code creates a block of solid red color around the email id text box   
js.executeScript("arguments[0].setAttribute("style,'border: "),username) // this code removes the block , so this above 2 lines of code will resemble the highlighting operation 

Any comments please paste in Comment section

Database Testing (MS access) using Selenium

Selenium does not support Database Testing but partially we can do.


Approach- We can connect to Database using ODBC and verify whether data (DB table)is updated or not.

Let see how to connect with Database using ODBC Driver

These are the simple steps to follow

Step 1- Load the driver

Step 2-Create a connection

Step 3- Create a statement

Step 4- Execute your query

Step 5- Store the data in Result set

Step 6- Verify whether data (table) is updated or not

Lets implement the same using Java and DB as Oracle

Precondition- Set the DSN (Data Source Name)

Step to setup DSN-

1- Control Panel > Administrative tool > Click on ODBC

2- Go to user DSN and Click on Add button

3- Select the respective database which you want to connect in this case I selected Oracle 11G

4- Give the name to DSN and Save

Here we go


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.testng.annotations.Test;

public class TestDatabase {



@Test
public void TestVerifyDB(){

try {
                       
                         // This will load the driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver Loaded");



    // Specify the path of the database

String dblocation= "C:\\Users\\Desktop\\DB\\FacebookDB1.accdb";    
    // This will connect with Database , getConnection taking three argument
    //  first argument Test_Oracle is the dsn which you can change as per your system,
Connection con=DriverManager.getConnection("jdbc:odbc:AscentAccess;DBQ="+dblocation);            

System.out.println("Connection created");

   // This will create statement
       Statement smt=con.createStatement();
         
       System.out.println("Statement created");

   // Now execute the query, here facebook is the table which I have created in DB
   
ResultSet rs=  smt.executeQuery("Select * from Facebook");

System.out.println("Query Executed");

  // Iterate the resultset now

      while(rs.next()){
 
String uname=    rs.getString("username");
String pass=        rs.getString("password");
String email=      rs.getString("email");

System.out.println("Uname is "+uname+" password is "+pass+" email id is "+email);
 
 }
}
catch (Exception e) {
System.out.println(e.getMessage());
}


}

}

Tuesday, 27 May 2014

MindTree



Selenium:

1. how to handle dynamic object
2. how to work with button which is in div tag and and u have to click without using xpath
3. JVM is dependent or independent platform
4.how many Test script you write in day
5. describe your framework
6. how to parameterized your junit
7.how to handle ssl security
8. how to handle window pops
9. diffnct between implicit and explicit
10.what are the types of assertion and what are assertion in junit

Java

1.JVM is dependent or independent platform
2.diffn bw hashmap and hash set, set and linkedlist, arraylist and vector list , linkedhash set and hashset
3.abstract and interface
4.throw and throws
5.how to split
6.checked and unchecked exception
7.how to work with azax aplication
8.why sring is immutable
9.wat is the retru ntype of getwindowhandles();
10.what are the types of assertion and what are assertion in java

Manhattan Associates 2

Face to Face Interview Questions 

1.what is the meaning of this line
        WebDriver driver=new FirefoxDriver();
        can we write firefoxDriver d=new firefoxDriver();

2.login on facebook and description of each method
3.can we use other function behalf of get() to go on specific url.
4.how do you log the defact in manual testing.
5.Defect life cycle.
6.there is 2 textbox id password.something is already written in text field like
"Emailid",how can you copy from emailid field and paste in password field.
7.about yourself.
8.project description.
9.About my current company environment.
10.puzzle:-3 bulb and 3 switches problem.
11.How to handle the drop downlist.
12.overloading and overridding
13.it's a overloading or overridding will it compile or not.
        public int m1(int a,int b)
        public float m1(int c,int d)

14.we have a excel sheet some thing is written in excel sheet then compare those value
with web page values.
15.how many bugs have you found yet.tell me 2 complex bug.
16.string reverse .
17. find highest value in list.
18.find the duplicate value in list.
19.how will upload a file if the text is not editable.
20.write inner query .

Manhattan Associates.

1st round:written test

10 question from testing
10 question including analytical and logical and puzzle
10 questions from database to predict output
10 question from java to predict output


2nd round with technical panel:

1.xpath for dynamic objects(they gave 1 table structure)

2.webdriver code to read the data from excel sheet and login into application

3.code for database connectivity

4.how to handle exception

5.Automation test cycle

6.fuctions to find objects in UI

7.code to click on a link which will open another window and perform an operation on 2nd window to open a frame and then perform an operation on a frame

8.types of wait in webdriver and difference

9.code to work with IE and settings required for this

10.which framework u used in your company and why

11.what is dataprovider why we use dataprovider

12.what is pagefactory and why we use page factory

13.what is SVN

14.what is selenium grid and why we use this

15.which test cases can't be automated

16.Interface and why we use it

17.diffrence between interface and abstract class,and when we use interface,when we use abstract class

18.explain oop's concept

19.bug life cycle

20.regression,compatibility,adhoc,smoke,useability.load,stability,security testing and why we do these testing

21.functional,integration,system testing,and what is module,what is component

22.test case design techniques,give an example of boundary value analysis

23.what is severity and priority

24.when we set bug status as deferred

25.which bug tracking tool u used in ur company

26.explain test scenario and test case

27.throws for runtime or compile time? and try catch for runtime or compile time?



3rd round:(technical and managerial with director)

1.what is class and why we use class

2.what is inheritence and why we use it,write a code

3.WebDriver code to print username in the welcome page

4.code to find a particular word from a string and explain line by line

5.code to write a java program (any program)

6.explain public static void main

7.access specifiers and their use

8.difference between primary key and unique key

10.write test case template which u follow in ur company

11.difference between array and linklist

12.7-8 managerial questions

Basic Sorting

Sorting


1. Write a Program for Bubble Sort.
import java.io.*;
public class BubbleSort{
 public static void main(String args[])throws Exception
 {
   BufferedReader br1=new BufferedReader(new  InputStreamReader(System.in));
   System.out.print("Enter the Size of the Array: ");
   int size=Integer.parseInt(br1.readLine());
   int arr[]=new int[size];
   for(int a=0;a
   {
     BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
     System.out.print("Enter The "+(a+1)+" Element=");                                             
     arr[a]=Integer.parseInt(br.readLine());
   }
   for(int i=0;i<arr.length;i++)
   {
     for(int k=1;k<arr.length;k++)
     {
       if(arr[k-1]>arr[k])
       {
         int j=arr[k-1];
         arr[k-1]=arr[k];
         arr[k]=j;
       }
     }
   }
   System.out.print("Sorted Elements are: ");
   for(int b=0;b
   {
     BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
     System.out.print(" "+arr[b]);
   }
 }
}

Bubble sort Example: 6, 5, 1, 7, 2, 4, 9
Array size=7
5,6,1,7,2,4,9  
5,1,6,7,2,4,9
5,1,6,7,2,4,9
5,1,6,2,7,4,9
5,1,6,2,4,7,9
5,1,6,2,4,7,9
=============
1,5,6,2,4,7,9
1,5,2,6,4,7,9
1,5,2,4,6,7,9
=============
1,2,5,4,6,7,9
1,2,4,5,6,7,9
=============

2. Write a Program for Selection Sort.
 public void SelectionSort()
{
   for (int b=arr.length-1;b>0;b--)
   {
      int maxPosition=0;
      for(int c=1;c<=b;c++)
      {
         if(arr[c]>arr[maxPosition])
         maxPosition=c;
      }
      int l=arr[maxPosition];
      arr[maxPosition]=arr[b];
      arr[b]=l;
      }
}

Selection sort Example:
4, 3, 5, 6, 1
Maxposition=2
4, 3, 5, 6, 1
Maxposition=3
4, 3, 5, 6, 1
=============
4, 3, 5, 1, 6
4, 3, 5, 1, 6
=============
4, 3, 1, 5, 6
=============
1, 3, 4, 5, 6

3. Write a Program for Insertion Sort.

public void InsertionSort()
{
  long timeNs=System.nanoTime();
  for(int i=1;i<arr.length;i++)
  {
    int current=arr[i];
    int j=i;
    while(j>0 && arr[j-1]>current)
    {
      arr[j]=arr[j-1];
      j--;
    }
    arr[j]=current;
  }
  nanoTime=System.nanoTime()-timeNs;
}

Basic Code

1.  Find the top 3 elements of an array, Do not use sorting use 3 variables.
(Amazon Interview Question)
public class LargeNumberArray {
 public static void main(String args[]){
   int a[]={7,2,8,1,3,5,10,0,12,11};
   int large=a[0],second=a[0],third=a[0];
   int index=0,index1=0,index2=0;
   for (int i=0;i<a.length;i++)
   {
     if(a[i]>=large)
     {
        large=a[i];
        index=i;  
     }
   }
   for (int i=0;i<a.length;i++)
   {
      if(a[i]<large && a[i]>second))
      {
         second=a[i];
         index1=i;
      }
    }
   for (int i=0;i<a.length;i++)
   {
      if(a[i]<second && a[i]>third))
      {
         third=a[i];
         index2=i; 
      }
   }
   System.out.println("Large Number: "+large+ " Index: "+index);
   System.out.println("Large Number: "+second+ " Index: "+index1);
   System.out.println("Large Number: "+third+ " Index: "+index2);
  }
}

2.  Program for Fibonacci series.
import java.io.*;
public class Fibonacci {
public static void main(String args[])throws Exception
{
InputStreamReader ir=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(ir);
System.out.println("Enter Number: ");
String s=br.readLine();
int n=Integer.parseInt(s);
System.out.print("Series=");
fibonacci(n);
}
public static void fibonacci(int n)
{
int a=0,b=1;
for(int i=0;i<n;i++)
{
System.out.print(a+", ");
a=a+b;
b=a-b;
}
}
}

3. Program to check Palindrome Number.
import java.io.*;
public class Pallendrome {
public static void main(String[] args) throws Exception
{
InputStreamReader ir=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(ir);
System.out.print("Enter Number: ");
String s=br.readLine();
int n=Integer.parseInt(s);
palindrome(n);
}
public static void palindrome(int n)
{
int temp,reversed=0;
int number=n;
while(number>0)
{
temp=number%10;
number=number/10;
reversed=(reversed*10)+temp;
}
if (n==reversed)
{
System.out.println(n +"is Pallendrome") ;
}
else
{
System.out.println("Number is not Pallendrome "+ reversed) ;
}
}
}

4. Program to Reverse a string.
import java.io.*;
public class ReverseString {
public static void main(String args[])throws Exception
{
  InputStreamReader ir=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(ir);
System.out.print("Enter Number: ");
String s=br.readLine();
char c[]=s.toCharArray();
int length=c.length-1;
int l=0;
char j[]=new char[c.length];
for(int i=length;i>=0;i--)
{
j[i]=c[l];
l++;
}
String st = new String(j);
System.out.println("Reversed String: "+st);
}
}

5. How to find duplicate words in a string.

import java.util.*;
public class DupSearch {
    public static void main(String args[]){
        String s="a b f e a sd g t y uf s a b d x e c ";
        List<String> list = Arrays.asList(s.split(" "));
        Set<String> uniqueWords = new HashSet<String>(list);
        for (String word : uniqueWords) {
            System.out.println(word + ": " + Collections.frequency(list, word));
        }
    }
}


6. Swap two numbers by using two variables use exception handling and function. 

import java.io.*;

public class Swapping {
public static void main(String args[])throws Exception{
    swap();
}
public static void swap()throws Exception{
    InputStreamReader ir=new InputStreamReader(System.in);
    BufferedReader br= new BufferedReader(ir);
    try{
        System.out.print("Enter the Value of A= ");
        String s=br.readLine();
        int a=Integer.parseInt(s);
        System.out.println("A= "+a);
        System.out.print("Enter the Value of B= ");
        String s2=br.readLine();
        int b=Integer.parseInt(s2);
        System.out.println("B= "+b);
        a=a*b; // a=12
        b=a/b; // b=3
        a=a/b; // a=4
        System.out.println("**** Swapping the values ****");
        System.out.println("A=> "+a);
        System.out.println("B=> "+b);
    }
    catch (NumberFormatException e){
        System.out.println("Please Enter valid Number");
        swap();
    }
}
}

Data Driven Frame Work

Data Driven Frame Work

     One of the widely used frame work  .
   
     In this frame work the whole automation process is driven by data( saved in excel,word doc or Data base)
 
     In the link below

    Key Word Driven Framework , i had explained how the key word driven frame work works

Please find the image below which is self explanatory





















In the above image we are using 2 Excel sheet

1. Driver sheet : Which drives the whole automation
2. Data Sheet : Which provides the input to the modules

Driver sheet

Name itself tells it drives the whole automation . In the above Sheet we have 2 coloumns

Module name and ExecuteFlag

Module name = Specifies the name of the module to run or name or the test case

Execute Flag =  Specifies whether the Module to be run or not ( if the value is "Y" execute the corresponding code else skip it )


Complete flow 


Let us see with an example the

We have 3 rows inside the Driver sheet , as per the above description only code related to LoginMail and SendMail as to be execute .

Steps


  1.  main() Method reads the Driver sheet
  2. Checks for Execute Flag for "Y" , if its Y , it captures the Module name 
  3. Checks with the case statement and compare with the case values , if anything is matched , it has to execute the corresponding code , Here comes the Data Sheet , This sheet can be used to give the input for the modules (in the above example we can see LoginName and Pwd required for logining in )
  4. Repeat the above steps until no rows in Driver sheet







Friday, 23 May 2014

Key Word Driven Framework

Key Word Driven Framework
Framework where for a particular test case, you would first identify a set of Keywords and then associate a method (or function) to each of these keywords.
Consider for example login flow of Face book is the case to be automated
Steps 1 . Login to Face Book
Steps 2 . Check any notifications
Steps 3 . Logout

Now we have got the steps ( taking pure modular approach we can divide the steps into modules or functions )
So there are 3 methods / functions

Test cases

  1. Login to Facebook
  2. Check the notifications
  3. Logout from Face book

Once Test cases are identified 

        Identify the Keywords ( Keywords can be any name which is easier to remember or understand)
       

  1. FBLogin 
  2. FBNotificationCheck
  3. FBLogout

Once keywords are identified next step is to associate the Keywords to Methods





Now according to the above case we need to do 3 steps
1. Create a keyword and save it somewhere
2. Develop a module 
3. Associate the keyword and the respective modules

Part of the work is done , now the flow comes to picture

Below is the list of common components or questions appears in most of the keyword driven  frameworks.
1. Where to save the Keywords and Modules

         Once the Keywords are identified we can use Excel sheet to save the Keywords, but write a 
          Method(Main() ) to open the excel sheet and get the keywords 

2. Where to save the Modules ?

         In Keyword Driven framework methods play a very important role , so You would have to built all the          necessary intelligence in the java methods so that it can read the excel sheets and call the different                  Modules/Methods based on the Keywords.

         Better we save the methods in a separate folder naming Business flow ( as per individuals interest or              project requirements)

         Build all your business flow or function intelligence here and save as separate files or single , depends            on the developer and requirements

3. Data sheet needed ? 

         It depends – To save the data we need to for the Test case to be used by the application

4. Test Scripts ( As per project requirement)
        
         You can have separate test scripts for each manual test case or a single driver script that will execute            all the test cases

below flow indicates the full flow 


















From the above figure, you can see that the generic flow of a Keyword Driven Framework is something like this -

1) MAIN Method  calls the other Methods which has code to read the excel sheet

2) The Methods called from the Main method opens the excel sheet and reads the first keyword associated with the test case.

3) Once the keyword is read from the excel sheet , It searches for the associated Methods ,Once the associated methods are identified  then the method is excuted on the application that is being tested.

4) Control returns back to main function (in Step 2) which then reads the next keyword. Steps 2 to 4 are repeated till all the keywords associated with a particular test case are called.



Now how to associate the keywords is important ( it depends on project )

If we search in the net for Key word Driven Framework . We can find wide variety of answers .
It depends on the requirements

Broadly dividing it into 2 ways

1 . Associate the keywords to a whole function or method

2 . Associate the keywords to a object level operations like
associating one key word for entering username , one for entering password , one for clicking button and so on


To Explain the above two implementation let us consider 3 test cases

TC_01= Login to Facebook , check for notification's , logout
TC_02 = Login to Facebook , check for friends request , logout
TC_03 = Login to Facebook , check for birthday notifications , logout


Associate the keywords to a whole function or method

  This is the most general format that is used in many of the places


 
   In the above diagram we can see how the associations are done

   Now when the Main method is called it opens the excel sheet , reads the first line .

  1. It captures the Test case name TC_01 , once the Test case name is captured
  2. It capture the first Keyword i.e FBLogin in this case, once the keyword is got , it checks for the associated method and execute it against the AUT
  3. Step 2 is repeated until all the keywords are done for First case ( TC_01)
  4. Once the TC_01 is done it jumps to next Test case(TC_02) and repeat the 2 step for its corresponding keywords



Associate the keywords to a object level operation

This is another method of implementation



In the above diagram we can see how the associations are done on operations level ( its self explanatory)

Now when the Main method is called it opens the excel sheet , reads the first line .


  1. It captures the BrowserType , Title , now the element is captured .
  2. Once the element is captured it checks the properties 
  3. Once the properties are captured it checks for the operations to be performed 
  4. Here the values are associated to it 


Any doubts or any extra information to be added , Please Post a comment




Thursday, 22 May 2014

[24]7 Innovation Labs.



Round - 1.

1. Tell me about youself.
2. Given an array of size n of (0,1) and k where k < n. find the minimum size sub array which contain k no od 1's
3. What are the data structure you are aware of.
4. Implement linked list using Enqueu and Dequeu.
5. Implement stack using linked list.
6. Given a linked list , find whenther it contain cycle or not.

Round - 2

1. Tell Me about yourself.
2. There is page, in selenium how do you check whether it is completely loaded or not.
3. How do you check whether page is stuck in infinite loop.
4. what are the annotation in testng.
5. How do you run dependen testcases, bulk run.
6. Write selenium to login into yahoo, with proper assertation and validation.
7. write tescase for add cart functionality of flip kart.
8. write a program to reverseing a sentance, ex "this is [24]7" o/p "[24]/7 is  this"
9. what are joins in sql, explain with a example.
10. Two table having one colummn common, fetch all the data where, table1.commomcol != table2.commoncol

Round - 3

1. Have you worked on unix.
2. Tel me some command which you have used.
3. How to see process in unix.
4. How to kill a process.
5. How do i find a pattern in a file using unix command
6. what are the diff modes of vi.
7. Given a csv file as follow
ID,Name,Address,Loc
1,a,abc,abc
2,b,abc,abc
3,c,abs,asd
1,a,abc,abc

write a program to read the file and give output only the row having id as unique

o/p

1,a,abc,abc
2,b,abc,abc
3,c,abs,asd

8. Given MxN matrix, write a program to find mim element in the matrix.


Round - 4

1. Tell me abt your self.
2. What is the duration of release in your company.
3. How do you give esitimation for the testing.
4. What if you buffer in the plan is over and you are colse to deadline.
5. We have monthly releases. Work will be little hetic, how will you manage.
6. Its SDET profile, What makes you suite for the profile.
7. Do you have any question to ask.

Round - 5 (HR)

1. Tel me about your self.
2. Why you are looking for the job.
3. The profile we are hiring for sdet and you are manual tester, why should i hire you.
4. Do you have any offer with you.
5. If you have offer with you, the what gurantee you will join us.
6. How much is your expectation..