Skip to content

Commit 5e97ee4

Browse files
authored
[patch] [34] issue - missing assertions (#35)
1 parent a40bd51 commit 5e97ee4

File tree

2 files changed

+156
-12
lines changed

2 files changed

+156
-12
lines changed
+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
import { visitHtml } from '../../common/helper';
2+
3+
describe('assertions', () => {
4+
beforeEach(() => {
5+
//visitHtml();
6+
visitHtml({
7+
body: `
8+
<div data-test-id="item">
9+
<div>Apple</div>
10+
<div data-test-id="other-item">Hello</div>
11+
</div>
12+
</br>
13+
<div data-test-id="item">
14+
<div>Banana</div>
15+
<div data-test-id="other-item">Buy</div>
16+
</div>
17+
</br>
18+
<div data-test-id="item">
19+
<div>Orange</div>
20+
<div data-test-id="other-item">Is Round</div>
21+
</div>
22+
23+
<div data-qa-id="task-card-title">
24+
<div>Task card</div>
25+
</div>
26+
27+
`,
28+
script: `
29+
// add element after some time
30+
setTimeout(()=> {
31+
var child = document.createElement("div");
32+
child.setAttribute('data-test-id','item');
33+
child.innerHTML = '<div>Lichi</div><div data-test-id="other-item">Fruit</div>';
34+
document.body.appendChild(child);
35+
}, 300);
36+
// adds second after 300ms
37+
setTimeout(()=> {
38+
39+
var child2 = document.createElement("div");
40+
child2.setAttribute('data-test-id','item');
41+
child2.innerHTML = '<div>Lichi</div><div data-test-id="other-item">Tropical Fruit</div>';
42+
document.body.appendChild(child2);
43+
}, 600);
44+
45+
// adds second after 1000ms
46+
setTimeout(()=> {
47+
48+
var child2 = document.createElement("div");
49+
child2.setAttribute('data-qa-id','task-card-title');
50+
child2.innerHTML = '<div>Task Card 2</div>';
51+
document.body.appendChild(child2);
52+
}, 1000);
53+
`,
54+
});
55+
});
56+
57+
it('test', () => {
58+
cy.get('div').should(() => {
59+
expect(1, ' 1 should eq').eq(1);
60+
});
61+
});
62+
63+
it('assertion: synchronous asserts', () => {
64+
expect(1).eq(1);
65+
expect(1, 'sync assert').eq(1);
66+
});
67+
68+
it('assertion: exist cypress function', () => {
69+
cy.get('div').should('exist');
70+
});
71+
72+
it('assertion: exist cypress function', () => {
73+
cy.get('div').should('exist');
74+
});
75+
76+
it('assertion: exist as chai function', () => {
77+
cy.get('div').should(t => {
78+
expect(t).to.exist;
79+
});
80+
});
81+
82+
it('assertion: exist as chai function with custom message', () => {
83+
cy.get('div').should(t => {
84+
expect(t, 'custom assert').to.exist;
85+
});
86+
});
87+
88+
it('01 assertion: should contain', () => {
89+
cy.window().then(w => {
90+
cy.get('div').should('contain', 'Some text');
91+
92+
cy.url().should('contain', 'mytest.com/123');
93+
cy.qaId('task-card-title').should('contain', 'Task Card 2');
94+
setTimeout(() => {
95+
w.location.href = '/mytest.com/123';
96+
//cy.visit('/mytest.com/123');
97+
}, 500);
98+
setTimeout(() => {
99+
w.location.href = '/mytest.com';
100+
//cy.visit('/mytest.com/123');
101+
}, 800);
102+
cy.url().should('contain', 'mytest.com');
103+
cy.url().should('contain', 'mytest.com');
104+
cy.url().should('contain', 'mytest.com');
105+
});
106+
});
107+
108+
it('02 several url', () => {
109+
cy.window().then(w => {
110+
setTimeout(() => {
111+
w.location.href = '/mytest.com/123';
112+
}, 500);
113+
cy.url().should('contain', 'mytest.com/123');
114+
cy.url().should('contain', 'mytest.com');
115+
cy.url().should('contain', 'mytest.com');
116+
});
117+
});
118+
119+
it('03 several urls', () => {
120+
cy.url().should('contain', 'mytest.com');
121+
cy.url().should('contain', 'mytest.com');
122+
cy.url().should('contain', 'mytest.com');
123+
});
124+
125+
it('04 several asserts', () => {
126+
cy.qaId('task-card-title').should('contain', 'Task Card 2');
127+
cy.qaId('task-card-title').should('contain', 'Task Card 2');
128+
cy.qaId('task-card-title').should('contain', 'Task Card 2');
129+
cy.qaId('task-card-title').should('contain', 'Task Card 2');
130+
cy.qaId('task-card-title').should('contain', 'Task Card 2');
131+
cy.qaId('task-card-title').should('contain', 'Task Card 2');
132+
cy.wait(1000);
133+
});
134+
135+
it('assertion: should contain after some time', () => {
136+
cy.get('div').should('contain', 'Tropical Fruit').and('contain', 'Lichi');
137+
});
138+
139+
it('assertion: url should', () => {
140+
cy.url().should('contain', 'mytest.com');
141+
});
142+
143+
it('assertion: several sync assertions', () => {
144+
cy.get('div');
145+
146+
for (let t = 0; t < 20; t++) {
147+
expect(t).eq(t);
148+
}
149+
});
150+
});

src/setup/cypress-events.ts

+6-12
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,11 @@ export const handleCyLogEvents = (
236236
const ingoreAllCommands = () =>
237237
[...ignoreCommands(), 'should', 'then', 'allure', 'doSyncCommand'].filter(t => t.trim() !== '');
238238
const customCommands: string[] = [];
239-
const commands: string[] = [];
240-
const logCommands: string[] = [];
239+
const allLogged: string[] = [];
241240
const emit = createEmitEvent(runner);
242241

243242
Cypress.Allure.on('test:started', () => {
244-
commands.splice(0, commands.length);
245-
logCommands.splice(0, logCommands.length);
243+
allLogged.splice(0, allLogged.length);
246244
});
247245

248246
const allureAttachRequests = Cypress.env('allureAttachRequests')
@@ -363,19 +361,17 @@ export const handleCyLogEvents = (
363361
withTry('report log:added', () => {
364362
const cmdMessage = stepMessage(log.name, log.message === 'null' ? '' : log.message);
365363
const logName = log.name;
366-
const lastCommand = commands[commands.length - 1];
367-
const lastLogCommand = logCommands[logCommands.length - 1];
364+
const lastAllLoggedCommand = allLogged[allLogged.length - 1];
368365
// const isEnded = log.end;
369366

370367
// logs are being added for all from command log, need to exclude same items
371368
if (
372-
cmdMessage !== lastCommand &&
373-
cmdMessage !== lastLogCommand &&
369+
cmdMessage !== lastAllLoggedCommand &&
374370
!cmdMessage.match(/its:\s*\..*/) && // its already logged as command
375371
!ingoreAllCommands().includes(logName) &&
376372
logName !== COMMAND_REQUEST
377373
) {
378-
logCommands.push(cmdMessage);
374+
allLogged.push(cmdMessage);
379375
debug(`step: ${cmdMessage}`);
380376

381377
Cypress.Allure.startStep(cmdMessage);
@@ -428,7 +424,7 @@ export const handleCyLogEvents = (
428424
debug(`started: ${cmdMessage}`);
429425
Cypress.Allure.startStep(cmdMessage);
430426

431-
commands.push(cmdMessage);
427+
allLogged.push(cmdMessage);
432428

433429
withTry('report command:attachment', () => {
434430
const requestAndLogRequests = allureAttachRequests && name === COMMAND_REQUEST;
@@ -462,8 +458,6 @@ export const handleCyLogEvents = (
462458
return;
463459
}
464460

465-
commands.pop();
466-
467461
if (name === COMMAND_REQUEST) {
468462
withTry('report attach:requests', () => {
469463
attachRequests(allureAttachRequests, command, { compactAttachments: allureCompactAttachmentsRequests });

0 commit comments

Comments
 (0)