You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/testing/cypress.md
+25-1Lines changed: 25 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -133,14 +133,38 @@ Cypress tests are compiled / packed and run in the browser. So feel free to impo
133
133
134
134
For example you can share Id values between UI and Tests to make sure the CSS selectors don't break:
135
135
136
-
```ts
136
+
```js
137
137
import { Ids } from'../../../src/app/constants';
138
138
139
139
// Later
140
140
cy.get(`#${Ids.username}`)
141
141
.type('john')
142
142
```
143
143
144
+
## Tip: Creating Page Objects
145
+
Creating objects that provide a convenient handle for all the interactions that various tests need to do with a page is a common testing convention. You can create page objects using TypeScript classes with getters and methods e.g.
146
+
147
+
```js
148
+
import { Ids } from'../../../src/app/constants';
149
+
150
+
classLoginPage {
151
+
visit() {
152
+
cy.visit('/login');
153
+
}
154
+
155
+
getusername() {
156
+
returncy.get(`#${Ids.username}`);
157
+
}
158
+
}
159
+
constpage=newLoginPage();
160
+
161
+
// Later
162
+
page.visit();
163
+
164
+
page.username.type('john');
165
+
166
+
```
167
+
144
168
## Tip: Implicit assertion
145
169
Whenver a cypress command fails you get a nice error (instead of something like `null` with many other frameworks) so you fail quickly and know exactly when a test fails e.g.
0 commit comments