Friday, August 2, 2024

Automation Testing - Top interview question



In this post , we will be discussing answers to questions asked in interviews for automation


What is Automation Testing?

Automation testing is a software testing technique that uses automated tools and scripts to perform tests on software applications. The primary goal of automation testing is to increase the efficiency, effectiveness, and coverage of the testing process. This approach is especially beneficial for repetitive and regression testing tasks.

What is difference between automation and manual testing?

Automated testing uses scripts and tools to perform tests, whereas manual testing requires human intervention to execute tests. Automated testing is faster and more reliable for repetitive tasks, while manual testing is better for exploratory, usability, and ad-hoc testing

What are key features of automation?



What are different Types of tests that are automated?

Unit Tests
  • Validates: individual components or units of code.
  • Tools : junit, TestNG and microtests

Integration Tests

  • Validates: interaction between integrated units or components
  • Tools: junit, TestNG and microtests

Functional Tests

  • Validates: application functions as the specified requirements. Includes both UI and API workflows.
  • Tools: Selenium, Playwright, Rest Assured, Cucumber

Performance Tests

  • Validates: application's performance under various conditions. Includes load testing, stress testing.
  • Tools: Jmeter, LoadRunner, Locust

What are best suited tasks for automation?

Repetitive, time-consuming tasks, regression tests, smoke tests, performance tests, data-driven tests, and tasks that require precision and consistency are well-suited for automation.

What are most used automation tools and frameworks?

Popular tools and frameworks include Selenium, JUnit, TestNG, Cypress, Appium, Jenkins, Cucumber, Playwright and Robot Framework.

What is a test automation framework?

Definition: A structured set of guidelines and best practices designed to help testers and developers automate the testing of software applications. 

Key Components and Characteristics: 
  • Code Reusability: Encourages the reuse of code, reducing duplication and maintenance efforts. 
  • Scalability: Supports scaling of test scripts to handle larger and more complex applications.
  • Modularity: Test scripts and components are organized in a modular fashion for easier management. 
  • Maintainability: Provides clear guidelines and structure for easier maintenance and updates. 
  • Test Data Management: Offers mechanisms to handle test data efficiently. 
  • Reporting: Includes reporting tools for detailed test execution results and logs. 
  • Integration: Can integrate with various tools and systems (e.g., CI/CD, version control). 
  • Best Practices: Promotes best practices in coding, such as design patterns and naming conventions. 

Types of Automation Frameworks: 

  • Linear Scripting Framework: Record-and-playback approach.
  • Modular Testing Framework: Breaks down application into smaller, independent modules. 
  • Data-Driven Framework: Separates test scripts from test data. 
  • Keyword-Driven Framework: Uses keywords to represent actions for readability and maintenance. 
  • Hybrid Framework: Combines features of multiple frameworks. 
  • Behavior-Driven Development (BDD) Framework: Uses natural language constructs for test cases.

What are the merits and demerits of using Selenium for automation?

Merits of Selenium:

  • Open Source: Selenium is free to use, which makes it a cost-effective option for businesses of all sizes.

  • Language Support: Supports multiple programming languages.

  • Browser Compatibility: Works with all major browsers ensuring broad compatibility.

  • Platform Independence: Can run on various operating systems 

  • Framework Integration: Easily integrates with other tools and frameworks like TestNG, JUnit, Maven, Jenkins, and Docker, facilitating continuous integration and continuous deployment (CI/CD).

  • Community Support: Has a large and active community, providing extensive resources.

  • Flexibility: Offers flexibility in designing tests, such as using a wide range of locators for identifying web elements.

Demerits of Selenium:

  • Limited to Web Applications: doesn't support desktop or mobile application testing natively.

  • Steep Learning Curve: Requires knowledge of programming languages and frameworks

  • Maintenance Overhead: Tests can become fragile and require updates with UI changes.

  • No Built-in Reporting: use of third-party tools for generating test reports.

  • Complexity with Dynamic Elements: Handling dynamic web elements (such as AJAX-based elements) can be complex and may require additional coding.

  • Browser-Specific Issues: Tests might behave differently across different browsers.

  • Performance: Can be slower compared to other automation tools like playwright

