L&T Infotech Selenium Webdriver Interview Questions

L&T Infotech Selenium Webdriver Interview Questions and Answers with examples.L&T Infotech is located in Pune and Hiring for Mumbai Location for Selenium Test Engineer with Selenium ,TestNG,Appium Mobile App Testing,Rest API testing using Soap UI skills.


 L&T Infotech Selenium Webdriver Interview Questions



L&T Infotech Selenium Webdriver Interview Questions

ALSO READ


What is the difference between list and set?

List: 

It is an Interface and it will display the list data in which order it is inserted.

Set:

Set is an interface and it will display the list values in random way not in a insertion order.If want to display in inserted order then we can go for TreeSet<> interface.

------------------------------------------------------------------------------
How will you switch to other window?

driver.switchTo().Window(window id);

or 

driver.switchTo.window(driver.getWIndowHandles.)

------------------------------------------------------------------------------
What is the return type of driver.findelement/driver.getwindowhandles()?

findElements() takes argument of type of By class and returns all the matching web elements present in currently loaded web page only. This method returns all matching web elements in a List of type WebElement which is an interface in Collection framework.

findElement() method takes argument of By class and returns first matching web element on currently loaded web page. If passed locator is matching with multiple web elements, it will return only first matching web element.

------------------------------------------------------------------------------
What is the difference between Private and Protected?

private hides from other classes within the package. public exposes to classes outside the package. protected is a version of public restricted only to subclasses.

Private

Like you'd think, only the class in which it is declared can see it.

Package Private

Can only be seen and used by the package in which it was declared. This is the default in Java.

Protected

Package Private + can be seen by subclasses or package member.

Public

Everyone can see it.
------------------------------------------------------------------------------
How will you achieve dynamic polymorphism?

Dynamic Polymorphism also called as RunTime Polymorphism.

------------------------------------------------------------------------------

What is inheritance and encapsulation?

Inheritance

Inheritance in java is one object can access all parent object properties and values from another class.


Encapsulation:

Encapsulation is nothing but binding data and code into a single unit for example package  which contains number of classes,those classes are binding together into a single package.

------------------------------------------------------------------------------
Can you override static methods?

We cannot override static methods. Static methods are belogs to class, not belongs to object. Inheritance will not be applicable for class members.

We can declare static methods with same signature in subclass, but it is not considered overriding as there won’t be any run-time polymorphism. Hence the answer is ‘No’.

------------------------------------------------------------------------------
Can main method be overloaded?

Yes, you can overload main method in Java. But the program doesn't execute the overloaded main method when you run your program, you have to call the overloaded main method from the actual main method.

that means main method acts as an entry point for the java interpreter to start the execute of the application. where as a loaded main need to be called from main.

Example:

class Simple{  

  public static void main(int a){  
  System.out.println(a);  
  }  

  public static void main(String args[]){  
  System.out.println("main() method invoked");  
  main(10);  
  }  
}  


------------------------------------------------------------------------------
What is Singleton?

Singleton is a Class in Java ,which is having only one Object at a time.Singleton class purpose is to control object creation,limiting the number of objects to one object.

1.Constrctor as a private
2.Need Static method with return type object

------------------------------------------------------------------------------
What is collections in Java?

Ans:collections is a class,where Collection is an interface.
A collection is simply a object that groups multiple elements into a single unit.

-------------------------------------------------------------------------------
What is nested class?

Java Programming allow to creates a class under another class.
------------------------------------------------------------------------------
How will you call a protected method in a nested class?

In a web page, how will you ensure that page has been loaded completely?

JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("return document.readyState").toString().equals("complete");

------------------------------------------------------------------------------
What is the difference between build and perform method in Actions Class?

The build() method is used compile all the listed actions into a single step.
we have to use build() when we are performing sequence of operations and no need to use only if we are performing single action.

example where build() required
Actions builder = new Actions(driver);
builder.clickAndHold((WebElement)listItems.get(0)).clickAndHold((WebElement)listItems.get(3)).click().build().perform();

in the above code we are performing more than one operations so we have to use build() to compile all the actions into a single step

example where build is not required

WebElement draggable = driver.findElement(By.id("draggable")); 
WebElement droppable = driver.findElement(By.id("droppable")); 
new Actions(driver).dragAndDrop(draggable, droppable).perform();
in the above code we are performing just a single operations so no need to use build()

------------------------------------------------------------------------------

What are different annotations in TestNG?

@BeforeSuite: The annotated method will be run before all tests in this suite have run. 
@AfterSuite: The annotated method will be run after all tests in this suite have run. 
@BeforeTest: The annotated method will be run before any test method belonging to the classes inside the <test> tag is run. 
@AfterTest: The annotated method will be run after all the test methods belonging to the classes inside the <test> tag have run. 
@BeforeGroups: The list of groups that this configuration method will run before. This method is guaranteed to run shortly before the first test method that belongs to any of these groups is invoked. 
@AfterGroups: The list of groups that this configuration method will run after. This method is guaranteed to run shortly after the last test method that belongs to any of these groups is invoked. 
@BeforeClass: The annotated method will be run before the first test method in the current class is invoked. 
@AfterClass: The annotated method will be run after all the test methods in the current class have been run. 
@BeforeMethod: The annotated method will be run before each test method. 
@AfterMethod: The annotated method will be run after each test method.

