Selenium Flashcards

1
Q

What is Selenium?

A

Selenium is a free (open source) automated testing suite for web applications across different browsers and platforms. It is quite similar to HP Quick Test Pro (QTP now UFT) only that Selenium focuses on automating web-based applications.

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

What are the advantages of using Selenium over QTP?

A

QTP and Selenium are the most used tools in the market for software automation testing. Hence it makes sense to compare the pros of Selenium over QTP.

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

What are the disadvantages of using Selenium over QTP?

A

Here are some disadvantages when comparing these two technologies

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

What is WebDriver?

A

WebDriver is a web automation framework that allows you to execute your tests against different browsers, not just Firefox, Chrome (unlike Selenium IDE).

WebDriver also enables you to use a programming language in creating your test scripts (not possible in Selenium IDE).

You can now use conditional operations like if-then-else or switch-case. You can also perform looping like do-while.

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

What is the syntax for instantiating a new driver class?

A

The syntax is dependent on which browser the user plans to use. The syntax for FireFox, Google Chrome, and Internet Explorer in order are:

WebDriver driver = new FirefoxDriver();

WebDriver driver = new ChromeDriver();

WebDriver driver = new InternetExplorerDriver();

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

What are locators?

A

Locators provide a way to access the HTML elements from a web page to perform operations on it. Types of locators include:

  • Id
  • Name
  • Classname
  • Link text
  • CSS selector
  • Xpath
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What would be an example of an unreliable id?

A

If an id includes alpha numeric characters, then it is not reliable

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

What is an example of an unreliable classname?

A

Class names should not include spaces

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

From what direction does Selenium scan the DOM?

A

Selenium scans from top left to bottom right

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

What is an example of an unreliable xpath?

A

If an xpath starts with html, it is not reliable

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

What is the syntax for verifying xpaths and CSS locators in the DOM console?

A

$(“”) for CSS

$x(“”) for xpath

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

What is the syntax for an xpath?

A

//tagname[@attribute=’value’]

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

What are the syntaxes for CSS locators?

A

tagName[attribute=’value’]

tagName#id

tagname.classname

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

What is the syntax for an xpath regular expression?

A

//tagName[contains(@attribute,’value’)]

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

What is the syntax for a CSS regular expression?

A

tagName[Atrribute*=’value’]

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

What is the difference between a relative xpath and an absolute xpath?

A

An absolute xpath starts with the root node

A relative xpath is one where the path starts from the node of your choice

17
Q

What are xpath axes?

A

XPath axes comes in handy when the exact element tagname or its attribute value are dynamic and cannot be used to locate an element. In this case locating element after traversing through child/sibling or parent will be the standard approach

18
Q

What is the syntax for “Following” xpath axes?

A

This XPath axes helps to locate element following the current node

Xpath=//input[@name=’ organization_name’]//following::input[1]

Xpath= //input[@name=’ organization_name’]//following::input

In the above-mentioned examples, the first one will select the input following the organization element, whereas in the second example, it will select all elements following the organization element having input tag.

19
Q

What is the syntax for “Following sibling” axes?

A

In case of following siblings, all following nodes of the context node, that shares the same parent, are applicable. In this case all siblings are referred to as children of the parent node. So if you are referencing one of the children and wish to navigate to other children of the same parent that follows it, following sibling does the job

Xpath= //li[@class=’sign-in’]//following-sibling::li

20
Q

What is the syntax for the “preceding” axes?

A

This method helps in locating element before the current node, as in the preceding element from the current node with XPath in Selenium

In the example below, the first one will locate element with the field as email whereas the other one will locate all elements before the current node i.e. password field.

Xpath=//input[@name=’password’]//preceding::input[1]

Xpath=//input[@name=’password’]//preceding::input

21
Q

What are some important Get Commands?

A

Get commands fetch various important information about the page/element. Here are some important “get” commands you must be familiar with.

22
Q

What are some important navigate commands?

A

These commands allow you to refresh,go-into and switch back and forth between different web pages

23
Q

What are some commands for closing browser windows?

A
24
Q

