Automation Testing Interview Questions and Answers: A Comprehensive Guide

Automation testing has become an integral part of software development and quality assurance processes. As companies seek to enhance their efficiency and reliability, the demand for skilled automation testers has soared. If you’re preparing for an automation testing interview, you’ve come to the right place. In this article, we’ll cover a range of commonly asked interview questions and provide insightful answers to help you succeed. Let’s dive into the world of automation testing!

Introduction to Automation Testing

Automation testing involves using specialized software tools to automate the execution of test cases. It reduces manual effort, accelerates testing cycles, and enhances accuracy. Automation testers write scripts to simulate user interactions with applications and validate their behavior.

Benefits of Automation Testing

Automation testing offers numerous advantages, including faster execution, broader test coverage, and consistent results. It’s particularly beneficial for repetitive tasks and regression testing.

Common Automation Testing Tools

There are several popular automation testing tools available, such as Selenium, Appium, and JUnit. Each tool has its strengths and is suited for different types of testing.

Technical Questions for Automation Testers

1. How much you rate yourself in selenium out of 5?

Out of 5 I will rate myself 3.5 in selenium.

2. Which locator you are using in your framework and why?

Mostly we used ID and Xpath because Id is the fastest and unique one and after that we prefer Xpath.
Anyways we have other locators as well like css , class name, tag name, Link text, Partial Link text.

3. What is the difference between findelement & findelements?

findelement will give the first appearance of that element which matches our locator, whereas
findelements will give us list of all the elements which is present over the webpage and matching our
locator. And if we don’t find the element findelement will give us nosuchelementexception whereas
findelements will return NULL/Empty list.

4. Can you tell me how you will handle multiple window in selenium?

We have windowhandle & windowhandles function for handling Multiple windows. Windowhandle will
give the string value of only the active window that is open whereas windowhandles will give set of all the
windows that are open in browser.

5. How you will move from one window to another?

First we will check what all windows are open by using driver.getwindowhandles, to get set of opened
windows , then I use iterator to iterate over each of the pages and inside for loop will check like Current
URL matches with the excepted page, if match then switch to that window by using
driver.switchTo(Destination window) -> to return back to main parent window use driver.defaultwindow.

6. Tell me the difference between Implicit & Explicit wait?

Implicit wait applies for all the elements and all the tests like if we give 10 sec of implicit wait it will wait
for 10 sec for each element before giving nosuchelement exceptions.
While Explicit wait can be applied for any particular step for which you want extra wait time so we can use
explicit wait. We can use mix of both waits to depend on the situation of the step.

7. Can you tell me some exceptions in selenium?

NoSuchElementException, NoSuchWindowException NoSuchframeException,
StaleElementReferenceException, TimeoutException.

8. Can you tell me about StaleElementReferenceException?

Stale means old or decayed, here it sounds like element which was present on that page is no longer
there or decayed. To handle this, we can refresh the webpage before pointing to that element. We can
write script for waiting via explicit wait by writing expected condition.refresh. Or we can go with page
object model in that we can over come this stale element exception.

9.What do you mean by User Defined Exception?

User Defined Exception or custom exception is creating your own exception class and throws
that exception using ‘throw’ keyword. This can be done by extending the class Exception. … The keyword
“throw” is used to create a new Exception and throw it to the catch block.

10.Can you tell me what is assert in TestNG?

Assert is like verification where we check like expected thing and actual thing are same or not.

11. Which assert you have used in TestNg?

We have used Hard assert and Soft assert, while applying Hard assert if we found any glitch in expected
and actual then it will through exception and move to next @test while Soft assert it won’t give exception
and move to next step of that test. And to get all the exceptions in console we need to write at the end
assert.all.

12.Can you tell me about the order of TestNG annotations?

@BeforeSuite
@BeforeTest
@BeforeClass
@BeforeMethod
@Test
@AfterMethod
@AfterClass
@AfterTest
@AfterSuite

13.Do you heard about Priority in TestNg can we set -ve priority?

Yes, like priority is 0, -1, TestNg will run -1 then 0 then 1. And if we have any @test which is not having any
priority set, then in that case it will search via alphabetic order whichever comes first and execute test
respectively.

14. Do you work in cucumber, can you tell me what all files required in cucumber?

In cucumber we have Feature file, Step Definition file and Test Runner file.
In feature file we used to write scenario in gherkin language which is most like in plain English language.
Here we use some of the keywords like feature, scenario, scenario outline, given, when, then, and,
example, background keywords for writing our test scenarios steps
In Step Definition file we write mapping code for all the scenario of feature file.
In test Runner file we provide the address of the feature file, step definition file, and all-important Tags,
Plugin, Listeners in that.

15. What is the difference between scenario & scenario outline?

When we have single scenario and we need to run it one time at that place we use Scenario.
If you want some parametrization or Data Driven testing at that time, we can use scenario outline where
we have to use Example keyword like if we are running this scenario for 3 different data set like username
& pass. so, it will run 3 times.

16. Can you tell me more about Background Keyword?
Background is used when we have some common Given part. Suppose we have pre-condition that we
have to check this before each scenario. so in order to avoid rewriting same step we can write it in
Background.

17.What is the use of Dry Run in cucumber?
Dry run is not running our whole application it will check whether all features are mapped with Step
definition.

18.What is hooks in cucumber?

In cucumber we use hooks for common functionalities, hooks are like we want to run before & after each
of the scenario. In hooks we have 2 different @before, @ after which run before and after of each
scenario. Also @beforestep, @afterstep which run before and after each step

19. Can you tell me how you will re-run failed scenario in cucumber?