How does a (CI/CD) pipeline integrate with automation testing?

CI/CD pipelines automatically run tests every time code is committed, ensuring new changes don't break existing functionality. They integrate with automation tools to execute tests, report results.

How do you handle dynamic elements in web automation?

We can handle dynamic elements using dynamic XPath/CSS selectors, waiting mechanisms (explicit, implicit, and fluent waits), and interacting with elements based on properties like text, class, or other attributes.

What is the difference between functional and non-functional automation?

Functional testing checks if the application functions according to requirements. Non-functional testing evaluates aspects like performance, usability, and security.

What is the Page Object Model (POM)?

The Page Object Model (POM) is a design pattern in Selenium that enhances test maintenance and reduces code duplication by encapsulating web elements and their interactions in separate classes.

What is data-driven testing?

Data-driven testing is a methodology in which test data is stored separately from test scripts, allowing tests to be run multiple times with different sets of data.

What is a headless browser?

A headless browser is a web browser without a graphical user interface (GUI). It is used for faster, resource-efficient testing where GUI interaction is not necessary.

How do you handle an element with locator dynamically changing?

Here are a few approaches to manage dynamically changing locators:
  • Relative locators can help you find elements based on their position relative to other stable elements.
  • XPath axes allow you to navigate to elements based on their relationships to other elements.
  • Use CSS selectors to navigate through the DOM based on the hierarchy of elements
  • Some locators allow the use of regular expressions to match dynamic parts of the locator.
  • Use of java script executor

What are  ‘flaky tests’?

Flaky tests are tests that produce inconsistent results, sometimes passing and sometimes failing without any changes in the codebase. They can be caused by timing issues, environmental dependencies, or unreliable locators. 

To fix flaky tests:
  • Add appropriate waits to handle timing issues.
  • Ensure test environments are stable and consistent.
  • Use more reliable locators and checking for element visibility or readiness.
  • Creating independent test to ensure no impact of a test on other
  • Running tests multiple times to identify and address flaky behavior.

Sunday, July 21, 2024

BDD with cucumber and gherkins using MindMap

 Business-Driven Development is a collaborative approach that focuses on aligning software development with business goals through the creation of executable specifications

Business driven development

Translating Business-Driven Development to executable specification in gherkins

Keywords and code blocks in Gherkins specification

  • Feature is to provide a high-level description of a software feature.
  • Rule is to represent one business rule that should be implemented
  • Scenario or Example is a concrete example that illustrates a business rule
  • Scenario Outline is used to run the same Scenario multiple times, with different set of data.


  • Steps are used to define scenarios. steps can be:
    • Given - describe the precondition of the system
    • When - describes an event, or an action
    • Then - describe an expected outcome, or result
    • But - describe an outcome that is not expected
  • There can be multiple steps of same type in a scenario.
  • Background define a set of steps that are common to all scenarios in a feature file. Execution is after each scenarios
  • Hooks are blocks of code that run before or after certain events. they are defined by annotation "@Before" and "@After" annotations. these are setup() and teardown() code in the application.

Understanding components of a cucumber framework

Components of a cucumber framework

Feature File:

  • File corresponding to a feature/rule
  • Can have multiple scenarios/examples, scenario outline and background.
  • Annotations can be used to group tests, e.g: smoke, nightly, regression

Step definition File

  • For given, when then, but steps defined in feature file, the logical code is written in a step definition file.
  • Annotation @Given, @then are used to match the step definition method with the one provided in feature file


TestRunner File to execute tests

  • TestRunner file defines the tests to be executed,

