|
| 1 | +'@fixture TestCafe Example Page'; |
| 2 | + |
| 3 | +'@page http://testcafe.devexpress.com/Example'; |
| 4 | + |
| 5 | +'@test'['act.type examples'] = { |
| 6 | + 'Type name': function () { |
| 7 | + act.type($('#Developer_Name'), 'Peter'); |
| 8 | + }, |
| 9 | + 'Replace with last name': function () { |
| 10 | + act.type($('#Developer_Name'), 'Paker', { |
| 11 | + replace: true |
| 12 | + }); |
| 13 | + }, |
| 14 | + 'Update last name': function () { |
| 15 | + act.type($('#Developer_Name'), 'r', { |
| 16 | + caretPos: 2 |
| 17 | + }); |
| 18 | + }, |
| 19 | + 'Check result': function () { |
| 20 | + eq($('#Developer_Name').val(), 'Parker'); |
| 21 | + } |
| 22 | +}; |
| 23 | + |
| 24 | +'@test'['act.click, array parameter, ok() assertion'] = { |
| 25 | + 'Click two checkbox labels': function () { |
| 26 | + var labels = [$(':containsExcludeChildren(Support for testing on remote devices)'), |
| 27 | + $(':containsExcludeChildren(Reusing existing JavaScript code for testing)')]; |
| 28 | + act.click(labels); |
| 29 | + }, |
| 30 | + 'Confirm checked state': function () { |
| 31 | + ok($('#testing-on-remote-devices').is(':checked')); |
| 32 | + ok($('#re-using-existing-javascript').is(':checked')); |
| 33 | + } |
| 34 | +}; |
| 35 | + |
| 36 | +'@test'['act.click on an input, eq() assertion'] = { |
| 37 | + 'Type name': function () { |
| 38 | + act.type(getInput(), 'Peter Parker'); |
| 39 | + }, |
| 40 | + 'Move caret position': function () { |
| 41 | + act.click(getInput(), { |
| 42 | + caretPos: 5 |
| 43 | + }); |
| 44 | + }, |
| 45 | + 'Erase a character': function () { |
| 46 | + act.press('backspace'); |
| 47 | + }, |
| 48 | + 'Check result': function () { |
| 49 | + eq(getInput().val(), 'Pete Parker'); |
| 50 | + } |
| 51 | +}; |
| 52 | + |
| 53 | +'@test'['act.press example'] = { |
| 54 | + 'Type name': function () { |
| 55 | + act.type(getInput(), 'Peter Parker'); |
| 56 | + }, |
| 57 | + 'Erase Peter': function () { |
| 58 | + act.press('home right . delete delete delete delete'); |
| 59 | + }, |
| 60 | + 'Check result': function () { |
| 61 | + eq(getInput().val(), 'P. Parker'); |
| 62 | + } |
| 63 | +}; |
| 64 | + |
| 65 | +'@test'['ok() vs notOk() assertions'] = { |
| 66 | + 'Check comments area is disabled': function () { |
| 67 | + ok($('#Developer_Comments').is(':disabled')); |
| 68 | + }, |
| 69 | + 'Click label "I have tried TestCafe"': function () { |
| 70 | + var label = $(':containsExcludeChildren(I have tried TestCafe)'); |
| 71 | + act.click(label); |
| 72 | + }, |
| 73 | + 'Check comments area is enabled': function () { |
| 74 | + notOk($('#Developer_Comments').is(':disabled')); |
| 75 | + } |
| 76 | +}; |
| 77 | + |
| 78 | +'@test'['eq() assertion example'] = { |
| 79 | + 'Type name': function () { |
| 80 | + act.type(getInput(), 'Peter Parker'); |
| 81 | + }, |
| 82 | + 'Submit form': function () { |
| 83 | + var submitButton = $('.button.blue.fix-width-180'); |
| 84 | + act.click(submitButton); |
| 85 | + }, |
| 86 | + 'Check message': function () { |
| 87 | + var header = $('.article-header'); |
| 88 | + eq(header.html(), 'Thank You, Peter Parker!'); |
| 89 | + } |
| 90 | +}; |
| 91 | + |
| 92 | +'@test'['act.drag example'] = { |
| 93 | + 'Click label "I have tried TestCafe"': function () { |
| 94 | + var label = $(':containsExcludeChildren(I have tried TestCafe)'); |
| 95 | + act.click(label); |
| 96 | + }, |
| 97 | + 'Check initial slider value': function () { |
| 98 | + eq($('#Developer_Rating').val(), 0); |
| 99 | + }, |
| 100 | + 'Drag slider handle': function () { |
| 101 | + var sliderHandle = $('.ui-slider-handle'); |
| 102 | + act.drag(sliderHandle, 357, 0, { |
| 103 | + offsetX: 10, |
| 104 | + offsetY: 10 |
| 105 | + }); |
| 106 | + }, |
| 107 | + 'Check resulting slider value': function () { |
| 108 | + eq($('#Developer_Rating').val(), 7); |
| 109 | + } |
| 110 | +}; |
| 111 | + |
| 112 | +'@test'['act.hover example'] = { |
| 113 | + 'Hover over the combo box': function () { |
| 114 | + var div = $('.text-field'); |
| 115 | + act.hover(div); |
| 116 | + }, |
| 117 | + 'Select "Both"': function () { |
| 118 | + var div = $(':containsExcludeChildren(Both)').eq(0); |
| 119 | + act.click(div); |
| 120 | + }, |
| 121 | + 'Check result': function () { |
| 122 | + var value = $('.text-field').html(); |
| 123 | + eq(value, 'Both'); |
| 124 | + } |
| 125 | +}; |
| 126 | + |
| 127 | +'@test'['act.wait example'] = { |
| 128 | + 'Initiate animation and wait': function () { |
| 129 | + $('.article-header').animate({ |
| 130 | + opacity: 0 |
| 131 | + }, 1e3); |
| 132 | + act.wait(1e4, isTransparent); |
| 133 | + }, |
| 134 | + 'Type': function () { |
| 135 | + var input = $('#Developer_Name'); |
| 136 | + act.type(input, 'The wait is over!'); |
| 137 | + } |
| 138 | +}; |
| 139 | + |
| 140 | +'@test'['handleConfirm() example'] = { |
| 141 | + '1.Click "Populate"': function () { |
| 142 | + var populateFormButton = $(':containsExcludeChildren(Populate)'); |
| 143 | + handleConfirm('OK'); |
| 144 | + act.click(populateFormButton); |
| 145 | + }, |
| 146 | + '2.Click "Submit"': function () { |
| 147 | + this.autoGeneratedName = $('#Developer_Name').val(); |
| 148 | + var submitButton = $('.button.blue.fix-width-180'); |
| 149 | + act.click(submitButton); |
| 150 | + }, |
| 151 | + 'Check result': function () { |
| 152 | + var header = $('.article-header'); |
| 153 | + var expectedResult = 'Thank You, ' + this.autoGeneratedName + '!'; |
| 154 | + eq(header.html(), expectedResult); |
| 155 | + } |
| 156 | +}; |
| 157 | + |
| 158 | +'@test'['video example'] = { |
| 159 | + '1.Click "MacOS"': function () { |
| 160 | + var label = $(':containsExcludeChildren(MacOS)'); |
| 161 | + act.click(label); |
| 162 | + }, |
| 163 | + '2.Type a name': function () { |
| 164 | + var input = $('#Developer_Name'); |
| 165 | + act.type(input, 'Peter Parker', { |
| 166 | + offsetX: 59, |
| 167 | + offsetY: 22, |
| 168 | + caretPos: 0 |
| 169 | + }); |
| 170 | + }, |
| 171 | + '3.Hover over "Visual recorder"': function () { |
| 172 | + var div = $('.text-field'); |
| 173 | + act.hover(div); |
| 174 | + }, |
| 175 | + '4.Click "Both"': function () { |
| 176 | + var div = $(':containsExcludeChildren(Both)').eq(0); |
| 177 | + act.click(div, { |
| 178 | + offsetX: 71, |
| 179 | + offsetY: 12 |
| 180 | + }); |
| 181 | + }, |
| 182 | + '5.Click "Submit"': function () { |
| 183 | + var submitButton = $('#submit-button'); |
| 184 | + act.click(submitButton, { |
| 185 | + offsetX: 126, |
| 186 | + offsetY: 38 |
| 187 | + }); |
| 188 | + }, |
| 189 | + '6. Check Result': function () { |
| 190 | + var header = $('.article-header'); |
| 191 | + eq(header.html(), 'Thank You, Peter Parker!'); |
| 192 | + } |
| 193 | + |
| 194 | +}; |
| 195 | + |
| 196 | +//helpers |
| 197 | +var isTransparent = function () { |
| 198 | + return $('.article-header').css('opacity') == 0; |
| 199 | +}; |
| 200 | + |
| 201 | +var getInput = function () { |
| 202 | + return $('#Developer_Name'); |
| 203 | +}; |
0 commit comments