Selenium With Java Interview Questions and Answers

Selenium With Java Interview Questions And Answers for experienced professionals from Codingcompiler. These Selenium with Java interview questions were asked in various interviews conducted by top multinational companies across the globe. We hope that these interview questions will help you in cracking your next job interview. All the best and happy learning.

Selenium With Java Interview Questions

  1. What is the different use of this statement in java?
  2. Is it possible to call finally block after throwing an exception?
  3. Can a Interface have complete method.
  4. What is run time polymorphism in java?
  5. Which method is used to convert String to Char?
  6. What is a web driver ?
  7. What are different locators in selenium?
  8. Explain what does @Test(invocationCount=?) and @Test(threadPoolSize=?) indicate.
  9. Can we use private member of parent class in sub class?
  10. What is Selenium WebDriver?

Selenium With Java Interview Questions and Answers

Q1. What is the different use of this statement in java?

This is a keyword in java used for referring same class instance variable, same class method, returning same class instance.

Q2. Is it possible to call finally block after throwing an exception?

Yes. Finally, will always be executed

Q3. Can a Interface have complete method.

Yes. After java ver 8, Interface can have complete methods but the method should be static and default.

Q4. What is run time polymorphism in java?

In java, calling to a method is defined based on the type of object created in runtime. That is run time polymorphism.

Q5. Which method is used to convert String to Char?

Ans: by using toCharArray();

Q6. What is a web driver ?

Webdriver is an Interface which provide different APIs to perform automation across browsers.

Q7. What are different locators in selenium?

ID, name,xpath,CSS,class name, tag name, link text, partial linktext

Q8. Explain what does @Test(invocationCount=?) and @Test(threadPoolSize=?) indicate.

@Test(invocationCount=?) is a parameter that indicates the number of times this method should be invoked. @Test(threadPoolSize=?) is used for executing suites in parallel. Each suite can be run in a separate thread.

To specify how many times @Test method should be invoked from different threads, you can use the attribute threadPoolSize along with invocationCount.

Example:

@Test(threadPoolSize = 3, invocationCount = 10)
public void testServer() 
{
}

Q9. Can we use private member of parent class in sub class?

Answer : No.. It will not allow to use private members like private method, variable of parent class in child class. Private members are accessible only inside same class. VIEW MORE about class modifiers.

Q10. What is Selenium WebDriver?

  • It is an automation framework that allows you to execute your tests against different browsers.
  • WebDriver also enables you to use a programming language in creating your test scripts
  • Java, .Net, PHP, Python, Ruby, Perl
  • It supports Chrome ,Firefox ,Opera , Safari , IE , HTML unit driver(headless)

Frequently Asked Selenium With Java Interview Questions And Answers

