Test Automation 1725355821
Test Automation 1725355821
Test Automation 1725355821
com
+918130877931
Test Automation
QnA
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
WebDriver Interface:
Upcasting to WebDriver interface allows you to change the browser driver (e.g.,
ChromeDriver, FirefoxDriver) without changing the code that interacts with the
driver, thus making your code more flexible and maintainable.
3. If we do not add driver exe file what will happen and what kind of exception
will be generated?
If the driver executable is not added, Selenium won't be able to communicate with
the browser, and a WebDriverException will be thrown.
quit(): Closes all the browser windows and ends the WebDriver session.
navigate().to(): Does the same as get() but allows for additional navigation
options like back, forward, and refresh.
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
7. How to get all the links in the current page? Which locator will you use other
than XPath?
List<WebElement> links =
driver.findElements(By.cssSelector("a"));
8. Methods of WebDriver?
Download the WebDriver executable from the official site of the respective
browser (e.g., ChromeDriver for Chrome).
System.setProperty("webdriver.chrome.driver",
"path/to/chromedriver");
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
driver.get("http://example.com");
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
WebDriver: A tool to directly interact with web browsers without needing a server.
17. How do you get the URL of the current web page?
20. Assume browser version is different and exe file version is different, what
kind of exception will you get?
Maximize:
driver.manage().window().maximize();
Minimize:
driver.manage().window().minimize();
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
23. How do you capture a screenshot for a failed test script? Write syntax.
getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshot, new
File("path/to/save/screenshot.png"));
24. When do we go for findElements method and what is the return type?
This exception is thrown when WebDriver is unable to interact with the browser.
Possible reasons include incorrect WebDriver setup, browser crashes, or network
issues.
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
29. We have 4 tabs in the browser currently I am in parent tab how do you
switch into 4th tab?
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
int y = location.getY();
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
getRect() provides the location and size of the element in a single method.
element.sendKeys("text");
41. How do you pass data into a text field without using sendKeys()?
Use JavaScript:
42. How do you click on the WebElement without using click() method?
Use JavaScript:
js.executeScript("arguments[0].click();", element);
43. How will you check whether the element is displayed or not?
44. How will you check whether the element is enabled or not?
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
45. How will you check whether the element is selected or not?
46. How do you get all the links of the current web page?
To allow locating elements both at the document level (using WebDriver) and
within a specific parent element (using WebElement).
Use getCssValue():
driver.manage().deleteAllCookies();
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
Disabled elements cannot be interacted with directly. You may use JavaScript to
interact with them:
js.executeScript("arguments[0].removeAttribute('disabled');", element);
52. How will you handle scroll up and scroll down webpage?
Use JavaScript:
// Scroll down
js.executeScript("window.scrollBy(0,1000)");
// Scroll up
js.executeScript("window.scrollBy(0,-1000)");
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
Synchronization:
Synchronization refers to handling the timing issues when there are delays in
loading elements or pages, ensuring that Selenium waits for elements to be
available before performing actions on them.
56. Which wait statement will be used to wait until the page gets loaded?
Use explicit waits to wait for the object to appear, and use flexible locators like
XPath or CSS selectors that can handle dynamic attributes.
Implicit wait: Sets a default wait time for the WebDriver to wait for elements to
appear.
Fluent wait is a type of explicit wait with polling intervals. It repeatedly checks for a
condition at specified intervals, ignoring exceptions.
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
60. If an element fails to load within implicit wait, what exception will you get?
NoSuchElementException.
Locators:
ID, Name, Class Name, Tag Name, Link Text, Partial Link Text, CSS Selector, XPath.
When you need a fast and flexible locator that can handle complex CSS attribute
matching.
When the element has a unique ID attribute, which is the fastest and most reliable
locator.
When other locators are not suitable, especially for complex and dynamic
elements.
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
CSS selector is generally faster and more readable. XPath is more powerful and
flexible, especially for complex element hierarchies.
Absolute XPath: Starts from the root and follows a complete path (e.g.,
/html/body/div).
Relative XPath: Starts from the middle of the HTML DOM structure (e.g.,
//div[@id='example']).
You can use the browser's developer tools to inspect elements and generate
XPath.
XPath axes refer to the relationship between nodes in the document. Common
axes include parent, child, ancestor, descendant, following-sibling, and
preceding-sibling.
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
73. What is your approach to find the location of WebElement if we do not have
any attribute in the tag?
Use the element's position relative to other elements, or use text-based XPath.
74. How will you handle if the locator value is matching with multiple elements?
75. Will locator value of the WebElement change from one browser to another?
Justify.
Pop-Ups:
76. How do you identify whether it is an alert pop-up or not? How do you handle
it?
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
80. How do you identify whether it is a notification pop-up or not? How do you
handle it?
Notification pop-ups are handled by the browser. You can use WebDriver to
interact with the notification permissions.
driver.get("http://username:password@url.com");
Use sendKeys() to input the file path into the file input element.
83. If alert pop has text field how will you enter the value to the field?
driver.switchTo().alert().sendKeys("text");
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
85. Can I handle file upload pop-up with the help of Robot class? If yes, explain.
Yes, Robot class can simulate keyboard and mouse actions to handle file upload
pop-ups.
Runtime.getRuntime().exec("path/to/autoit/script.exe");
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
Drop Down:
90. How will you identify if a dropdown is single select or multi select?
select.selectByVisibleText("Option");
94. How will you handle dropdown without using Select class?
Click on the dropdown and then click on the desired option using WebDriver
methods.
95. How will you get all the options from dropdown?
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
Loop through the options and select every alternate one using Select methods.
97. How will you get only selected options from dropdown?
Loop through the options list and select options with even indices.
99. How will you get the first selected option from dropdown?
100. How will you check if the content in dropdown is not duplicate?
- Store options in a Set and compare its size with the original list.
- It returns a WebElement.
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
105. How do you de-select the selected option from the dropdown?
106. How do you de-select all the selected options from the dropdown?
107. We have two dropdowns in a web page. How will you compare all the
options of one dropdown with all the options of another dropdown?
- Get the options of both dropdowns using getOptions() method and compare
their text values.
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
Actions Class:
actions.doubleClick(element).perform();
actions.contextClick(element).perform();
actions.dragAndDrop(sourceElement, targetElement).perform();
113. Can I perform keyboard actions with the help of Actions class?
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
- build(): Compiles the actions into a single step. - perform(): Executes the
actions.
Frames:
driver.switchTo().frame(frameElement);
- Use switchTo().frame()
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
122. How to work with frame, when frame does not have id & @name attribute?
Data-driven:
- A framework where test data is driven from external data sources like Excel, CSV,
or databases.
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
- Apache POI is a Java API for manipulating Microsoft documents like Excel.
129. How do you get the data from Excel sheet? Write syntax.
130. How do you set the data into Excel sheet? Explain with syntax.
- It is a class.
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
141. How do you set multiple data into Excel sheet dynamically?
- Use loops to iterate through rows and cells, setting data dynamically.
142. How do you get data from all the columns of the last row in an Excel sheet?
- Use getLastRowNum() to find the last row and then iterate through columns.
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
143. What are the jars/dependencies we need to add to get/set the data from
Excel sheet?
TestNG:
- TestNG is a testing framework inspired by JUnit and NUnit, designed for testing
needs in Java.
- In Eclipse: Go to Help > Eclipse Marketplace > Search for TestNG > Install. - Maven:
Add the TestNG dependency to pom.xml.
- When there are issues with TestNG configuration or when tests fail to execute
properly.
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
- TestNG is a class.
- Define tests in
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
160. I have 200 test cases, what is your approach if I want to execute them
parallelly in two different browsers?
161. I have 200 test cases, what is your approach if I want to execute them
parallelly in the same browser?
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
164. How do you run all the test cases at the project level?
- Use the testng.xml file at the project root or use Maven/Gradle build tools.
- Use testng.xml to define a single test or run it directly from the IDE.
- For parameterizing tests and providing multiple sets of data to a test method.
168. How do you run the same test case 100 times?
@Test(invocationCount = 100)
169. How will you create dependency between two test cases?
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
@Test(enabled = false)
@Test(priority = 1)
174. How do you convert all the test cases into testNG.xml file?
- Use the TestNG Eclipse plugin to generate testng.xml or manually create the file.
- Yes, you can create multiple testNG.xml files for different test suites.
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
177. Can I create multiple testNG.xml files with the same name?
- Yes, you can run it directly from the IDE or through the command line.
- It provides detailed HTML reports of test execution with logs and results.
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
186. I will run 100 test cases but 10 got failed. How do you run only those failed
test cases?
POM:
- Page Object Model (POM) is a design pattern to create object repositories for
web UI elements.
- Each page of the application should have a corresponding class. This class
should contain WebElements and methods to interact with those elements.
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
- Re-locate the element, use retry logic, or wait until the DOM is stable.
- findBy: Finds a single element. - findBys: Finds elements matching all specified
criteria. - findAll: Finds elements matching any of the specified criteria.
- To ensure that the WebElements are accessed only through methods in the POM
class, enhancing maintainability and readability.
197. Why do we need to call initElements() method only inside the constructor?
- To initialize the elements as soon as the object of the POM class is created.
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
General:
- To save time, reduce human errors, increase test coverage, and perform
repetitive tasks efficiently.
- Automation testing involves using tools and scripts to perform tests on software
applications automatically.
hr@kasperanalytics.com
kasper-analytics
kasperanalytics.com
+918130877931
- GitHub is a web-based platform for version control and collaboration using Git.
It allows multiple developers to work on projects simultaneously, track changes,
and manage repositories.
- Maven is a build automation tool used primarily for Java projects. It helps
manage project dependencies, build processes, and project documentation.
hr@kasperanalytics.com
kasper-analytics