Top Test Automation Engineers Q&A 2024
What is the difference between Page Object Model and Page Factory?
Page Object Model (POM):
POM is a Selenium design pattern; we can see it as a repository where we store all the WebElements. This has become very popular in industry these days, because it is very easy to manage, reusability of code and eliminates duplication of code.
The key benefit if UI changes in the future, then we can update WebElements to Page Classes in POM or Object Repository accordingly
Page Factory:
Page Factory in Selenium WebDriver is an integrated concept or API. Here we follow again the same principle of keeping repository objects or page classes separate from test classes.
Here we use @FindBy to find elements and to initialize WebElements using initElements process.
What are all the locators that support selenium?
Name: Same as ID although it is not unique
CSS Selector: Works on element tags and attributes
XPath: Searches elements in the DOM, Reliable but slow
Class name: Uses the class name attribute
TagName: Uses HTML tags to locate web elements
LinkText: Uses anchor text to locate web elements
Partial Link Text: Uses partial link text to find web elements ID-
How To Overcome StaleElementReferenceException in Selenium?
The reference to an element is now “stale”; the element will no longer appear on the page’s DOM. In simple words, when you started interacting with it, the element you located using the findElement method disappeared.
Add exception handling to your action and, if the exception is stale, try to locate the element after a simple wait for 500 milliseconds and repeat these actions until the action or max iterations have been successful.
How to access the CSS selector using the nth element?
Here is a syntax for using the CSS selector to access the nth attribute: <type>:nth-child(n)
Ex: tr:nth-child(2)
How to handle alerts in Selenium WebDriver?
WebDriver provides an API to handle alert dialogs. Alerts cannot able to inspect if there is no Alert in the screen, you will get ‘NoAlertPresentException’
The Alert interface contains a number of APIs to execute different actions.
The following list:
Alert alert = driver.switchto().alert();
alert.accept(); This is equivalent to the OK button action on the dialog
alert.dismiss(); This is equivalent to clicking on the CANCEL action button
alert.sendKeys(“String”); This will allow to type in some text into the alert
alert.getText(); This will return the text that appears on the dialog
Only Questions:
- How do you use Map Collections in your Selenium Project (Give some examples) ?
2) Can we have duplicate key value in HashMap?
3) How do you select the drivers to launch a URL?
4) Explain the concept of Object Repository?
5) How to fetch an element when its attributes are changing frequently?
6) There are four browser windows opened and you don’t have any idea where the required element is present. What will be your approach to find that element? Also write down the code logic
7) If a page contains 1000 images, how can you fetch 100th image?
8) What will this Java code print: String x = “Latest version”; String y = “of Selenium”; int z = 3; System.out.println(“We are learning Selenium”+” and the “+x+” “+y+” is “+z); ?
9) How can you determine if String has all Unique Characters?
10) How to convert String to integer without using any direct method
in Java.
11) Can you arrange the below testng.xml tags from parent to child?
<test>
<suite>
<class>
<methods>
<classes>
12) How we can retrieve the dynamically changing Ids?
13) How can you handle multipart requests using Rest Assured?
14) How do you handle response headers in Rest Assured tests?
15) How can you handle authentication using OAuth 2.0 in Rest Assured?
16) How do you run a Maven build in parallel?
17) What must be checked when performing API testing?
18) How is a Web Service different from an API?
19) Why do we need HTTPS, when HTTP is present?
20) Why do mocks and stubs not be used in End to End Testing?
-x-x-
To get answers for all the above mentioned questions and more: Link
Want to become Full Stack QA? Let’s dive in depth and become a successful Test Architect: Link
My LinkedIn: https://www.linkedin.com/in/japneet-sachdeva
#japneetsachdeva