Selenium Flashcards

1
Q

Explain the statement WebDriver driver = new ChromeDriver();

A

WebDriver is an interface provided by Selenium WebDriver & driver is a reference variable & equal to the assignment operator
Creating a reference variable of type WebDriver assigns the driver object to different browser specific drivers.
It allows multi browser testing by assigning the driver object to any of the desired browsers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Implicit wait

A

The implicit wait is a single line of code and can be declared in the setup method of the test script. The syntax and approach are simpler than explicit wait.
Include the above line of code into your test script soon after instantiation of WebDriver instance variable
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
The implicit wait mandates to pass two values as parameters. The first argument indicates the time in the numeric digits that the system needs to wait. The second argument indicates the time measurement scale

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explicit wait

A

Explicit waits are used to halt the execution until the time a particular condition is met or the maximum time has elapsed. Explicit waits are applied for a particular instance only.

WebDriverWait wait = new WebDriverWait(driver,30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(“//div[contains(text(),’COMPOSE’)]”)));

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Explicit wait ExpectedConditions

A
  • alert_is_present
  • title_is
  • element_to_be_clickable
  • text_to_be_present_in_element
  • element_to_be_selected
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the use of Desired Capabilities?

A

Desired Capabilities is a class in Selenium used to set properties of browsers to perform cross browser testing of web applications.
Desired capabilities are used to set browser properties like browser name, browser version, path of browser driver in the system, what operating system to execute, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is DOM (document object model)?

A

The Document Object Model (DOM) is a programming interface for web documents. It represents the page so that programs can change the document structure, style, and content. The DOM represents the document as nodes and objects; that way, programming languages can interact with the page.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is XPath & how it works (how it will find an element)?

A

XPath is a technique in Selenium to navigate through the HTML structure of a page. It will look for a given tag (text, attribute, etc.) Basically, XPath works based on the DOM structure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the difference between absolute & relative XPath?

A
  • Absolute Xpath is the direct way to find the element, but the disadvantage of the absolute XPath is that if there are any changes made in the path of the element then that XPath gets failed.
    The key characteristic of XPath is that it begins with the single forward slash(/), which means you can select the element from the root node.
  • Relative Xpath starts from the middle of HTML DOM structure. It starts with a double forward slash (//). It can search elements anywhere on the webpage, which means no need to write a long XPath and you can start from the middle of HTML DOM structure. Relative Xpath is always preferred as it is not a complete path from the root element.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the use of JavaScriptExecutor?

A

JavaScriptExecutor is an interface that is used to execute JavaScript with Selenium.
- To Click on a Button
- To Type Text in a Text Box without using sendKeys() method
- To refresh the browser window using Javascript
- To get the URL of a webpage

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to handle multiple windows in Selenium?

A

By using get window handles and then driver.switchTo().window(window id)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the difference between getWindowHandle() & getWindowHandles()?

A

getWindowHandle() returns the window handle of currently focused window/tab. getWindowHandles() returns all windows/tabs handles launched/opened by same driver instance including all parent and child window.
Return type of getWindowHandle() is String while return type of getWindowHandles() is Set<String>. The return type is Set as window handle is always unique</String>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to find how many options are in the drop down menu?

A

We can extract all the options in a dropdown in Selenium with the help of Select class which has the getOptions() method. This retrieves all the options on a Select tag and returns a list of web elements. This method does not accept any arguments. And then use a size() method to have all the options

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How to handle the mouse operations?

A

We use Actions class method which has several methods such as left click, right click, double click, move to element

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the difference between hard assertion & soft assertion in TestNG?

A
  • Hard Assertion throws AssertionError immediately when an Assert Condition fails and moves to next @Test method
  • Soft Assert does not throw an exception when an Assert Condition fails and continues with the next step after the Assert Condition.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is prioritization in TestNG?

A

In TestNG, Priority is an attribute that helps the users define the order in which they want the test cases to be executed. When you have multiple test cases and want them to run in a particular order, you can use the Priority attribute to set test priority in TestNG
Number 0 has the default (highest) priority
If we want to give a test method, priority higher than the default priority then we can simply assign a negative value to the priority attribute of that test method
@Test(priority = -1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to execute only failed cases?

A
  • After the first run of an automated test run. Right click on Project – Click on Refresh.
  • A folder will be generated named “test-output” folder. Inside “test-output” folder, you could find “testng-failed. xml”
  • Run “testng-failed. xml” to execute the failed test cases again
17
Q

What are the benefits of using Maven?

A
  • Helps manage all the processes, such as building, documentation, releasing, and distribution in project management
  • Simplifies the process of project building
  • Increases the performance of the project and the building process
  • Provides easy access to all the required information
  • In Maven, it’s easy to add new dependencies by writing the dependency code in the pom file
18
Q

What are the different types of Maven Plugins?

A
  • Building Plugins: These plugins are used at the time of build and are defined in the building element of the pom file.
  • Reporting Plugins: These plugins are used at the time of site generation and are defined in the reporting element of the pom file.
19
Q

Name the build phases in Maven Build Lifecycle.

A
  • Validate: Checks if all the preconditions information to trigger the build is obtained.
  • Compile: Project source code is compiled.
  • Test: The Source code that is compiled is tested with the unit test framework. In this phase, the code is not deployed or packaged.
  • Package: Source code after compilation is packaged in the form of ZIP or JAR files.
  • Integration- test: After the package is deployed in an environment, the integration test cases are executed.
  • Verify: Examines to ensure that the package is correct and it meets all the required quality specifications.
  • Install: Installation of packages into the local repository.
  • Deploy: A specimen of the final package is made accessible to the remote repository for distribution among the other developers across projects.
20
Q

What is the purpose of command mvn clean in Maven?

A

mvn clean aims to clean the project artifacts created by the previous Maven builds from the target directories. This is generally executed before initiating a new build process.

21
Q

What do you mean by a Maven Repository?

A

Maven repository is the location of a directory where all the related project artifacts, jars, libraries, plugins are kept and can be utilized by Maven easily.

22
Q

Most common Selenium Exceptions

A

NoSuchWindowException.
NoSuchFrameException.
NoSuchElementException.
NoAlertPresentException.
InvalidSelectorException.
TimeoutException.
ElementNotVisibleException.
ElementNotSelectableException.