Components of a Test Runner File:

  • Annotations: uses annotations from testing frameworks like JUnit or TestNG to define its purpose and behavior.
  • Glue: specifies the package where Cucumber can find the step definitions
  • Features: feature files which needs to be executed
  • Plugins: defines the reporting path, tags and formatting.




References :

https://www.linkedin.com/learning/cucumber-essential-training

https://cucumber.io/docs/gherkin/reference/

Understanding and Implementing Rest Assured using workflows and MindMap

Understanding Rest API

A REST API (Representational State Transfer Application Programming Interface) is a set of rules and conventions for building and interacting with web services.

Below diagram show the principles/workflow and response status code for Rest API.


Key Components of Rest API


1. Endpoint: This is the URL where the API can be accessed. Each endpoint corresponds to a specific resource or collection of resources.

2. HTTP Methods: These define the action to be performed on the resource. These are also known as CRUD (create, request, update and delete) operations

- GET: Retrieve data from the server.

- POST: Send data to the server to create a new resource.

- PUT: Update an existing resource with new data.

- DELETE: Remove a resource from the server.

3. Headers: These provide additional information with the request or response. Common headers include Content-Type (indicating the media type of the resource) and Authorization (containing credentials to authenticate a user).

4. Parameters: These are used to modify the request. They can be included in the URL (query parameters) or in the request body.

5. Request Body: This contains the data sent to the server when making POST or PUT requests. It's typically formatted in JSON or XML.

6. Response Codes: status of the request.




Common Crude actions/verb and response status code mapping

Understanding Rest Assured


REST Assured is an open-source Java-based library designed for testing and validating RESTful web services. It integrates well with testing frameworks like TestNG and JUnit. Below are key things, we will discuss in the article to keep it short and refresher only.

Basic Workflow for getting response from Rest requests for different verbs


Basic Workflow for getting response from Rest requests for different verbs

Code Understanding for basic operations 



How to Fit Rest-Assured tests in Framework


MindMap for basic framework with rest assured

Please comment, in case any observations/queries in understanding the process and documentation

Reference for learning :


Rest API - https://www.ibm.com/docs/en/mfci/7.6.1?topic=apis-rest-api

JSON cheat-sheet - https://codebeautify.org/json-cheat-sheet

JSONpath cheat-sheet - https://gist.github.com/mackoj/5786f8b95da0a82e8e003f444c4295bf

Understanding hamcrest :

https://www.baeldung.com/java-junit-hamcrest-guide

That's all for this article.Please comment, in case any observations/queries in understanding the proce
ss and documentation

Saturday, July 20, 2024

Understanding Page Object Model using workflows and examples

Page Object Model: Overview and Benefits

Page Object Model (POM) is a design pattern used in Selenium automation testing to enhance test maintenance and reduce code duplication.

Key concepts of Page Object Model:

Code Reusability:  Page Objects separate the test logic from the UI logic, promoting reuse of code across multiple tests.

Code Maintainability: Changes to UI elements identifiers are updated within the Page Object resulting minimal impact on test classes.

Improves Test Structure: Tests become more readable and easier to maintain as they interact with methods exposed by Page Objects rather than dealing with raw Selenium commands.

Reduces Duplication: Common interactions with elements (like clicking a button, entering text, etc.) are encapsulated within methods of Page Objects, eliminating redundant code in tests.

Scalability: Supports scaling of automation efforts by providing a structured approach to managing page interactions.


Page Object Model - Workflow



Components of Page Object Model (POM)

Page Object Model


Page Objects 

  • Classes that encapsulate the behavior and structure of a web page.
  • Each page in the application under test has its own corresponding Page Object class
  • Page Objects interact with the page elements (like button, input) and provide methods to perform actions on these elements
  • A Page class has:
    • Identifiers of elements in the Page.
    • methods to work with the identified elements in the page

Page Object Factory

  • Page Factory is a concept in POM that initializes elements of a Page Object.
  • It uses annotations (@FindBy) to locate elements on the web page.
  • These annotations are used in Page Object classes to find and initialize WebElement objects.

