GroTechMinds

top 20 automation testing interview questions

TOP 20 Automation Testing Interview Questions for Experienced

Q1) When to do Automation Testing?

  • To avoid repetitive tasks we should do Automation Testing.
  • To do Regression Testing we should do Automation Testing.
  • When you need to run the same tests with different sets of data, test automation can efficiently handle multiple data combinations.
  • For projects with a long lifecycle, automated tests can be maintained and reused, making them cost-effective over time.

Q2) What are legacy classes in Java?

  • JDK 1.0 version Java provides classes and interfaces to store the data/Objects for example: Vector, Stack, Hashtable, Properties, and Dictionary.
  •  JDK 1.2 version collection Framework was Introduced.

Legacy Classes: Some classes i.e. Vector, Stack, Hashtable, etc. were introduced in the JDK 1.0 version but when the collection framework was introduced in the JDK 1.2 version these classes were modified or re-engineered so that they could be adjusted in the new collection hierarchy, these older classes are known as Legacy classes.

 

Q3) What are the main differences between Array and Collection in Java?

Arrays

  • It can store only homogeneous values.
  • Arrays are known for their fixed size-we cannot increase or decrease the size of an array at run time
  • Arrays are an inbuilt feature of Java but we have to develop the logic

Syntax:

  • String name[]=new String[3];
  • String name[]={“RAM”,”Vishnu”,”Sham”};

Collection

  • It can store both homogeneous and heterogeneous values.
  • here we can increase or decrease the size of a collection at run time
  • A collection framework is an API that provides classes, methods and interfaces in it

Syntax:

ArrayList a1=new new ArrayList();

Q4) Using Selenium can we do compatibility testing?

Yes

Q5) What things we automate using the Actions class in Selenium?

16

Case 1: How to Drag and Drop in Selenium using Actions Class

Code snippet:

				
					ChromeDriver driver=new ChromeDriver();
	driver.get("https://grotechminds.com/drag-and-drop/");
	driver.manage().window().maximize();
	WebElement drag=	driver.findElement(By.xpath("(//div[@id='div1'])[7]"));
	WebElement drop=	driver.findElement(By.xpath("//div[@id='div2']"));

	Actions a1=new Actions(driver);
a1.dragAndDrop(drag, drop).perform();
	

				
			

Output Screen:

17

Case 2: How to Right Click in Selenium using Actions Class

Code snippet:

				
					WebDriver driver=new EdgeDriver();
	//searchDropdownBox
	driver.get("https://www.google.com");
	driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
	driver.manage().window().maximize();
	WebElement e1=	driver.findElement(By.linkText("Gmail"));
	Actions a1=new Actions(driver);
	a1.contextClick(e1).perform();

				
			

Output Screen:

18

Case 3: How to Hoverover in Selenium using Actions Class

Code snippet:

				
					ChromeDriver driver=new ChromeDriver();
	driver.get("https://www.amazon.in");
	driver.manage().window().maximize();
	WebElement accountandlist=			driver.findElement(By.xpath("//span[@class='nav-line-2 ']"));
	Actions a1=new Actions(driver);
	a1.moveToElement(accountandlist).perform();
	WebElement signin=	driver.findElement(By.xpath("(//span[.='Sign in'])[1]"));
	signin.click();

				
			

Output Screen:

19

Case 4: How to Double Click in Selenium using Actions Class

Code snippet:

				
					ChromeDriver driver=new ChromeDriver();
	driver.get("https://www.google.com");
	driver.manage().window().maximize();
	WebElement e1=	driver.findElement(By.linkText("Gmail"));
	Actions a1=new Actions(driver);
	a1.doubleClick(e1).perform();

				
			

Output Screen:

20

Q6) In the given String find out how many are alphabets involved using Java.

  • Code snippet:
				
					static int countofalpha=0;//initially 0 because as of now the count is 0
public static void main(String[] args) 
{
String name="Manish Kumar Tiwari";
	char [] c1=	name.toCharArray();//it converts given string into array of char type
	System.out.println(Arrays.toString(c1));// it helps to print your array
	for(int i=0;i<c1.length;i++)
	{
	boolean answer=	Character.isAlphabetic(c1[i]);	//Character is a class
	if(answer==true)
	{
		countofalpha++;//whenever the condition is true, we are incrementing the value of countofalpha
	}
	}
	System.out.println("The Total count of Alphabets are-> "+countofalpha);

				
			

Output Screen:

21

Q7) Explain the ‘contains’ method of ArrayList.

Code Snippet:

				
					ArrayList a1=new ArrayList();
	a1.add("Ram");
	a1.add("Sita");
	a1.add(12);
	a1.add("67");
	a1.add(true);
	a1.add(98);
	System.out.println(a1.size());
	System.out.println(a1.contains("Sita"));// I am checking here if a1 contains Sita in it, the result will be true 
	System.out.println(a1);



				
			

Output Screen:

22

Q8) Explain “NoAlertPresentException” in Selenium

This exception comes when there is no alert present but you have written the code to handle the same.

Output Screen:

23

