You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

apigeek-dialect-webapi

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apigeek-dialect-webapi

An BDD Dialect for REST APIs

1.0.14
latest
Source
npmnpm
Version published
Weekly downloads
27
1250%
Maintainers
1
Weekly downloads
 
Created
Source

Dialect For Web APIS

A scenario describes a test case - essentially it's a list of instructions and expectations.

The framework interprets each step in the scenario using the Web API Dialect.

Read about authentication, proxies and SSL/TLS in Advanced Web APIs .

Let's create a simple example:

@dialect=webapi
Scenario: Test Google's homepage 

Given I enable redirects
When I GET http://google.com/
Then response code should be 200
And header Content-Type should contain text/html

Note: The example deliberately contravenes best practice to showcase a few concepts.

1) Enable redirect handling.
2) Issue an HTTP GET request to Google.
3) Evaluate an arbitrary Javascript expression and store the boolean result in a variable called "ResponseSucceeded".
4) Test that the HTTP status code is 200 (after an initial 302 redirect)
5) Test that a Content-Type exists.
6) Test that a Content-Type contains "text/html".
7) Check that "ResponseSucceeded" variable was set to "true" in line 3. This is redundant since line 4 already makes same assertion.

Working with multiple hosts

You can create a "target" secion in your configuration that allows you to define "hostname", "protocol", "port" and "basePath" outside of your scenarios.

"target": {
	"google": {
		"protocol": "https",
		"hostname": "google.com"
	}
}

Now, we can simply write:

When I GET /

Now, you can run the same feature but specify a different config file to switch targets - for example: from dev -> test -> production.

For more sophisticated environments, you can specify a "targets" section to support named targets.

"targets": {
	"google": {
		"protocol": "https",
		"hostname": "google.com"
	},
	"yahoo": {
		"protocol": "http",
		"hostname": "yahoo.com",
		"port": "80"
	}
}

Then you can switch targets using @target within a feature, scenario or --target for CLI and shell scripts.

This allows us to re-use our features in new environments without recoding. For example:

$ apigeek --target=yahoo

FAQs

Package last updated on 18 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts