Skip to content

Commit 4019cd0

Browse files
committed
update Cypress application with the latest documentation
1 parent 082333b commit 4019cd0

File tree

7 files changed

+203
-16
lines changed

7 files changed

+203
-16
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
node_modules
1+
node_modules
2+
cypress/videos
3+
cypress/screenshots
4+
cypress/fixtures

README.md

Lines changed: 198 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,219 @@
1+
# Cypress Web Application
2+
3+
## Description
4+
5+
A sample web application that uses Cypress a JavaScript End to End Testing, which can be used locally and on CI to test the web application. Cypress contains a number of benefits compared to other web testing frameworks like Selenium.
6+
7+
## Contents
8+
9+
- [Setup Steps](#setup-steps)
10+
- [How to run the project locally](#how-to-run-the-project-locally)
11+
- [Tools](#tools)
12+
- [Update Dependencies](#update-dependencies)
13+
- [Releases](#releases)
14+
- [Documentations](#documentations)
15+
- [Helpful resources](#helpful-resources)
16+
17+
## Setup Steps
18+
19+
To setup a Cypress project, we need to go to the terminal and add the following
20+
21+
```javascript
122
mkdir cypress-web-application
23+
```
224

3-
npm install cypress --save-dev
25+
Then change directory into `cypress-web-application` and run the following in your terminal at the root of the project to install Cypress and and keep a record saved of the dependency to the `package.json` file.
426

5-
<!-- Open cypress dashboard -->
6-
npx cypress open
27+
```javascript
28+
npm install cypress --save-dev
29+
```
730

31+
After that we also want to install the following `ejs` and `Express` to make a simple project we can use to test Cypress. So, run the following at the root of the project in the terminal.
832

33+
```javascript
934
npm install ejs --save
1035
npm install express --save
36+
```
1137

38+
Then we want to install the following `start-server-and-test`, see the Github repo [link](https://github.com/bahmutov/start-server-and-test), as it allows to start our node project server and be able to test on this server that has started. In the past, we would have issue where we could start the server, but could not run the tests in tandem, this library allows us to do both.
1239

13-
Let’s create a new file in the cypress/integration folder that was created for us:
40+
```javascript
41+
npm install --save-dev start-server-and-test
42+
```
1443

15-
create `sample_spec.js`
44+
To launch the `Cypress` dashboard and run the tests locally to make sure they work, run the following in your terminal.
1645

17-
npm install --save-dev start-server-and-test
46+
```javascript
47+
npx cypress open
48+
```
49+
50+
To see a list of example tests that `Cypress` provides when installing the end to end test framework, go the following directory path.
51+
52+
```javascript
53+
cypress/integration/examples
54+
```
55+
56+
To create our own `Cypress` tests we want to do the following, let’s create a new file in the `cypress/integration` folder that was created for us when we installed `Cypress` called `sample_spec.js`.
57+
58+
In this file we want something like the following, the next time we run our tests locally or on CI, we can run these tests against our sample Express project.
59+
60+
```javascript
61+
describe("My First Test", () => {
62+
it("Does not do much!", () => {
63+
expect(true).to.equal(true);
64+
});
65+
});
66+
67+
// describe('My First Test', () => {
68+
// it('Does not do much!', () => {
69+
// expect(true).to.equal(false)
70+
// })
71+
// })
72+
73+
// To test this locally we need to run the server in one tab and run the tests in another tab
74+
// describe("Launch the website", () => {
75+
// it("Visits the Kitchen Sink", () => {
76+
// cy.visit("http://localhost:8080");
77+
// });
78+
// });
79+
80+
describe('My First Test', function() {
81+
it('Visits page', function() {
82+
cy.visit('https://example.cypress.io')
83+
cy.contains('type')
84+
})
85+
})
86+
```
87+
88+
To run our Cypress tests on CI specifically Github Actions, we want something like the following in out `.yml` file.
89+
90+
```yml
91+
name: End-to-end tests
92+
on: [push]
93+
jobs:
94+
cypress-run:
95+
runs-on: ubuntu-latest
96+
container: cypress/browsers:node12.18.3-chrome87-ff82
97+
steps:
98+
- name: Checkout
99+
uses: actions/checkout@v1
100+
101+
- name: Cypress run
102+
uses: cypress-io/github-action@v2.9.3
103+
with:
104+
start: npm test
105+
wait-on: http://localhost:8080
106+
```
107+
108+
We want to modify the `package.json` to be like the following to make running certain script commands easier like the following instead of using `node app.js` to launch our web server, we could use `npm start` instead.
109+
110+
```json
111+
{
112+
"name": "Cypress-web-application",
113+
"version": "1.0.0",
114+
"description": "",
115+
"main": "app.js",
116+
"scripts": {
117+
"start": "node app.js",
118+
"cy:run": "cypress run",
119+
"test": "start-server-and-test start http://localhost:8080 cy:run"
120+
},
121+
"devDependencies": {
122+
"cypress": "^6.8.0",
123+
"start-server-and-test": "^1.12.1"
124+
},
125+
"dependencies": {
126+
"ejs": "^3.1.6",
127+
"express": "^4.17.1"
128+
}
129+
}
130+
```
131+
## How to run the project locally
132+
133+
To open the `Cypress` Dashboard locally run, we want to type the following in our terminal at the root of the project.
134+
135+
```javascript
136+
npx cypress open
137+
```
138+
139+
To launch our web server, we want to type one of the following in our terminal at the root of the project.
140+
141+
```javascript
142+
node app.js
143+
```
144+
or
145+
```javascript
146+
npm start
147+
```
148+
149+
To run our `Cypress` tests locally we want to use the following in our terminal at the root of the project, which calls a script from our `package.json`.
150+
151+
```javascript
152+
npm test
153+
```
154+
155+
## Tools
156+
157+
**Linter:** we use the following linter [link](https://github.com/github/super-linter).
158+
159+
**Uploading Artifacts:** we use the following way to upload Artifacts, they allow you to persist data like test results after a job has completed, see the following documentation [link](https://docs.github.com/en/actions/configuring-and-managing-workflows/persisting-workflow-data-using-artifacts).
160+
161+
**Creating images/icons:** we use Figma to create images and icon. Figma makes it very easy to create designs in many different formats.
162+
163+
**Creating a Mock Server:** we use a mock server with Postman to quickly test apis, to see how to create a mock server, see the following video [link](https://www.youtube.com/watch?v=rJY8uUH2TIk).
164+
165+
### Mobile Specific Tools:
166+
167+
**Fastlane:** Fastlane allows us to automate our development and release process [link](https://docs.fastlane.tools/).
168+
169+
**App Center:** App Center is used to distribute an app, making it very easy to test on a physical device by using a fastlane plugin [link](https://github.com/microsoft/fastlane-plugin-appcenter).
170+
171+
**Proxyman:** we use Proxyman to view HTTP/HTTPS requests as they happen, it is easier to debug network connections on mobile on Proxyman where we can test and mock specific network responses, see the following documentation [link](https://docs.proxyman.io/debug-devices/ios-simulator).
172+
173+
## Update Dependencies
174+
175+
**Npm:** How to update a npm package.
176+
- [link](https://docs.npmjs.com/cli/update).
177+
178+
**Gemfile:** How to update a Gemfile package.
179+
- [link](https://bundler.io/man/bundle-update.1.html#UPDATING-A-LIST-OF-GEMS).
180+
181+
## Documentations
182+
183+
**Git Squash:** How to Git Squash with VS Code [link](documentations/gitSquashDocument.md).
184+
185+
**Git Worktree:** How to use Git Worktree [link](documentations/gitWorktreeDocument.md).
186+
187+
**Git Empty Commit:** How to use Git Empty Commit [link](documentations/gitEmptyCommitDocument.md).
188+
189+
**Common Design Patterns and App Architectures for Mobile**: [link](https://www.raywenderlich.com/18409174-common-design-patterns-and-app-architectures-for-android#toc-anchor-001) and [link](https://dev.to/codalreef/learn-dependency-injection-with-doug-the-goldfish-3j43).
190+
191+
## Releases
18192

193+
How to manage releases in a repository [link](https://help.github.com/en/github/administering-a-repository/managing-releases-in-a-repository).
19194

20-
https://docs.cypress.io/guides/guides/command-line.html#cypress-run
195+
## Helpful resources
21196

22-
https://docs.cypress.io/guides/continuous-integration/introduction.html#Setting-up-CI
197+
The following link provides helpful information on why you would want to use `Cypress` as your End to End test framework for Web development compared to Selenium.
198+
- [link](https://docs.cypress.io/guides/overview/why-cypress.html#In-a-nutshell).
23199

24-
https://www.cypress.io/blog/2019/11/20/drastically-simplify-your-testing-with-cypress-github-action/
200+
The following link provides a helpful example on how you could set up your own simple website using nodejs and `Express` and how to test this with Cypress.
201+
- [link](https://www.345tool.com/blog/automate-node-js-website-e2e-test-with-cypress-and-github-actions).
25202

26-
https://docs.cypress.io/guides/getting-started/testing-your-app.html#Step-2-Visit-your-server
203+
The following link provides a real world example of `Cypress` being used with `Github Actions`
204+
- [link](https://docs.cypress.io/guides/continuous-integration/github-actions.html#Cypress-Real-World-Example-with-GitHub-Actions).
27205

28-
https://docs.cypress.io/guides/getting-started/writing-your-first-test.html#Write-a-real-test
206+
The following link provides info on how to set up `Cypress` over `CI`.
207+
- [link](https://docs.cypress.io/guides/continuous-integration/introduction.html#Setting-up-CI).
29208

30-
https://docs.cypress.io/guides/overview/why-cypress.html#Cypress-in-the-Real-World
209+
The following link provides some information on how you would run `Cypress` tests on `Github Actions`.
210+
- [link](https://www.cypress.io/blog/2019/11/20/drastically-simplify-your-testing-with-cypress-github-action/).
31211

32-
https://docs.cypress.io/guides/overview/why-cypress.html#In-a-nutshell
212+
The following link provides some information on how you would write some real tests using `Cypress`.
213+
- [link](https://docs.cypress.io/guides/getting-started/writing-your-first-test.html#Write-a-real-test).
33214

34-
https://www.345tool.com/blog/automate-node-js-website-e2e-test-with-cypress-and-github-actions
215+
The following link provides information how would you write a test in `Cypress` to visit your server.
216+
- [link](https://docs.cypress.io/guides/getting-started/testing-your-app.html#Step-2-Visit-your-server).
35217

36-
https://docs.cypress.io/guides/continuous-integration/github-actions.html#Cypress-Real-World-Example-with-GitHub-Actions
218+
The following links to a library `start-server-and-test` that allows us to run our server and tests at the same time without it our ci would get stuck running the server and not be able to run the `Cypress` tests.
219+
- [link](https://github.com/bahmutov/start-server-and-test).

cypress/integration/sample_spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe("My First Test", () => {
1010
// })
1111
// })
1212

13+
// To test this locally we need to run the server in one tab and run the tests in another tab
1314
// describe("Launch the website", () => {
1415
// it("Visits the Kitchen Sink", () => {
1516
// cy.visit("http://localhost:8080");

images/baseCommitInPr.png

46.6 KB
Loading

images/exampleImage.png

1.87 KB
Loading

images/mixedReset.png

23.6 KB
Loading

images/resetCurrentBranch.png

105 KB
Loading

0 commit comments

Comments
 (0)