For that we can use re-run attribute in our test runner file. After that we can write one file location.
Where all the test cases which failed while execution get stored. So next time while running execution we
can give this file location and run the failed TC.

20.You have worked in Cucumber & TestNG according to you which one is best?

I will consider Cucumber as it is most likely understood by Laymen people which is English plain language.
Because in order to understand the functionality flow no need to go look and script/code. Via Scenario
steps lines only we can get clear understanding about the functionality.
It helps to come all the QA members Dev, Client, Product Owner on same page.

21.Can you explain me TestNG?

TestNG is advanced version of Junit only. It is mainly used by Dev/QA for maintain the code easily and for
unit testing. It provides lots of benefits to us like we can create a suite and we can write all the required Tc
in one go only using that suite. We can group our Tc we can set priority we can run our tc in parallel
mode, We can generate good reports via TestNG. We can write functionality depends on methods,
depends on group. We can run single tc multiple time with single set of data of multiple set of Data.

22.How to run single method multiple time in TestNG?

We have invocation count attribute in @test annotiation. We can write invocation count as 3 if we want
to run it 3 times. Apart from that we can write threadpull.size if we want to run that case in multiple
thread.

23. Have you used GIT in your project can you explain about it?

Yes I have used GIT, It is a version control tool. Where we can maintain our central repo. we used to
manage our code via GIT only. We use Git to maintain our project in our local system. So, if someone like
to work on that project I need to send complete update copy to him and after that he can work on that.
There are chances that single project is handled by multiple teams across the globe. So, it will be difficult
if we won’t use GIT.

24.Can you give me some GIT commands which you used on daily basis?

Git status– which shows status of all the files,if we have some files which is not yet added to our repo so it
will give us untracked file.
After that we can use GIT add command after adding it will added to particular index and we can commit
this file using Git Commit-(Message) we can commit this untracked file. Also we have Git Merge, Git Post,
Git Pull, Git It in etc.

25. How to solve Merge conflict in GIT?

As we are only 2 tester working on this project, if we have any merge conflict I used to pull all the latest
file/scripts to my local system. Then I will analyze the difference between that particular file and merge
file. After that I will check with my team member whether all his imp things are covered then I will add my
steps and push the script to the central repo.

26. What is the difference between Smoke & Sanity Testing?

Smoke and Sanity we can are like same thing because both are checking important functionality.
Smoke testing is done on first stable build from developer to check like whether it is stable enough to
move further or not. While Sanity testing is subset of regression test which we perform on stable build
and here also we used to check all the imp functionality.

27. What is Agile ceremony?

We have 4 Agile ceremony -Sprint planning, Sprint review, Sprint Retrospective, Daily scrum meeting.

28. Explain Git workflow?

Step 1: Set up a Github Organization. …
Step 2: Fork Organization Repository to Your Personal GitHub. …
Step 3: Clone the Repository to Your Local Machine. …
Step 4: Create a Branch for your Working Files. …
Step 5: Set Remote Repository to the GitHub Organization. …
Step 6: Get Coding!
Step 7: Pull the Most Recent Files From the Organization Repo
Step 8: Merge the Master Branch Into the Feature Branch
Step 9: Push Your Code to your GitHub Repo
Step 10: Make a Pull Request to the Organization Repo

29. Apart from sendkeys, are there any different ways, to type content onto the editable field?

WebDriver driver = new FirefoxDriver();
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("document.getElementById("textbox_id").value='new value';);

30. How do you handle keystrokes in Selenium?

Using Actions Class: Actions action = new Actions(driver); action. keyDown(Keys. …
Using SendKeys Chord: driver. findElement(By. …
Using Robot Class: // Create Robot class Robot rb = new Robot(); // Press control keyboard key rb.

31. What is dry run in Cucumber?

Dry-run is used to compile feature files and step definitions in cucumber. It is specially used in the stage
when you will have to see if there are any compilation errors, to check that you can use dry-run. Dryrun options can either set as true or false.

32.Annotations in Cucumber
Total 11 Annotations -Feature, Scenario, Background, given, when , then, and, but, example, scenario
outline, scenario template.

33. How do you handle if XPath is changing dynamically?

Option 1: Look for any other attribute which Is not changing every time In that div node like name, class
etc. So If this div node has class attribute then we can write xpath as bellow.

//div[@class=’post-body entry-content’]/div[1]/form[1]/input[1]

Option 2: We can use absolute xpath (full xpath) where you do not need to give any attribute names In
xpath.

/html/body/div[3]/div[2]/div[2]/div[2]/div[2]/div[2]/div[2]/div/div[4]/div[1]/div/div/div/div[1]/div/div/di
v/div[1]/div[2]/div[1]/form[1]/input[1]

Option 3: We can use starts-with function. In this xpath’s ID attribute, “post-body-” part remains same
every time. 

//div[starts-with(@id,’post-body-‘)]/div[1]/form[1]/input[1]

Option 4: We can use contains function. Same way you can use contains function as
bellow.

div[contains(@id,’post-body-‘)]/div[1]/form[1]/input[1]

34. When finally block get executed?

The finally block always executes when the try block exits. This ensures that the finally
block is executed even if an unexpected exception occurs.

Conclusion

In the rapidly evolving landscape of software development, automation testing is a critical component of ensuring high-quality products. By mastering the concepts, tools, and best practices outlined in this article, you’ll be well-prepared to excel in automation testing interviews and contribute to the success of your projects.

Automation testing continues to evolve, and staying updated with the latest trends and technologies is essential for long-term success in this field. Good luck on your journey to becoming an automation testing expert!