Automation Interview Questions - 1




Hello Folks,

Hope you all are doing good and safe under the current situation. Hereby I'm presenting a few of the most commonly asked questions for the Software Test Automation Interview - Java. This is going to be a long thread and would surely put up many such topics related to Interviews for your convenience.

So, without wasting a second let us jump to the very first and most asked Question:
    
•  Swapping 2 numbers without using third variable
    int x = 10;  
    int y = 20;  
    System.out.println("Before Swap : X is "+x +" and Y is "+ y);  
    x = x + y;   
    y = x - y;   
    x = x - y;   
    System.out.println("After Swap : X is "+x +" and Y is "+ y); 
    
    Output:
    Before Swap : X is 10 and Y is 20
    After Swap : X is 20 and Y is 10
    
The logic used for 2 numbers say, 10 & 20 is
X = X + Y = 10 + 20  = 30
Y = X - Y = 30 - 20 = 10
X = X -Y = 30 - 10 = 20


Swapping 2 numbers using a variable

    
    int x = 10, y = 20, temp;  
    System.out.println("Before Swap : X is "+x +" and Y is "+ y);   
    temp = x;  
    x = y;  
    y = temp;    
    System.out.println("After Swap : X is "+x +" and Y is "+ y); 
    
    Output:
    Before Swap : X is 10 and Y is 20
    After Swap : X is 20 and Y is 10
    

Swapping 2 strings without using any variable

    
    String a = "Abhishek";  
    String b = "Verma";  
    System.out.println("Before Swap : A is "+a +" and B is "+ b);  
    a = a + b;  
    b = a.substring(0, a.length() - b.length());  
    a = a.substring(b.length());  
    System.out.println("After Swap : A is "+a +" and B is "+ b); 
    Output:
    Before Swap : A is Abhishek and B is Verma
    After Swap : A is Verma and B is Abhishek
    
The logic used for 2 string here says:

1. a+b:
Concat the 2 strings "AbhishekVerma" and store in var a
2. a.substring(0, a.length() - b.length()) 
  • Substring of var a from length 0 to [(length)a - (length)b]
  • That is, substring 0 to (13 - 5) => 0 to 8
  • Store the substr(0,8) in var b
3. a.substring(b.length()) 
  • Substring of var from length starting from the index [(length)b]
  • That is, substring from index 8, so it will pick data from 8th index to the last
  • Store the substring(8) in var a
 
Sorting an array of integer object in ascending/descending order
   
    Integer arr1[] = {4,5,7,6,7,0,3,4,5,6};
    Arrays.sort(arr1);

    System.out.println("Array in Ascending order");
    for(int a : arr1) {
    	System.out.print(a + " ");
    }
        
    System.out.println("Array in Descending order");
    Arrays.sort(arr1, Collections.reverseOrder());
    for(int a : arr1) {
    	System.out.print(a + " ");
    }
    
    Output:
    Array in Ascending order
    0 3 4 4 5 5 6 6 7 7 
    Array in Descending order
    7 7 6 6 5 5 4 4 3 0 
    


Moving all 0's in an array to the end keeping the order same for other elements
    static void pushZerosToEnd(int arr[], int n) 
    { 
        int count = 0;  // Count of non-zero elements  
       /* While traversing if element is non-zero, 
       then replace the element at the index 'count' with this element */
        for (int i = 0 ; i < n ; i+1) {
            if (arr[i] != 0) {
                arr[count] = arr[i]; 
                count++;	// count incremented by 1 value of index
  	    }
        }   
        while (count < n) 
            arr[count++] = 0; 
    } 
    
    public static void main (String[] args) 
    { 
        int arr[] = {1, 9, 8, 4, 0, 0, 2, 7, 0, 0, 9}; 
        int n = arr.length; 
        pushZerosToEnd(arr, n); 
        System.out.println("Array after pushing zeros to the back: "); 
        for (int i=0; i<n; i++) 
            System.out.print(arr[i]+" ");
    } 
    Output:
    Array after pushing zeros to the back: 
    1 9 8 4 2 7 9 0 0 0 0  

• Is Webdriver a class or an Interface

WebDriver is a public interface, we create a reference variable (driver). Now any object we assign to it must be an instance of another class like ChromeDriver, FirefoxDriver which implement the interface.

• Difference b/w findElement and findElements

For detailed ref. of this topic, please follow the link having a detailed description on it.


Thank You !!

Comments

Popular posts from this blog

Passing Data From the TestNG.xml file to Tests

Demo Click Jack Maropost.Com