July 31, 2020 • ☕️ 5 min read
Before I begin discussing the questions, I’d like to emphasize that Manual testing is time-consuming, tedious, boring, and prone to errors. This gave rise to automation testing and in-turn, demand for Selenium automation testers.
Exceptions in Selenium are similar to exceptions in other programming languages. The most common exceptions in Selenium are:
=> TimeoutException: This exception is thrown when a command performing an operation does not complete in the stipulated time
=> NoSuchElementException: This exception is thrown when an element with given attributes is not found on the web page
=> ElementNotVisibleException: This exception is thrown when the element is present in DOM (Document Object Model), but not visible on the web page
=> StaleElementException: This exception is thrown when the element is either deleted or no longer attached to the DOM
Selenium supports the following types of testing:
=> Functional Testing
=> Regression Testing
Selenese is the set of selenium commands which are used to test your web application.
You can even make use of:
=> Actions: Used for performing operations
=> Assertions: Used as checkpoints
=> Accessors: Used for storing a value in a particular variable
Assert: Assert command checks whether the given condition is true or false. Let’s say we assert whether the given element is present on the web page or not. If the condition is true then the program control will execute the next test step but if the condition is false, the execution would stop and no further test would be executed.
Verify: Verify command also checks whether the given condition is true or false. Irrespective of the condition being true or false, the program execution doesn’t halt i.e. any failure during verification would not stop the execution and all the test steps would be executed.
Page Object Model is a design pattern for creating an Object Repository for web UI elements. Each web page in the application is required to have it’s own corresponding page class. The page class is thus responsible for finding the WebElements in that page and then perform operations on those WebElements.
The advantages of using POM are:
=> Allows us to separate operations and flows in the UI from Verification – improves code readability
=> Since the Object Repository is independent of Test Cases, multiple tests can use the same Object Repository
=> Reusability of code
=> Implicit Wait
=> Explicit Wait
Implicit Wait: Implicit waits are used to provide a default waiting time (say 30 seconds) between each consecutive test step/command across the entire test script. Thus, the subsequent test step would only execute when the 30 seconds have elapsed after executing the previous test step/command.
Explicit Wait: Explicit waits are used to halt the execution till the time a particular condition is met or the maximum time has elapsed. Unlike Implicit waits, explicit waits are applied for a particular instance only.
=> CSS Selector
XPath Absolute: XPath Absolute enables users to mention the complete XPath location from the root HTML tag to the specific elements.
Syntax: //html/body/tag1[index]/tag2[index]/.../tagN[index] Example: //html/body/div/div/div/div/div/div/fieldset/form/div/input
XPath Attributes: XPath Attributes is always recommended when you don’t have a suitable id or name attribute for the element you want to locate.
Syntax: //htmltag[@attribute1='value1' and @attribute2='value2'] Example: //input[@id='passwd' and @placeholder='password']
=> findElement(): It is used to find the first element within the current page using the given “locating mechanism”. It returns a single WebElement.
=> findElements(): It uses the given “locating mechanism” to find all the elements within the current page. It returns a list of web elements.