サイプレスのAPIテスト.IO
4053 ワード
サイプレスとは何か
サイプレスは、現代のWebのために構築された次世代フロントエンドのテストツールです.Cypress.ioとその機能について学んでください.
事前の要件ノードをインストールします.JSとNPM https://www.npmjs.com/get-npm
あなたが を使いたいAPI
セットアッププロジェクトとCDのディレクトリを作成します.
は、新しいNPMパッケージプロジェクトを設定するために はNPM は、 現在、サイプレスと一緒のサイプレスフォルダ.JSONファイルはプロジェクトディレクトリに作成されます.“統合”フォルダには、サイプレステストの例が含まれます. “cypress . json”ファイルを編集して、すべてのテストのためのbaseURLを追加します
「統合」フォルダの下のは新しいファイルを作成します."typicode api test . js "という名前を付けます
応答中に返される他のいくつかのオブジェクトをアサートし、正しく動作しているか確認してください.
アサーション
レスポンスオブジェクトの使用可能なキーをチェックします.
ノートオブジェクト.キー( object )は利用可能なキーの配列を返します. とキー配列を反復処理し、includeメソッドでアサートします. 新しいユーザー投稿を投稿します.
リクエスト本文は次のようになります
無視されたテストとして追加することで例題フォルダを無視します.JSON
これが役に立つことを願っています.あなたのフィードバックを残してください.
サイプレスは、現代のWebのために構築された次世代フロントエンドのテストツールです.Cypress.ioとその機能について学んでください.
事前の要件
セットアップ
mkdir cypress-api-automation-tests && cd cypress-api-automation-tests
を実行します.npm init --y
を介してサイプレスをインストールする.npm i cypress --save-dev
を実行することによってサイブレスを確認します.{
"baseUrl": "https://jsonplaceholder.typicode.com/"
}
テストの作成と実行「統合」フォルダの下の
/// <reference types="cypress" />
describe('JSON Typicode', () => {
it('Get all user posts', () => {
cy.request('/posts')
.then((response) => {
expect(response.status).to.equal(200);
})
})
})
2 . cypressでテストを実行し、結果を通知します.応答中に返される他のいくつかのオブジェクトをアサートし、正しく動作しているか確認してください.
アサーション
レスポンスオブジェクトの使用可能なキーをチェックします.
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}
userid、id、titleおよびbodyキーがResponseオブジェクトに存在するかどうかを確認する必要があります./// <reference types="cypress" />
describe('JSON Typicode', () => {
it('Get all user posts', () => {
cy.request('/posts')
.then((response) => {
let first_response_object = Object.keys(response.body[0]);
let keys = [`userId`, `id`, `title`, `body`];
for (let key of keys) {
expect(first_response_object).to.includes(key)
}
})
})
})
結果はノート
リクエスト本文は次のようになります
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}
無視されたテストとして追加することで例題フォルダを無視します.JSON
{
"baseUrl": "https://jsonplaceholder.typicode.com/",
"ignoreTestFiles": "**/examples/*.js"
}
GITレポ:https://github.com/Bharath-Kumar-S/cypress-api-automation-testsこれが役に立つことを願っています.あなたのフィードバックを残してください.
Reference
この問題について(サイプレスのAPIテスト.IO), 我々は、より多くの情報をここで見つけました https://dev.to/bharathkumars/api-tests-with-cypress-io-3f76テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol