Skip to content

Instantly share code, notes, and snippets.

@philmander
Last active November 12, 2019 10:27
Show Gist options
  • Save philmander/eb9078b87383904ac974c63b3d62c689 to your computer and use it in GitHub Desktop.
Save philmander/eb9078b87383904ac974c63b3d62c689 to your computer and use it in GitHub Desktop.
Bat talk snippets
Given('I do a custom login', function(credentials) {
const { username, password } = credentials;
const agent = this.currentAgent;
await agent
.post(this.replaceVars(`${base}/api/login`));
.send({
username,
password,
});
});
const xpath = require('xpath');
const dom = require('xmldom').DOMParser;
const { expect } = require('chai');
Then('the xpath at {string} should evaluate to {string}', function(xpath, expectedText) {
// get response body (xml)
const { body } = await this.getResponse();
// evaluate xpah
const doc = new dom().parseFromString(body);
const actualText = xpath.select(`string(${xpath})`, doc);
// assert value
expect(actualText).to.equal(expectedText);
});
Feature: Twitter Search API
Background: Set up common auth
Given I am a "twitter client"
And I am using basic authentication using credentials from: "./examples/auth.json"
And get token from "https://api.twitter.com/oauth2/token" using:
| grant_type | client_credentials |
Feature: Twitter Search API
Scenario: Use previous response data
When I send a 'GET' request to '{base}/1.1/users/lookup.json?user_id={userId}'
And I set the placeholder 'userId' using the json path '$.statuses[0].user.id'
from the last 'GET' to '{base}/1.1/search/tweets.json'
Feature: Twitter Search API
Scenario: Use previous response data
When I send a 'GET' request to '{base}/1.1/users/lookup.json?user_id={userId}'
And I set the placeholder 'userId' using the json path '$.statuses[0].user.id'
from the last 'GET' to '{base}/1.1/search/tweets.json'
Feature: Hacker News
Scenario: Get top stories
Given I am anonymous
When GET "https://hacker-news.firebaseio.com/v0/topstories.json"
Then receive status 200
Feature: Twitter Search API
Returns a collection of relevant Tweets matching a specified query.
Background:
Given I set the variable:
| base | https://api.twitter.com |
Scenario: Search for tweets containing "Lets Check"
Given I am using basic authentication with the credentials:
| username | sarah |
| password | releaseworker |
And I obtain an access token from "{base}/oauth2/token" using:
| grant_type | client_credentials |
Feature: Twitter Search API
Returns a collection of relevant Tweets matching a specified query.
Scenario: Search for tweets containing "Lets Check"
Given ...
When ...
Then I should receive a response with the status 200
And should receive a response within 500ms
And the response body json path at "$.search_metadata.query" should equal "Lets Check"
Feature: Twitter Search API
Returns a collection of relevant Tweets matching a specified query.
Scenario: Search for tweets containing "Lets Check"
Given ...
When I send a 'GET' request to '{base}/1.1/search/tweets.json'
And I add the query string parameters:
| q | Lets Check |
Then ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment