Skip to content

Commit 7e45726

Browse files
committed
Add a POST test
1 parent b734250 commit 7e45726

File tree

5 files changed

+68
-23
lines changed

5 files changed

+68
-23
lines changed

README.md

+15-10
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ You will analyze risks and prevent those risks with functional testing, api test
4747

4848
## Your Instructor: Nikolay Advolodkin
4949

50+
<img src="public/images/family.jpg" alt="api-testing" width="500"/>
51+
5052
- 🏢 I’m a Sr Solutions Architect at Sauce Labs
5153
- 🔭 I’m the founder of [Ultimate QA](https://ultimateqa.com/)
5254
- 🌱 I’m currently working on [Sauce Bindings](https://github.com/saucelabs/sauce_bindings)
@@ -70,7 +72,7 @@ The safest way to ensure that we all have the same environment is for us to [use
7072
### Sign up for accounts
7173

7274
1. Free [Sauce account](https://saucelabs.com/sign-up)
73-
2. Request [Demo Screener account](https://saucelabs.com/demo-request-vt). **!Request ASAP before the workshop as it's a manual process to add users.**
75+
2. Request [Demo Screener account](https://saucelabs.com/demo-request-vt). **!Request ASAP before the workshop as it's a manual process to add users.**
7476

7577
### Get your username and api key
7678

@@ -108,11 +110,12 @@ SCREENER_API_KEY:
108110
- Give the repo a ⭐ or you can't participate in the workshop😝
109111

110112
3. In the browser address bar, prepend the current GitHub url with `https://gitpod.io/#`
111-
* The resulting url should look as follows:
112-
113-
> https://gitpod.io/#https://github.com/YOUR-USERNAME/comprehensive-testing-js
114-
115-
4. Once the Gitpod.io URL is loaded, you will need to sign in with the GitHub account you created earlier
113+
114+
- The resulting url should look as follows:
115+
116+
> https://gitpod.io/#https://github.com/YOUR-USERNAME/comprehensive-testing-js
117+
118+
4. Once the Gitpod.io URL is loaded, you will need to sign in with the GitHub account you created earlier
116119

117120
### Start the app
118121

@@ -177,8 +180,9 @@ npm run test:sanity:eu
177180
1. Use NVM for this installation by [following instructions](https://github.com/nvm-sh/nvm#install--update-script)
178181
- It should be just a single command to run in our terminal
179182
- **!Don't forget to restart your terminal!**
180-
- After installation, confirm install with `nvm --version`
181-
3. Intall Node 16 with `nvm install --lts`
183+
- After installation, confirm install with `nvm --version`
184+
2. Intall Node 16 with `nvm install --lts`
185+
182186
- Confirm node installation with `node --version` and seeing `v16.x` or similar
183187
- Confirm NVM is set to 16 for default by running the following commands:
184188

@@ -213,8 +217,9 @@ Follow the [same setup instructions](#Start-the-app) for starting the app and ru
213217
ℹ️ The main difference is that you will set environmenta variables by [following these instructions](https://docs.saucelabs.com/basics/environment-variables/#setting-up-environment-variables) depending on your OS.
214218

215219
ℹ️ Some individuals aren't allowed to set their environment variables on their machines (Employer policy). In that case, you can hardcode them by modifying
216-
* [3 visual keys](https://github.com/saucelabs-training/comprehensive-testing-js/blob/9309d16a9cf56dd14607b9e4c478f3b2f698e9d8/wdio.visual.conf.js#L2-L9)
217-
* [2 keys for functional tests](https://github.com/saucelabs-training/comprehensive-testing-js/blob/9309d16a9cf56dd14607b9e4c478f3b2f698e9d8/wdio.sanity.conf.js#L9-L10)
220+
221+
- [3 visual keys](https://github.com/saucelabs-training/comprehensive-testing-js/blob/9309d16a9cf56dd14607b9e4c478f3b2f698e9d8/wdio.visual.conf.js#L2-L9)
222+
- [2 keys for functional tests](https://github.com/saucelabs-training/comprehensive-testing-js/blob/9309d16a9cf56dd14607b9e4c478f3b2f698e9d8/wdio.sanity.conf.js#L9-L10)
218223

219224
You will need to hardcode these values as we do exercises.
220225

cypress/integration/network/exercise.spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,19 @@
22

33
context("Network Requests", () => {
44
const baseUrl = "https://jsonplaceholder.typicode.com";
5+
6+
it("Can create new user on /posts", () => {
7+
// resource will not be really updated on the server but it will be faked as if
8+
// TODO supply the body of the request
9+
cy.request("POST", `${baseUrl}/posts`, {
10+
// TODO add json body here
11+
})
12+
// note that the value here is the returned value of the 2nd request
13+
// which is the new post object
14+
.then((response) => {
15+
console.log(response);
16+
// TODO expect the response status to be 201
17+
// TODO expect the response body to contain the title = "Cypress Test"
18+
});
19+
});
520
});

cypress/integration/network/solution.spec.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,21 @@ context("Network Requests", () => {
1414
});
1515

1616
it("Can create new user on /posts", () => {
17-
// first, let's find out the userId of the first user we have
17+
// resource will not be really updated on the server but it will be faked as if
1818
cy.request("POST", `${baseUrl}/posts`, {
1919
userId: 11,
20-
title: "Cypress Test Runner",
20+
title: "Cypress Test",
2121
body: "new body",
2222
})
2323
// note that the value here is the returned value of the 2nd request
2424
// which is the new post object
2525
.then((response) => {
2626
console.log(response);
27+
// expect the response status to be 201
2728
expect(response).property("status").to.equal(201); // new entity created
28-
expect(response).property("body").to.contain({
29-
title: "Cypress Test Runner",
29+
// expect the response body to contain the title = "Cypress Test"
30+
expect(response.body).to.contain({
31+
title: "Cypress Test",
3032
});
3133
});
3234
});

docs/API.md

+32-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
[SUT](https://jsonplaceholder.cypress.io/)
88

9-
[Docs](https://jsonplaceholder.typicode.com/guide/)
9+
[Guide to API](https://jsonplaceholder.typicode.com/guide/)
1010

1111
## What is API Testing?
1212

@@ -49,24 +49,47 @@ it("comments returns 200 and 500 body length", () => {
4949
});
5050
```
5151

52-
Run the tests w/ `npx cypress run --spec **/exercise.spec.js`
52+
Run the tests
5353

54-
## Our tools
54+
`npx cypress run --spec **/exercise.spec.js`
5555

56-
### [WebdriverIO](https://webdriver.io/)
56+
### 🏋️‍♀️ Let's try a `POST`
5757

58-
Next-gen browser and mobile automation test framework for Node.js
58+
> Use POST when you want to add a child resource under resources collection
5959
60-
### [Screener](https://screener.io/)
60+
1. In your browser go to (API Fortress)[https://app.saucelabs.com/api-testing]
61+
2. Use this URL for your POST `https://jsonplaceholder.typicode.com/posts`
62+
3. Use this body
6163

62-
Automatically detect visual regressions across your UI
64+
```json
65+
{
66+
"userId": 11,
67+
"title": "any title you want",
68+
"body": "any body"
69+
}
70+
```
71+
72+
4. Send the request
73+
74+
### 🏋️‍♀️ Let's automate a `POST`
75+
76+
- Go to `cypress/integration/network/exercise.spec.js`
77+
- Follow instructions for test `it("Can create new user on /posts", () => {`
78+
- Run the tests
79+
80+
`npx cypress run --spec **/exercise.spec.js`
6381

6482
## 📝Summary
6583

66-
Visual e2e testing is a simple and efficient way to ensure visual consistency cross-platform and cross-OS
84+
6785

68-
We used WebdriverIO + Screener.io to write our visual e2e tests
86+
6987

7088
## ⏭️[Let's make our testing more efficient with component tests](./COMPONENT-TESTS.md)
7189

7290
🎁 Bonus exercises at the end of the `solution.spec.js`
91+
92+
## Expand your learning
93+
94+
[What is REST blog post](https://restfulapi.net/)
95+
[API testing in JavaScript](https://testautomationu.applitools.com/javascript-api-testing/)

public/images/family.jpg

3.15 MB
Loading

0 commit comments

Comments
 (0)