What is an implicit wait?

A

The implicit wait will tell to the web driver to wait for certain amount of time before it throws a “No Such Element Exception”. The default setting is 0. Once we set the time, web driver will wait for that time before throwing an exception.

In the below example we have declared an implicit wait with the time frame of 10 seconds. It means that if the element is not located on the web page within that time frame, it will throw an exception.

driver.manage().timeouts().implicitlyWait(TimeOut, TimeUnit.SECONDS);

25
Q

What is an explicit wait?

A

The explicit wait is used to tell the Web Driver to wait for certain conditions (Expected Conditions) or the maximum time exceeded before throwing an “ElementNotVisibleException” exception.

The explicit wait is an intelligent kind of wait, but it can be applied only for specified elements. Explicit wait gives better options than that of an implicit wait as it will wait for dynamically loaded Ajax elements.

In the below example, we are creating reference wait for “WebDriverWait” class and instantiating using “WebDriver” reference, and we are giving a maximum time frame of 20 seconds.

WebDriverWait wait = new WebDriverWait(WebDriverRefrence,TimeOut);

WebElement guru99seleniumlink; guru99seleniumlink = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(“/html/body/div[1]/section/div[2]/div/div[1]/div/div[1]/div/div/div/div[2]/div[2]/div/div/div/div/div[1]/div/div/a/i”))); guru99seleniumlink.click();

In the above example, wait for the amount of time defined in the “WebDriverWait” class or the “ExpectedConditions” to occur whichever occurs first.

The above Java code states that we are waiting for an element for the time frame of 20 seconds as defined in the “WebDriverWait” class on the webpage until the “ExpectedConditions” are met and the condition is “visibilityofElementLocated”.

26
Q

What is fluent wait?

A

The fluent wait is used to tell the web driver to wait for a condition, as well as the frequency with which we want to check the condition before throwing an “ElementNotVisibleException” exception.

Frequency: Setting up a repeat cycle with the time frame to verify/check the condition at the regular interval of time

Let’s consider a scenario where an element is loaded at different intervals of time. The element might load within 10 seconds, 20 seconds or even more then that if we declare an explicit wait of 20 seconds. It will wait till the specified time before throwing an exception. In such scenarios, the fluent wait is the ideal wait to use as this will try to find the element at different frequency until it finds it or the final timer runs out.

Wait<webdriver> wait = new FluentWait<webdriver>(driver) .withTimeout(30, TimeUnit.SECONDS) .pollingEvery(5, TimeUnit.SECONDS) .ignoring(NoSuchElementException.class);</webdriver></webdriver>

27
Q

What is Assert?

A

Asserts helps us to verify the conditions of the test and decide whether test has failed or passed. A test is considered successful ONLY if it is completed without throwing any exception

assertEqual(String actual,String expected) :- It takes two string arguments and checks whether both are equal, if not it will fail the test.

assertEqual(String actual,String expected, String message) :- It takes three string arguments and checks whether both are equal, if not it will fail the test and throws the message which we provide.

assertEquals(boolean actual,boolean expected) :- It takes two Boolean arguments and checks whether both are equal, if not it will fail the test.

assertEquals(java.util.Collection actual, java.util.Collection expected, java.lang.String message) :- Takes two collection objects and verifies both collections contain the same elements and with the same order. if not it will fail the test with the given message.

Assert.assertTrue(condition) :- It takes one boolean arguments and checks that a condition is true, If it isn’t, an AssertionError is thrown.

Assert.assertTrue(condition, message) :- It takes one boolean argument and String message. It Asserts that a condition is true. If it isn’t, an AssertionError, with the given message, is thrown.

Assert.assertFalse(condition) :- It takes one boolean arguments and checks that a condition is false, If it isn’t, an AssertionError is thrown.

Assert.assertFalse(condition, message) :- It takes one boolean argument and String message. It Asserts that a condition is false. If it isn’t, an AssertionError, with the given message, is thrown.

28
Q

What Selenium class is used for drop down lists?

A

The following are the most common methods used on drop down list.

29
Q
A