Wednesday, July 13, 2022

Karate Training

Understanding REST

Great introduction article - https://www.smashingmagazine.com/2018/01/understanding-using-rest-api/

API testing is done with the following tools:

Postman for exploratory testing

Karate for automation

The following are public APIs that you can use to try out API testing tools. 

http://petstore.swagger.io/ 

https://jsonplaceholder.typicode.com/

https://reqres.in/

https://openweathermap.org/api

https://github.com/toddmotto/public-apis/blob/master/README.md

https://any-api.com/

Testing REST APIs

Postman

    Select one of these public APIs for your use getting started

    Install Postman

    Walk through Postman docs to get started - https://www.getpostman.com/docs/v6/

    Review your public API via Postman

Karate

    Install IDE as stated in the next section

    Review Karate readme at https://github.com/intuit/karate; walk through to understand basics

    Clone repos 

    Complete your machine set up

    Write sample tests for your public API using Karate

    Review Karate Usage Guidelines

        Cover the following items with Karate and your public API:

        Using Scenarios

        Using Scenario Outlines - https://github.com/intuit/karate#data-driven-tests

        Different types of asserts - https://github.com/intuit/karate#index > "Assert" row

        Reading in files - https://github.com/intuit/karate#reading-files

        Calling other feature files for code re-use - https://github.com/intuit/karate#calling-other-feature-files

        Using js function output in scenarios - https://github.com/intuit/karate#calling-javascript-functions

        Using Java method output in scenarios - https://github.com/intuit/karate#calling-java


I also recommend watching this video from the tool author - 

https://www.techgig.com/webinar/Karate-DSL-for-writing-web-service-API-acceptance-tests-BDD-1042


IDE Setup

    The project expects JDK 1.8 (at least jdk1.8.0_162), Maven 3.5.2 and JUnit 4.

    Install the following:

    Java Development Kit: JDK 8 (http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html)

    Apache Maven 3.5 or newer - binary zip archive (https://maven.apache.org/download.cgi)

    IDE: Eclipse IDE for Java EE Developers Oxygen or newer. NOTE: You need the Java EE Developers edition (http://www.eclipse.org/downloads/packages/)

Set JAVA and Maven environment variables: Under System variables,

    Define JAVA_HOME with the path to the JDK installation.

    For example:

    JAVA_HOME

    C:\Program Files\Java\jdk1.8.0_192

Add the following variables under Path:

    %JAVA_HOME%\bin

    <path to Maven folder>\bin

    For example: 'C:\apache-maven-3.5.2\bin'



In Eclipse, set up your workspace as follows:

    Set Maven path: Go to Window menu > Preferences > Maven > Installations, add Maven install location and set as default.

    Set JDK path: Go to Window menu > Preferences > Java > Installed JREs, add installed JDK (as Standard VM) and set as default.

    Set default Java path to the JDK: Go to Window menu > Preferences > Java > Installed JREs > Execution Environments, set 'JavaSE 1.8' to the JDK.

    JUnit comes pre-installed with Eclipse. No further configuration needed for this.

    Install the free Cucumber-Eclipse plugin. Go to Eclipse Help > Eclipse Marketplace and install the latest version. This will provide syntax-coloring for feature files.

Go to the Eclipse Preferences > Cucumber > User Settings, and enter the following Root Package Name: com.intuit.karate . This resolve an issue where you encounter "does not have a matching glue code" warnings (refer to the Cucumber-Eclipse wiki for more).

Your environment is set. Follow the Bitbucket repo readme instructions to clone and set up the project.

No comments:

Post a Comment

Thanks for your comment..! Keep commenting for more and more updates. To get post updates subscribe Blog or become a follower of this blog. Thanks Again..!