(Add Documentation for) Passing API return values between given/when/then
See original GitHub issueHi,
I’m using cypress-cucumber-preprocessor to e2e test an API, and am having trouble using cy.request due to it naturally needing to be chained.
In Cypress I would normally do
cy.request('/test').its('status').should(...) etc
In the example given you use cy.visit, and I assume this stores it in the cy object? What is the best way to do this? Or is this not the correct way of thinking? Currently I am doing this:
/* global cy, then, when, given */
const testEndpoint = '/test'
let response
given('I have access to the test endpoint', () => {
// expect(true).to.be.equal(true)
})
when('I request the GET /test endpoint', () => {
response = cy.request(testEndpoint)
})
then(`I get a {int} response code`, (responseCode) => {
response.its('status').should('eq', responseCode)
})
whilst this works this is obviously not great, and when I want to split out the then
into its own shared file etc it will become a nightmare!
Many thanks
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
(Add Documentation for) Passing API return values between ...
Hi, I'm using cypress-cucumber-preprocessor to e2e test an API, and am having trouble using cy.request due to it naturally needing to be ...
Read more >How to write REST API Test in Cucumber BDD ... - Tools QA
The test will start by generating a Token for Authorization; Get List of available books in the library; Add a book from the...
Read more >Parameterize BDD Tests | TestComplete Documentation
This applies to all numerical values, whether they are integer or floating-point. Let's check what values TestComplete passes to the generated functions.
Read more >How to perform API testing with REST Assured | TechBeacon
Getting started: Configuration · First test: Understanding the syntax · Validating technical response data · Parameterizing tests · Accessing secured APIs · Passing...
Read more >Welcome to Pytest-BDD's documentation! — Pytest-BDD 6.1.1 ...
Welcome to Pytest-BDD's documentation! BDD library for the pytest runner. Install pytest-bdd; Example; Scenario decorator; Step aliases; Step arguments ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You can use everything that’s in Cypress with this library.
If I was doing this in a single function, I’d use the “Cy.as” syntax and then wait for it. I think you should be able to do this across steps in the same scenario, though.
E.G.
@OllyNuralAND We have prepared an example of how to share context between given, when, then steps. You can see it here: https://github.com/TheBrainFamily/cypress-cucumber-preprocessor/pull/74 Note that we alias the input in
When
step as addNewItemInput and we use this reference inThen
step to make sure it’s empty.