Q11. What is implicit wait in Selenium WebDriver?`

The implicit wait will tell the WebDriver to wait a certain amount of time before it throws a “No Such Element Exception.” 

The default setting of implicit wait is zero. Once you set the time, the web driver will wait for that particular amount of time before throwing an exception.

Syntax:
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

Q12. Why we prefer Java for Selenium?

  • Selenium written in Java, it doesn’t mean that Java only more compatible with selenium, we can use other supported languages also.
  • Good support for Selenium with Java, You can get more help documents and implementations from Internet.
  • Majority of Selenium Testers(nearly 77%) using Java, so knowledge sharing is very easy.
  • Java is platform independent language, we can use it on any Operating environment.

Q13. How much Java is required for Selenium?

  • For Test Automation using Selenium Core Java knowledge is sufficient, Advanced Java not required.
  • Java Basics and Object Oriented Concepts are enough.
  • Java Basics are Data Types, Variables, Modifiers, Operators, Flow Control statements, Functions, Comments etc…
  •  Java OOPS concepts are Abstraction, Polymorphism, Inheritance, and Encapsulation.

Q14. What is soft assertion in Selenium? How can you mark a test case as failed by using soft assertion?

Soft Assertions are customized error handlers provided by TestNG. Soft Assertions do not throw exceptions when assertion fails, and they simply continue to the next test step. They are commonly used when we want to perform multiple assertions.

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

@Test
public void myTest() 
{
    SoftAssert softAssert = new SoftAssert();
    softAssert.assertTrue(“”);
    softAssert.assertTrue(“”);
    softAssert.assertAll();
}

Q15. Explain DataProviders in TestNG using an example. Can I call a single data provider method for multiple functions and classes?

DataProvider is a TestNG feature, which enables us to write DataDriven tests. When we say, it supports DataDriven testing, then it becomes obvious that the same test method can run multiple times with different data-sets. DataProvider is in fact another way of passing parameters to the test method.

@DataProvider marks a method as supplying data for a test method. The annotated method must return an Object[] where each Object[] can be assigned to parameter list of the test method.

To use the DataProvider feature in your tests, you have to declare a method annotated by @DataProvider and then use the said method in the test method using the “dataProvider” attribute in the Test annotation

As far as the second part of the question is concerned, Yes, the same DataProvider can be used in multiple functions and classes by declaring DataProvider in separate class and then reusing it in multiple classes.

Example:

@DataProvider(name=”UserDetails”)
public Object[][] getDataFromDataprovider()
{
    return new Object[][]
    {
        { “Ram”, “India” },
        { “John”, “UK” },
        { “John”, “UK” },
        { “Ben”, “USA” }
    };
}
@Test(dataProvider=”UserDetails”)
public void testMethod(String name, String country)
{
}

Q16. What is the difference between static and not static variable?

  • Answer : Main differences are as bellow.
  • Static variables are preceded by static keyword. For non-static variable, there is not any preceding keyword.
  • Memory is allocated for static variables at the time of class loading. Memory is allocated to non- static variables whenever an object is created.
  • Memory is allocated only once to static variables on class loading. Memory is allocated multiple time whenever a new object is created to non-static variables.
  • Static variable example : Collage name of students, Company name of employees..

Q17. What is Inheritance?

Ans:

It is a process of Inheriting (reusing) the class members (Variables and Methods) from one class to another class is called Inheritance.

• Non static (Object Level) class members only can be inherited.

• The class where the class members are getting inherited is called as Super class / parent class / Base class.

• The class to which the class members are getting inherited is called Sub class / Child class / Derived class.

• The inheritance between Super class and Sub class is achieved using “extends” keyword.

Q18. What is Polymorphism?

Polymorphism means, existence of Object behavior in many forms.

There are two types of Polymorphism in Java:

i) Compile Time Polymorphism / Static binding / Method overloading

ii) Run Time Polymorphism / Dynamic binding / Method overriding

Q19. What is Abstraction?

It is a process of hiding implementation details and showing only functionality to the user.

Q20. What is the usage of Java Constructor in Selenium Testing?

Constructor Is a code block which Is Called and executed at the time of object creation and constructs the values (i.e. data) for object and that’s why It Is known as constructor.

We use Java Constructor in Selenium Page Object Model (Centralized maintenance of elements/objects).

Advanced Selenium With Java Interview Questions and Answers

Q21. How to run the same test case 10 times with TestNG?

Answer: Use invocation count annotation in the test annotation. Click here to know more about Invocation count.

Q22. Which protocol REST API uses?

Answer: HTTPS protocol.

Q23. How to instantiate the chrome browser?

Answer: WebDriver driver=new ChromeDriver();

Here ChromeDriver has fully implemented a class which is used to establish a secure connection with the browser. We are creating the object and its type is WebDriver.

Q24. What is a framework?

Framework is a constructive blend of various guidelines, coding standards, concepts, processes, practices, project hierarchies, modularity, reporting mechanism, test data injections etc. to pillar automation testing.

Q25. What is the difference between Implicit Wait and Explicit Wait ?

Answer: Explicit Wait will make the WebDriver wait for a specific web element for the specified time. i.e. Using Explicit Wait, we can make the WebDriver wait for web element ‘a’ for 5 seconds and another web element ‘b’ for 10 seconds.

Where as Implicit Wait will make the WebDriver wait for all web elements for the same specified time. Its generally not set for one or two web elements, instead it is once set will be applicable for all elements.  i.e. Unlike Explicit Wait, Implicit Wait once set will be applicable to all the web elements and hence the specified wait time will be applicable for all the web elements.

Q26. What are the different Classes which implement WebDriver ?

Answer: First of all WebDriver is an Interface and there are different classes which implement this Interface in Selenium. The Classes which implement the WebDriver interface in Selenium are FirefoxDriver, ChromeDriver, InternetExplorerDriver, OperaDriver, SafariDriver, RemoteWebDriver, EdgeDriver and EventFiringWebDriver Classes.

Example: In the statement WebDriver driver = new FirefoxDriver(); , WebDriver is an Interface and FirefoxDriver is one of the Classes which is implementing WebDriver Interface.

Q27. What is the difference between equals() and ==  operator in Java ?

Answer: equals() method is used to compare two Strings in Java, where as == operator is a relational operator which is used to compare two data type values of same type.

Q28. How to access the variables and methods of another Class in Java ?

Answer: In order to access the variables and methods from another class in Java, we have to create an Object for the Class having those variables and methods.

Q29. Can Selenium automate Desktop Applications ?

Answer: No. Selenium can only automate Web Applications.

Examples: Web Applications like Facebook.com, Gmail.com etc can be automated by Selenium. Where as the Desktop Applications like Paint, Skype, MS Office etc. cannot be automated by Selenium.

Q30. What are the different components / tools in Selenium ?

Answer: Selenium comprises of 4 different components / tools. i.e. Selenium IDE, Selenium RC, Selenium WebDriver and Selenium Grid.

Q31. Why is selenium selected as a test tool?

Selenium is used as a testing tool because:

It is free and open source.
It has a large user base and helping communities.
Compatible on different platforms i.e. Windows, Mac OS, Linux etc.
Have cross browser compatibility (Chrome, Firefox, IE, Safari etc.)
Support multiple programming languages ( Java, C#, Ruby, PERL, Python etc.)
Support distributed testing.

Q32. What is an Xpath?

Xpath is used to locate a web element based on its XML path. It can be used to locate HTML elements.

Q33. Can you edit tests in Selenium IDE?

Yes, tests in Selenium IDE can be edited. There are two ways to edit tests in Selenium IDE.

Q34. What is the difference between assert and verify commands?

Assert: Assert command checks if the given condition is true or false. If the condition is true, the program control will execute the next phase of testing, and if the condition is false, execution will stop and nothing will be executed.

Verify: Verify command also checks if the given condition is true or false. It doesn’t halts program execution i.e. any failure during verification would not stop the execution and all the test phases would be executed.

Q35. How can you “submit” a form using Selenium ?

WebElement el  = driver.findElement(By.id(“ElementID”));

el.submit();

Top Selenium With Java Interview Questions and Answers

Q36. What are different ways in which you can generate the reports of TestNG results?

 Listeners: For implementing a listener class, the class has to implement the org.testng.ITestListener interface. These classes are notified at runtime by TestNG when the test starts, finishes, fails, skips, or passes.

Reporters: For implementing a reporting class, the class has to implement an org.testng.IReporter interface. These classes are called when the whole suite run ends. The object containing the information of the whole test run is passed to this class when called.

Q37.  what is POM?

Within your web app’s UI there are areas that your tests interact with. A Page Object simply models these as objects within the test code. This reduces the amount of duplicated code and means that if the UI changes, the fix need only be applied in one place.

Related Interview Questions

  1. Apigee Interview Questions
  2. Cloud Foundry Interview Questions And Answers
  3. Actimize Interview Questions
  4. Kibana Interview Questions
  5. Nagios Interview Questions
  6. Jenkins Interview Questions
  7. Chef Interview Questions
  8. Puppet Interview Questions
  9. DB2 Interview Questions
  10. AnthillPro Interview Questions
  11. Angular 2 Interview Questions
  12. Hibernate Interview Questions
  13. ASP.NET Interview Questions
  14. PHP Interview Questions
  15. Kubernetes Interview Questions
  16. Docker Interview Questions
  17. CEH Interview Questions
  18. CyberArk Interview Questions
  19. Appian Interview Questions
  20. Drools Interview Questions


Leave a Comment