Writing API Tests with Karate Enhance Your API Testing for Improved Security and Performance

Software in recent years is moving away from centralized systems and monoliths to smaller, scalable components that communicate with each other through APIs. Testing these communication interfaces is becoming increasingly important to ensure the security, performance, and extensibility of the softwa...

Descripción completa

Detalles Bibliográficos
Otros Autores: Bischoff, Benjamin, author (author), Thomas, Peter, writer of foreword (writer of foreword)
Formato: Libro electrónico
Idioma:Inglés
Publicado: Birmingham, England : Packt Publishing Ltd [2023]
Edición:First edition
Materias:
Ver en Biblioteca Universitat Ramon Llull:https://discovery.url.edu/permalink/34CSUC_URL/1im36ta/alma991009743440206719
Tabla de Contenidos:
  • Cover
  • Title Page
  • Copyright and Credits
  • Foreword
  • Contributors
  • About the reviewer
  • Table of Contents
  • Preface
  • Part 1:Karate Basics
  • Chapter 1: Introducing Karate's Core Concepts
  • Technical requirements
  • What makes Karate stand out?
  • Discovering Karate's strong points
  • Core features
  • BDD versus Karate
  • What is BDD?
  • Glue code
  • The Karate way
  • Supported data types in Karate
  • JSON
  • GraphQL
  • XML
  • YAML
  • CSV
  • Other text-based formats
  • Binary formats
  • The JavaScript engine
  • Java interoperability
  • Summary
  • Chapter 2: Setting up Your Karate Project
  • Technical requirements
  • Installing Java
  • Setting the JAVA_HOME environment variable
  • Getting to know Karate standalone
  • Preparing the IDE
  • Setting up Visual Studio Code
  • Setting up IntelliJ IDEA
  • Importing the example project
  • Setting up Karate projects with Maven
  • What is Maven?
  • Installing Maven
  • Adding Maven to the PATH variable
  • Setting up a Karate project with the Maven archetype
  • The roles of the different Karate project files
  • Summary
  • Chapter 3: Writing Basic Karate Tests
  • Technical requirements
  • Exploring the API under test
  • The JSONPlaceholder API
  • Creating a new Karate project
  • Adding a new feature file
  • Configuring test runs
  • Adding a scenario
  • Calling endpoints and setting parameters
  • Setting a URL
  • Specifying the HTTP method
  • Separating the base URL from the path
  • Setting query parameters
  • Matching status codes and responses
  • Matching the status code and type
  • Making the test fail
  • Using assertions and matchers on the response
  • Exploring the response variable
  • Handling nested JSON elements
  • Asserting the number of elements with the length property
  • Using matchers
  • Making requests with payloads
  • Using variables and data tables
  • Using variables.
  • Using data tables
  • Using a set
  • Summary
  • Chapter 4: Running Karate Tests
  • Technical requirements
  • Running and debugging Karate tests through the IDE
  • Running via CodeLens and the Karate CLI
  • Debugging via CodeLens and Karate standalone
  • Using the debug server
  • Running tests with Maven
  • Understanding Karate runners
  • Running tests against different environments
  • Using a custom property in a feature file
  • Using Karate's environment property
  • Setting up karate-config.js
  • Running specific tests
  • Running specific runner class methods
  • Running specific scenarios
  • Filtering tests by tags
  • Summary
  • Chapter 5: Reporting and Logging
  • Technical requirements
  • Configuring log options
  • Understanding log levels
  • Changing the log level
  • Suppressing print
  • Using Karate's built-in reports
  • The different report pages
  • Preserving old reports
  • Deciding what to report
  • Configuring third-party report libraries
  • Setting the appropriate Karate options
  • Using Cluecumber as a Maven plugin
  • Technical requirements
  • Using Cluecumber from a Karate runner
  • Generating a Surefire report
  • Surefire XML
  • Using JUnit reports
  • Summary
  • Part 2:Advanced Karate Functionalities
  • Chapter 6: More Advanced Karate Features
  • Technical requirements
  • Working with headers and cookies
  • More about headers
  • Setting headers
  • More about cookies
  • Using different configuration and run options
  • Using the karate object for configuration and execution
  • Request retries
  • Using advanced tags
  • Defining and using expressions with def
  • Defining inline methods
  • Using embedded expressions with JSON
  • Using embedded expressions with XML
  • Working with external files
  • Understanding JSONPath and XPath
  • Testing GraphQL
  • Understanding GraphQL requests
  • Exploring the mock API
  • Using GraphQL in Karate.
  • Collecting data into a new array
  • Summary
  • Chapter 7: Customizing and Optimizing Karate Tests
  • Technical requirements
  • Using Karate hooks
  • Implementing a new hook class
  • Overriding handler methods
  • Registering a hook class in the runner
  • Running a test using the hook class
  • Defining hooks inside feature files
  • Defining and calling Java functions
  • Understanding the basics
  • Working with databases
  • Using Karate as a mock server
  • Authoring a mock scenario
  • Firing up the mock server from within a test
  • Using a standalone mock server
  • Making your tests more concise
  • Reducing code by calling other feature files
  • Data-driven tests with scenario outline
  • Avoiding code duplication with background scenarios
  • Summary
  • Chapter 8: Karate in Docker and CI/CD pipelines
  • Technical requirements
  • Triggering Karate tests from shell scripts
  • Creating a batch script for Windows
  • Creating a Bash script
  • Running Karate tests in a Docker container
  • Understanding Docker
  • Installing Docker
  • Starting and verifying a Docker installation
  • Downloading a Docker image
  • Running a Maven command in a Maven Docker container
  • Running Karate tests inside a Maven Docker container
  • Running our shell script inside Docker
  • Customizing our tests
  • Passing database credentials as system properties
  • Using the system properties in the database connection class
  • Passing parameters from Docker
  • Environment variables
  • Integrating Karate tests into GitHub workflows
  • Understanding GitHub workflows
  • Managing secrets
  • Adding a GitHub workflow to a repository
  • Setting up the Docker-based GitHub workflow
  • Using Karate in a GitHub workflow without Docker
  • Summary
  • Chapter 9: Karate UI for Browser Testing
  • Technical requirements
  • What Karate UI is for
  • Related testing capabilities.
  • Writing a basic Chrome scenario
  • Opening a website in Chrome
  • Finding and interacting with elements
  • Understanding locators
  • Knowing the different kinds of locators
  • Determining element locators
  • Interacting with elements
  • Using interactions in a test scenario
  • Making web element assertions
  • Making web element list assertions
  • Debugging UI tests
  • Taking screenshots
  • Highlighting elements
  • Exporting PDFs
  • Using the debugger
  • Using karate.stop to pause execution
  • Redirecting HTTP calls
  • Investigating API requests
  • Adding a mock response
  • Configuring the mock
  • Using the mock in a test
  • Summary
  • Chapter 10: Performance Testing with Karate Gatling
  • Technical requirements
  • Creating the test scenario
  • What is Gatling?
  • Setting up Karate Gatling
  • Setting up Scala in VS Code
  • Creating Maven profiles
  • Running Karate tests as performance tests
  • Creating a simulation
  • Running the simulation
  • Using tags
  • Testing different simulations
  • Gatling assertions
  • Checking out Gatling reports
  • Summary
  • Index
  • Other Books You May Enjoy.