/G-Stack

让你无需写代码就能搞定的自动化验收/接口测试,基于Gauge的全栈测试平台

Primary LanguageJavaOtherNOASSERTION

G-Stack

让你无需写代码就能搞定的自动化验收/接口测试,基于Gauge的全栈测试平台

Gauge Badge

Requirements

  • Maven 3+
  • Java 1.8+
  • Gauge
  • IDEA
  • Gauge plugins: guage-java, gauge-java, gauge-java-maven, gauge-intellij-idea, gauge-html-report

DSL reference

Syntax

G-Stack Syntax is fully compatible with Gauge, reference here for more detail on Gauge Syntax

Basic Syntax

  • If you want to print messages into both console & reports:
    PRINT "content"

  • If you want to assert an actual value to an expected value:

* ASSERT <actual> <match> <expected>

build-in matches: =, <>, !=, contains

  • If you want to assert multiple actual values to their expected values one by one in one step:
* ASSERT <table>

<table> format:

|actual|match|expected|
|------|-----|--------|
  • If you want execution to be paused for seconds:
    * WAIT <seconds>

  • If you want to share data between steps, scenarios or specs:

* SET:SCENARIO <name> <value>
* SET:SPEC <name> <value>
* SET:SUITE <name> <value>

or share multiple values:

* SET:SCENARIO <table>
* SET:SPEC <table>
* SET:SUITE <table>

<table> format:

|name|value|
|----|-----|
|m   |4    |
|n   |5    |
// @{m} => 4
// @{n} => 5

or dynamic table

|col1|col2|col3|
|----|----|----|
|x   |10  |20  |
// @{col1.x.col2} => 10
// @{col1.x.col3} => 20

or dynamic table with explicitly id column

|col1#|col2|col3|
|-----|----|----|
|x    |10  |20  |
// @{col1.x.col2} => 10
// @{col1.x.col3} => 20
  • After set value to their name, you could get the value by our Argument Syntax: @{name}

Arguments

* SET:SCENARIO "hello" "world"
* SET:SCENARIO "suffix" "llo"
* PRINT "@{hello}"
* PRINT "I will say: @{hello}"
* PRINT "hello, @{he@{suffix}}!"

The output will be:

world
I will say: world
hello, world!

Dynamic Arguments

There are some arguments whose value can be generated automatically. Build-in dynamic arguments:

@{timestamp}

HTTP Syntax

Arrange Request

  • If you want to set baseUri:
* BASE <baseUri>
  • If you want to set basePath:
* PATH <basePath>
  • If you want to add query parameters to Url
* QUERY <name> <value>

or

* QUERY <table>

<table> format:

|name|value|
|----|-----|

e.g.

* QUERY "a" "1"
* QUERY "a" "2"
* QUERY
|name|value|
|----|-----|
|b   |1    |
|c   |2    |
|c   |3    |

the final query string will be

?a=1&a=2&b=1&c=2&c=3
  • If you want to add request headers:
* HEADER <name> <value>

or (<table> format is same to QUERY)

* HEADER <table>
  • If you want to add cookies:
* COOKIE <name> <value>

or (<table> format is same to QUERY)

* COOKIE <table>
  • If you want to set Content-Type
* CONTENTTYPE <contentType>

or

* CONTENTTYPE <contentType> <charSet>
  • If you want to add form parameters:
* BODY:FORM <name> <value>

or (<table> format is same to QUERY)

* BODY:FORM <table>
  • If you want to add text content to body:
* BODY:CONTENT <content>
  • If you want to build a whole new request:
* REQUEST:NEW
  • If you want to build a whole new request from a config file:
* HTTP:SETUP <jsonConfig>

e.g.

* HTTP:SETUP <file:dir/request.config>
{
  "method": "GET",
  "baseUri": "https://requestloggerbin.herokuapp.com",
  "basePath": "/",
  "httpVersion": "HTTP/1.1",
  "cookies": {
    "c1": "d4c19a20393919416cc88d29a4dec3cbe1528282256",
    "c2": "null"
  },
  "headers": {
    "accept": "application/json",
    "accept-language": "zh-CN,zh;q=0.9,en;q=0.8"
  },
  "queryString": {
    "a": [
      "1",
      "2"
    ],
    "b": "3"
  },
  "postData": {
    "mimeType": "application/x-www-form-urlencoded",
    "forms": {
      "c": [
        "5",
        "4"
      ],
      "d": "6"
    }
  }
}

Http Act

  • If you want to send GET request:
* GET <url>
  • If you want to send POST request:
* POST

or

* POST <url>

Assert Response

  • If you want to assert response status code:
STATUS <statusCode>
  • If you want to assert response body content:
// entirely match
* CHECK:BODY <content>

// partial match
* CHECK:CONTENT <content>

// not match
* FAIL:BODY <content>

// not contain
* FAIL:CONTENT <content>
  • If you want to check response as a JSON by GPath (Note that the <jsonPath> is a GPath)
* CHECK:JSONPATH <jsonPath> <expected>
* FAIL:JSONPATH <jsonPath> <unexpected>

or

* CHECK:JSONPATH <table>

<table> format:

|path|value|
|----|-----|
  • If you want to check response as a JSON by JSON Schema Validation:
* CHECK:JSONSCHEMA <schema>
  • If you want to check response headers:
// header with expected value
* CHECK:HEADER <name> <value>

// not exist header
* CHECK:HEADER <name> null
  • If you want to check response cookies:
* CHECK:COOKIE <name> <value>
* CHECK:COOKIE <name> null

Extract response values

If you want to share response data between steps or scenarios in current specification, you could use extraction syntax.

  • If you want to extract body content:
* EXTRACT:CONTENT <variableName>
  • If you want to extract value of a GPath
* EXTRACT:JSONPATH <path> <variableName>
  • If you want to extract headers
* EXTRACT:HEADER <header> <variableName>
  • If you want to extract cookies
* EXTRACT:HEADER <cookie> <variableName>

Log requests and response

  • If you want to log requests and response into console or report:
// before the request is sent
* HTTP:LOG

MySql Syntax

  • If you want to execute single sql statement:
* SQL:STATEMENT <connection> <sql>
  • If you want to execute assertion in sql:
// <sql> returns 0 for fail and 1 for pass
* SQL:ASSERT <connection> <sql>
  • If you want to execute batch sql statements:
* SQL:SCRIPT <connection> <sql>
  • If you want to execute insert and share auto-generated id with other steps:
* SQL:INSERT <connection> <table>

note that the <table> is a dynamic table with explicitly id column:

|col1#|col2|col3|
|-----|----|----|
|x    |10  |20  |
// @{col1.x.id} => new generated id
// @{col1.x.col2} => 10
// @{col1.x.col3} => 20

Web UI Syntax

  • If you want to use Web UI Automation, you must use scope syntax first:
* UI:WEB BEGIN
// perform some actions here
* UI:WEB END
  • If you want to open browser:
* OPEN <url>
  • If you want to define an element with a name:
DEF <name> <cssSelector>
  • If you want to enter text into element:
* ENTER <name> <text>
  • If you want to click on an element:
* CLICK <name>
  • If you want to submit an element:
* SUBMIT <name>
  • If you want to close browser:
* QUIT

License

GNU Public License version 3.0 G-Stack is released under GNU Public License version 3.0

Copyright

Copyright 2018 CHUN.LI