You are on page 1of 20

Whenever you use driver.

findElements() method, Always the return type should be


list.
How to get the total count of links in the page and text of each link on the page?
List<WebElement>linkList = driver.findElements(By.tagName("a"));
sysout(linkList.size());
for(int i=0; i<linkList.size();i++){
String linkText = linkList.get(i).getText();
sysout(linkText);
}

Try to watch : 1) Data provider 2) Xpath videos by Naveen Automation Labs

https://www.softwaretestingmaterial.com

when will a class have a default constructor?


When we do not explicitly define a constructor for a class, then java creates a
default constructor for the class. It
is essentially a non-parameterized constructor, i.e. it doesn't accept any
arguments. The default constructor's job is
to call the super class constructor and initialize all instance variables.

why do we need default constructor in java?


Constructor is used to initialize an object. ... Without initializing an object we
can't use its properties. But there
is no need to define or declare a default constructor in Java. The compiler
implicitly add a default constructor in
the program if we have not declared or defined it.

GainSight - Done
WHat is an Interface?
What are the selenium dependencies that required to be configured into the
framework.
What is the logic that should be written in step definition i.e how data tables is
passed in step definition logic. Scenario outline case.
How to get the data and compare in web tables.
Parameterized constructors.
How an object is instantiated?
Ex: public class Demo{
Demo d = new Demo()
What is Demo()? Method or constructor?
Infor - Done
How can you findout automation test cases?
Sol:1) 1. Test case executed with different set of data
2. Test case executed with different browser
3. Test case executed with different environment
4. Test case Involves large amount of data
5. Test case has any dependency
Sol2) 1.Identify the modules of your application which you want to automate because
you are not supposed to automate each and every module. For e.g. if
there are any modules which can be tested manually more effectively or in less
time, So there is no need to include these modules in automation.�
2. Once you identify the modules, first try to work with positive scenarios and
then negative (NOT MUCH), mainly focuses on test data(Which test data you
need to work with), because using different frameworks you can run a single scripts
with multiple set of data[Including positive or negative].
How can you transfer the money at a time? Example: Axis bank
How can you manage all the data in the framework?
Write the logic for the sorting of a string without using sort method.
How can you select the dropdown?
What is jenkins?
l Where duplicate values are allowed?
What is cucumber?
What is the difference between Usecase and Scenario?
How to connect db using selenium?

Zettamine -
first framework adigaru
java concepts emi use chesaru framework lo annaru
difference between find Element and findElements
write a dynamic xpath annadu
fibonnaci program
string reverse program adigadu
SQL basics ani cheppu. so basic level adiugadu
select and updte statement adigadu
implicit and explicit wait adigadu
Agile ante enti ani adigadu
SDLC and STLC stages cheppamannadu
elements locators priority cheppamnnadu
first id, class last lo xpath ala cheppamnnadu
mana framework lo Collections emi use chesamu andi adigadu
List, Hash Map

Difference between Array & arrayList?


Array is a fixed size data structure while ArrayList is not(Dynamic). One need not
to mention the size of Arraylist while creating its object. Even if we
specify some initial capacity, we can add more elements.ArrayList has a set of
methods to access elements and modify them.

Difference between ArrayList & LinkedList?


1) ArrayList internally uses dynamic array to store the elements. LinkedList
internally uses doubly linked list to store the elements.
2) Manipulation with ArrayList is slow because it internally uses array. If any
element is removed from the array, all the bits are shifted in memory
Manipulation with LinkedList is faster than ArrayList because it uses doubly
linked list so no bit shifting is required in memory.
3) ArrayList is better for storing and accessing data. LinkedList is better for
manipulating data.

GRhombus - 1st round

1. About performance testing


2. Cucumber, Runner class, How feature file starts it's execution, Runner class.
3. How you will integrate selenium and cucumber into step definitions - Sol: Adding
dependencies to the pom.xml file.
3. Page object model
4. selenium - How u will identify the checkbox and the other element that is
presented after the checkbox is checked?
5. How you will compare two strings - equals method
6. Oops concepts, Interface, Maps.
7. There is a string called "Good Morning India". How can you print as "India
Morning Good"? (Refer swapping strings in JavaPrograms)
8. There are two classes Class and Subclass which extends and also having display
methods in both the classes . How
can you execute both the methods and only parent class method. - Using child
class object and parent class reference.
GRhombus - 2nd round

