Trick Software Automation Questions Flashcards

1
Q

What is the difference between an Assert and a Verify with Selenium Commands?

A

Assert allows to check whether an element is on the page or not. The test will stop on the step failed, if the asserted element is not available.

Verify command will check whether the element is on the page, if it is not then the test will carry on executing. In verification, all the commands are going to run guaranteed even if any of test fails.

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

What is one big difference between SilkTest and Selenium?

A

Selenium supports many browsers like Internet Explorer, Opera, Chrome, Firefox, Safari.

SilkTest supports only Internet Explorer and Firefox

Another difference is Selenium has many language bindings like Java, .Net, Perl, PHP, Python, Ruby under test while SilkTest uses 4Test scripting language to describe the test procedure.

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

Which browsers can Selenium IDE be run in?

A

FireFox

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

How does one get rid of the right-pointing green triangle?

A

Right click on that line and remove break point.

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

How can one add vertical white space between sections of a single test?

A

You can use vertical bars at the beginning of lines to produce blank lines in the output.

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

What does SIDE stand for?

A

Selenium Integrated Development Environment.

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

What regular expression special character(s) means “any character?”

A
  • = star or asterisk
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What distinguishes between an absolute and relative URL in SIDE?

A

Absolute will have Double Slash

Relative will have single slash

An absolute URL contains more information than a relative URL does. Relative URLs are more convenient because they are shorter and often more portable. However, you can use them only to reference links on the same server as the page that contains them.

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

How would one access a Selenium variable named “count” from within a JavaScript snippet?

A

${count} = dollar sign curly brackets count

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

What Selenese command can be used to display the value of a variable in the log file, which can be very valuable for debugging?

A

We can use echo command to log information in the test result output.

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

Where did the name Selenium come from?

A

Actually, Selenium is a chemical element name. But Thoughtworks used it for test automation framework api.

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

Which Selenium command(s) simulates selecting a link?

A

For simulating selecting a link, we can use findElement(By.Link(“LinkName”))

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

Which two commands can be used to check that an alert with a particular message popped up?

A

Use command VerifyAlertPresent

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

What command simulates selecting the browser’s Back button?

A

driver.navigate().back() command

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

If the Test Case frame contains several test cases, how can one execute just the selected one of those test cases?

A

Users can use “Play current test case” function of Selenium IDE

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

What is the generic name for an argument (to a Selenese command) which starts with //?

A

Xpath

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

What Selenese command is used to choose an item from a list?

A

Select command

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

How can one get SIDE to always record an absolute URL for the open command’s argument?

A

In the Selenium IDE options, check “Record Absolute URL” option.

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

What Selenese command and argument can be used to transfer the value of a JavaScript variable into a SIDE variable?

A

Use “store” command

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

Explain the different exceptions in Selenium WebDriver.

A

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.

NoAlertPresentException

StaleElementException: This exception is thrown when the element is either deleted or no longer attached to the DOM.

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

What is exception test in Selenium?

A

An exception test is an exception that you expect will be thrown inside a test class.

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

Why and how will you use an Excel Sheet in your project?

A

It can be used as data source for tests. An excel sheet can also be used to store the data set while performing DataDriven Testing

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

What is POM (Page Object Model)? What are its advantages?

A

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.

improves code readability
multiple tests can use the same Object Repository
Reusability of code

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

What is Page Factory?

A

Page Factory gives an optimized way to implement Page Object Model. When we say it is optimized, it refers to the fact that the memory utilization is very good and also the implementation is done in an object oriented manner

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

What is the difference between Implicit Wait and Explicit Wait

A

Implicit wait instructs the WebDriver to wait for some time by polling the DOM. Once you have declared implicit wait, it will be available for the entire life of the WebDriver instance.

Explicit wait instructs the execution to wait for some time until some condition is achieved. Some of those conditions to be attained are:

elementToBeClickable
elementToBeSelected
presenceOfElementLocated

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

Write a code to wait for a particular element to be visible on a page. Write a code to wait for an alert to appear.