------------------------------------------------------------------------------
What is the difference between before method and before test?

@BeforeMethod: The annotated method will be run before each test method. 

@BeforeTest: The annotated method will be run before any test method belonging to the classes inside the <test> tag is run. 

------------------------------------------------------------------------------
How will you display the character count in a string "Steve Jobs" by ignoring space on between?

String test = "Steve Jobs";
System.out.println(test.replace(" ", "").length());

Replacing empty space with 0 character
------------------------------------------------------------------------------
What is a constructor and when will you use this and super in a constructor?

------------------------------------------------------------------------------
If you want to call a constructor from parent class, what will you do?

------------------------------------------------------------------------------
How will you run your tests using Data Driven Framework?

------------------------------------------------------------------------------
What are static variables and methods?

Static Variables

Variables declared with static keyword is known as Static Variables and it is a class level variables.
Static variables are shared among all the instances of class,this type of variables are useful in memory management.

Examples:

public static String username="admministrator";
public static int mobileNo="2222222222";

Static Method

Static Methods are the methods in Java that can be called without creating an object of class.They are referrenced by the class name itself .
No need to create any object to access static methods from another class .

Examples

Class 1:


public class Student{


public static String student_Name=" ";

public static void studentsNames(String name){

student_Name = name;

}

Class 2:

Accessing class 1 static method 

public class CSEStudents{

Student.studentsNames("Rajesh");
System.out.println(Student.student_Name);


//You can access student_Name method with creating object as below

Student obj = new Student();
obj.studentsNames("Kuchana");


}

}

Output:

Rajesh
Kuchana

------------------------------------------------------------------------------
How will you handle Alerts in selenium?

Alert obj = driver.switchTo.alert();
String alertText=obj.getText();

if (alertText.equals("Enter valid Username")){
obj.accept();

}else{
System.out.println("Alert is not present- giving exception");
}


-------------------------------------------------------------------------------
How will you handle a file upload window using Selenium?

There's no API for WebDriver that would allow you to work with browser dialog's,we can use below code to file uploading.

String filePath = System.getProperty("user.dir") + "/src/res/test.pdf;
 driver.findElement(By.id("elementID")).sendKeys(filePath);


------------------------------------------------------------------------------
Can I define one class into another class?

Yes ,those are nested class

two types

1.Static class
2.Inner Classes

------------------------------------------------------------------------------
What are different types of modifiers present in Java?

default
public
private
protected

------------------------------------------------------------------------------
How will you make a build using Jenkins?

1.Click on New Item in Jenkins Dashboard
2.Enter Item Name
3.Select Free Style Project
4.Click on OK
5.Enter Description 
6.Select check box Delete Build before Build Starts in Build Environment
7.Select Windows Batch Command in Build Tab

Enter Command as below to run selenium Test Scripts:

set projectpath=E:\Selenium_Practice
cd %projectpath%
set classpath=%projectpath%\bin;%projectpath%\libs\*
java org.testng.TestNG %projectpath%\testng.xml


8.Select Publish Test Results in Post-Build Actions Tab

Enter TestNG XML report pattern as " **/testng-results.xml"

9.Click on Save button


------------------------------------------------------------------------------
How will you install ReportNG in your project?


1.Download ReportNG jar files
2.Add those jar files to project build path
3.In textng.xml file add listners as below

 <listeners>
        <listener class-name="org.uncommons.reportng.HTMLReporter"/>
        <listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>        
    </listeners>
------------------------------------------------------------------------------
How will you control data using XML?

We can use textng.xml file to pass the data for parameterization

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="TestSuite" thread-count="3" >
<parameter name="author" value="Selenium WebDriver" />
<parameter name="searchKey" value="America" />
<test name="testGuru">
<parameter name="searchKey" value="India" />
<classes>
<class name="parameters.ParameterWithTestNGXML">
</class>
</classes>
</test>
</suite>


@Test
@Parameter({"author","searchKey"})
public testing(string author,string searchKey){

 WebElement searchText = driver.findElement(By.name("q"));
        //Searching text in google text box
        searchText.sendKeys(searchKey);

        System.out.println("Welcome ->"+author+" Your search key is->"+searchKey);
}

------------------------------------------------------------------------------
How will you display a value of a particular cell in a web table?


------------------------------------------------------------------------------
How will you handle dynamic elements using XPath?

Using below two methods,we can handle dynamic elements using XPATH in Selenium Webdriver

1.Absolute path

Creating xpath for web element from root of the element to destination element as below

/html/body/div/div[1]/h1/li

2.Using contains and start-with()

driver.findElement(By.xpath(“//*[contains(@id,’username’)]”)).sendKeys(“username”);
driver.findElement(By.xpath(“//*[starts-with(@id,’user’)]”)).sendKeys(“username”);

------------------------------------------------------------------------------
What is POM?

A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects.

Example:

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <version>1</version>
</project>

------------------------------------------------------------------------------

Post a Comment

0 Comments