Q9) What are Selenium Disadvantages.

  1. Not supportive for automation of mobile applications

Even though using Selenium we can automate web based applications and websites present in web pages, it is not possible to automate mobile based applications using selenium.

  1. Not compatible with Standalone Applications

Standalone applications are those applications which do not require use of the internet for its functioning. Automation Testing using Selenium is possible only in the presence of the internet. So Automation testing of Standalone applications using Selenium is not possible due to absence of internet.

  1. Not supportive for automation of OTP, Captcha and Barcode

Using Selenium testers will not be able to automate OTP, Captcha and Barcode. So to automate Captcha OTP and Barcode Selenium needs to be integrated with some third party tools like ZXing API. ZXing API is one of the most popular tools available in the market with the help of which testers can automate barcode and OTP after integrating it with Selenium.

4. Need update of Test Scripts from time to time

Since there are frequent updates of web applications and websites through code modification by developers, testers also need to frequently modify the test scripts in order to adapt to the changes in web applications and ensure successful test execution of web applications after updates. So modifying the test scripts becomes a time-consuming job for testers.

5. Time-consuming in writing automation scripts due to no scope of code reusability in some scenarios

Even though Selenium provides scope for code reusability in test scripts, in some test scripts there is no scope for code reusability. As a result, testers write new programming codes for every test case which becomes time-consuming and in turn affects the completion and delivery of software applications on time.

  1. Not compatible with performing image-based testing

Through Selenium automation testers are not able to perform image-based testing like comparison of different screenshots even though selenium is used for taking screenshots of actions performed on web elements. Image based testing is crucial in checking the visual functionality of an application and Selenium being not compatible for image based testing is one of the major drawbacks of Selenium.

  1. Dependence on external tools to generate Test Reports

Automation test reports cannot be generated through Selenium. So Selenium always needs to be configured with any third party tools like TestNG, or JMeter to generate reports containing the duration of running each test suite, the number of test suites passed, the number of test suites failed, the number of test suites skipped, and the number of times the test suite is tried. Even TestNG and Jmeter have their limitations of not displaying more systematic test results as a result of which it becomes difficult to share test results with all team members involved in software development and testing. So there arises a need to use more third-party tools to get more comprehensive test results.

  1. Initial Cost is high

Although Selenium is free, easy to use, and open source easily available in the market, its initial cost is high. The reason for its high initial cost is that creating an Automation framework through selenium from the very beginning takes a longer time. As a result, costs increase with the increase in time and urgency in requirements.

Q10) Write the diffrences between Test Scenarios and Test Cases.

17 (1)

Q11) Write the difference between local and Global Variables.

18 (1)

Q12) Name some Selenium Exceptions.

a)TimeoutException

Why does it happen? This exception is thrown if a command fails to execute or complete within the defined waiting period. TimeoutException is triggered when the page components fail to load within the specified wait duration.

How to Avoid this? Increasing the wait time to allow the website to fully load the web page will resolve this exception.

b)NoSuchElementException

Why does it happen? This occurs when items on a web page or application cannot be found or accessed by locators and also this occurs due to the use of incorrect element locators in the driver.findelement by method.

How to Avoid this? In such cases updating the locators correctly in the script will resolve the issue. Sometimes we have to add a certain wait also.

c)InvalidSelectorException

Why does it happen? The syntax of the selector is incorrect. The selector provided does not follow the appropriate syntax for the chosen locator strategy (e.g., CSS, XPath).

How to Avoid this? Check the locator syntax to avoid this exception. Make sure the locator is syntactically correct.

d)NoSuchWindowException

Why does it happen? While using multiple windows or tabs when the webDriver is unable to locate the necessary browser window or tab that it wants to interact with.

How to Avoid this? First, check the windows availability using driver.getwindowhandles() or put the correct window id/name/index while switching between windows, we can also put the wait time accordingly in the script.

e) NoSuchFrameException

Why does it happen? When you are switching between multiple frames but it is not available or you have given incorrect frame ID/name/index while switching between them.

How to Avoid this? First, get the total number of frames then according to the name/id/index switch to the needed frame, 

In case it is taking time to load the page we can put the wait condition accordingly in the script.

f) ElementNotVisibleException

Why does it happen? The element is there but is not visible to the user, which prevents the user from seeing it or performing actions on it like clicking or sending keyboard commands.

How to Avoid this?

1. First check the web element  availability using the below command

WebDriverWait wait = new WebDriverWait(driver, Duration.ofsecond(10));

WebElement button = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(“buttonId”)));

  1. Sometimes refreshing the web page will refresh the DOM structure and the element becomes visible.

g)ElementNotInteractableException

Why does it happen? Whenever we use a particular locator to search for an element or click an element it doesn’t search or click and as a result action is not performed.

How to Avoid this? We need to change the locator.

h) UnexpectedTagNameException

Why does it happen? if the tagname is wrong.

How to Avoid this? We should put the correct tagname.

 

Q14) How to run the same test case 10 times using TestNG?

Using invocationCount Parameter we can do it in TestNG.