1. Lets say we have an array


[2,5,6,7,8] target=6 -> return index of the element 6
[3,5,6,9] target=4 -> return index of element 4

2. How to instantiate Int array and character array


3. Print the array elements using parameters in code
4. Explain about OOPS COncepts.
5. Tell me about Yourself
6. Explain Agile methodology.
7. Explain about Page Object Model
8. Defect life cycle
9. How you will analyse the stories.
10. Anything which you didn't like in cucumber.
11. How can you identify the test cases that should be automated.
12.Let's say we have an array of elements ,Print the required integer by passing
parameters in the methods.

Trianz - 1st Round

1. What is a Set and List


2. What is the difference between Interface and Abstract class
3 . What is OOPS Concepts.
Sol: a. Abstraction:
Show only necessary thing to user that he required, not extra information (use
public private, protected).
Abstraction is the methodology of hiding the implementation of internal details
and showing the functionality to the
users. Example: Mobile Phone.

Abstraction in Java is achieved using abstract classes and interfaces.


Abstract class:
We can easily identify whether a class is an abstract class or not. A class which
contains abstract keyword in its
declaration then it is an Abstract Class. Syntax: abstract class <class-name>{}

Points to remember:
1. Abstract classes may or may not include abstract methods
2. If a class is declared abstract then it cannot be instantiated. If instantiated:

Exception: Exception in thread "main" java.lang.Error: Unresolved compilation


problem:
Cannot instantiate the type AbstractSuperClass
3. If a class has abstract method then we have to declare the class as abstract
class
4. When an abstract class is subclassed, the subclass usually provides
implementations for all of the abstract methods
in its parent class. However, if it does not, then the subclass must also be
declared abstract.

Abstract Method:
An abstract method is a method that is declared without an implementation (without
braces, and followed by a semicolon),
like this: abstract void myMethod();

In order to use an abstract method, you need to override that method in sub class.
We use abstraction when we know that our class should have some methods but we are
not sure how exactly those methods should
function. Assume, I am creating a class of Vehicle which should have a method
called start(). There will be some other
subclass of this Vehicle class such as Car, Bike and these two subclasses use
start() method. But the implementation
of start() method in Car is different from Bike. So in this case I don�t implement
the start() method in Vehicle class
and implement those in subclasses.

Abstract classes doesn�t give 100% abstraction since abstract class allows
concrete methods. With abstract class we can
achieve partial abstraction where as we can achieve 100% abstraction with
interface.

b. Encapsulation:
Group all relevant things together. I.e. encapsulation is wrapping/binding up of
data and member functions in single
unit. In simple, abstraction is hiding the implementation and encapsulation is to
hide data.

Encapsulation is a mechanism of binding code and data together in a single unit.


Let�s see how can we implement encapsulation. Set the instance variables private so
that these private variables cannot
be accessed directly by other classes. Set getter and setter methods of the class
as public so that we can set and get
the values of the fields. See Example below

package encapsulationClass;

public class EncapsulationClassOne {

// Variables declared as private


// These private variables can only be accessed by public methods of class
private int age;
private String name;

// getter method to access private variable


public int getAge(){
return age;
}

public String getName(){


return name;
}

// setter method to access private variable


public void setAge(int inputAge){
age = inputAge;
}

public void setName(String inputName){


name = inputName;
}

package encapsulationClass;
public class EncapsulationClassTwo {

public static void main(String [] args){

EncapsulationClassOne obj = new EncapsulationClassOne();


// Setting values of the variables
obj.setAge(25);
obj.setName("Rajkumar");

System.out.println("My name is "+ obj.getName());


System.out.println("My age is "+ obj.getAge());

In the above example, you can find all the data member (variables) are declared as
private. If the data member is
private it means it can only be accessed within the same class. No other class can
access these private variables of
other class. To access these private variables from other classes, we used public
getter and setter methods such as
getAge(), getName(), setAge(), setName(). So, the data can be accessed by public
methods when we can set the variables
private and hide their implementation from other classes. This way we call
encapsulation as data hiding.

c. Inheritance: Inheritance is a process where one class inherits the properties of


another class.
If something already exist, why should I recreate it (same as re-inventing a
wheel). Use inheritance to inherit all
things of that class into your class. Inheritance enables you to create new
classes that re-use, extend and modify
the behaviour that is defined in other classes
d. Polymorphism:
Polymorphism allows us to perform a task in multiple ways. We can perform
polymorphism by
1. Compile time polymorphism(static binding)- Method overloading

There are three ways to overload a method.

a) Parameters with different data types


Ex: myMethod(int a)
myMethod(String a)

b) Parameters with different sequence of a data types


Ex: myMethod(int a, String b)
myMethod(String a, int b)

c) Different number of parameters


Ex: myMethod(int a)
myMethod(int a, int b)
2. Runtime polymorphism(Dynamic binding) - Method overriding
Declaring a method in child class which is already present in the parent class is
called Method Overriding.
In simple words, overriding means to override the functionality of an existing
method.
In this case, if we call the method with child class object, then the child class
method is called. To call
the parent class method we have to use super keyword.
Method overriding is also known as runtime polymorphism. Let�s see why we call it
as runtime polymorphism.
When a parent class reference refers to the child class object then the call to the
overridden method is determined at the runtime.
So it is called runtime polymorphism. It is because during method call which method
(parent class or child class) is to
be executed is determined by the type of an object.
4. Let's say We have two strings
String s1="Selenium testing"
String s2="Automation training"
Expected o/p: Selenium training
Automation testing
How to swap?
5. Which exception will be thrown if Child class reference and object of parent is
created?
Ex: Child c = new Parent();
sol: CE(Cmd prompt): incompatible types: Parent class cannot be converted to
Child class.
sol: CE(Eclipse):Type mismatch: cannot convert from ParentClass1 to ChildClass1
6. What is the refernce variable used when ? <String> set
=driver.getWindowHandles(); is used?Ex: List, Set etc.
7. How to capture full page screenshot when there is scrolling as well?
Sol:1. By using the api Shutterbug
First add the dependency selenium-shutterbug in pom.xml file
Shutterbug.shootpage(driver,ScrollStrategy.BOTH_DIRECTIONS,scrollTimeout:500,
useDevicePixelRatio:true).withName("Expected").save();
Sol:2 There is one more method to handle this by using third party utility
called Ashot. Specilaity of Ashot is it can
capture the entire page screenshot and individual webelement screenshot also.
Ex: Button

8. What is a String?
9. Why String is immutable?
10. Given two strings and used concat() method asked output.
11. Difference between quit() and close()
quit - This method is used to destroy the instance of WebDriver. It closes all
Browser Windows associated with that
driver and safely ends the session.
close - This method is used to close the current open window. It closes the
current open window on which driver has
focus on.

Selenium Interview questions

What are the limitations of Selenium?


Selenium supports testing of only web based applications.
Mobile applications cannot be tested using selenium. We can test only by
integrating third party tool like Appium to Selenium.
Captcha and barcode readers cannot be tested using selenium.
Reports can only be generated using third party tools like TestNG or Junit.
User is expected to possess prior programming language.

Different types of locators in Selenium


Id
ClassName
LinkText
PartialLinkText
Xpath
Css selector
Tagname

What is selenium grid?


Selenium grid will help to trigger the test in same time in two different systems
with two different browsers.
Parallel exection will happen.

What does mean by implicitlyWait?


implicit wait is applicable for the entire page. Driver will wait until the entire
page is loaded.
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

What does mean by explicitWait?


explicit wait is applicable when a particular element has to be loaded. Driver will
wait until that element is present.
Once the element is available, the exection flow will continue.
WebDriverWait wait = new WebDriverWait(driver, 60);
wait.until(ExpectedConditions.elementToBeSelected(driver.findElement(By.xpath("")))
);

The following are the Expected Conditions that can be used in Explicit Wait

alertIsPresent()
elementSelectionStateToBe()
elementToBeClickable()
elementToBeSelected()
frameToBeAvaliableAndSwitchToIt()
invisibilityOfTheElementLocated()
invisibilityOfElementWithText()
presenceOfAllElementsLocatedBy()
presenceOfElementLocated()
textToBePresentInElement()
textToBePresentInElementLocated()
textToBePresentInElementValue()
titleIs()
titleContains()
visibilityOf()
visibilityOfAllElements()
visibilityOfAllElementsLocatedBy()
visibilityOfElementLocated()

What does mean by fluentWait?


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

What is Thread.sleep()
It will make the script to halt for given seconds eventhough the page is loaded as
expected.

Watch Selenium interview question answer series for more waits.


