Automation Test
Automation Test
It is used
to automate Web and Mobile environments. It consists of
Selenium supports scripting in languages like Java, C#, Python, Ruby, PHP, Perl,
Javascript
Accessors:StoreTitle,StoreAllButtons,StoreAllFields,StoreAllLinks,StoreAllWindowTitles,
StoreAllWindowNames,StoreText,Store Value
Assertions or Asserts:
Wait ForPageToLoad,WaitForElementPresent.
6. What is Xpath?
While DOM is the recognized standard way for navigating through an HTML element tree, XPath is
the navigation tool used to locate a web element based on its XML path.
XML stands for ‘Extensible Markup Language’ and is used to store, organize, and transport
arbitrary data. It stores data in a key–value pair that is very much similar to HTML tags. Both being
markup languages and falling under the same umbrella, XPath can be used to locate HTML
elements.
The fundamental concept behind locating elements using XPath is traversing between various
elements across the entire page and thus enabling a user to find an element with the reference of
another element.
7. Explain the difference between single slash and double slash in Xpath.
Single slash (/): Single slash is used to create an XPath with an absolute path. In this case, the
XPath would start selection from the document’s start node.
Double slash (//): Double slash is used to create an XPath with a relative path. In this case, the
XPath would start selection from anywhere within the document.
8. Why should you use Selenium for test automation?
=>Selenium should be used for test automation as it:
Is a free and open-source tool
Has a large user base and community support
Has cross-browser compatibility (Firefox, Chrome, Internet Explorer, Safari, etc.)
Has great platform compatibility (Windows, Mac OS, Linux, etc.)
Supports multiple programming languages (Java, C#, Ruby, Python, Perl, etc.)
Has fresh and regular repository developments
Supports distributed testing.
9. Does Selenium have any technical limitations? If so, what are those
limitations?
Yes, Selenium has a few limitations:
Testing of only web applications is possible using Selenium.
Testing of mobile applications or desktop applications is not possible.
Captcha and barcode readers cannot be tested using Selenium.
A third-party tool like TestNG or JUnit should be used to generate reports.
As Selenium is a free tool, there is no ready vendor support through which users can find various
helping communities.Prior programming language knowledge is expected from users.
11. What is the difference between type keys and type commands?
TypeKeys() will trigger JavaScript events, while type() won’t. TypesKeys collects different value
attributes using JavaScript. Whereas, the type commands imitate an actual user typing.
17. What is POM (Page Object Model)? What are its advantages?
Page Object Model is a design pattern used to create object repositories for the web UI elements.
Every web page of an application has a corresponding page class that is responsible for locating
the web elements and performing actions on them.
Its advantages are as follows:
It provides support to separate operations and flows on the UI from verification, hence improving
code readability.
As the object repository is independent of test cases, multiple tests can use the same object
repository.It increases the reusability of the code
@Test: The @Test annotation finds a method to be a test method. When used before a test
method, it is mentioned as ‘@Test’; it informs the JUnit framework that the following method is a
test method.
@Before: The @Before annotation is used to find the method that is executed before executing
the test method. This method can be used to set up the test environment.
@After: The @After annotation is a method that is executed after executing the test method. This
method can be used to do a teardown, i.e., it is a method used to delete all temporary data, set up
default values, clean up the test environment, etc.
@BeforeClass: The @BeforeClass method is used only once before the start of all tests. Basically,
this is used to perform cumbersome activities, like connecting to a database.
@AfterClass: The @AfterClass method is used only once after executing all tests. This is used to
carry out clean-up activities, like disconnecting from a database.
20. What are the four elements that you have to pass in Selenium?
Four parameters that need to be passed in Selenium are:
Host, Port number ,Browser ,URL
Example:
driver = webdriver.Firefox()
element = driver.find_element_by_id("fileUpload")
element.send_keys("C:\myfile.txt")
26. If you want to insert a breakpoint in Selenium IDE, how can you do
that?
To insert a breakpoint:
First, select ‘Toggle Breakpoint’ by right-clicking on the command in Selenium IDE
Then, press ‘B’ on the keyboard and select the command
The same step should be repeated for deselecting a breakpoint
• Testing a Windows application: Selenium is just a web-based driver. It does not support
Windows-based apps and only supports web apps.
• Testing mobile apps: With the help of Selenium, we can test web apps on any OS and
browser that run on desktops. But, we cannot test mobile apps with Selenium because it
does not work with OS such as Android and iOS. However, there is an alternative for this,
i.e., Appium. It is an open-source automation testing tool that uses the WebDriver protocol
to drive native, hybrid, and iOS and Android, which is built specifically for testing mobile
apps.
• Limited reporting: It is one of the key challenges. In Selenium, we cannot generate efficient
and accurate reports. Accurate reports help developers fix all bugs and errors. We can
create reports using TestNG or ExtentReports.
• Handling dynamic elements: With the surge in the use of web apps, the management of
dynamic elements should be as much efficient as possible. When a web page loads, the
content present on the page changes depending on the user, location, and other factors.
Most of today’s web apps are dynamic in nature for better user experience, e.g., e-
commerce websites. In Selenium automation, the handling of dynamic web content is a
major challenge. However, Selenium provides an explicit wait feature, where we can set a
time interval for the automation testing process to hold the process for the new content to
load. Also, another alternative is to utilize the implicit wait feature.
• Handling page load: Some of the web pages in a web app are user-specific. They load
elements depending on the user. Also, some elements may be loaded depending on the
user’s previous activities. During background processes, the Selenium script might not be
able to identify a specific element. To overcome this, we can use explicit waits to provide
sufficient time to load and discover the element.
• Handling pop-up windows: Whenever any simple, prompt, or confirmation alert pops up, it
is difficult to automate it. Windows-based OS alerts are beyond Selenium’s capabilities as
they are part of the OS instead of the browser. However, Selenium WebDriver can utilize
multiple windows, and the web-based alerts can easily be handled with the help of the
switchTo method. It manages the OS-based pop-ups while keeping the browser running in
the background.
Explicit wait: These waits are used to halt the execution until a particular condition is met or the
maximum time has elapsed.
31. How do you handle a frame in WebDriver?
An iframe (an acronym for ‘inline frame’) is used to insert another document within the current
HTML document.
Selecting iframe by ID:
driver.switchTo().frame(“ID of the frame“);
Library architecture testing framework: Instead of dividing AUT into test scripts, with this
framework, we segregate the application into functions or rather common functions that can be
used by the other parts of the application as well. Thus, we create a common library constituting
common functions for AUT. Therefore, these libraries can be called from the test scripts whenever
required.
Data-driven testing framework: The data-driven testing framework helps us segregate the test
script logic and the test data from each other. It lets us store the test data into an external
database. The data is conventionally stored in ‘key–value’ pairs. Keys can be used to access and
populate the data within the test scripts.
Hybrid testing framework: A hybrid testing framework is a combination of more than one of the
above-mentioned frameworks. The best thing about such a setup is that it leverages the benefits
of all kinds of associated frameworks.
Start points: Start points are the points from where the execution should begin. Start points can
be used when we want to run the test script from the middle of the code or after a breakpoint.
36. Mention the need for session handling while working with Selenium.
While working with Selenium, we need session handling. This is because, during test execution,
Selenium WebDriver has to interact with the browser all the time to execute the given commands.
It is also possible that, before the current execution completes, someone else starts the execution
of another script in the same machine and in the same type of browser. So, to avoid such a
situation, we need session handling.
Web Driver and RC: It provide the APIs for a variety of languages like Java, .NET, PHP, etc. With
most of the browsers Web driver 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
Single slash ‘/ ’
Single slash ( / ) start selection from the document node
It allows you to create ‘absolute’ path expressions
10) What is the difference between type keys and type commands ?
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.
13) While using click command can you use screen coordinate?
To click on specific part of element, you would need to use clickAT command. ClickAt command
accepts element locator and x, y co-ordinates as arguments-
clickAt (locator, cordString)
21) What are the features of TestNG and list some of the functionality in
TestNG which makes it more effective?
TestNG is a testing framework based on JUnit and NUnit to simplify a broad range of testing needs,
from Unit Testing to Integration Testing. And the functionality which makes it efficient testing
framework are
->Support for annotations
->Support for data-driven testing
->Flexible test configuration
->Ability to re-execute failed test cases
23) Which attribute you should consider throughout the script in frame
for “if no frame Id as well as no frame name”?
27) Explain how you can login into any site if it’s showing any
authentication popup for password and username?
Pass the username and password with url
Syntax-http://username: password@url
ex- http://creyate:[email protected]
WebElement el = driver.findElement(By.id(“ElementID”))
//get test from element and stored in text variable
String text = el.getText();
//assert text from expected
Assert.assertEquals(“Element Text”, text);
36) Explain how you can find broken images in a page using Selenium
Web driver ?
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
38) Using web driver how you can store a value which is text box?
You can use following command to store a value which is text box using web driver
driver.findElement(By.id(“your Textbox”)).sendKeys(“your keyword”);
39) Explain how you can switch between frames?
To switch between frames webdrivers [ driver.switchTo().frame() ] method takes one of the three
possible arguments
A number: It selects the number by its (zero-based) index
A name or ID: Select a frame by its name or ID
Previously found WebElement: Using its previously located WebElement select a frame
41) Explain using Webdriver how you can perform double click ?
You can perform double click by using
Syntax- Actions act = new Actions (driver);
act.doubleClick(webelement);
HTMLUnit Driver implementation is fastest, HTMLUnitDriver does not execute tests on browser
but plain http request, which is far quick than launching a browser and executing tests
44) Explain how you can handle frames using Selenium 2.0 ?
To bring control on HTML frame you can use “SwitchTo” frame method-
driver.switchTo().frame(“frameName”);
To specify a frame you can use index number
driver.switchTo().frame(“parentFrame.4.frameName”);
This would bring control on frame named- “frameName” of the 4th sub frame names
“parentFrame”
51) How can you prepare customized html report using TestNG in hybrid
framework ? Or how to create Html test report from test script?
There are three ways
Junit: With the help of ANT
TestNG: Using inbuilt default.html to get the HTML report. Also XST reports from ANT, Selenium,
Testng combinations
Using our own customized reports using XSL jar for converting XML content to HTML
67) What if you have written your own element locator and how would you
test it?
To test the locator one can use “Find Button” of Selenium IDE, as you click on it, you would see on
screen an element being highlighted provided your element locator is right or or else an error
message will be displayed.
68) What is regular expressions? How you can use regular expressions in
Selenium?
A regular expression is a special text string used for describing a search pattern. In Selenium IDE
regular expression can be used with the keyword- regexp: as a prefix to the value and patterns
needs to be included for the expected values.
71) How will you verify the specific position of an web element?
You can use verifyElementPositionLeft & verifyElementPositionTop. It does a pixel comparison of
the position of the element from the Left and Top of page respectively
80) Can we use Selenium RC to drive tests on two different browsers on one operating
system without Selenium Grid?
Yes, it is possible when you are not using JAVA testing framework. Instead of using Java testing
framework if you are using java client driver of selenium then TestNG allows you to do this. By
using “parallel=test” attribute you can set tests to be executed in parallel and can define two
different tests, each using different browser.
82) Explain how you can capture server side log Selenium Server?
To capture server side log in Selenium Server, you can use command
java –jar .jar –log selenium.log
83) Other than the default port 4444 how you can run Selenium Server?
You can run Selenium server on java-jar selenium-server.jar-port other than its default port
84) How Selenium grid hub keeps in touch with RC slave machine?
At predefined time selenium grid hub keeps polling all RC slaves to make sure it is available for
testing. The deciding parameter is called “remoteControlPollingIntervalSeconds” and is defined in
“grid_configuration.yml”file
86) To enter values onto text boxes what is the command that can be used?
To enter values onto text boxes we can use command sendkeys()
87) How do you identify an object using selenium?
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
Breakpoints: When you implement a breakpoint in your code, the execution will stop right there.
This helps you to verify that your code is working as expected.
StartpointsStartpoint :indicates the point from where the execution should begin. Startpoint can
be used when you want to run the testscript from the middle of the code or a breakpoint.
90) Mention what are the challenges in Handling Ajax Call in Selenium Webdriver?
The challenges faced in Handling Ajax Call in Selenium Webdriver are Using “pause” command for
handling Ajax call is not completely reliable. Long pause time makes the test unacceptably slow
and increases the testing time. Instead, “waitforcondition” will be more helpful in testing Ajax
applications. It is difficult to assess the risk associated with particular Ajax applications. Given full
freedom to developers to modify Ajax application makes the testing process challenging. Creating
automated test request may be difficult for testing tools as such AJAX application often use
different encoding or serialization technique to submit POST data.
99) Mention why do you need Session Handling while working with
Selenium?
While working with Selenium, you need Session Handling. This is because, during test execution,
the Selenium WebDriver has to interact with the browser all the time to execute given commands.
At the time of execution, it is also possible that, before current execution completes, someone
else starts execution of another script, in the same machine and in the same type of browser. So
to avoid such situation you need Session Handling.
100) Mention what are the advantages of Using Git Hub For Selenium?
The advantages of Using Git Hub for Selenium are
Multiple people when they work on the same project they can update project details and inform
other team members simultaneously.
Jenkins can help you to build the project from the remote repository regularly. This helps you to
keep track of failed builds.
2) When will you automate a test?
Automation in preferred in following cases
Repetitive Tasks
Smoke and Sanity Tests
Test with multiple data set
Regression test cases
5) What are the points that are covered while planning phase of automation?
During planning phase of automation things which must be taken in concern are
Selection the “right” Automation tool
Selection Automation Framework if any
List of In scope and out of scope items for automation
Test Environment Setup
Preparing Grant Chart of Project timelines for test script development & execution.
Identify Test Deliverables
-
C# Interview Questions-
->Abstraction: It is a process of identifying the critical behavior and data of an object and
eliminating the irrelevant details.
->Inheritance: It is the ability to create new classes from another class. It is done by accessing,
modifying and extending the behavior of objects in the parent class.
->Polymorphism: The name means, one name, many forms. It is achieved by having multiple
methods with the same name but different implementations.
Unmanaged code is any code that is executed by application runtime of any other framework
apart from .Net. The application runtime will take care of memory, security and other
performance operations.
Sealed class: It is a class that cannot be inherited. To access the members of a sealed class, we
need to create the object of the class. It is denoted by the keyword Sealed.
Abstract class: It is a class whose object cannot be instantiated. The class can only be inherited. It
should contain at least one method. It is denoted by the keyword abstract.
Static class: It is a class that does not allow inheritance. The members of the class are also static.
It is denoted by the keyword static. This keyword tells the compiler to check for any accidental
instances of the static class.
Class Struct
Supports Inheritance Does not support Inheritance
Class is Pass by reference (reference type) Struct is Pass by Copy (Value type)
Members are private by default Members are public by default
Good for larger complex objects Good for Small isolated models
Can use waste collector for memory Cannot use Garbage collector and hence no
management Memory management
Q #8) What is the difference between the Virtual method and the Abstract method?
Answer: The Virtual method must always have a default implementation. However, it can be
overridden in the derived class, although it is not mandatory. It can be overridden using the
override keyword.
An Abstract method does not have an implementation. It resides in the abstract class. It is
mandatory that the derived class implements the abstract method. An override keyword is not
necessary here though it can be used.
A driver of the car should know the details about the Car such as color, name, mirror, steering,
gear, brake, etc. What he doesn’t have to know is an internal engine, exhaust system.
So, Abstraction helps in knowing what is necessary and hiding the internal details from the outside
world. Hiding of the internal information can be achieved by declaring such parameters as Private
using the private keyword.
Q #14) What are C# I/O classes? What are the commonly used I/O classes?
Answer: C# has System.IO namespace, consisting of classes that are used to perform various
operations on files like creating, deleting, opening, closing, etc.
Some commonly used I/O classes are:
File – Helps in manipulating a file.
StreamWriter – Used for writing characters to a stream.
StreamReader – Used for reading characters to a stream.
StringWriter – Used for reading a string buffer.
StringReader – Used for writing a string buffer.
Path – Used for performing operations related to the path information.
Q #15) What is StreamReader/StreamWriter class?
Answer: StreamReader and StreamWriter are classes of namespace System.IO. They are used
when we want to read or write charact90, Reader-based data, respectively.
Class Program1
//----------------code to read-------------------//
{
//-------------code to write-------------------//
}
}
Explicit conversion of same reference type (created by boxing) back to value type is called
Unboxing.
For Example:
//————UnBoxing——————//
int UnBoxing = int (boxedValue);
Finalize method is called just before garbage collection. It is used to perform clean up operations
of Unmanaged code. It is automatically called when a given instance is not subsequently called.
Q #21) What is an Array? Give the syntax for a single and multi-dimensional array?
Answer: An Array is used to store multiple variables of the same type. It is a collection of variables
stored in a contiguous memory location.
For Example:
double numbers = new double[10];
int[] score = new int[4] {25,24,23,25};
A single dimensional array is a linear array where the variables are stored in a single row. Above
example is a single dimensional array.
Arrays can have more than one dimension. Multidimensional arrays are also called rectangular
arrays.
For Example, int[,] numbers = new int[3,2] { {1,2} ,{2,3},{3,4} };
Q #26) What is an Escape Sequence? Name some String escape sequences in C#.
Answer: An Escape sequence is denoted by a backslash (\). The backslash indicates that the
character that follows it should be interpreted literally or it is a special character. An escape
sequence is considered as a single character.
String escape sequences are as follows:
\n – Newline character
\b – Backspace
\\ – Backslash
\’ – Single quote
\’’ – Double Quote
Q #27) What are Regular expressions? Search a string using regular expressions?
Answer: Regular expression is a template to match a set of input. The pattern can consist of
operators, constructs or character literals. Regex is used for string parsing and replacing the
character string.
For Example:
* matches the preceding character zero or more times. So, a*b regex is equivalent to b, ab, aab,
aaab and so on.
Searching a string using Regex:
static void Main(string[] args)
{
The above example searches for “Python” against the set of inputs from the languages array. It
uses Regex.IsMatch which returns true in case if the pattern is found in the input. The pattern can
be any regular expression representing the input that we want to match.
Modify: Replace(a,b) is used to replace a string with another string. Trim() is used to trim the string
at the end or at the beginning.
500 is an integer. So, the Parse method converts the string 500 into its own base type, i.e int.
Follow the same method to convert a DateTime string.
string dateTime = “Jan 1, 2018”;
DateTime parsedValue = DateTime.Parse(dateTime);