A
WebDriverWait wait=new WebDriverWait(driver, 20);
Element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath( “
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

What is the use of JavaScriptExecutor?

A

JavaScriptExecutor is an interface which provides a mechanism to execute Javascript through the Selenium WebDriver. It provides “executescript” and “executeAsyncScript” methods, to run JavaScript in the context of the currently selected frame or window.

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

How to scroll down a page using JavaScript in Selenium?

A

window.scrollBy() function.

((JavascriptExecutor) driver).executeScript(“window.scrollBy(0,500)”);

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

How to scroll down to a particular element?

A

scrollIntoView().

((JavascriptExecutor) driver).executeScript(“arguments[0].scrollIntoView();”, element);

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

How to handle keyboard and mouse actions using Selenium?

A

using Advanced User Interactions API

clickAndHold() - Clicks (without releasing) the current mouse location.

dragAndDrop() - Performs click-and-hold at the location of the source element, moves.

source, target() - Moves to the location of the target element, then releases the mouse.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q
  1. What are different types of frameworks?
A

Data Driven Framework:-
When the entire test data is generated from some external files like Excel, CSV, XML or some database table,

Keyword Driven Framework:-
When only the instructions and operations are written in a different file like an Excel worksheet,

Hybrid Framework:-
A combination of both the Data Driven framework and the Keyword Driven framework

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

How can you fetch an attribute from an element? How to retrieve typed text from a textbox?

A

getAttribute() method

WebElement eLogin = driver.findElement(By.name(“Login”);
String LoginClassName = eLogin.getAttribute(“classname”);

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

How to send ALT/SHIFT/CONTROL key in Selenium WebDriver?

A

keyDown(modifier_key) and keyUp(modifier_key)
 Parameters: Modifier_key (keys.ALT or Keys.SHIFT or Keys.CONTROL)

.click()
.keyDown(txtUserName, Keys.SHIFT)
.sendKeys(txtUserName, “hello”)
.keyUp(txtUserName, Keys.SHIFT)

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

How to take screenshots in Selenium WebDriver?

A

TakeScreenshot function

By using getScreenshotAs() method you can save that screenshot.

File scrFile = ((TakeScreenshot)driver).getScreenshotAs(outputType.FILE);

35
Q

How to set the size of browser window using Selenium?

A

driver.manage().window().maximize(); – To maximize the window

To resize the current window to a particular dimension, use the setSize() method

System.out.println(driver.manage().window().getSize());
Dimension d = new Dimension(420,600);
driver.manage().window().setSize(d);
36
Q

How to handle a dropdown in Selenium WebDriver? How to select a value from dropdown?

A

Identify the ‘select’ html element (Because dropdowns must have the ‘select’ tag)
To identify the ‘select’ html element from the web page, we need to use findElement() method.

Select an option from that dropdown element

Now to select an option from that dropdown, we can do it in either of the three ways:

dropdown. selectByVisibleText(“Bikes”); → Selecting an option by the text that is visible
dropdown. selectByIndex(“1”); → Selecting, by choosing the Index number of that option
dropdown. selectByValue(“option2”); → Selecting, by choosing the value of that option

WebElement mySelectElement = driver.findElement(By.id("mySelect"));
Select dropdown = new Select(mySelectElement);
37
Q

How to switch to a new window (new tab) which opens up after you click on a link?

A

driver.switchTo().window();

Once you have the name of the window, then you can use an enhanced for loop to switch to that window. Look at the piece of code below.

String handle= driver.getWindowHandle();
for (String handle : driver.getWindowHandles())
{
driver.switchTo().window(handle);
}
38
Q

Can we enter text without using sendKeys()?

A

We can do it using JavaScriptExecutor.

Using DOM method of identification of an element, we can go to that particular document and then get the element by its ID (here login) and then send the text by value.

JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript(“document.getElementById(‘Login’).value= Test text without sendkeys”);

39
Q

Explain how you will login into any site if it is showing any authentication popup for username and password?

A

Pass the username and password with url

Syntax-http://username:password@url
ex- http://creyate:tom@www.gmail.com

40
Q

Explain how can you find broken links in a page using Selenium WebDriver? This is a trick question :

He can provide a situation where in there are 20 links in a web page, and we have to verify which of those 20 links are working and how many are not working (broken).

A

First, we have to use the anchor tags <a> to determine the different hyperlinks on the web page.</a>

For each </a><a> tag, we can use the attribute ‘href’ value to obtain the hyperlinks and then analyze the response received for each hyperlink when used in driver.get() method.</a>

Whenever you use driver.get() method to navigate to a URL, it will respond with a status of 200 – OK. 200 – OK denotes that the link is working and it has been obtained. If any other status is obtained, then it is an indication that the link is broken.

</a>

41
Q

Which technique should you consider using throughout the script “if there is neither frame id nor frame name”?

A

If neither frame name nor frame id is available, then we can use frame by index.

driver.switchTo().frame(int arg0);

The first frame would be at index “0”, the second at index “1” and the third at index “2”.

42
Q

What is the significance of testng.xml?

A

It allows execution of multiple test cases from multiple classes

It allows parallel execution

It allows execution of test cases in groups, where a single test can belong to multiple groups

43
Q

What is the difference between Relative XPATH and Absolute XPATH?

A

Absolute Xpath: It contains the complete path from the Root Element to the desire element and uses single slash

Relative Xpath: You can simply start by referencing the element you want and go from there and uses double slash

44
Q

What is a Stale Element?

A

an old element or no longer available element. If the DOM changes then the WebElement goes stale.

When a page loads and selenium finds an element it is attached to the current dom (document object model). When the page is refreshed or if you go to another
page and come back, a new dom is present and if you don’t re-find the element, selenium will try to locate the element form the previous dom (which is unavailable)
which results in a stale element reference exception.

45
Q

Difference between findElement() and findElements(), what does the method return?

A

findElement() method returns a webElement object

findElements() method returns a list of type webElement

46
Q

On the webpage, you have 5 text fields that all have the same ids and class names. How do you locate and act on the 3rd text field and input data into it?

A

findElements() to locate the list of the 5 text fields and then specify the 3rd ele-
ment of the list (or the 2nd index) and then use the sendKeys() method to input data into the text field.

47
Q

I’m trying to input data to text fields on a webpage. The page has 4 text fields that have the same id and classes, there is nothing different about them. The problem is that when I navigate to the page, there is an overlay that appears for 3 seconds and then goes away. Only when the overlay goes away can I access the text fields, how do I automate that?

A

Find the locator of the overlay (via id, css selector or xpath) and store it into a vari-
able (storing the variable is optional but good practice). Then I implement a new

Webdriver wait (because I’m waiting for the overlay to disappear not appear so I
can’t use implicit wait, also see below usage of the Webdriver wait)
- I give it the wait a maximum of 6 seconds (or 10) and then I make a list of type
webElement to capture the list of text fields and store into a variable. I implement
a for loop (see below) to input text into all the text fields.
- new WebDriverWait(driver,10).until(ExpectedConditions.invisibilityOfEle-
mentLocated(locator));
  • for(i=0; i
48
Q

My application has about 10 pages in it and I seem to be repeating so many actions on each page. I find myself just writing the same code for every page. The page has radio buttons and I need to click yes or no across all of them for a different test. Is there a way to optimize this code?

A
I would create a separate class (either utilities or helperMethods) and inside of it I
would create a method to handle such repetitive behavior. Inside the class I would
create a method (any method name) and give it a parameter of a webElement list.

Inside that method I would have a for loop to navigate through each element and
click either a yes or no for each radio button.
- In the Page classes now I would have 2 webElement Lists, one for the radio buttons
with yes values and one for the radio buttons with no values. In the base class

(which all pages extend) I would create an object for the Utilities class. Now when-
ever I have a page with radio buttons all I would have to do is call that method from

the utilities class and pass in the specific webElementList

class Utilities {

public void radioButtonHelper( ArrayList list) {

for (int i=o, i yesButtons = …;

private ArrayList noButtons = …;

public void fillOutPage() {

utilities.radioButtonHelper(yesButtons);.

49
Q

I have hidden elements on the page, they are 5 radio buttons and then there is a text field that is displayed only after the 5 radio buttons are all selected. How do I enter text to that text field in this scenario. Only the first radio button is visible, after that is selected the next one is displayed and so on until all 5 radio buttons are selected and then the text field shows up on the webpage.

A

I would first grab the common locator of all the radio buttons and then store them
into a list of webElements. Afterwards I would create a for loop in which I would
first check if the element is displayed and then click the element. Afterwards I

would then have a if statement to check if the text field is displayed and if it’s dis-
played I would fill in the data.

  • You can then further ask that you want to make sure that the radio buttons appear
    after a maximum of 3 seconds. In which the loop and the if statement had to be
    modified with waitUntilVisible methods giving a maximum wait time of 3 seconds.
50
Q

I have a few links on the page and when you click them they each open to a new tab. I want to validate that each link has the correct title. All the links are in order, the first link will always have the a certain title and so on. How do I validate that?

A

First I would create either an Array or ArrayList to store all the titles that I’ll need to validate against. Then I would create a for loop that would handle all my links,

inside the for loop I would have logic to handle switching to a new tab, validating the title, closing the tab and switching back to my original window.

class Demo {
string[] titles = {.......}; ArrayList links = ...;
public void validateLinks() {
for(int i; i windows = new ArrayList(driver.getWindowHandles()); driver.switchTo().window(windows.get(1)); assertEquals(links[i].getTitle(), titles[i]); driver.close(); driver.switchTo().window(windows.get(0));
}
51
Q

What is the difference between getWindowHandle() and getWindowHandles()

A

“getWindowHandle()” method will provide a unique identifier(handle) of the current browser window which is being controlled by the WebDriver and return type is string

Whereas “getWindowHandles()” will provide a set(collection) of all existing window identifiers(handles) present at a given time and its return type is Set

52
Q

How do you find size of the Window with javaScript

A

long height = (Long)js.executeScript(“return window.innerHeight;”);

53
Q

What are examples of Explicit Wait conditions?

A

alertisPresent

elementToBeClickable

presenceOfElementLocated

visbilityOfElementLocated

54
Q

If you use Implicit Wait of 10 seconds and explicit wait of 20 seconds, how much time Selenium WebDriver will wait before timing out?

A

The code will time out
It is unpredictable

It is not recommended to use both Explicit and Implicit waits in the same code

55
Q

How to get Value of Element attribute?

A

driver.get(baseUrl);

WebElement element = driver.findElement(By.id(“name”));

String attributeValue = element.getAttribute(“type”);

System.out.println(“Value of attribue is: “ + attributeValue);

56
Q

What is TestNG Assert.assertTrue()

A

Assert true statement fails the test and stop the execution of the test if the actual output is false

57
Q

What is TestNG Assert.assertFalse()

A

Assert.assertFalse() works if you want your test to continue only if when some certain element is not present on the page. You will use Assert false, so it will fail the test in case of the element present on the page.

58
Q

What are Assert.assertEquals()

A

It will also stop the execution if the value is not equal and carry on the execution if the value is equal.

String expectedString = "Hello World";
SomeClassToTest obj = new SomeClassToTest();
String result = obj.addStrings("Hello", "World");
Assert.assertEquals(result, expectedString);
59
Q

What is the difference between HARD and SOFT Assertions ?

A

Hard = throws an exception immediately when an assert statement fails and continues with the next test in the test suite.

Soft = do not throw an exception when an assertion fails and would continue with the next step after assert statement.

Used when our test requires multiple assertions to be executed and the user want all of the assertions/codes to be executed before failing/skipping the tests.

To mark a test as failed with soft assertions, call assertAll() method at the end of the test.

60
Q

What is TimeoutException in WebDriver

A

This exception is thrown when a command performing an operation does not complete in the stipulated time

61
Q

What is NoSuchElementException in WebDriver

A

This exception is thrown when an element with given attributes is not found on the web page

62
Q

What is ElementNotVisibleException in WebDriver

A

This exception is thrown when the element is present in DOM but not visible on the web page

63
Q

What is StaleElementException in WebDriver

A

This exception is thrown when the element is either deleted or no longer attached to the DOM

64
Q

What is exception test in Selenium?

A

An exception test is an exception that you expect will be thrown inside a test class.

65
Q

What are the commands in Selenium to handle window pop-ups?

A

dismiss(): This method is called when the ‘Cancel’ button is clicked in the alert box.

accept(): This method is called when you click on the ‘OK’ button of the alert.

getText(): This method is called to capture the alert message.

sendKeys(String stringToSed): This is called when you want to send some data to alert box.

66
Q

Can you navigate back and forth the webpage in Selenium?

A

driver. navigate().forward()
driver. manage().back()
driver. manage().navigate()
driver. navigate.to(“url”)

67
Q

What is Selenium and what is composed of?

A

Selenium IDE (Integrated Development Environment) : It is a tool for recording and playing back. It is a firefox plugin

WebDriver and RC: It provide the APIs for a variety of languages like Java, .NET, PHP, etc. With most of the browsers Webdriver and RC works.

Grid: With the help of Grid you can distribute tests on multiple machines so that test can be run parallel which helps in cutting down the time required for running in browser test suites. For example: 200 tests, 100 on each system at the same time can be run. Also known as parallel/ sequential execution

68
Q

How will you find an element using Selenium?

A
ID
Name
Tag
Attribute
CSS
Linktext
PartialLink Text
Xpath
69
Q

What is the difference between type keys and type commands ?

A

TypeKeys() will trigger JavaScript event in most of the cases whereas .type() won’t.

Type key populates the value attribute using JavaScript whereas .typekeys() emulates like actual user typing

70
Q

What is the difference between setSpeed() and sleep() methods?

A

Both will delay the speed of execution.

Thread.sleep () : It will stop the current (java) thread for the specified period of time. Its done only once

SetSpeed () : For specific amount of time it will stop the execution for every selenium command.

This command is useful for demonstration purpose or if you are using a slow web application

71
Q

What is regular expressions? How you can use regular expressions in Selenium ?

A

A regular expression is a special text string used for describing a search pattern.

regexp: as a prefix to the value and patterns needs to be included for the expected values.

72
Q

Explain what is the main difference between web-driver and RC ?

A

The main difference between Selenium RC and Webdriver is that, selenium RC injects javascript function into browsers when the page is loaded. On the other hand, Selenium Webdriver drives the browser using browsers built in support

73
Q

How do you identify an object using selenium?

A

To identify an object using Selenium you can use

isElementPresent(String locator)

isElementPresent takes a locator as the argument and if found returns a Boolean

74
Q

What are some types of Assertions

A

Assert, Verify , waitfor

75
Q

What is Datadriven framework ?

A

Datadriven framework: In this framework, the test data is separated and kept outside the Test Scripts, while Test Case logic resides in Test Scripts.

76
Q

Explain how you can find broken images in a page using Selenium Web driver ?

A

To find the broken images in a page using Selenium web driver is

Get XPath and get all the links in the page using tag name
In the page click on each and every link
Look for 404/500 in the target page title

77
Q

How can you retrieve the message in an alert box ?

A

storeAlert command will fetch the message of the alert pop up and store it in a variable.

78
Q

What are some JUnit Annotations ?

A
Test
Before
After
Ignore
BeforeClass
AfterClass
RunWith
79
Q

What are the advantages of Selenium?

A

It supports many language bindings
It supports different browsers
It has got powerful methods to locate elements (Xpath, DOM , CSS)
It has highly developer community supported by Google

80
Q

What are the features of TestNG and list some of the functionality in TestNG which makes it more effective?

A

Support for annotations
Support for data-driven testing
Flexible test configuration
Ability to re-execute failed test cases

81
Q

Explain using Webdriver how you can perform double click ?

A

Syntax- Actions act = new Actions (driver);

act.doubleClick(webelement);

82
Q

Explain how you can switch back from a frame?

A

To switch back from a frame use method defaultContent()

Syntax-driver.switchTo().defaultContent();

83
Q

List out different types of locators?

A
By.id()
By.name()
By.tagName()
By.className()
By.linkText()
By.partialLinkText()
By.xpath
By.cssSelector()
84
Q

What is Keyword driven framework?

A

Keyworddriven framework: The keyword driven frameworks requires the development of data tables and keywords, independent of the test automation.