GithubHelp home page GithubHelp logo

jakimli / pandaria Goto Github PK

View Code? Open in Web Editor NEW
74.0 9.0 15.0 6.79 MB

Lightweight API testing tool based on cucumber JVM

License: MIT License

Java 78.02% Gherkin 21.96% JavaScript 0.03%
api-testing cucumber-jvm automation-testing automated-testing testing testing-framework graphql-testing

pandaria's Introduction

Pandaria

Lightweight API testing tool based on cucumber JVM

Build Status Maven Central

Introduction

Pandaria is a DSL written based on cucumber JVM to simplify the HTTP/Graphql API testing, everything with cucumber still works. Using pandaria you don't need to learn programming

中文介绍

Example

You can call your api and verify the response

* uri: http://localhost:10080/users/me
* send: GET
* status: 200
* verify: '$.username'='jakim'
* verify: '$.age'=18

And you can query database and verify the results

* query:
"""
SELECT NAME, AGE FROM USERS
"""
* verify: '$[0].name'='jakim'
* verify: '$[0].age'=18

Or like this:

* query: select.sql
* verify: '$[0].name'='jakim'
* verify: '$[0].age'=18

Multiple data source is supported

Mongo DB also supported

And you can wait until the verification passed:

* wait: 1000ms times: 3
* uri: /sequence
* send: GET
* response body:
"""
3
"""

Above code send GET to /sequence and expect response body equals 3, if not it will sleep 1000ms and then retry, until it succeded passing or exceeds max 3 times and fail. same with database query.

* wait: 1000ms times: 3
* query: select.sql
* verify: '$[0].name'='jakim'
* verify: '$[0].age'=18

You can also verify JSON schema:

* uri: /products/1
* send: get
* verify: '$' conform to:
"""
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://example.com/product.schema.json",
"title": "Product",
"description": "A product in the catalog",
"type": "object"
}
"""

* verify: '$' conform to: schema/product.schema.json

More Usage 更多用法

Resources

Latest Release

  • 0.3.5

See Release Notes

Get Started

If you don't need to verify database mongo, or graphql, just remove the pandaria-db, pandaria-mongo or pandaria-graphql from dependency declarations.

Gradle

dependencies {
    testCompile(
            "io.cucumber:cucumber-junit:4.0.0",
            'com.github.jakimli.pandaria:pandaria-core:0.3.5',
            'com.github.jakimli.pandaria:pandaria-db:0.3.5',
            'com.github.jakimli.pandaria:pandaria-mongo:0.3.5',
            'com.github.jakimli.pandaria:pandaria-graphql:0.3.5'
    )
}

Maven

<dependencies>
  <dependency>
    <groupId>com.github.jakimli.pandaria</groupId>
    <artifactId>pandaria-core</artifactId>
    <version>0.3.5</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>com.github.jakimli.pandaria</groupId>
    <artifactId>pandaria-db</artifactId>
    <version>0.3.5</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>com.github.jakimli.pandaria</groupId>
    <artifactId>pandaria-mongo</artifactId>
    <version>0.3.5</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>com.github.jakimli.pandaria</groupId>
    <artifactId>pandaria-graphql</artifactId>
    <version>0.3.5</version>
    <scope>test</scope>
  </dependency>
</dependencies>

If you need to verify database, remember to add specific jdbc driver for your database to build.gradle or pom.xml, and add you datasource connection in application.properties

application.properties

spring.datasource.url=jdbc:mysql://localhost:3307/pandaria?useSSL=false&allowMultiQueries=true
spring.datasource.username=root
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

If you need to interact with mongo db, also add:

mongo.db.name=test
mongo.db.connection=mongodb://root:password@localhost:27017

If you're using JUnit, you might want to add below:

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(plugin = {
        "pretty",
        "junit:build/cucumber-reports/cucumber.xml",
        "json:build/cucumber-reports/cucumber.json",
        "html:build/cucumber-reports",
},
        features = "classpath:features/",
        glue = {"com.github.jakimli.pandaria"},
        tags = "not @ignore")
public class RunCucumberTest {
}

Make sure com.github.jakimli.pandaria is in the list of cucumber glue.

Above code also configures reports for junit, json and html. also it excludes all features that marks as @ignore from execution. You can ajust this according to your requirement.

Then you can start to write your first automation test.

Feature: hello world
  This is the first feature for pandaria

  Scenario: hello world
    * uri: https://github.com
    * send: GET
    * status: 200

Powered By

Thanks to JetBrains

pandaria's People

Contributors

jakimli avatar meixuesong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pandaria's Issues

How to use it for changed Bear token

After I reviewed the introduction and code I found the stationary token is saved in application.properties file:
http.headers.Authorization=Bear Token
http.headers.global=globalHeader

http.headers.will_be_overrided=not_overrided
But if the Bear token will be expired after a period, and need to call a custom method to generate a new token, such as call "/tokens/generate?entity-id=" API to generate before test, how can I use the project for cucumber-api testing?

Unable to use a query result in the verification step

Hello!
I'm trying to compare if the value of a property from the response body is equals to a value obtained from the database.

My scenario is very similar to this one below I tried in very different ways to use the verify but it
either it can't be evaluated or is evaluate to null.

Scenario: Compares database and response body
        * uri: http://www.myservice.com/get_something
        * dir: features/queries
        * query: find_something.sql
        # It's finding a single line like [ { id=123, name="SomeName"} ]
        * var: query_result<-'$[0]'
        * send: GET
        # response body {"id": 123, "name": "SomeName"}
        * status: 200
        # some verify usages that I tried 
        * verify: '$.id'=code: ${query_result.id}
        * verify: '$.id'=code: ${query_result.get('id')}
        * verify: '$.id'=${query_result.id}

Did pandaria implemented this kind of step already?

https://app.leanboard.io/board/2888ba13-a6b1-43bd-999f-195766a0cef5

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.