Cypress/Cucumber/API Tesing #16877
Replies: 3 comments 1 reply
-
Hi @aleksandar-julovski-atomia Here are 'stupid' example of what gherkin could look like.
or
or
In this case you could have steps with variables for statusCode and an enum mapping statusCode names & codes. You could also just put '200' instead of 'OK' in your gherkin. In the same manner, some people put method names (GET, POST, ...) in gherkin sentences. Not my style, but you do you ✋. As steps are isolated from each-other, so that gherkin shows clearly what you assert on (assert are not included in 'When' steps'). This means the 'when I call ...' that does the API call needs to store the reply so that the 'Then ...' have it to assert on. You'll need to store what the call retrieve in the shared context (cypress aliases). This way, the then step can find this response an assert on it. Have it a try on a side, with for ex https://rickandmortyapi.com/documentation/#rest and see how it goes for you. |
Beta Was this translation helpful? Give feedback.
-
Hey, thank you very much for your response.
How would you do it in this example:
login.feature
Feature: Login Functionality
Scenario: User Should Login With Valid Credentials
Given For a specific user
When Provide Valid Credential
Then Status_code equals 200
LoginSteps.js
import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps'
const loginCredentials = {
"user": {
"email": ***@***.***",
"password": "Password123"
}
}
Given('For a specific user', () => {
...
})
When('Provide Valid Credential', () => {
cy.request('POST', 'https://conduit.productionready.io/api/users/login', loginCredentials).then(response => {
expect(response.status).to.eq(200)
})
})
Then('Status_code equals 200', () => {
...
})
…On Thu, Jun 10, 2021 at 10:06 AM sandra-ouadghiri ***@***.***> wrote:
Hi @aleksandar-julovski-atomia
<https://github.com/aleksandar-julovski-atomia>
I'm using that. It works nicely. I've used that in several companies over
several microservices.
Here are 'stupid' example of what gherkin could look like.
Scenario: Create a user
When I create a new user
Then the response status should be Created
And the response body should have
| connection | 0 |
| active | true |
or
Scenario: Create a user
When I create a new user such as
| familyName | A name |
| firstName | Another name |
Then the response status should be Created
And the response body should have the property id a strictly positive number
And the response body should have
| familyName | A name |
| firstName | Another name |
or
Scenario: Delete a user
Given I create a new user
And the response status should be Created
When I delete this user
Then the response status should be OK
When I retrieve this user
Then the response status should be Not Found
In this case you could have steps with variables for statusCode and an
enum mapping statusCode names & codes. You could also just put '200'
instead of 'OK' in your gherkin. In the same manner, some people put method
names (GET, POST, ...) in gherkin sentences. Not my style, but you do you
✋.
As steps are isolated from each-other, so that gherkin shows clearly what
you assert on (assert are not included in 'When' steps'). This means the
'when I call ...' that does the API call needs to store the reply so that
the 'Then ...' have it to assert on. You'll need to store what the call
retrieve in the shared context (cypress aliases). This way, the then step
can find this response an assert on it.
Have it a try on a side, with for ex
https://rickandmortyapi.com/documentation/#rest and see how it goes for
you.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#16877 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQIPJCGT5RAGNLFZKOCMPGTTSBXB5ANCNFSM46MIWUHQ>
.
|
Beta Was this translation helpful? Give feedback.
-
It worked.
<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
Virus-free.
www.avg.com
<http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
…On Fri, Jun 11, 2021 at 9:32 PM sandra-ouadghiri ***@***.***> wrote:
Hi @aleksandar-julovski-atomia
<https://github.com/aleksandar-julovski-atomia>
I guess your credz are for your call body.
What about
cy.request({
method: 'POST',
url: `${Cypress.config('baseUrl')}/api/users/login`,
headers: {
'Content-Type': 'application/json'
},
body: {
email: user.login,
password: user.password
}
})
I advise you to try with hardcoded value, and once it works, move
credentials aside (ex in fixtures) and use a baseUrl.
Then you can .its('body')... or .then( (response) => {
cy.wrap(response).its('body')... } )
As you're using cucumber, and probably what your assertions in another
step, you'll need to store whatever you need (body, status code, ...) into
aliases, so that you can retireve it in another step and assert on it.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#16877 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQIPJCBT7KDDSU64SD2OOP3TSJQETANCNFSM46MIWUHQ>
.
|
Beta Was this translation helpful? Give feedback.
-
Hello, my name is Aleksandar and I am a QA Engineer in my company.
My tool of choice is Cypress
I have a question for you, what do you think about the Cypress/Cucumber combination for API testing? What I mean by that is a combination of feature files and using only cy.request() for registering, logging in, remembering tokens, using tokens for APi interactions, asserting requests and responses, but without ever using GUI for that.
This is the plugin that I want to explore: cypress-cucumber-preprocessor
I believe it's relatively easy to Automate front-end but for API calls there are several obstacles.
Can you tell me your opinion on this topic, and how you would implement it?
Beta Was this translation helpful? Give feedback.
All reactions