Code snippet:

				
					public class InvocationCount_TestNg 
{
@Test(invocationCount=10)
public void scenerio1()
{
	System.out.println("1");
}
}

				
			

Output Screen:

32

Q15) How to run failed test cases in TestNG?

In the below screenshot, you can see we are running 3 classes together and as you can see all 3 of them are passed.

Output Screen:

33

Look at the below screenshot in this we are running 4 test cases but in the report one of them failed.[Failed for any reason]

Output Screen:

35

Whenever a test case gets failed it generates an XML file called “testng-failed.xml” as shown below

Output Screen:

36

After clicking on “testng-failed.xml” we can see the below screenshot

Output Screen:

40

To run the failed test cases in testNg we need to just run the “testng-failed.xml” by doing right click on it and clicking on Run As ->TestNG Suite

Output Screen:

42

Q16) What is Headless Browser Automation?

Headless refers to any material or thing which has no head. So Headless browser automation refers to the testing of software applications in browsers that have no user interface(UI). In headless browser automation, a browser is used for complete testing without the presence of browser UI. The headless browser performs all the operations similar to the normal browser like navigation to web pages, clicking on links, uploading and downloading of files, etc in the absence of UI. Since we are unable to see the UI in Headless automation so all the testing activities happen at the back end. Headless automation ensures Test execution in the full version of the browser. Due to the absence of UI test execution becomes faster and more efficient as compared to browser automation with user interface.

Q17) Write Code Snippets for Headless Browser Automation in ChromeBrowser, Firefox Browser, and Edge Browser.

1. Headless Browser Automation in Chrome Browser

Code snippet:

				
					1. Headless Browser Automation in Chrome Browser
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class HeadlessBrowser {
	public static void main(String[] args) {
		ChromeOptions options= new ChromeOptions();
		options.addArguments("--headless");
		ChromeDriver driver= new ChromeDriver(options);

	}
}

				
			

2.Headless Browser Automation in Edge Browser

Code Snippet:

				
					import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;
public class HeadlessBrowser {
	public static void main(String[] args) {
		EdgeOptions options= new EdgeOptions();
		options.addArguments("--headless");
		EdgeDriver driver= new EdgeDriver(options);

	}
}

				
			

3. Headless Browser Automation in Firefox Browser

Code snippet:

				
					import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
public class HeadlessBrowser {
	public static void main(String[] args) {
		FirefoxOptions options= new FirefoxOptions();
		options.addArguments("--headless");
		FirefoxDriver driver= new FirefoxDriver(options);

	}
}


				
			

Q18) What are throw and throws keywords in Java?

19 (1)

Q19) Reverse a String in Java.

Code snippet:

				
					public class StringReverse 
{
	public static void main(String[] args) 
{
		String input="Software"; // This is the string input which is taken to be    reversed
		String output=""; // The output of the string after getting reversed will be stored here and since the string is not yet reversed so it is taken as ""

	for(int i=input.length()-1;i>=0;i--) //For Loop is used to print all elements of string and in string reversal printing will start from last element and end in first element of string so the initial condition is taken as position or index of  last element of string and since indexing ends at position less than length of string so the last index is taken as length-1  and final condition is index of first element and it is taken as zero because indexing starts from zero.
	{
		char reverse= input.charAt(i);// It is used for finding out characters at each index position in reverse order
	output=output+reverse; // For finding out the string in the reverse order

	}

	System.out.println(output);// It will print the string in reverse order
	}
	}

				
			

Q20) How to check if 2 strings are palindrome?

Code snippet:

				
					public class Pallindrome {
	public static void main(String[] args) {
		String input="radar"; // Before checking if 2 strings are palindrome first we take 2 strings, reverse the strings and store them in separate variables output and output1 for input and input1 strings respectively.
		String output="";
		String input1="ramesh";
		String output1="";
		for(int i=input.length()-1;i>=0;i--)// For Loop is used to print all elements of string and in string reversal printing will start from last element and end in first element of string so the initial condition is taken as position or index of  last element of string and since indexing ends at position less than length of string so the last index is taken as length-1  and final condition is index of first element and it is taken as zero because indexing starts from zero.
		{
			char rev=input.charAt(i); // It is used for finding out characters at each index position in reverse order


			output=output+rev; // For finding out the string in the reverse order


		}
System.out.println(output); // It will print the string in reverse order


if(input.equals(output)) //Using equals method of string concept we are comparing whether given string stored in ”input” variable is equal to its reversed string value stored in “output” variable.
{
	System.out.println("is a pallindrome");//If the string and its reverse are equal it will print this statement
}
else
{
	System.out.println("not a pallindrome"); //If the string and its reverse are not equal it will print this statement


}//The similar procedure we are following for “ramesh” string stored in “input1” variable and its reversed stored in “output1” variable.
for(int i=input1.length()-1;i>=0;i--)
		{
			char rev1=input1.charAt(i);
			output1=output1+rev1;
		}
System.out.println(output1);
if(input1.equals(output1))
{
	System.out.println("is a pallindrome");
}
else
{
	System.out.println("not a pallindrome");
}
	}
}

				
			

Also read:

Upskill Yourself
Consult Us