Skip to content

Commit

Permalink
Add new test and feature
Browse files Browse the repository at this point in the history
  • Loading branch information
wlsf82 committed Jan 15, 2024
1 parent 521a636 commit 550cf16
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cypress/e2e/playground.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,10 @@ describe('Cypress Playground - Test Design Masterclas TAT', () => {
cy.contains('#intercept ul li', `Completed: ${todo.completed}`).should('be.visible')
cy.contains('#intercept ul li', `User ID: ${todo.userId}`).should('be.visible')
})

it('makes an HTTP request and asserts on the returned status code', () => {
cy.request('GET', 'https://jsonplaceholder.typicode.com/todos/1')
.its('status')
.should('be.equal', 200)
})
})
10 changes: 10 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ <h2>
<br>
<button>Get TODO</button>
</div>
<div id="request" class="section">
<h2>
<pre>cy.request()</pre>
</h2>
<p>Another great Cypress feature is the<a href="https://on.cypress.io/request" target="_blank"><code>cy.request()</code></a>.</p>
<p>Differently than the<code>cy.intercept()</code> command (which "listens" to the requests), with<code>cy.request()</code>, you can make an HTTP request, like you would with a tool like Postman.</p>
<p>For example:<code>cy.request('GET', 'https://api.example.com/todos/1')</code></p>
<p>After making the request, you could even run an assertion, to ensure it returned the correct status code.</p>
<p>For example:<code>cy.request('GET', 'https://api.example.com/todos/1').its('status').should('be.equal', 200)</code></p>
</div>
</div>
<script src="script.js"></script>
</body>
Expand Down

0 comments on commit 550cf16

Please sign in to comment.