Selenium Flashcards Preview

Selenium > Selenium > Flashcards

Flashcards in Selenium Deck (29)
Loading flashcards...
1

What is Selenium?

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. 

2

What are the advantages of using Selenium over QTP?

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.

3

What are the disadvantages of using Selenium over QTP?

Here are some disadvantages when comparing these two technologies

4

What is WebDriver?

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.

5

What is the syntax for instantiating a new driver class?

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();

6

What are locators?

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

7

What would be an example of an unreliable id?

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

8

What is an example of an unreliable classname?

Class names should not include spaces

9

From what direction does Selenium scan the DOM?

Selenium scans from top left to bottom right

10

What is an example of an unreliable xpath?

If an xpath starts with html, it is not reliable

11

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

$("") for CSS

$x("") for xpath

12

What is the syntax for an xpath?

//tagname[@attribute='value']

13

What are the syntaxes for CSS locators?

tagName[attribute='value'] 

tagName#id

tagname.classname

14

What is the syntax for an xpath regular expression?

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

15

What is the syntax for a CSS regular expression?

tagName[Atrribute*='value']

16

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

An absolute xpath starts with the root node

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

17

What are xpath axes?

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

What is the syntax for "Following" xpath axes?

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

What is the syntax for "Following sibling" axes?

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

What is the syntax for the "preceding" axes?

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

What are some important Get Commands?

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

22

What are some important navigate commands?

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

23

What are some commands for closing browser windows?

24

What is an implicit wait?

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

What is an explicit wait?

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

What is fluent wait?

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 wait = new FluentWait(driver) .withTimeout(30, TimeUnit.SECONDS) .pollingEvery(5, TimeUnit.SECONDS) .ignoring(NoSuchElementException.class);

27

What is Assert?

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

What Selenium class is used for drop down lists?

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

29