https://github.com/LearnByBhanuPratap/seleniumBasic/tree/master/src/test/java/selen
ium/questionsAndAnswers

How to enter data in textbox


Webdriver driver = new ChromeDriver();
driver.findElement(By.id("")).sendKeys();

How to check element is displayed or not.


By using isDisplayed() method
driver.findElement(By.id("")).isDisplayed();
Returns true if element is displayed else exception will be thrown. To handle this
surround with try catch.

How to check checkbox is selected or not


driver.findElement(By.id("")).isSelected();
driver.findElement(By.id("")).getAttribute("class").contains("checked");

What is method to find element on UI.


By using findElement()

What is method to find all elements in UI


driver.findElements(By.tagname("//a")).size - will return all the links present on
the page.

Difference between webdriver.get() and webdriver.navigate()


The first thing you�ll want to do with WebDriver is navigate to a page.
driver.get("http://www.google.com");
WebDriver will wait until the page has fully loaded (that is, the onload event has
fired) before returning control to your test or script.

driver.navigate().to("http://www.example.com");
To reiterate: navigate().to() and get() do exactly the same thing.
The navigate interface also exposes the ability to move backwards and forwards in
your browser�s history:
driver.navigate().forward();
driver.navigate().back();

How to Run Selenium WebDriver in Different Popular Browsers?


Selenium supports only web-based applications and to open them we need a browser.
When we first start with Selenium automation our very first line of code comes as:
WebDriver driver = new FireFoxDriver ();
It means that WebDriver is an interface and we are defining a reference variable
(driver) whose type is an interface.
Now, any object we assign to it must be an instance of class (FireFoxDriver) or any
other drivers that implement that
interface. In our case, FireFoxDriver is a class and interface is WebDriver.
When all our driver setup is done we execute any Selenium command such as:
driver.getTitle ();
What happens now is that internally a HTTP request is created and sent to the
specific browser driver that we defined,
the browser driver uses that HTTP server for getting the HTTP requests and it
determines the steps needed for
implementing the Selenium command.
Our created logic is executed on the browser, then execution result is sent back to
HTTP server and it again sends
back the status to the automation script.
Thus, after setting the driver we can access all the in-built methods of driver�s
class like:

findElement();
close();
getClass(); and many more

Comparing two strings:

String title_Of_Page = driver.getTitle();


Assert.assertEquals(driver.getTitle(), title_Of_Page);
System.out.println("Page title matched");

How to get URL of current window.


driver.getCurrentUrl();

How to get title of the page


driver.getTitle();

Watching selenium interview question answer series4

How to get window id in runtime?


Set<String> windowsId = driver.getWindowHandles();
Iterator<String> itr = windowsId.iterator();
ArrayList<String>ids = new ArrayList<String>();
while(itr.hasNext()){
ids.add(itr.next());
// Adding all the window id's into arraylist
}

Ex:
// It will get and store the main window page handle or id
String mainpage = driver.getWindowHandle();
String subwinhandleString = null;
//set a loop which will store all window pop up handles
Set<String> handle = driver.getWindowHandles();
Iterator<String> iterator = handle.iterator();
while(iterator.hasNext ()) {
subwinhandleString = iterator.next( );
}
driver.switchTo().window(subwinhandleString);
System.out.println(driver.getTitle());
Thread.sleep(2000);
driver.close();
//Again switch back to main window
driver.switchTo().window(mainpage);
System.out.println(driver.getTitle());
}
}

How to read the data from properties file using Java selenium?
'.properties' files are mainly used in Java programs to maintain project
configuration data, database config or project
settings etc. Each parameter in properties file are stored as a pair of strings, in
key and value format, where each
key is on one line. You can easily read properties from some file using object of
type Properties.
Ex:
public static void main(String[] args) {
File file = new File("D:/Dev/ReadData/src/datafile.properties");

FileInputStream fileInput = null;


try {
fileInput = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
// Create Properties object
Properties prop = new Properties();
//load properties file
try {
prop.load(fileInput);
} catch (IOException e) {
e.printStackTrace();
}
WebDriver driver = new FirefoxDriver();
driver.get(prop.getProperty("URL"));

driver.findElement(By.id("Email")).sendKeys(prop.getProperty("username"));

driver.findElement(By.id("Passwd")).sendKeys(prop.getProperty("password"));
driver.findElement(By.id("SignIn")).click();
System.out.println("URL ::" + prop.getProperty("URL"));

How to handle multiple window?


Set<String> windowsId = driver.getWindowHandles();
Iterator<String> itr = windowsId.iterator();
ArrayList<String>ids = new ArrayList<String>();
while(itr.hasNext()){
ids.add(itr.next());
// Adding all the window id's into arraylist
}

driver.switchTo().window(ids.get(2));
driver.findElement(By.xpath("")).isDisplayed();
driver.close();

//Now lets switch to parent window. Most probably parent window will be stored in
the index of 0.
driver.switchTo().window(ids.get(0));

How to maximize window?


driver.manage().window().maximize();

How to do mouse over?


Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.xpath(""))).build().perform();

