Interview Selenium Java API Automation-Cognizant




1st Round : Technical

Duration    : 50 mins

Total Questions : 21


1. ls –ltr stands for?

Ans: To list the files of a directory in –l long listing format, (-t)sorted by modified time,(-r) in the reverse order


2. Utilities that you have created in your robot framework/selenium frame work

Ans: Any thing that is reusable can go into utilities. Explain that as per your project.

For e.g. there can be functional functionally reusable actions project specific and 

generic utilities. Excel, file handling, datetime methods, converting list string[], random number generator, log, report utilities


3. What are different concepts in java that you have used in selenium automation 

Ans: Inheritance: is used where ever I extend base class to the child classes.

 In a typical Page Object Model, we create a Base Class where we initialize WebDriver interface, Data Source, Excel Reader, Property File or Config File, WebDriver waits and so on. We extend the Base Class in our Test Class and Utility Class.


polymorphism: method over loading is used at many places where I have to call a method that applies same logic but for values of different data types.

Polymorphism also relies on the concept of one interface supporting multiple methods. As we know, WebDriver is an interface that supports multiple methods of different browsers like ChromeDriver(), IEDriver(), SafariDriver() and FirefoxDriver().

Also the Methods of webdriver interface are overridden by methods of child classes chrome,firefoxdrivers... Etc. 

Method overloading is common observed in many selemium classes like 

          driver.manage().wait() .pollingEvery(Duration.ofMillis(500))

               .wait(millisec) . pollingEvery(long duration,TimeUnit time)

               .wait(millisec,nanosec)

Encapsulation: wherever classes are used with private data members encapsulation is implemented. Typically In a POM Project, we know that we create a separate class for every page. All these classes are the best examples of Encapsulation where we keep the data of a class separated from the other class.

In these POM Classes, we declare the data members using @FindBy and initialize them using a constructor with initElement() to utilize them in the test methods.

Abstraction: concept is implemented in web driver.

Collection classes


4. Can Method overloading be achieved by returning different data types

Ans: No. It will throw compilation error.


5. Parent class of object…..

Ans: Object is the parent class of all classes and so there is no parent class to object


6. Parent class of all classes in java

Ans: Object class is the parent class of all classes


7. Where did you use Object?

Ans: I have used it @DataProvider, places where you won’t be sure of what data type you will handle and places where you have to return multiple data types


8. Collections and where did you use them.

Ans: list, arraylist, sets,hashmaps.

Classic example is that we create different classes for every page and there would be a situation when we want to switch the tabs and do some operation in the current tab. Here we use our collection interface called Set.

The return type of every window is stored as a str ing and the group of the window is stored in a Set of type String.

Hashmaps are used whereever you need key,value pair for e.g. you can use it to set chromeOptions to handle/turnoff  the alerts


9. Stale element and no such element exception and differences

Ans: The NoSuchElementException is thrown when the element you are attempting to find is not in the DOM

using waits you can overcome.

StaleElementReferenceException is when you find an element, the DOM gets modified then you reference the WebElement.

 stale element exceptions using waits or refresh or rerun the tests.


10. What is parent class of all exception?

Ans: The Throwable class is the superclass of all Java exceptions and errors. Click here to read more on this.....


11. Schema validations in API in rest assured....?

Ans: (2) API/JSON schema validation||REST assured-REST API Automation||Episode#3.1 - YouTube


12. How do you verify the response code of the API in rest-assured.

Ans: resp.StatusCode(); ………  DEMO


13. What is assertThat() and different to other asserts

Ans: AssertThat has a different semantic. It Asserts that actual satisfies the condition specified by matcher. If not, an AssertionError is thrown with information about the matcher and failing value.  WHERE AS assertEquals(object actual, object expected) asserts whether the actual string/integer/object equals the expected. If not throws an AssertionError.

Junit assertThat() is deprecated now and have to use hamcrest matcher- MatcherAssert.assertThat()


14. What are different status codes in API responses.

Ans: Worked on 200,201,400,500 series. Check here for more details.


15. Difference between 404, 409??

Ans: 

404 Not Found:  

The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address. This status code is commonly used when the server does not wish to reveal exactly why the request has been refused, or when no other response is applicable. 


409 Conflict:

The request could not be completed due to a conflict with the current state of the resource. This code is only allowed in situations where it is expected that the user might be able to resolve the conflict and resubmit the request. The response body SHOULD include enough information for the user to recognize the source of the conflict. Ideally, the response entity would include enough information for the user or user agent to fix the problem; however, that might not be possible and is not required.

Conflicts are most likely to occur in response to a PUT request. For example, if versioning were being used and the entity being PUT included changes to a resource which conflict with those made by an earlier (third-party) request, the server might use the 409 response to indicate that it can't complete the request. In this case, the response entity would likely contain a list of the differences between the two versions in a format defined by the response Content-Type. 


16. Difference between 200, 204

Ans: 

200-- Unlike the 204 status code, a 200 response should include a response body. The information returned with the response is dependent on the method used in the request, for example:

GET an entity corresponding to the requested resource is sent in the response;

HEAD the entity-header fields corresponding to the requested resource are sent in the response without any message-body;

POST an entity describing or containing the result of the action;

TRACE an entity containing the request message as received by the end server.


204 (No Content):

The 204 status code is usually sent out in response to a PUT, POST, or DELETE request when the REST API declines to send back any status message or representation in the response message’s body.

An API may also send 204 in conjunction with a GET request to indicate that the requested resource exists, but has no state representation to include in the body.

If the client is a user agent, it SHOULD NOT change its document view from that which caused the request to be sent. This response is primarily intended to allow input for actions to take place without causing a change to the user agent’s active document view. However, any new or updated metainformation SHOULD be applied to the document currently in the user agent’s dynamic view.

The 204 response MUST NOT include a message-body and thus is always terminated by the first empty line after the header fields.


17. What are different authorizations you have worked on

Ans: In my project we used clientid, client secret in the header as an authorization. In general there are Oauth1.0, Oauth2.0,

 basic authorization. Most of the recent applications have Oauth2 authentication.


18. When there is a change in the underlying architecture how do Compare APIs before and after the change….., what is your approach and how do you design your frame work to handle it.

Ans: This entirely depends on the type of changes that the project is undergone.

For example 

Change1: if there are changes in the schema of the API that there are two more new fields are introduced and 4 existing fields are removed.

Solution1: You should design your frame work in such a way that you keep a folder where you maintain the schemas of your APIs in an organized manner. Your test validations are designed in such a way that it would validate the API response against the schema that is stored in the folder.


Change2: if there is functional change that the values in the existing fields are changed and also need to validate values in the new fields.

Solution2: The frame should have designed to validate the dynamic changes. If the validations are tagged to DB rather then hardcoding then this is taken care of. Also having check points defined separately and reusing them wherever is needed will increase the reusability.


19. How do you validate headers in the response.

Ans: See the DEMO in the above video.


20. If you have to skip certain validations for an API when you run it in different envi how do you achieve it.

OR for an API called getUsers if you have to carry on set of validations called set1 in an environment envi1

and for the same API if you have to skip some validations from set1 in envi2, how do you handle it?

Ans: you can keep the check points separate from the actual tests. you control the execution and choose the list of check points which needs to be executed based on the envi the tests are executed.


21. String s = "cat dog cat tiger rat cat dog" how do get output as cat=3 times, dog=2 times, tiger=1,rat=1 and you don’t know that the string has cat/dog/rat in it

OR how do you identify unique word counts from the given String

Ans:  See the DEMO in the above video. Find the code here........













No comments:

Post a Comment