[英]Is it possible to test API endpoints with Playwright just like Cypress?
我已經使用 Cypress 有一段時間了,但是這個街區的新孩子已經到來,Playwright 解決了我使用 Cypress 時遇到的一些痛點。 不過,我對 Cypress 的最佳使用是將它用作我的 API 和 UI 測試的中央存儲庫。 我只是想知道 Playwright 是否可以做到這一點(是的,我試圖用谷歌搜索並檢查他們的文檔,但也許我錯過了一些東西,因為它似乎不太明確)
例如,我有這個測試,其中包含關於正文、狀態和屬性的斷言。 cypress/support/commands.js
(自定義命令)
Cypress.Commands.add('something', (method) => { // api for something
return cy.request({
method: method,
url: 'https://something.com/api/',
auth: {
bearer: '12332asa42412412asda341'
},
body:
'description': 'this is my description'
},
headers: {
'Content-Type': 'application/json'
},
failOnStatusCode: false // test all status codes
});
});
cypress/integration/apitest.js
(實際測試)
cy.something('POST').should((resp) => {
expect(resp.status).to.eq(201);
expect(resp.headers).to.have.property('content-type', 'application/json');
expect(resp.body.description).to.eq('this is my description');
});
好的,有了這個版本1.18-rc1
,我相信它現在已啟用(雖然我還沒有嘗試過,但語法類似於 Cypress API 測試)。 這讓我更多地考慮 Playwright: https ://playwright.dev/docs/test-api-testing
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.