How to do drag and drop


Actions action = new Actions(driver);
WebElement source = driver.findElement(By.xpath(""));
target = driver.findElement(By.xpath(""));
action.dragAndDrop(source, target);

How to do double click.


Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.xpath(""))).doubleClick();

How a Keys class works


Actions action = new Actions(driver);
action.sendKeys(Keys.F6);
// Keys class contains all the keyboard keys

How to work with Javascript alert?


Alert alert = driver.switchTo().alert();
alert.accept();
alert.dismiss();

How to find broken links in selenium?


If a link is not working, we face a message as 404 Page Not Found
200 � Valid Link
404 � Link not found
400 � Bad request
401 � Unauthorized
500 � Internal Error

Code:

//Used tagName method to collect the list of items with tagName "a"
//findElements - to find all the elements with in the current page. It returns a
list of all webelements or an empty list if nothing matches
List<WebElement> links = driver.findElements(By.tagName("a"));
//To print the total number of links
System.out.println("Total links are "+links.size());
//used for loop to
for(int i=0; i<links.size(); i++) {
WebElement element = links.get(i);
//By using "href" attribute, we could get the url of the requried link
String url=element.getAttribute("href");
//calling verifyLink() method here. Passing the parameter as url which we
collected in the above link
//See the detailed functionality of the verifyLink(url) method below
verifyLink(url);
}
}

// The below function verifyLink(String urlLink) verifies any broken links and
return the server status.
public static void verifyLink(String urlLink) {
//Sometimes we may face exception "java.net.MalformedURLException". Keep
the code in try catch block to continue the broken link analysis
try {
//Use URL Class - Create object of the URL Class and pass the urlLink as parameter
URL link = new URL(urlLink);
// Create a connection using URL object (i.e., link)
HttpURLConnection httpConn =(HttpURLConnection)link.openConnection();
//Set the timeout for 2 seconds
httpConn.setConnectTimeout(2000);
//connect using connect method
httpConn.connect();
//use getResponseCode() to get the response code.
if(httpConn.getResponseCode()== 200) {
System.out.println(urlLink+" - "+httpConn.getResponseMessage());
}
if(httpConn.getResponseCode()== 404) {
System.out.println(urlLink+" - "+httpConn.getResponseMessage());
}
}
//getResponseCode method returns = IOException - if an error occurred connecting
to the server.
catch (Exception e) {
//e.printStackTrace();
}
}
}

How to work with iframe?


// First get all the iframes present in the UI
driver.findElements(By.tagName("iframe")).size();
driver.switchTo().frame(0); // By index
driver.switchTo().frame("auto"); // By frame name
driver.switchTo().frame(driver.findElement(By.className(""))); // By using
webElement

How to work with select class?


// select the webelement by using any of the locators on which we are going to work
Select select = new Select(driver.findElement(By.xpath("")));
select.selectByIndex(1);
select.selectByValue("valuesName");
select.selectByVisibleText("textName");

select.deselectAll();
select.deselectByIndex(1);
select.deselectByValue("valuesName");
select.deselectByVisibleText("textName");

How to execute java script?


There are two ways: 1. By casting (driver) variable to JavascriptExecutor.
JavascriptExecutor javascript =
((JavascriptExecutor)driver).executeScript(arg0,arg1);

2. By creating object of EventFiringWebdriver


EventFiringWebDriver driver = new EventFiringWebDriver(dr);
driver.executeScript("document.getElementById("\"idName\")");
driver.executeScript("document.getElementById("\"idName\").value=\"test\"");

How to work with properties file?(contains keys and values)


Properties is a class, so create an Object. Also properties is a file, So create
file object, In the file object we need
to supply the path of the file(i.e "user.dir" gives upto Project location and to
get the remaining path right click
on properties file and click properties). Next to read the file in one shot create
FileInputStream object. Then load the
input stream and get the values in properties file using key.

Properties properties = new Properties();


File file = new File(System.getProperty("user.dir")+"");
FileInputStream input = new FileInputStream(file);
properties.load(input);
sopln(properties.getProperty("userName"));

What are the java script functions for selenium object location
following-sibling
preceding-sibling
starts-with()
ends-with()
following
preceding
contains

css:
nth-child(1)
$ (starts-with)
^ (ends-with)

How many test scripts do you write?


It depends on the scenario, sometimes it will take more than a day.
UI scenarios max upto 6 to 7.
If it is end to end max up to 2.
Also it depens on framework where the page libraries are present or not. If not we
need to write from scratch.

What are your roles and responsibilities?


Involved in evaluating selenium for web UI automation.
Involved in designing test automation scripts.
Performed automation regression testing in coordination with manual testing team.

What are the challenges in automation?


Handling dynamic changing objects, Using selenium functions, css functions,
following siblings, preceding sibling,
starts with, ends with.
To make the scripts to pass 100%.
The way the framework is designed i.e it's should be in a position to accept the
changes.
Defining methods that should work when the UI is changing.

What are the methods of excel reader?


First define the variables:
1. FileInputStream fis;
2. XSSFWorkbook workbook;
3. XSSFSheet sheet;
4. XSSFRow row;
5. XSSFCell cell;
// Create object of FileInputStream and pass the path of the file.
fis = new FileInputStream("Path")
// Create object of XSSWorkbook
workbook = new XSSFWorkbook(fis);
// Get the sheet index based on sheet name or index
sheet = workbook.getSheetAt(index)
int index = workbook.getSheetIndex("LoginPage")
//Getting row
row = sheet.getRow(0);
//Getting cell number
row.getLastCellNum();
cell = row.getCell(3);
//Getting cell values
if(cell.getCellType() == Cell.CELL_TYPE_STRING){
cell.getStringCellValue();
} elseif(cell.getCellType() == Cell.CELL_TYPE_NUMERIC){
cell.getNumericCellValue();
}elseif(cell.getCellType() == Cell.CELL_TYPE_BOOLEAN){
cell.getBooleanCellValue();
}

What repository you have worked on?


Git - We can
Push the code, Pull the code, we can rebase, We can resolve the conflicts, can
merge, can checkout the project

What is the need of automation?


To make sure that existing functionality is working as expected. To reduce the
regression testing time. Whenever a build is
deployed just running the automation script to check the existing functionality.

Which exection engine you have used?


It's nothing but testNG or Junit.

How will you execute only failed test scripts?


In testNG, itself generates failed testNG suite in the test output report. Aslo by
using retry mechanism during runtime,
Its based on the configurations.

How can you capture screenshot during runtime?


By using listner classes and another way is in the code when the failure has
occured it has to go to the catch block where
the screenshot capturing code is written and the screenshot should be linked to in
the report.

Explaining framework:
Root folder: POMProject where it has two sub packages src/main/java and
src/test/java

Why src/main/java?
1. It will have only java code which will support to execute the framework.
2. As we know that every test case will have certain parameters that is common
accross for that we need to design a testBase
In testBase, We can write how to navigate to the browser, how to select the
browser, reading the data from the properties file,
maximizing the browser,reading data from external source, waits. Simply it will
drive our framework.
3. What is config
Whenever we do automation there are certain parameters that is fixed for all the
scripts.
For Example: We have an username, password, url, browser these four parameters are
fixed. Inside the config we can create
the properties file say OR.properties and place these four parameters.
What is the need of that?
Say that these properties file will be consumed by all the test scripts. Apart from
that, In the framework lets say
there is database connectivity. Database will have certain set of properties like
db url, username, password, db drivers
all these can be placed in OR.properties
Then what is APP.properties?
Here we can write application specific verifications Ex: Application Text
What is excelReader
It will help us to read the data from the excel sheet and supply to the test
scripts. When there is a dependency to get
the data from external source we can define all the methods in Excel_Reader class
What is pageActions
Here we will define all the pages present in the application and define the
specific methods related to the particular
page Ex: loginPage, HomePage, BagPage, PaymentsPage etc
What is customListener
This Listener class will be provided by testNG and whenever a failure occurs in the
test scripts it will capture the screenshots
nd will attach to the Html report or testnG report
What is data
The data which will be used by all the test scripts it can be either excel sheet or
xml or properties file.
What is report
When we run automation scripts, At the end of run need to generate a report.
What is screenShot
Whenever a test case is passed or failed the screenshots will be saved for the
proof of evidence

Why src/test/java?
1. It will have only test scripts which we will execute using testNG or JUnit
What is testScripts
Based on the pages which we have a module is created for each page and the
corresponding test cases will be written

At the project level i.e POMProject we have


a. testNG.suite - where we can execute the scripts at one shot and based on the
requirements(testNG will provide that methods)
b. pom.xml - Since it's a maven project it will help us to download all the
required jar files to support the project
c. log4j.properties - It will help us to log the required logs Ex: 100 scripts has
been executed and need to know all the
steps that has been executed whether it's passed or failed
d test-output - The Html file generated by the testNG

What are the different dependencies you will be using with cucumber?
cucumber-java
cucumber-jvm
cucumber-junit
cucumber-jvm-deps
cucumber-reporting
gherkin
junit
selenium java
Natural plugin - Search in market eclipse place, If not google it and just drag and
drop in opened eclipse

CTS:

1. Tags and plugins in maven:


dependencies, artifact etc
2. How to check whether the button is enabled or not in a last cloumn of all the
rows present.
3. How to get the text in dropdown.
4. What is Implicit and explicit waits, Write Sytax
5. Write git commands
6. About Jenkins
7. How to run a particular FF in framework?
8. What is Abstract class and Interface?
9. Method overloading and overriding?
10. About FF?
11.What is absolute and relative xpath.
12. Types of locators in selenium
13. What is POM?
14. What is StaleElementReferenceException? How to overcome that?
Sol: Stale Element means an old element or no longer available element. If we
try to interact with an element
which is staled then the StaleElementReferenceException occurs.
You could refresh the page and try again for the same element.

Pennant:

What is the difference between assert and verify in selenium


When an �assert� command fails, the test execution will be aborted. So when the
Assertion fails, all the test steps
after that line of code are skipped. The solution to overcoming this issue is to
use a try-catch block.
When a �verify� command fails, the test will continue executing and logging the
failure.

Jenkins:

How to start the Jenkins server?


Open cmd promt where the Jenkins war is available.
Execute the command: java -jar jenkins.war

**To generate proper Extent/HTML Report in Jenkins, use following script in Script
Console of Jenkins:
System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "")

What is log?
Capturing info/activities at the time of program execution.

What are the types of logs?


