PWC Test Automation Interview Questions and Answers for Experienced QA
Here is a next addition of PWC automation QA interview question and answers
Please note: these question are already verified from respective source. If you have any additional question feel free to post in the comment section.
1) What is collection in java.?
A Collection is a group of individual objects represented as a single unit. Java provides Collection Framework which defines several classes and interfaces to represent a group of objects as a single unit.
The Collection interface (java.util.Collection) and Map interface (java.util.Map) are the two main “root” interfaces of Java collection classes.
2) What is Hashmap, please provide one example?
HashMap is a part of Java’s collection since Java 1.2. It provides the basic implementation of Map interface of Java. It stores the data in (Key, Value) pairs. To access a value one must know its key. HashMap is known as HashMap because it uses a technique called Hashing. Hashing is a technique of converting a large String to small String that represents same String. A shorter value helps in indexing and faster searches. HashSet also uses HashMap internally.
// Java program to illustrate
// Java.util.HashMap
import java.util.HashMap;
import java.util.Map;
public class GFG
{
public static void main(String[] args)
{
HashMap<String, Integer> map = new HashMap<>();
print(map);
map.put("vishal", 10);
map.put("sachin", 30);
map.put("vaibhav", 20);
System.out.println("Size of map is:- " + map.size());
print(map);
if (map.containsKey("vishal"))
{
Integer a = map.get("vishal");
System.out.println("value for key \"vishal\" is:- " + a);
}
map.clear();
print(map);
}
public static void print(Map<String, Integer> map)
{
if (map.isEmpty())
{
System.out.println("map is empty");
}
else
{
System.out.println(map);
}
}
}
3) Write a program Search a letter in string?
/ Java program to illustrate to find a character
// in the string.
import java.io.*;
class GFG
{
public static void main (String[] args)
{
// This is a string in which a character
// to be searched.
String str = "GeeksforGeeks is a computer science portal";
// Returns index of first occurrence of character.
int firstIndex = str.indexOf('s');
System.out.println("First occurrence of char 's'" +
" is found at : " + firstIndex);
// Returns index of last occurrence specified character.
int lastIndex = str.lastIndexOf('s');
System.out.println("Last occurrence of char 's' is" +
" found at : " + lastIndex);
// Index of the first occurrence of specified char
// after the specified index if found.
int first_in = str.indexOf('s', 10);
System.out.println("First occurrence of char 's'" +
" after index 10 : " + first_in);
int last_in = str.lastIndexOf('s', 20);
System.out.println("Last occurrence of char 's'" +
" after index 20 is : " + last_in);
// gives ASCII value of character at location 20
int char_at = str.charAt(20);
System.out.println("Character at location 20: " +
char_at);
// throws StringIndexOutOfBoundsException
// char_at = str.charAt(50);
}
}
4) Write a java program to Reverse a number?
public class ReverseNumber {
public static void main(String[] args) {
int num = 1234, reversed = 0;
while(num != 0) {
int digit = num % 10;
reversed = reversed * 10 + digit;
num /= 10;
}
System.out.println("Reversed Number: " + reversed);
}
}
5) write a program to Sort an array?
// A sample Java program to sort a subarray
// using Arrays.sort().
import java.util.Arrays;
public class SortExample
{
public static void main(String[] args)
{
// Our arr contains 8 elements
int[] arr = {13, 7, 6, 45, 21, 9, 2, 100};
// Sort subarray from index 1 to 4, i.e.,
// only sort subarray {7, 6, 45, 21} and
// keep other elements as it is.
Arrays.sort(arr, 1, 5);
System.out.printf("Modified arr[] : %s",
Arrays.toString(arr));
}
}
6) What is page object model?
you can read about page object model here
7) Between css and xpath which one is faster?
CSS selectors perform far better than Xpath and it is well documented in Selenium community. Here are some reasons, Xpath engines are different in each browser, hence make them inconsistent. IE does not have a native xpath engine, therefore selenium injects its own xpath engine for compatibility of its API.
8) What is exception.types of exceptions?
Exception is a type of case where the code is not behaving as per the requirement. You can read more about exception and its types here
9) Tell some exception which you got while working in selenium?
You can refer my article types of exception in selenium here
10) How to handle exception ?
There are many ways to handle the exception the common ways by sung try ..catch block.
import java.io.*;
public class ExcepTest {
public static void main(String args[]) {
try {
int a[] = new int[2];
System.out.println("Access element three :" + a[3]);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Exception thrown :" + e);
}
System.out.println("Out of the block");
}
}
That's it for this article. If you have any question with selenium, Cucumber, Appium framework development. I am more than happy to help. Feel free to put in the comment section.
** If you see I am helping community then please help to endorse my skill set so that community can be benefited **
Senior Software Quality Assurance Tester
6 年very helpful