|
| 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 | +}); |
0 commit comments