BasePage Class

  • This class serves as a foundational class that other Page Objects inherit from. 
  • Examples of common functionality that are shared across multiple Page Objects and should be defined in BasePage class includes:
    • WebDriver Initialization - Initialize the WebDriver instance in the base Class, so that it is used in the page Objects
    • Common Page Actions - Define reusable methods for common actions that occur across multiple pages.
    • Common Page Interactions: methods for handling common interactions  across different pages like handling alerts, executing JavaScript.

    • Wait Mechanisms: Implement methods for waiting and waiting strategies to be used across pages

Any additional method that might be beneficial across multiple Page Objects.

Relation between Test Class and Page Class



Base Class with logic for common implementations


Code example base class


Creation of Page class extending the Base class




Implementation of the Page Class in Test class




Thursday, July 11, 2024

Object Oriented Programming Concepts in a MindMap

 

Understanding Object-Oriented Programming (OOP) is fundamental for modern software development. OOP concepts, such as classes and objects, encapsulation, inheritance, and polymorphism, allow developers to create modular, reusable, and maintainable code. 

MindMap Representation of OOP's Concept


Object-Oriented Programming (OOP) is a programming paradigm that uses "objects" to design applications and computer programs.

Understanding Class

Class in Java is a  blueprint of attributes and behavior (actions) of an object.

Below are the members of a class:

  • Class Variables (Static Fields): These are common to all instances of a class and are declared with the `static` modifier. 
  • Instance Variables (Non-static Fields): These are unique to each instance of a class. Following the `Bicycle` example, `cadence`, `gear`, and `speed` would be instance variables, with each `Bicycle` object having its own copy.
  • Methods: These are functions that define the behavior of the objects created from the class. They can be static (class methods) or non-static (instance methods).
  • Constructors: Special methods used to initialize new objects. They have the same name as the class and may take parameters to set initial values for the instance variables.
  • Nested Classes: Classes can contain other classes, known as nested classes.

Principle of OOPs concept:

  •  Encapsulation: Bundling the data with the code that manipulates it
    • Bundling data (variables) and methods (functions) that operate on the data into a class. 
    • Access to the data is restricted and controlled through public methods known as getters and setters. 
    • Allows for data hiding, where internal workings of a class are hidden from outside  interference and misuse. 
    • Promotes modularity and maintainability of code 
    • Enhances data security, as only approved methods can modify the internal state of objects.

    • Data Types 

      • Public: accessible from any other class, not just the class in which it is declared.
      • Protected: accessible within its own class and by derived classes.
      • Private: accessible within the class in which it is declared, and not from any other class.

  • Abstraction: Hiding complex realities while exposing only the necessary parts.
    • Achieved through abstract classes and interfaces, allowing for the creation of classes that cannot be instantiated on their own but can be sub classed.
    • Abstract classes may contain abstract methods without a body; these methods must be implemented by subclasses.
    • An interface is a blueprint for a class
      •  Include abstract methods and constants.
      • Used to achieve abstraction and multiple inheritance, as a class can implement multiple interfaces.
      • Class implementing an interface must override all of its methods.
      • Interfaces cannot be instantiated—they can only be implemented by classes or extended by other interfaces.

  • Inheritance: Allowing new objects to take on the properties of existing one.
    • Inheritance in Java allows one class to inherit the features (fields and methods) of another class.
    • Syntax for inheritance uses the `extends` keyword
    • Java supports different types of inheritance: single, multilevel, and hierarchical.
    • Multiple inheritance is not supported in Java through classes, but it can be achieved using interfaces.
  • Polymorphism: Allows objects to take on multiple forms.
    • Manifests in two primary forms: compile-time (static) and runtime (dynamic) polymorphism.
    • Compile-time polymorphism is achieved through method overloading, where multiple methods have the same name but different parameter lists.
    • Runtime polymorphism is realized through method overriding, where a subclass provides a specific implementation of a method that is already defined in its superclass.