1. Info 2. Warn 3. debug 4. fatal
{ Define the Logger class at the class level
Logger log = Logger.getLogger(LoginTest.class)
log.info("");
log.warn("");
log.debug("");
log.debug("");

How to generate the logs?


Use Apache log4j Api(log4j jar)

How it works?
It reads log4j configuration from log4j.properties file

Where to create?
Create inside resources folder(Create a source folder as src/main/resources).

What is the property to append the existing logs?


log4j.appender.file.Append=false

Oracle:

1. How to get the color of an element - getCSSAttribute('color')


2. How to get the text from an element
3. Difference between / and //, quit and close
4. Static binding and Dynamic binding
5. Polymorphism and interface
6. We are adding dependency in pom and downloading from git. What the case if we
have our own created dependency.How can we place it in Maven central repository to
make it accessible to everyone.
7. Regression testing
8. Defect Life cycle(in resume)
9. Software Test Life cycle(in resume)
10.Difference between git fetch and git pull
11.What is maven
12.Folder where our maven dependencies are stored in our local - .m2 folder
13.What are implict wait, explicit waits with syntax.
14.What is the difference between Selenium web driver and Selenium IDE.
15.Client is enrolled for 1day delivery while creating profile.So when placing
order in shipment and payment section delivery type dropdown is shown as 1day
delivery. How can you validate that it is showing the expected(1 day delivery) in
shipment and payment section.
16.What is JVM and JRE
17.What is Heap and stack memory. Where does the objects created are stored?
18.What are different types of locators in Selenium
19.Difference between css and xpath
20.What is Page Object model.
21.DB connection code
22.getting data from json file
23.getting data from excel
24.screenshot code
25.diffe b/w priority and severity
26.diff b/w defect and bug, issue, error, failure
A mistake in coding is called Error, error found by tester is called Defect, defect
accepted by development team then
it is called Bug, build does not meet the requirements then it Is Failure.� ... In
other words Defect is the
difference between expected and actual result in the context of testing
Bug: Simply Bug is an error found BEFORE the application goes into production. A
programming error that causes a program
to work poorly, produce incorrect results, or crash. An error in software or
hardware that causes a program to malfunction.

STLC
Diff b/w SDLC and STLC

CTS:

Explain the structure of framework? Which framework you have used.


How can you load the properties file using Map concept(Keys and values) and get the
values?
Sol: Properties prop = new Properties();
Map<String,String> map = new HashMap<String, String>();
prop.load();
for(Entry<Object, Object> entry: prop.entrySet()){
map.put((String)entry.getKey(), (String)entry.getValue());
}
Given rows of data as key and values, What is the output using Map?
What is an Iterator?
What is Throwable, Throw and Throws?
What is Abstarct class and Interface?
If the subclass is also not implemented sbstarct method What will happen?
How you will compare Integer type of data and String type of data?(Know it)
Sol: int i=10;
String s="10";
String x= String.valueOf(i);
if(s.equals(x)){
System.out.println("done");
}
else
System.out.println("false");
DO you know about TestNg?
Sntax of Map?(Written incorrectly)

Prithvi say that - As per my knowledge term incase you are not confident enough.

How to read JSON file?

Sample code:

protected JSONObject getDataFile(String dataFileName) {


String dataFilePath = "src/test/resources/";
JSONObject testObject = null;

try {
FileReader reader = new FileReader(dataFilePath + dataFileName);

JSONParser jsonParser = new JSONParser();


JSONObject jsonObject = (JSONObject) jsonParser.parse(reader);
testObject = (JSONObject) jsonObject;
} catch (Exception ex) {
ex.printStackTrace();
}
return testObject;
}

Sample JSON file:

{
"Name": "crunchify.com",
"Author": "App Shah",
"Company List": [
"Compnay: eBay",
"Compnay: Paypal",
"Compnay: Google"
]
}

Refer screenshot() in desktop.


How to connect the database?
Step 1) Make a connection to the Database using method.
con = DriverManager.getConnection(URL, "userid", "password")

Step 2) Create Query to the Database using the Statement Object.


Statement stmt = con.createStatement();

Step 3) Send the query to database using execute query and store the results in the
ResultSet object.
ResultSet rs = stmt.executeQuery(select * from employee;)

Oracle:

1. There is a file sample.txt which has the text "Selenium automation and Java
automation are not easy as you think".
How to read the file and finding the duplicate words and repitition of duplicate
letters.
2. factorial of a number using Recursive program
3. Bubblesort
4. Common code to select the checkbox(Male and Female)
<div>
<label> Male <label>
<type> checkbox <type>
<div>

<div>
<label> Female <label>
<type> checkbox <type>
<div>
5. There are two tables Employee and Department. Get all the employee details from
the department QA.

Git & Git Hub:


Git is a version control tool and it's a open source.
Git hub is used to interact with Git

How to handle dynamic WebTable In Selenium

There are two ways of handling WebTable:

Method � 1:
� Iterate row and column and get the cell value.
� Using for loop
� Get total rows and iterate table
� Put if(string matches) then select the respective checkbox
� Lengthy method

Method � 2:
� Using custom XPath
� Using parent and preceding-sibling tags
� No need to write for loop
� No full iteration of table
� Single line statement
� More dynamic
� Efficient and fast

Refer:
F:\java_workspace\Shutterbug\src\main\java\seleniumSessions\DynamicWebTableHandle.j
ava

ZenQ-

1. screenshot code.
2. There is an integer int a = 132. Print in string format.
3. Git commands.
4. testNG.xml file. What is it and how its useful?
5. Maven - What is dependency(inside the dependency)?
6. OOPS concepts.
7. Implicit wait and Explicit wait(When it will be used)
7. testNG.
8. Do you know about listeners.
9. How to access the data from excel sheets?
10. There is a method add. when a child class having the same method and it extends
parent class. Does it throws CE?
11. Is there any overloaded methods in selenium?
12. How can you perform parallel execution without using selenium grid?

1. StaleElementException
2. How to handle uploading documents.
3. Git commands
4. Rerunning failed scenarios.
5. Json wire protocol
6.

You might also like