QA Interview Concepts Cheatsheet
1. ObjectMapper - Serialization (JAVA object to JSON) and Deserialization (JSON to JAVA
object)
Jackson - ObjectMapper mapper = new ObjectMapper();
Member member = readValue(jsonStr, Member.class)
jsonStr = writeWithDefaultPrettyPrinter().writeValueAsString(member);
2. PageFactory.initElements(driver, this)
3. Cookies in Selenium
Each cookie is associated with a name, value, domain, path, expiry, and the status of whether it is secure
or not. In order to validate a client, a server parses all of these values in a cookie.
driver.manage().getCookies(); Return The List of all Cookies
driver.manage().getCookieNamed(arg0); Return specific cookie according to name
driver.manage().addCookie(arg0); Create and add the cookie
driver.manage().deleteCookie(arg0); Delete specific cookie
driver.manage().deleteCookieNamed(arg0); Delete specific cookie according Name
driver.manage().deleteAllCookies(); Delete all cookies
4. Singleton Class in Java
Remember the key points while defining a class as a singleton class:
- Make a constructor private.
- Write a static method that has the return type object of this singleton class. Here, the concept of Lazy
initialization is used to write this static method.
- The primary purpose of a java Singleton class is to restrict the limit of the number of object creations
to only one. This often ensures that there is access control to resources, for example, socket or database
connection.
- We can use this single object repeatedly as per the requirements. This is the reason why multi-threaded
and database applications mostly make use of the Singleton pattern in Java for caching, logging, thread
pooling, configuration settings, and much more.
- Ensure that only one instance of the class exists.
- Provide global access to that instance by declaring all constructors of the class to be private.
- Providing a static method that returns a reference to the instance. The lazy initialization concept is
used to write the static methods.
- The instance is stored as a private static variable.
5. Scenario Outline - Examples Table and its Implementation
The Scenario Outline keyword can be used to run the same Scenario multiple times, with different
combinations of data. The Parameterized variables are specified within angular brackets <> which acts
as Headers in the examples table.
Test data for Scenario outline will be placed under the scenario using keyword “Examples”. A Scenario
Outline must have one or more “Examples” associated with it.
Cucumber automatically runs the complete Scenario (i.e all Given/When/Then steps of that scenario) once for
each row of data provided beneath Examples keyword. Here, the header is not counted as Data.
Cucumber will replace the parameterized variables <> in the Scenario Outline with actual data from the
examples table during the execution.
6. Data Table and its Implementation
Data Table works only for the single step below which it is defined rather than the entire scenario.
Data tables from Gherkin can be accessed by using the DataTable object as the last parameter in a step
definition. This conversion can be done either by Cucumber or manually.
Test Data is directly specified below the particular step in a Scenario and no separate keyword is needed to
define the test data. It doesn’t necessarily have a Header row either. Note: In the case where header row is
provided in the data table, we would skip the first row while parsing the data in step definition.
Separate code is required (e.g. List, Map) to interpret the Data Tables in Step Definitions (or Glue code).
Several methods are provided to convert tables to common data structures such as lists, maps etc. There are
different ways to handle it, depending on the structure and complexity of the data. Most common are: (1)
list of lists (2) list of maps and (3) table transformer.
Data Tables can be accessed by using the DataTables object as a parameter in the Step Definition. For
Example: In the case of the below two scenarios, ‘DataTable datatable’ will be passed as a parameter in the
functions for ‘Given’ step and ‘When’ step respectively.
Depending on the input data, Data Table can be implemented using various Collections, for example:
List<List<String>> tableName
Map<String, String> tableName
List<Map<String, String>> tableName
Example of DataTable without header in Feature File - Implementation of above data table using
List<List<String>> approach.
Example of DataTable with header and single row in Feature File - Implementation of above data table using
Map<String, String> approach.
Example of DataTable with header and multiple rows in Feature File - Implementation of above data table
using List<Map<String, String>> approach.