Automation Testing Q&A
Automation Testing Q&A
Automation Testing Q&A
answer me
The document contains a list of automation testing interview questions, primarily focused on Selenium
and related concepts. Let me know if you need answers to any specific questions or if you want
explanations for multiple topics.
That’s a long list, but I’ll cover all the answers systematically. Let’s start with the key concepts one by one.
1. Automation Testing
2. Selenium Architecture
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 1/16
1. Selenium IDE – A record-and-playback tool.
2. Selenium WebDriver – Communicates directly with browsers using their native support.
3. Selenium Grid – Runs tests on multiple machines in parallel.
4. Selenium RC (deprecated) – The older version replaced by WebDriver.
WebDriver is an interface in Selenium that provides methods to interact with web browsers.
java
driver.manage().window().maximize();
driver.manage().window().minimize();
`click()`
`sendKeys()`
`getText()`
`isDisplayed()`
`isEnabled()`
`isSelected()`
`clear()`
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 2/16
9. How to resize the browser?
java
10. How many locators are available in WebDriver & which is preferred?
Locators in Selenium:
1. ID
2. Name
3. Class Name
4. Tag Name
5. Link Text
6. Partial Link Text
7. CSS Selector
8. XPath
Preferred Locator:
ID is the fastest.
XPath and CSS are used for complex locators.
java
Functional Testing
Regression Testing
UI Testing
Cross-browser Testing
Data-driven Testing
Selenium IDE
Selenium WebDriver
Selenium Grid
`navigate().to(url)`
`navigate().back()`
`navigate().forward()`
`navigate().refresh()`
Open-source
Supports multiple languages
Works with multiple browsers
Integrates with CI/CD tools
Parallel execution
The browser navigates to the given URL and waits for the page to load completely.
`driver.navigate().to(url);`
`(//parent-element)[n]`
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 4/16
java
driver.findElement(By.id("textbox")).sendKeys("Hello");
java
java
java
Open-source
Supports multiple languages
No licensing cost
Supports multiple browsers
java
driver.findElement(By.id("fileUpload")).sendKeys("C:\\path\\to\\file");
java
java
driver.get("https://username:password@website.com");
I’ve covered the first 32 questions in detail. Since the list is long, I can either continue answering them in
the same way or summarize them in a document for easy reference. Let me know how you’d like me to
proceed! 😊
33. Difference between single slash `/` and double slash `//` in XPath
Single Slash `/`: Selects nodes from the root (absolute path). Example: `/html/body/div`
Double Slash `//`: Selects nodes anywhere in the document (relative path). Example:
`//div[@id='login']`
Selenium
TestComplete
QTP/UFT
Katalon Studio
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 6/16
Assert: If the condition fails, the test execution stops.
Verify: If the condition fails, the test continues to execute.
Example:
java
The Same-Origin Policy prevents scripts from accessing data from different origins (protocol,
domain, port).
Selenium bypasses this by using browser drivers that interact with the browser directly.
java
java
java
driver.findElement(By.id("upload")).sendKeys("C:\\path\\to\\file.txt");
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 7/16
java
java
java
Implicit Wait:
java
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
Fluent Wait checks for a condition repeatedly at regular intervals before timing out.
java
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 8/16
java
java
java
java
Example:
java
java
driver.switchTo().frame("frame1");
driver.switchTo().frame("frame2");
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 9/16
driver.switchTo().defaultContent(); // Switch back
1. By Index: `driver.switchTo().frame(0);`
2. By Name or ID: `driver.switchTo().frame("frameName");`
3. By WebElement: `driver.switchTo().frame(driver.findElement(By.tagName("iframe")));`
Running the same test with multiple data inputs using Excel, CSV, or databases.
java
Improves maintainability.
Reduces code duplication.
Enhances test readability.
Using `testng.xml`:
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 10/16
xml
Using `dependsOnMethods`:
java
@Test(dependsOnMethods = {"test1"})
public void test2() {
System.out.println("Runs only if test1 passes");
}
java
Example:
java
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 11/16
String url = prop.getProperty("url");
System.out.println("URL: " + url);
Page Object Model (POM) is a design pattern where each webpage is represented as a Java class with
locators and methods.
Example:
java
Occurs when the DOM is updated and an existing element reference becomes invalid.
Solution:
Example:
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 12/16
java
Example:
java
✅ Advantages:
Improves maintainability and reusability.
Separates UI elements from test logic.
❌ Disadvantages:
More effort is required for initial setup.
Needs expertise in object-oriented programming.
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 13/16
Annotations define test behavior before/after execution.
Annotation Description
`@BeforeSuite` Runs once before all tests
Example:
java
@BeforeMethod
public void setup() {
System.out.println("Setup before test");
}
@Test
public void testCase1() {
System.out.println("Test Case 1");
}
Batch execution means running multiple test cases together using `testng.xml`.
Example `testng.xml`:
xml
<suite name="BatchSuite">
<test name="Test1">
<classes>
<class name="TestClass1"/>
<class name="TestClass2"/>
</classes>
</test>
</suite>
Run with:
sh
mvn test
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 14/16
Example `testng.xml`:
xml
java
@Test(enabled = false)
public void testDisabled() {
System.out.println("This test won't run");
}
Example:
java
Assert.assertEquals(actualTitle, expectedTitle);
Using `dependsOnMethods`:
java
@Test
public void test1() {
Assert.fail(); // Forces failure
}
@Test(dependsOnMethods = "test1")
public void test2() {
System.out.println("Skipped because test1 failed");
}
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 15/16
Example:
java
1. Scroll by pixel:
java
2. Scroll to an element:
java
js.executeScript("arguments[0].scrollIntoView();", element);
java
js.executeScript("window.scrollTo(0, document.body.scrollHeight)");
Final Thoughts
Printed using ChatGPT to PDF, powered by PDFCrowd HTML to PDF API. 16/16