Best JavaScript code snippet using cypress
tests-run.js
Source:tests-run.js
1/* eslint-disable cypress/no-unnecessary-waiting */2const u = require('../../util/util.js');3describe('Tests', function () {4 beforeEach(() => {5 cy.checkPing();6 });7 it('posts a test, runs it, then checks /lastRunResult', function () {8 cy.postTests('/test/dev/cypress-backend-app', 'cypress-backend-app.zip', 'v1.2.3');9 cy.httpGet(`/test/dev/cypress-backend-app?noVideo=1&group=${u.rndGroup()}`, 200, '"failures":0');10 cy.visit('/test/dev/cypress-backend-app/lastReport');11 cy.get('body').contains('Account page').should('exist');12 cy.httpGet('/test/dev/cypress-backend-app/lastRunResult', 200, 'loads account page');13 });14 it('posts a test, runs it without waiting option, then tries to run again but cannot', function () {15 cy.postTests('/test/pat/cypress-backend-app', 'cypress-backend-app.zip', 'v3.5.18');16 cy.httpGet(17 `/test/pat/cypress-backend-app?noVideo=1&noWait=1&group=${u.rndGroup()}`,18 200,19 'Tests kicked off but not waiting for the result.',20 );21 cy.wait(1500);22 cy.httpGet(`/test/pat/cypress-backend-app?noVideo=1&group=${u.rndGroup()}`, 423, 'Tests are still running.');23 });24 it('posts a test, runs it without waiting option, then keeps trying to run again until it can', function () {25 cy.postTests('/test/yellow/cypress-backend-app', 'cypress-backend-app.zip', 'v3.5.18');26 const group = u.rndGroup();27 cy.httpGet(`/test/yellow/cypress-backend-app?noVideo=1&noWait=1&group=${group}`, 200, 'Tests kicked off');28 cy.wait(100);29 const newGroup = group + '_newGroup';30 cy.httpGet(`/test/yellow/cypress-backend-app?noVideo=1&group=${newGroup}`, 423, 'Tests are still running.');31 cy.httpGetRetry(`/test/yellow/cypress-backend-app?noVideo=1&group=${newGroup}`, 200, '"failures":0');32 });33 it('posts a test, runs only the canary suite', function () {34 cy.postTests('/test/uat/cypress-backend-app', 'cypress-backend-app.zip', 'v3.5.432');35 cy.httpGet(36 `/test/uat/cypress-backend-app?noVideo=1&suite=canary&group=${u.rndGroup()}`,37 200,38 'checks the canary page',39 'loads account page',40 );41 });42 it('runs two different suites for the same app in parallel', function () {43 const group = u.rndGroup();44 cy.postTests('/test/purple/cypress-backend-app', 'cypress-backend-app.zip', 'v3.5.221');45 cy.httpGet(`/test/purple/cypress-backend-app?suite=canary&group=${group}&noWait=1&noVideo=1`, 200, 'kicked off');46 cy.httpGet(`/test/purple/cypress-backend-app?suite=core-api&group=${group}&noVideo=1`, 200, '"failures":0');47 cy.httpGetRetry('/test/purple/cypress-backend-app/lastRunResult?suite=canary', 200, 'checks the canary page');48 });49 it('client is able to see that tests are running for an env and app', function () {50 const group = u.rndGroup();51 cy.httpGet('/test/perf/cypress-backend-app/status', 200, 'Tests are not running for this env and app');52 cy.postTests('/test/perf/cypress-backend-app', 'cypress-backend-app.zip', 'v1.1.111');53 cy.httpGet('/test/perf/cypress-backend-app/message', 200, 'unzipped ok');54 cy.httpGet(`/test/perf/cypress-backend-app?suite=canary&group=${group}&noWait=1&noVideo=1`, 200, 'kicked off');55 cy.httpGet('/test/perf/cypress-backend-app/status', 200, 'Tests are running for this env and app');56 // Allow canary test to run for a bit but make sure it is still running57 cy.wait(1000);58 cy.httpGet('/test/perf/cypress-backend-app/status', 200, 'Tests are running for this env and app');59 // Start off core-api and produce video to make it a little slower60 cy.httpGet(`/test/perf/cypress-backend-app?suite=core-api&group=${group}&noWait=1`, 200, 'kicked off');61 cy.httpGet('/test/perf/cypress-backend-app/status', 200, 'Tests are running for this env and app');62 // Wait for the canary test to complete63 cy.httpGetRetry('/test/perf/cypress-backend-app/summary', 200, 'class=..pass.. info=..canary', 100, 200);64 // Make sure core-api is still running and /status still returns running65 cy.httpGet('/test/perf/cypress-backend-app/status', 200, 'Tests are running for this env and app');66 cy.httpGet('/test/perf/cypress-backend-app/summary', 200, 'class=..pend.. info=..core-api');67 // Now core-api should finish68 cy.httpGetRetry('/test/perf/cypress-backend-app/summary', 200, 'All tests passed', 20, 1000);69 // /status shows tests are not running70 cy.httpGet('/test/perf/cypress-backend-app/status', 200, 'Tests are not running for this env and app');71 });72 it('tries to run the same suite twice (in parallel) but only first is allowed to run', function () {73 const group = u.rndGroup();74 cy.postTests('/test/red/cypress-backend-app', 'cypress-backend-app.zip', 'v4.783.21');75 cy.httpGet(`/test/red/cypress-backend-app?suite=canary&group=${group}&noWait=1&noVideo=1`, 200, 'kicked off');76 cy.httpGet(`/test/red/cypress-backend-app?suite=canary&group=${group}&noVideo=1`, 423, 'Tests are still running');77 cy.httpGetRetry('/test/red/cypress-backend-app/lastRunResult?suite=canary', 200, 'checks the canary page');78 });79 it('tries to run a suite followed by allSuites (in parallel) but only first is allowed to run', function () {80 const group = u.rndGroup();81 cy.postTests('/test/team1/cypress-backend-app', 'cypress-backend-app.zip', 'v3.183.23');82 cy.httpGet(`/test/team1/cypress-backend-app?suite=canary&group=${group}&noWait=1&noVideo=1`, 200, 'kicked off');83 cy.httpGet(`/test/team1/cypress-backend-app?group=${group}&noVideo=1`, 423, 'Tests are still running');84 cy.httpGetRetry('/test/team1/cypress-backend-app/lastRunResult?suite=canary', 200, 'checks the canary page');85 });86 it('tries to run allSuites followed by a suite (in parallel) but only first is allowed to run', function () {87 const group = u.rndGroup();88 cy.postTests('/test/yellow/cypress-backend-app', 'cypress-backend-app.zip', 'v1.113.23');89 cy.httpGet(`/test/yellow/cypress-backend-app?group=${group}&noWait=1&noVideo=1`, 200, 'kicked off');90 cy.httpGet(`/test/yellow/cypress-backend-app?suite=canary&group=${group}&noVideo=1`, 423, 'Tests are still running');91 cy.httpGetRetry('/test/yellow/cypress-backend-app/lastRunResult', 200, 'completes the search workflow');92 });93 it('posts a test, attempts to run a suite that does not exist', function () {94 cy.postTests('/test/uat/cypress-backend-app', 'cypress-backend-app.zip', 'v3.5.432');95 cy.httpGet(96 `/test/uat/cypress-backend-app?noVideo=1&suite=tomato&group=${u.rndGroup()}`,97 404,98 'Suite does not exist, cannot find',99 );100 });101 it('deploys while while running tests for the same app, original tests finish ok', function () {102 // Prove that deploying new tests for an app do not cause a problem with the tests currently running103 // 1. Do the first deployment, the start running the tests104 cy.postTests('/test/red/cypress-backend-app', 'cypress-backend-app.zip', 'v5.1.0');105 cy.httpGet(`/test/red/cypress-backend-app?noVideo=1&noWait=1&group=${u.rndGroup()}`, 200, 'Tests kicked off');106 // 2. Wait at least one second before doing the next deployment so it gets a unique results folder107 cy.wait(1500);108 // 3. Confirm the tests are still running from the first deployment, then do the second deployment109 // Note that for this test we deploy entirely different tests so we can tell the two deployments apart110 cy.httpGet(`/test/red/cypress-backend-app?noVideo=1&group=${u.rndGroup()}`, 423, 'Tests are still running.');111 cy.postTests('/test/red/cypress-backend-app', 'cypress-frontend-app.zip', 'v15.2.0');112 // 4. Now we wait until the original tests have finished - prove the are not affected by113 // the entirely different tests that we just deployed.114 cy.httpGetRetry('/test/red/cypress-backend-app/lastRunResult', 200, 'completes the search workflow');115 });116 it('deploys while running tests for the same app, new tests finish ok', function () {117 // Prove that deploying new tests then running them for an app while it already has running tests118 // works ok119 // 1. Do the first deployment, the start running the tests120 const group = u.rndGroup();121 cy.postTests('/test/pink/cypress-backend-app', 'cypress-backend-app.zip', 'v5.1.0');122 cy.httpGet(`/test/pink/cypress-backend-app?noVideo=1&noWait=1&group=${group}`, 200, 'Tests kicked off');123 // 2. Wait at least one second before doing the next deployment so it gets a unique results folder124 cy.wait(1100);125 // 3. Confirm the tests are still running from the first deployment, then do the second deployment126 // Note that for this test we deploy entirely different tests so we can tell the two deployments apart127 cy.httpGet(`/test/pink/cypress-backend-app?noVideo=1&group=${group}`, 423, 'Tests are still running.');128 cy.postTests('/test/pink/cypress-backend-app', 'cypress-frontend-app.zip', 'v15.2.0');129 // 4. Now we kick off the new tests and wait for them to complete ok130 const newGroup = group + '_newGroup';131 cy.httpGet(`/test/pink/cypress-backend-app?noVideo=1&group=${newGroup}`, 200, '"failures":0');132 });133 it('can run the tests for two different apps at the same time', function () {134 // 1. Do the first deployment, then kick off the tests without waiting for the result135 cy.postTests('/test/team1/cypress-backend-app', 'cypress-backend-app.zip', 'v3.8.7');136 cy.httpGet(`/test/team1/cypress-backend-app?noVideo=1&noWait=1&group=${u.rndGroup()}`, 200, 'Tests kicked off');137 // 2. Deploy the second app, then run its tests waiting for the tests to complete138 cy.postTests('/test/team1/cypress-frontend-app', 'cypress-frontend-app.zip', 'v12.16.8');139 cy.httpGet(`/test/team1/cypress-frontend-app?noVideo=1&group=${u.rndGroup()}`, 200, '"failures":0');140 // 3. Finally confirm that the tests for the first app also completed ok141 cy.httpGetRetry('/test/team1/cypress-backend-app/lastRunResult', 200, '"failures":0');142 });143 it('will not let you to run the same batch and suite twice (in a day)', function () {144 cy.postTests('/test/dev/cypress-backend-app', 'cypress-backend-app.zip', 'v0.3.9');145 const group = u.rndGroup();146 cy.httpGet(`/test/dev/cypress-backend-app?suite=canary&group=${group}&noVideo=1`, 200, '"failures":0');147 cy.httpGet(148 `/test/dev/cypress-backend-app?suite=canary&group=${group}&noVideo=1`,149 400,150 'You cannot run the same tests twice for a given batch in the same day. Please suppply a different group.',151 );152 });153 it('will not let you to run the same batch and suite twice (in a day)', function () {154 cy.postTests('/test/yellow/cypress-backend-app', 'cypress-backend-app.zip', 'v0.3.9');155 const group = u.rndGroup();156 cy.httpGet(`/test/yellow/cypress-backend-app?suite=canary&group=${group}&noVideo=1`, 200, '"failures":0');157 cy.httpGet(158 `/test/yellow/cypress-backend-app?group=${group}&noVideo=1`,159 400,160 'You cannot run all suites when you have already run a suite for that batch',161 );162 });163 it('gets the lastReport for two different suites', function () {164 const group = u.rndGroup();165 cy.postTests('/test/purple/cypress-backend-app', 'cypress-backend-app.zip', 'v8.5.221');166 cy.httpGet(`/test/purple/cypress-backend-app?suite=canary&group=${group}&noWait=1&noVideo=1`, 200, 'kicked off');167 cy.httpGet(`/test/purple/cypress-backend-app?suite=core-api&group=${group}&noVideo=1`, 200, '"failures":0');168 cy.httpGetRetry('/test/purple/cypress-backend-app/lastRunResult?suite=canary', 200, 'checks the canary page');169 cy.visit('/test/purple/cypress-backend-app/lastReport?suite=canary');170 cy.get('body').contains('checks the canary page').should('exist');171 cy.visit('/test/purple/cypress-backend-app/lastReport?suite=core-api');172 cy.get('body').contains('starts the search workflow').should('exist');173 });174 it('produces a summary.html report showing suites run and not run', function () {175 const group = `MyGroup${u.rndGroup()}`;176 cy.postTests('/test/blue/cypress-backend-app', 'cypress-backend-app.zip', 'v18.18.12');177 cy.httpGet(`/test/blue/cypress-backend-app?suite=core-api&group=${group}&noVideo=1`, 200, '"failures":0');178 const dt = '[0-9]{2,4}[.][0-9]{2}[.][0-9]{2}';179 const linkToMochawesome = `/results/blue/cypress-backend-app/${dt}/${group}/suite-core-api/mochawesome.html`;180 cy.httpGet(`/test/blue/cypress-backend-app/summary`, 200, `blue cypress-backend-app`); // title181 cy.httpGet(`/test/blue/cypress-backend-app/summary`, 200, `blue - cypress-backend-app v18.18.12`);182 cy.httpGet(`/test/blue/cypress-backend-app/summary`, 200, `Summary for run group MyGroup`);183 cy.httpGet(`/test/blue/cypress-backend-app/summary`, 200, `core-api`);184 cy.httpGet(`/test/blue/cypress-backend-app/summary`, 200, linkToMochawesome);185 cy.httpGet(`/test/blue/cypress-backend-app/summary`, 200, `6 tests`);186 cy.httpGet(`/test/blue/cypress-backend-app/summary`, 200, `class=."pass."`);187 cy.httpGet(`/test/blue/cypress-backend-app/summary`, 200, `20[0-9]{2}-[0-9]{2}-[0-9]{2}`);188 cy.httpGet(`/test/blue/cypress-backend-app/summary`, 200, `seconds`);189 cy.httpGet(`/test/blue/cypress-backend-app/summary`, 200, `ready`);190 cy.httpGet(`/test/blue/cypress-backend-app?suite=canary&group=${group}&noVideo=1`, 200, '"failures":0');191 cy.httpGet(`/test/blue/cypress-backend-app/summary`, 200, `core-api`);192 cy.httpGet(`/test/blue/cypress-backend-app/summary`, 200, `canary`);193 });194 it('produces a summary.html report showing a failed test', function () {195 const group = `MyGroup${u.rndGroup()}`;196 cy.postTests('/test/dev/cypress-big-app', 'cypress-big-app.zip', 'v1.1.1');197 cy.httpGet(`/test/dev/cypress-big-app?suite=suite06-fail&group=${group}&noVideo=1`, 200, '"failures":1');198 cy.httpGet(`/test/dev/cypress-big-app/summary`, 200, `suite06-fail`);199 cy.httpGet(`/test/dev/cypress-big-app/summary`, 200, `1 tests`);200 cy.httpGet(`/test/dev/cypress-big-app/summary`, 200, `class=."fail."`); // quotes escaped in cypress html...201 });202 it('produces a summary.html report handling a crash - missing JavaScript file so run does not start', function () {203 const group = `MyGroup${u.rndGroup()}`;204 cy.postTests('/test/dev/cypress-big-app', 'cypress-big-app.zip', 'v1.1.1');205 cy.httpGet(`/test/dev/cypress-big-app?suite=suite09-error&group=${group}&noVideo=1`, 200, '"failures":1');206 cy.httpGet(`/test/dev/cypress-big-app/summary`, 200, `suite09-error`);207 cy.httpGet(`/test/dev/cypress-big-app/summary`, 200, `0 tests`);208 cy.httpGet(`/test/dev/cypress-big-app/summary`, 200, `class=."crash."`); // quotes escaped in cypress html...209 });210 it('produces a summary.html report handling a runtime error in a cy closure', function () {211 const group = `MyGroup${u.rndGroup()}`;212 cy.postTests('/test/dev/cypress-big-app', 'cypress-big-app.zip', 'v2.2.2');213 cy.httpGet(`/test/dev/cypress-big-app?suite=suite10-error&group=${group}&noVideo=1`, 200, '"failures":1');214 cy.httpGet(`/test/dev/cypress-big-app/summary`, 200, `suite10-error`);215 cy.httpGet(`/test/dev/cypress-big-app/summary`, 200, `1 tests`);216 cy.httpGet(`/test/dev/cypress-big-app/summary`, 200, `class=."fail."`); // quotes escaped in cypress html...217 });218 it('produces a summary.html report for a big bunch of suites', function () {219 const group = `MyGroup${u.rndGroup()}`;220 cy.postTests('/test/pat/cypress-big-app', 'cypress-big-app.zip', 'v3.3.3');221 const prefix = '/test/pat/cypress-big-app?suite=suite';222 cy.httpGet(`${prefix}01&group=${group}&noVideo=1&noWait=1`, 200, 'Tests kicked off');223 cy.httpGet(`${prefix}02&group=${group}&noVideo=1&noWait=1`, 200, 'Tests kicked off');224 cy.httpGet(`${prefix}03&group=${group}&noVideo=1&noWait=1`, 200, 'Tests kicked off');225 cy.httpGet(`${prefix}04&group=${group}&noVideo=1&noWait=1`, 200, 'Tests kicked off');226 cy.httpGet(`${prefix}05&group=${group}&noVideo=1&noWait=1`, 200, 'Tests kicked off');227 cy.httpGet(`${prefix}06-fail&group=${group}&noVideo=1&noWait=1`, 200, 'Tests kicked off');228 cy.httpGet(`${prefix}07-fail&group=${group}&noVideo=1&noWait=1`, 200, 'Tests kicked off');229 cy.httpGet(`${prefix}08&group=${group}&noVideo=1&noWait=1`, 200, 'Tests kicked off');230 cy.httpGet(`${prefix}09-error&group=${group}&noVideo=1&noWait=1`, 200, 'Tests kicked off');231 cy.httpGet(`${prefix}10-error&group=${group}&noVideo=1&noWait=1`, 200, 'Tests kicked off');232 cy.httpGet(`${prefix}11-wait5&group=${group}&noVideo=1&noWait=1`, 200, 'Tests kicked off');233 cy.httpGet(`${prefix}12-wait5&group=${group}&noVideo=1&noWait=1`, 200, 'Tests kicked off');234 cy.httpGet(`${prefix}13-wait5&group=${group}&noVideo=1&noWait=1`, 200, 'Tests kicked off');235 cy.httpGet(`${prefix}14-wait5&group=${group}&noVideo=1&noWait=1`, 200, 'Tests kicked off');236 cy.httpGet(`${prefix}15-wait5&group=${group}&noVideo=1&noWait=1`, 200, 'Tests kicked off');237 cy.httpGet(`${prefix}16-wait2&group=${group}&noVideo=1&noWait=1`, 200, 'Tests kicked off');238 cy.httpGet(`${prefix}17-wait2&group=${group}&noVideo=1&noWait=1`, 200, 'Tests kicked off');239 cy.httpGet(`${prefix}18-wait2&group=${group}&noVideo=1&noWait=1`, 200, 'Tests kicked off');240 cy.httpGet(`${prefix}19&group=${group}&noVideo=1&noWait=1`, 200, 'Tests kicked off');241 cy.httpGet(`${prefix}20&group=${group}&noVideo=1&noWait=1`, 200, 'Tests kicked off');242 cy.httpGetRetry(`/test/pat/cypress-big-app/summary`, 200, `class=."pass." info=."suite01`);243 cy.httpGetRetry(`/test/pat/cypress-big-app/summary`, 200, `class=."pass." info=."suite02`);244 cy.httpGetRetry(`/test/pat/cypress-big-app/summary`, 200, `class=."pass." info=."suite03`);245 cy.httpGetRetry(`/test/pat/cypress-big-app/summary`, 200, `class=."pass." info=."suite04`);246 cy.httpGetRetry(`/test/pat/cypress-big-app/summary`, 200, `class=."pass." info=."suite05`);247 cy.httpGetRetry(`/test/pat/cypress-big-app/summary`, 200, `class=."fail." info=."suite06`);248 cy.httpGetRetry(`/test/pat/cypress-big-app/summary`, 200, `class=."fail." info=."suite07`);249 cy.httpGetRetry(`/test/pat/cypress-big-app/summary`, 200, `class=."pass." info=."suite08`);250 cy.httpGetRetry(`/test/pat/cypress-big-app/summary`, 200, `class=."crash." info=."suite09`);251 cy.httpGetRetry(`/test/pat/cypress-big-app/summary`, 200, `class=."fail." info=."suite10`);252 cy.httpGetRetry(`/test/pat/cypress-big-app/summary`, 200, `class=."pass." info=."suite11`);253 cy.httpGetRetry(`/test/pat/cypress-big-app/summary`, 200, `class=."pass." info=."suite12`);254 cy.httpGetRetry(`/test/pat/cypress-big-app/summary`, 200, `class=."pass." info=."suite13`);255 cy.httpGetRetry(`/test/pat/cypress-big-app/summary`, 200, `class=."pass." info=."suite14`);256 cy.httpGetRetry(`/test/pat/cypress-big-app/summary`, 200, `class=."pass." info=."suite15`);257 cy.httpGetRetry(`/test/pat/cypress-big-app/summary`, 200, `class=."pass." info=."suite16`);258 cy.httpGetRetry(`/test/pat/cypress-big-app/summary`, 200, `class=."pass." info=."suite17`);259 cy.httpGetRetry(`/test/pat/cypress-big-app/summary`, 200, `class=."pass." info=."suite18`);260 cy.httpGetRetry(`/test/pat/cypress-big-app/summary`, 200, `class=."pass." info=."suite19`);261 cy.httpGetRetry(`/test/pat/cypress-big-app/summary`, 200, `class=."pass." info=."suite20`);262 cy.httpGet(`/test/pat/cypress-big-app/summary`, 200, `There was a crash preventing a test start.`);263 });264 it('produces a summary.html report showing a suite as pend(ing) then changing to pass', function () {265 const group = `MyGroup${u.rndGroup()}`;266 cy.postTests('/test/live/cypress-big-app', 'cypress-big-app.zip', 'v3.3.3');267 cy.httpGet(`/test/live/cypress-big-app?suite=suite11-wait5&group=${group}&noVideo=1&noWait=1`, 200, 'Tests kicked off');268 cy.httpGet(`/test/live/cypress-big-app/summary`, 200, `class=."pend." info=."suite11`);269 cy.httpGet(`/test/live/cypress-big-app/summary`, 200, `Some tests have not started.`);270 cy.httpGetRetry(`/test/live/cypress-big-app/summary`, 200, `class=."pass." info=."suite11`);271 cy.httpGet(`/test/live/cypress-big-app/summary`, 200, `Some tests have not started.`);272 });273 it('overall summary status changes from ready thru pending to all tests passed', function () {274 const group = `MyGroup${u.rndGroup()}`;275 cy.postTests('/test/team2/cypress-frontend-app', 'cypress-frontend-app.zip', 'v5.5.5');276 cy.httpGet(`/test/team2/cypress-frontend-app?suite=core-frontend&group=${group}&noVideo=1&noWait=1`, 200, 'Tests kicked off');277 cy.httpGet(`/test/team2/cypress-frontend-app/summary`, 200, `Some tests have not started.`);278 cy.httpGet(`/test/team2/cypress-frontend-app?suite=canary&group=${group}&noVideo=1&noWait=1`, 200, 'Tests kicked off');279 cy.httpGet(`/test/team2/cypress-frontend-app/summary`, 200, `Test completion is still pending.`);280 cy.httpGetRetry(`/test/team2/cypress-frontend-app/summary`, 200, `All tests passed.`);281 });282 it('produces a summary.html report for allSuites - cypress-frontend-app', function () {283 const group = `MyGroup${u.rndGroup()}`;284 cy.postTests('/test/live/cypress-frontend-app', 'cypress-frontend-app.zip', 'v4.4.4');285 cy.httpGet(`/test/live/cypress-frontend-app?group=${group}&noVideo=1&noWait=1`, 200, 'Tests kicked off');286 cy.httpGet(`/test/live/cypress-frontend-app/summary`, 200, `Test completion is still pending.`);287 cy.httpGet(`/test/live/cypress-frontend-app/summary`, 200, `class=."pend." info=."allSuites`);288 cy.httpGetRetry(`/test/live/cypress-frontend-app/summary`, 200, `class=."pass." info=."allSuites`);289 cy.httpGet(`/test/live/cypress-frontend-app/summary`, 200, `All tests passed.`);290 });291 it('produces a summary.html report for allSuites - cypress-big-app', function () {292 const group = `MyGroup${u.rndGroup()}`;293 cy.postTests('/test/team1/cypress-big-app', 'cypress-big-app.zip', 'v5.5.5');294 cy.httpGet(`/test/team1/cypress-big-app?group=${group}&noVideo=1&noWait=1`, 200, 'Tests kicked off');295 cy.httpGetRetry(`/test/team1/cypress-big-app/summary`, 200, 'class=."fail." info=."allSuites', 15, 10000);296 cy.httpGet(`/test/team1/cypress-big-app/summary`, 200, `Some tests failed.`);297 });...
files_spec.js
Source:files_spec.js
1const { stripIndent } = require('common-tags')2const { _ } = Cypress3const okResponse = {4 contents: 'contents',5 filePath: '/path/to/foo.json',6}7describe('src/cy/commands/files', () => {8 beforeEach(() => {9 // call through normally on everything10 cy.stub(Cypress, 'backend').callThrough()11 })12 describe('#readFile', () => {13 it('triggers \'read:file\' with the right options', () => {14 Cypress.backend.resolves(okResponse)15 cy.readFile('foo.json').then(() => {16 expect(Cypress.backend).to.be.calledWith(17 'read:file',18 'foo.json',19 { encoding: 'utf8' },20 )21 })22 })23 it('can take encoding as second argument', () => {24 Cypress.backend.resolves(okResponse)25 cy.readFile('foo.json', 'ascii').then(() => {26 expect(Cypress.backend).to.be.calledWith(27 'read:file',28 'foo.json',29 { encoding: 'ascii' },30 )31 })32 })33 it('sets the contents as the subject', () => {34 Cypress.backend.resolves(okResponse)35 cy.readFile('foo.json').then((subject) => {36 expect(subject).to.equal('contents')37 })38 })39 it('retries to read when ENOENT', () => {40 const err = new Error('foo')41 err.code = 'ENOENT'42 let retries = 043 cy.on('command:retry', () => {44 retries += 145 })46 Cypress.backend47 .onFirstCall()48 .rejects(err)49 .onSecondCall()50 .resolves(okResponse)51 cy.readFile('foo.json').then(() => {52 expect(retries).to.eq(1)53 })54 })55 it('retries assertions until they pass', () => {56 let retries = 057 cy.on('command:retry', () => {58 retries += 159 })60 Cypress.backend61 .onFirstCall()62 .resolves({63 contents: 'foobarbaz',64 })65 .onSecondCall()66 .resolves({67 contents: 'quux',68 })69 cy.readFile('foo.json').should('eq', 'quux').then(() => {70 expect(retries).to.eq(1)71 })72 })73 it('really works', () => {74 cy.readFile('cypress.json').its('baseUrl').should('eq', 'http://localhost:3500')75 })76 it('works when contents are supposed to be null', () => {77 cy.readFile('does-not-exist').should('be.null')78 })79 describe('.log', () => {80 beforeEach(function () {81 this.logs = []82 cy.on('log:added', (attrs, log) => {83 this.lastLog = log84 this.logs.push(log)85 })86 return null87 })88 it('can turn off logging', () => {89 Cypress.backend.resolves(okResponse)90 cy.readFile('foo.json', { log: false }).then(function () {91 const logs = _.filter(this.logs, (log) => {92 return log.get('name') === 'readFile'93 })94 expect(logs.length).to.eq(0)95 })96 })97 it('logs immediately before resolving', function () {98 Cypress.backend.resolves(okResponse)99 cy.on('log:added', (attrs, log) => {100 if (attrs.name === 'readFile') {101 expect(log.get('state')).to.eq('pending')102 expect(log.get('message')).to.eq('foo.json')103 }104 })105 cy.readFile('foo.json').then(() => {106 if (!this.lastLog) {107 throw new Error('failed to log before resolving')108 }109 })110 })111 })112 describe('errors', {113 defaultCommandTimeout: 50,114 }, () => {115 beforeEach(function () {116 this.logs = []117 cy.on('log:added', (attrs, log) => {118 if (attrs.name === 'readFile') {119 this.lastLog = log120 this.logs.push(log)121 }122 })123 return null124 })125 it('throws when file argument is absent', function (done) {126 cy.on('fail', (err) => {127 const { lastLog } = this128 expect(this.logs.length).to.eq(1)129 expect(lastLog.get('error')).to.eq(err)130 expect(lastLog.get('state')).to.eq('failed')131 expect(err.message).to.eq('`cy.readFile()` must be passed a non-empty string as its 1st argument. You passed: `undefined`.')132 expect(err.docsUrl).to.eq('https://on.cypress.io/readfile')133 done()134 })135 cy.readFile()136 })137 it('throws when file argument is not a string', function (done) {138 cy.on('fail', (err) => {139 const { lastLog } = this140 expect(this.logs.length).to.eq(1)141 expect(lastLog.get('error')).to.eq(err)142 expect(lastLog.get('state')).to.eq('failed')143 expect(err.message).to.eq('`cy.readFile()` must be passed a non-empty string as its 1st argument. You passed: `2`.')144 expect(err.docsUrl).to.eq('https://on.cypress.io/readfile')145 done()146 })147 cy.readFile(2)148 })149 it('throws when file argument is an empty string', function (done) {150 cy.on('fail', (err) => {151 const { lastLog } = this152 expect(this.logs.length).to.eq(1)153 expect(lastLog.get('error')).to.eq(err)154 expect(lastLog.get('state')).to.eq('failed')155 expect(err.message).to.eq('`cy.readFile()` must be passed a non-empty string as its 1st argument. You passed: ``.')156 expect(err.docsUrl).to.eq('https://on.cypress.io/readfile')157 done()158 })159 cy.readFile('')160 })161 it('throws when there is an error reading the file', function (done) {162 const err = new Error('EISDIR: illegal operation on a directory, read')163 err.name = 'EISDIR'164 err.code = 'EISDIR'165 err.filePath = '/path/to/foo'166 Cypress.backend.rejects(err)167 cy.on('fail', (err) => {168 const { lastLog } = this169 expect(this.logs.length).to.eq(1)170 expect(lastLog.get('error')).to.eq(err)171 expect(lastLog.get('state')).to.eq('failed')172 expect(err.message).to.eq(stripIndent`\173 \`cy.readFile(\"foo\")\` failed while trying to read the file at the following path:174 \`/path/to/foo\`175 The following error occurred:176 > "EISDIR: illegal operation on a directory, read"`)177 expect(err.docsUrl).to.eq('https://on.cypress.io/readfile')178 done()179 })180 cy.readFile('foo')181 })182 it('has implicit existence assertion and throws a specific error when file does not exist', function (done) {183 const err = new Error('ENOENT: no such file or directory, open \'foo.json\'')184 err.name = 'ENOENT'185 err.code = 'ENOENT'186 err.filePath = '/path/to/foo.json'187 Cypress.backend.rejects(err)188 cy.on('fail', (err) => {189 const { lastLog } = this190 expect(this.logs.length).to.eq(1)191 expect(lastLog.get('error')).to.eq(err)192 expect(lastLog.get('state')).to.eq('failed')193 expect(err.message).to.eq(stripIndent`194 Timed out retrying after 50ms: \`cy.readFile(\"foo.json\")\` failed because the file does not exist at the following path:195 \`/path/to/foo.json\``)196 expect(err.docsUrl).to.eq('https://on.cypress.io/readfile')197 done()198 })199 cy.readFile('foo.json')200 })201 it('throws a specific error when file exists when it shouldn\'t', function (done) {202 Cypress.backend.resolves(okResponse)203 cy.on('fail', (err) => {204 const { lastLog } = this205 expect(this.logs.length).to.eq(1)206 expect(lastLog.get('error')).to.eq(err)207 expect(lastLog.get('state')).to.eq('failed')208 expect(err.message).to.eq(stripIndent`\209 Timed out retrying after 50ms: \`cy.readFile(\"foo.json\")\` failed because the file exists when expected not to exist at the following path:210 \`/path/to/foo.json\``)211 expect(err.docsUrl).to.eq('https://on.cypress.io/readfile')212 done()213 })214 cy.readFile('foo.json').should('not.exist')215 })216 it('passes through assertion error when not about existence', function (done) {217 Cypress.backend.resolves({218 contents: 'foo',219 })220 cy.on('fail', (err) => {221 const { lastLog } = this222 expect(this.logs.length).to.eq(1)223 expect(lastLog.get('error')).to.eq(err)224 expect(lastLog.get('state')).to.eq('failed')225 expect(err.message).to.eq('Timed out retrying after 50ms: expected \'foo\' to equal \'contents\'')226 done()227 })228 cy.readFile('foo.json').should('equal', 'contents')229 })230 })231 })232 describe('#writeFile', () => {233 it('triggers \'write:file\' with the right options', () => {234 Cypress.backend.resolves(okResponse)235 cy.writeFile('foo.txt', 'contents').then(() => {236 expect(Cypress.backend).to.be.calledWith(237 'write:file',238 'foo.txt',239 'contents',240 {241 encoding: 'utf8',242 flag: 'w',243 },244 )245 })246 })247 it('can take encoding as third argument', () => {248 Cypress.backend.resolves(okResponse)249 cy.writeFile('foo.txt', 'contents', 'ascii').then(() => {250 expect(Cypress.backend).to.be.calledWith(251 'write:file',252 'foo.txt',253 'contents',254 {255 encoding: 'ascii',256 flag: 'w',257 },258 )259 })260 })261 it('can take encoding as part of options', () => {262 Cypress.backend.resolves(okResponse)263 cy.writeFile('foo.txt', 'contents', { encoding: 'ascii' }).then(() => {264 expect(Cypress.backend).to.be.calledWith(265 'write:file',266 'foo.txt',267 'contents',268 {269 encoding: 'ascii',270 flag: 'w',271 },272 )273 })274 })275 it('yields null', () => {276 Cypress.backend.resolves(okResponse)277 cy.writeFile('foo.txt', 'contents').then((subject) => {278 expect(subject).to.not.exist279 })280 })281 it('can write a string', () => {282 Cypress.backend.resolves(okResponse)283 cy.writeFile('foo.txt', 'contents')284 })285 it('can write an array as json', () => {286 Cypress.backend.resolves(okResponse)287 cy.writeFile('foo.json', [])288 })289 it('can write an object as json', () => {290 Cypress.backend.resolves(okResponse)291 cy.writeFile('foo.json', {})292 })293 it('writes the file to the filesystem, overwriting existing file', () => {294 cy295 .writeFile('cypress/fixtures/foo.txt', '')296 .writeFile('cypress/fixtures/foo.txt', 'bar')297 .readFile('cypress/fixtures/foo.txt').should('equal', 'bar')298 .exec('rm cypress/fixtures/foo.txt')299 })300 describe('.flag', () => {301 it('sends a flag if specified', () => {302 Cypress.backend.resolves(okResponse)303 cy.writeFile('foo.txt', 'contents', { flag: 'a+' }).then(() => {304 expect(Cypress.backend).to.be.calledWith(305 'write:file',306 'foo.txt',307 'contents',308 {309 encoding: 'utf8',310 flag: 'a+',311 },312 )313 })314 })315 it('appends content to existing file if specified', () => {316 cy317 .writeFile('cypress/fixtures/foo.txt', 'foo')318 .writeFile('cypress/fixtures/foo.txt', 'bar', { flag: 'a+' })319 .readFile('cypress/fixtures/foo.txt').should('equal', 'foobar')320 .exec('rm cypress/fixtures/foo.txt')321 })322 })323 describe('.log', () => {324 beforeEach(function () {325 this.logs = []326 cy.on('log:added', (attrs, log) => {327 this.lastLog = log328 this.logs.push(log)329 })330 return null331 })332 it('can turn off logging', () => {333 Cypress.backend.resolves(okResponse)334 cy.writeFile('foo.txt', 'contents', { log: false }).then(function () {335 const logs = _.filter(this.logs, (log) => {336 return log.get('name') === 'writeFile'337 })338 expect(logs.length).to.eq(0)339 })340 })341 it('logs immediately before resolving', function () {342 Cypress.backend.resolves(okResponse)343 cy.on('log:added', (attrs, log) => {344 if (attrs.name === 'writeFile') {345 expect(log.get('state')).to.eq('pending')346 expect(log.get('message')).to.eq('foo.txt', 'contents')347 }348 })349 cy.writeFile('foo.txt', 'contents').then(() => {350 if (!this.lastLog) {351 throw new Error('failed to log before resolving')352 }353 })354 })355 })356 describe('errors', {357 defaultCommandTimeout: 50,358 }, () => {359 beforeEach(function () {360 this.logs = []361 cy.on('log:added', (attrs, log) => {362 if (attrs.name === 'writeFile') {363 this.lastLog = log364 this.logs.push(log)365 }366 })367 return null368 })369 it('throws when file name argument is absent', function (done) {370 cy.on('fail', (err) => {371 const { lastLog } = this372 expect(this.logs.length).to.eq(1)373 expect(lastLog.get('error')).to.eq(err)374 expect(lastLog.get('state')).to.eq('failed')375 expect(err.message).to.eq('`cy.writeFile()` must be passed a non-empty string as its 1st argument. You passed: `undefined`.')376 expect(err.docsUrl).to.eq('https://on.cypress.io/writefile')377 done()378 })379 cy.writeFile()380 })381 it('throws when file name argument is not a string', function (done) {382 cy.on('fail', (err) => {383 const { lastLog } = this384 expect(this.logs.length).to.eq(1)385 expect(lastLog.get('error')).to.eq(err)386 expect(lastLog.get('state')).to.eq('failed')387 expect(err.message).to.eq('`cy.writeFile()` must be passed a non-empty string as its 1st argument. You passed: `2`.')388 expect(err.docsUrl).to.eq('https://on.cypress.io/writefile')389 done()390 })391 cy.writeFile(2)392 })393 it('throws when contents argument is absent', function (done) {394 cy.on('fail', (err) => {395 const { lastLog } = this396 expect(this.logs.length).to.eq(1)397 expect(lastLog.get('error')).to.eq(err)398 expect(lastLog.get('state')).to.eq('failed')399 expect(err.message).to.eq('`cy.writeFile()` must be passed a non-empty string, an object, or an array as its 2nd argument. You passed: `undefined`.')400 done()401 })402 cy.writeFile('foo.txt')403 })404 it('throws when contents argument is not a string, object, or array', function (done) {405 cy.on('fail', (err) => {406 const { lastLog } = this407 expect(this.logs.length).to.eq(1)408 expect(lastLog.get('error')).to.eq(err)409 expect(lastLog.get('state')).to.eq('failed')410 expect(err.message).to.eq('`cy.writeFile()` must be passed a non-empty string, an object, or an array as its 2nd argument. You passed: `2`.')411 done()412 })413 cy.writeFile('foo.txt', 2)414 })415 it('throws when there is an error writing the file', function (done) {416 const err = new Error('WHOKNOWS: unable to write file')417 err.name = 'WHOKNOWS'418 err.code = 'WHOKNOWS'419 err.filePath = '/path/to/foo.txt'420 Cypress.backend.rejects(err)421 cy.on('fail', (err) => {422 const { lastLog } = this423 expect(this.logs.length).to.eq(1)424 expect(lastLog.get('error')).to.eq(err)425 expect(lastLog.get('state')).to.eq('failed')426 expect(err.message).to.eq(stripIndent`427 \`cy.writeFile(\"foo.txt\")\` failed while trying to write the file at the following path:428 \`/path/to/foo.txt\`429 The following error occurred:430 > "WHOKNOWS: unable to write file"`)431 expect(err.docsUrl).to.eq('https://on.cypress.io/writefile')432 done()433 })434 cy.writeFile('foo.txt', 'contents')435 })436 })437 })...
exec_spec.js
Source:exec_spec.js
1const { _, Promise } = Cypress2describe('src/cy/commands/exec', () => {3 const okResponse = { code: 0 }4 context('#exec', {5 execTimeout: 2500,6 }, () => {7 beforeEach(() => {8 // call through normally on everything9 cy.stub(Cypress, 'backend').callThrough()10 })11 it('triggers \'exec\' with the right options', () => {12 Cypress.backend.resolves(okResponse)13 cy.exec('ls').then(() => {14 expect(Cypress.backend).to.be.calledWith('exec', {15 cmd: 'ls',16 timeout: 2500,17 env: {},18 })19 })20 })21 it('passes through environment variables', () => {22 Cypress.backend.resolves(okResponse)23 cy.exec('ls', { env: { FOO: 'foo' } }).then(() => {24 expect(Cypress.backend).to.be.calledWith('exec', {25 cmd: 'ls',26 timeout: 2500,27 env: {28 FOO: 'foo',29 },30 })31 })32 })33 it('really works', () => {34 // output is trimmed35 cy.exec('echo foo', { timeout: 20000 }).its('stdout').should('eq', 'foo')36 })37 describe('.log', () => {38 beforeEach(function () {39 this.logs = []40 cy.on('log:added', (attrs, log) => {41 this.lastLog = log42 this.logs.push(log)43 })44 return null45 })46 it('can turn off logging', () => {47 Cypress.backend.resolves(okResponse)48 cy.exec('ls', { log: false }).then(function () {49 const logs = _.filter(this.logs, (log) => {50 return log.get('name') === 'exec'51 })52 expect(logs.length).to.eq(0)53 })54 })55 it('logs immediately before resolving', function () {56 Cypress.backend.resolves(okResponse)57 cy.on('log:added', (attrs, log) => {58 if (attrs.name === 'exec') {59 expect(log.get('state')).to.eq('pending')60 expect(log.get('message')).to.eq('ls')61 }62 })63 cy.exec('ls').then(() => {64 if (!this.lastLog) {65 throw new Error('failed to log before resolving')66 }67 })68 })69 })70 describe('timeout', () => {71 it('defaults timeout to Cypress.config(execTimeout)', () => {72 Cypress.backend.resolves(okResponse)73 const timeout = cy.spy(Promise.prototype, 'timeout')74 cy.exec('ls').then(() => {75 expect(timeout).to.be.calledWith(2500)76 })77 })78 it('can override timeout', () => {79 Cypress.backend.resolves(okResponse)80 const timeout = cy.spy(Promise.prototype, 'timeout')81 cy.exec('li', { timeout: 1000 }).then(() => {82 expect(timeout).to.be.calledWith(1000)83 })84 })85 it('clears the current timeout and restores after success', () => {86 Cypress.backend.resolves(okResponse)87 cy.timeout(100)88 const clearTimeout = cy.spy(cy, 'clearTimeout')89 cy.on('exec', () => {90 expect(clearTimeout).to.be.calledOnce91 })92 cy.exec('ls').then(() => {93 expect(cy.timeout()).to.eq(100)94 })95 })96 })97 describe('errors', {98 defaultCommandTimeout: 50,99 }, () => {100 beforeEach(function () {101 this.logs = []102 cy.on('log:added', (attrs, log) => {103 if (attrs.name === 'exec') {104 this.lastLog = log105 this.logs.push(log)106 }107 })108 return null109 })110 it('throws when cmd is absent', function (done) {111 cy.on('fail', (err) => {112 const { lastLog } = this113 expect(this.logs.length).to.eq(1)114 expect(lastLog.get('error')).to.eq(err)115 expect(lastLog.get('state')).to.eq('failed')116 expect(err.message).to.eq('`cy.exec()` must be passed a non-empty string as its 1st argument. You passed: \'\'.')117 expect(err.docsUrl).to.eq('https://on.cypress.io/exec')118 done()119 })120 cy.exec()121 })122 it('throws when cmd isn\'t a string', function (done) {123 cy.on('fail', (err) => {124 const { lastLog } = this125 expect(this.logs.length).to.eq(1)126 expect(lastLog.get('error')).to.eq(err)127 expect(lastLog.get('state')).to.eq('failed')128 expect(err.message).to.eq('`cy.exec()` must be passed a non-empty string as its 1st argument. You passed: \'3\'.')129 expect(err.docsUrl).to.eq('https://on.cypress.io/exec')130 done()131 })132 cy.exec(3)133 })134 it('throws when cmd is an empty string', function (done) {135 cy.on('fail', (err) => {136 const { lastLog } = this137 expect(this.logs.length).to.eq(1)138 expect(lastLog.get('error')).to.eq(err)139 expect(lastLog.get('state')).to.eq('failed')140 expect(err.message).to.eq('`cy.exec()` must be passed a non-empty string as its 1st argument. You passed: \'\'.')141 expect(err.docsUrl).to.eq('https://on.cypress.io/exec')142 done()143 })144 cy.exec('')145 })146 it('throws when the execution errors', function (done) {147 Cypress.backend.rejects(new Error('exec failed'))148 cy.on('fail', (err) => {149 const { lastLog } = this150 expect(this.logs.length).to.eq(1)151 expect(lastLog.get('error')).to.eq(err)152 expect(lastLog.get('state')).to.eq('failed')153 expect(err.message).to.eq('`cy.exec(\'ls\')` failed with the following error:\n\n> "Error: exec failed"')154 expect(err.docsUrl).to.eq('https://on.cypress.io/exec')155 done()156 })157 cy.exec('ls')158 })159 it('throws after timing out', function (done) {160 Cypress.backend.resolves(Promise.delay(250))161 cy.on('fail', (err) => {162 const { lastLog } = this163 expect(this.logs.length).to.eq(1)164 expect(lastLog.get('error')).to.eq(err)165 expect(lastLog.get('state')).to.eq('failed')166 expect(err.message).to.eq('`cy.exec(\'ls\')` timed out after waiting `50ms`.')167 expect(err.docsUrl).to.eq('https://on.cypress.io/exec')168 done()169 })170 cy.exec('ls', { timeout: 50 })171 })172 it('logs once on error', function (done) {173 Cypress.backend.rejects(new Error('exec failed'))174 cy.on('fail', (err) => {175 const { lastLog } = this176 expect(this.logs.length).to.eq(1)177 expect(lastLog.get('error')).to.eq(err)178 expect(lastLog.get('state')).to.eq('failed')179 done()180 })181 cy.exec('ls')182 })183 it('can timeout from the backend\'s response', (done) => {184 const err = new Error('timeout')185 err.timedOut = true186 Cypress.backend.rejects(err)187 cy.on('fail', (err) => {188 expect(err.message).to.include('`cy.exec(\'sleep 2\')` timed out after waiting `100ms`.')189 expect(err.docsUrl).to.eq('https://on.cypress.io/exec')190 done()191 })192 cy.exec('sleep 2', {193 timeout: 100,194 })195 })196 it('can really time out', (done) => {197 cy.on('fail', (err) => {198 expect(err.message).to.include('`cy.exec(\'sleep 2\')` timed out after waiting `100ms`.')199 expect(err.docsUrl).to.eq('https://on.cypress.io/exec')200 done()201 })202 cy.exec('sleep 2', {203 timeout: 100,204 })205 })206 describe('when error code is non-zero', () => {207 it('throws error that includes useful information and exit code', (done) => {208 Cypress.backend.resolves({ code: 1 })209 cy.on('fail', (err) => {210 expect(err.message).to.contain('`cy.exec(\'ls\')` failed because the command exited with a non-zero code.\n\nPass `{failOnNonZeroExit: false}` to ignore exit code failures.')211 expect(err.message).to.contain('Code: 1')212 expect(err.docsUrl).to.contain('https://on.cypress.io/exec')213 done()214 })215 cy.exec('ls')216 })217 it('throws error that includes stderr if it exists and is non-empty', (done) => {218 Cypress.backend.resolves({ code: 1, stderr: 'error output', stdout: '' })219 cy.on('fail', (err) => {220 expect(err.message).to.contain('Stderr:\nerror output')221 expect(err.message).not.to.contain('Stdout')222 done()223 })224 cy.exec('ls')225 })226 it('throws error that includes stdout if it exists and is non-empty', (done) => {227 Cypress.backend.resolves({ code: 1, stderr: '', stdout: 'regular output' })228 cy.on('fail', (err) => {229 expect(err.message).to.contain('\nStdout:\nregular output')230 expect(err.message).not.to.contain('Stderr')231 done()232 })233 cy.exec('ls')234 })235 it('throws error that includes stdout and stderr if they exists and are non-empty', (done) => {236 Cypress.backend.resolves({ code: 1, stderr: 'error output', stdout: 'regular output' })237 cy.on('fail', (err) => {238 expect(err.message).to.contain('\nStdout:\nregular output\nStderr:\nerror output')239 done()240 })241 cy.exec('ls')242 })243 it('truncates the stdout and stderr in the error message', (done) => {244 Cypress.backend.resolves({245 code: 1,246 stderr: `${_.range(200).join()}stderr should be truncated`,247 stdout: `${_.range(200).join()}stdout should be truncated`,248 })249 cy.on('fail', (err) => {250 expect(err.message).not.to.contain('stderr should be truncated')251 expect(err.message).not.to.contain('stdout should be truncated')252 expect(err.message).to.contain('...')253 done()254 })255 cy.exec('ls')256 })257 it('can really fail', function (done) {258 cy.on('fail', () => {259 const { lastLog } = this260 const { Yielded } = lastLog.invoke('consoleProps')261 // output is trimmed262 expect(Yielded).to.deep.eq({263 stdout: 'foo',264 stderr: '',265 code: 1,266 })267 done()268 })269 cy.exec('echo foo && exit 1')270 })271 describe('and failOnNonZeroExit is false', () => {272 it('does not error', () => {273 const response = { code: 1, stderr: 'error output', stdout: 'regular output' }274 Cypress.backend.resolves(response)275 cy276 .exec('ls', { failOnNonZeroExit: false })277 .should('deep.eq', response)278 })279 it('does not really fail', () => {280 cy.exec('echo foo && exit 1', {281 failOnNonZeroExit: false,282 })283 })284 })285 })286 })287 })...
tests-core.js
Source:tests-core.js
1const u = require('../../util/util.js');2describe('Tests', function () {3 beforeEach(() => {4 cy.checkPing();5 });6 it('POST to tests/dev/nofile but no file is provided', function () {7 const baseUrl = Cypress.config().baseUrl;8 const postUrl = `${baseUrl}/test/dev/nofile`;9 cy.request({10 url: postUrl,11 failOnStatusCode: false,12 method: 'POST',13 body: { version: 'v0.0.1' },14 }).then((response) => {15 expect(response.status).to.eq(400);16 expect(JSON.stringify(response.body.message)).to.match(/No file was uploaded/);17 });18 });19 it('POST myFile.txt to /test/dev/example1 - but expects .zip file', function () {20 cy.postTests('/test/dev/example1', 'myFile.txt', 'v1.1.1', 400, 'Please provide a .zip file');21 });22 it('POST cypress-frontend-app.zip to /test/dev/example2', function () {23 cy.postTests('/test/dev/example2', 'cypress-frontend-app.zip', 'v1.1.3');24 });25 it('POST cypress-frontend-app.zip to /test/dev/cypress-frontend-app', function () {26 cy.postTests('/test/dev/cypress-frontend-app', 'cypress-frontend-app.zip', 'v1.2.1');27 });28 it('ensures that a cypress-mars.json file exists when posting to environment mars', function () {29 cy.postTests(30 '/test/mars/cypress-frontend-app',31 'cypress-frontend-app.zip',32 'v1.0.0',33 400,34 'Please provide cypress-mars.json file at cypress root, e.g. cypress/cypress-mars.json',35 );36 });37 it('returns error message when requesting a built config file that does not exist', function () {38 cy.httpGet('/test/noenv/nofile/runConfig', 404, 'does not exist');39 });40 it('noRun=1 query string parameter returns `Not running the tests`', function () {41 cy.postTests('/test/uat/cypress-backend-app', 'cypress-backend-app.zip', 'v3.2.1');42 cy.httpGet(`/test/uat/cypress-backend-app?noRun=1&group=${u.rndGroup()}`, 200, 'Not running the tests');43 });44 it('returns cypress-dev-RUN.json with `env` config copied from cypress-dev.json', function () {45 cy.postTests('/test/dev/cypress-frontend-app', 'cypress-frontend-app.zip', 'v0.2.1');46 cy.httpGet(`/test/dev/cypress-frontend-app?noRun=1&group=${u.rndGroup()}`, 200, 'www.brand.dev.io');47 cy.httpGet('/test/dev/cypress-frontend-app/runConfig', 200, 'www.brand.dev.io');48 });49 it('returns cypress-dev-RUN.json with `baseUrl` copied from cypress-dev.json', function () {50 cy.postTests('/test/dev/cypress-frontend-app', 'cypress-frontend-app.zip', 'v0.2.2');51 cy.httpGet(`/test/dev/cypress-frontend-app?noRun=1&group=${u.rndGroup()}`, 200, 'localhost:4567/ping');52 cy.httpGet('/test/dev/cypress-frontend-app/runConfig', 200, 'localhost:4567/ping');53 });54 it('returns cypress-dev-RUN.json with `ignoreTestFiles` copied from cypress-dev.json', function () {55 cy.postTests('/test/dev/cypress-frontend-app', 'cypress-frontend-app.zip', 'v0.2.2');56 cy.httpGet(`/test/dev/cypress-frontend-app?noRun=1&group=${u.rndGroup()}`, 200, 'ignore-this.js');57 });58 it('returns cypress-dev-RUN.json with `blockHosts` copied from cypress-dev.json', function () {59 cy.postTests('/test/dev/cypress-frontend-app', 'cypress-frontend-app.zip', 'v0.2.2');60 cy.httpGet(`/test/dev/cypress-frontend-app?noRun=1&group=${u.rndGroup()}`, 200, 'www.block.this.host.io');61 });62 it('returns cypress-dev-RUN.json with `userAgent` copied from cypress-dev.json', function () {63 cy.postTests('/test/dev/cypress-frontend-app', 'cypress-frontend-app.zip', 'v0.2.2');64 cy.httpGet(`/test/dev/cypress-frontend-app?noRun=1&group=${u.rndGroup()}`, 200, 'this is my useragent string');65 });66 it('returns cypress-dev-RUN.json with `viewportHeight` and `viewportWidth` copied from cypress-dev.json', function () {67 cy.postTests('/test/dev/cypress-frontend-app', 'cypress-frontend-app.zip', 'v0.2.2');68 cy.httpGet(`/test/dev/cypress-frontend-app?noRun=1&group=${u.rndGroup()}`, 200, '770');69 cy.httpGet(`/test/dev/cypress-frontend-app?noRun=1&group=${u.rndGroup()}`, 200, '1110');70 });71 it('adds fixturesFolder to built runConfig', function () {72 cy.postTests('/test/dev1/cypress-backend-app', 'cypress-backend-app.zip', 'v0.0.1');73 cy.httpGet(`/test/dev1/cypress-backend-app?noRun=1&group=${u.rndGroup()}`, 200, 'www.brand.dev1.io');74 cy.httpGet('/test/dev1/cypress-backend-app/runConfig', 200, 'fixturesFolder');75 });76 it('adds integrationFolder to built runConfig', function () {77 cy.postTests('/test/dev1/cypress-backend-app', 'cypress-backend-app.zip', 'v0.0.2');78 cy.httpGet(`/test/dev1/cypress-backend-app?noRun=1&group=${u.rndGroup()}`, 200, 'www.brand.dev1.io');79 cy.httpGet('/test/dev1/cypress-backend-app/runConfig', 200, 'integrationFolder');80 });81 it('adds pluginsFile to built runConfig', function () {82 cy.postTests('/test/dev1/cypress-backend-app', 'cypress-backend-app.zip', 'v0.0.2');83 cy.httpGet(`/test/dev1/cypress-backend-app?noRun=1&group=${u.rndGroup()}`, 200, 'www.brand.dev1.io');84 cy.httpGet('/test/dev1/cypress-backend-app/runConfig', 200, 'pluginsFile');85 });86 it('adds supportFile to built runConfig', function () {87 cy.postTests('/test/dev1/cypress-backend-app', 'cypress-backend-app.zip', 'v0.0.5');88 cy.httpGet(`/test/dev1/cypress-backend-app?noRun=1&group=${u.rndGroup()}`, 200, 'www.brand.dev1.io');89 cy.httpGet('/test/dev1/cypress-backend-app/runConfig', 200, 'supportFile');90 });91 it('adds downloadsFolder to built runConfig', function () {92 cy.postTests('/test/pat/cypress-backend-app', 'cypress-backend-app.zip', 'v0.0.2');93 const group = u.rndGroup();94 cy.httpGet(`/test/pat/cypress-backend-app?noRun=1&group=${group}`, 200, 'www.brand.pat.io');95 const dt = '[0-9]{2,4}[.][0-9]{2}[.][0-9]{2}';96 cy.httpGet(97 '/test/pat/cypress-backend-app/runConfig',98 200,99 `"results/pat/cypress-backend-app/${dt}/${group}/allSuites/downloads"`,100 );101 });102 it('adds screenshotsFolder to built runConfig', function () {103 cy.postTests('/test/perf/cypress-backend-app', 'cypress-backend-app.zip', 'v0.1.8');104 const group = u.rndGroup();105 cy.httpGet(`/test/perf/cypress-backend-app?noRun=1&group=${group}`, 200, 'www.brand.perf.io');106 const dt = '[0-9]{2,4}[.][0-9]{2}[.][0-9]{2}';107 cy.httpGet(108 '/test/perf/cypress-backend-app/runConfig',109 200,110 `"results/perf/cypress-backend-app/${dt}/${group}/allSuites/screenshots"`,111 );112 });113 it('adds videosFolder to built runConfig', function () {114 cy.postTests('/test/pink/cypress-backend-app', 'cypress-backend-app.zip', 'v0.1.9');115 const group = u.rndGroup();116 cy.httpGet(`/test/pink/cypress-backend-app?noRun=1&group=${group}`, 200, 'www.brand.pink.io');117 const dt = '[0-9]{2,4}[.][0-9]{2}[.][0-9]{2}';118 cy.httpGet(119 '/test/pink/cypress-backend-app/runConfig',120 200,121 `"results/pink/cypress-backend-app/${dt}/${group}/allSuites/videos"`,122 );123 });124 it('adds reporter and reporterOptions to built runConfig', function () {125 cy.postTests('/test/pink/cypress-backend-app', 'cypress-backend-app.zip', 'v0.1.9');126 const group = u.rndGroup();127 cy.httpGet(`/test/pink/cypress-backend-app?noRun=1&group=${group}`, 200, 'www.brand.pink.io');128 const dt = '[0-9]{2,4}[.][0-9]{2}[.][0-9]{2}';129 cy.httpGet('/test/pink/cypress-backend-app/runConfig', 200, `"reporter":"mochawesome"`);130 cy.httpGet(131 '/test/pink/cypress-backend-app/runConfig',132 200,133 `"reportDir":"results/pink/cypress-backend-app/${dt}/${group}/allSuites"`,134 );135 });136 it('group parameter is mandatory for running tests', function () {137 cy.postTests('/test/dev/cypress-backend-app', 'cypress-backend-app.zip', 'v0.2.5');138 cy.httpGet(`/test/dev/cypress-backend-app?noRun=1`, 400, 'Group must be supplied to group suites for an app');139 });140 it('group parameter is used as part of the folder structure', function () {141 cy.postTests('/test/dev/cypress-backend-app', 'cypress-backend-app.zip', 'v0.2.5');142 const group = u.rndGroup();143 const dt = '[0-9]{2,4}[.][0-9]{2}[.][0-9]{2}';144 cy.httpGet(`/test/dev/cypress-backend-app?noRun=1&group=${group}`, 200, `cypress-backend-app/${dt}/${group}`);145 });146 it('suite parameter runs tests in all subfolders for given suite (top level folder under integration)', function () {147 cy.postTests('/test/dev/cypress-backend-app', 'cypress-backend-app.zip', 'v6.2.5');148 cy.httpGet(149 `/test/dev/cypress-backend-app?noRun=1&group=${u.rndGroup()}&suite=canary`,150 200,151 'cypress/integration/canary/[*][*]/[*]',152 );153 });154 it('not providing suite parameter runs tests in all subfolders under integration', function () {155 cy.postTests('/test/dev/cypress-backend-app', 'cypress-backend-app.zip', 'v7.2.5');156 cy.httpGet(`/test/dev/cypress-backend-app?noRun=1&group=${u.rndGroup()}`, 200, 'cypress/integration/[*][*]/[*]');157 });158 it('sets `video` to `false` so that video false will not be produced', function () {159 cy.postTests('/test/dev/cypress-backend-app', 'cypress-backend-app.zip', 'v0.2.5');160 cy.httpGet(`/test/dev/cypress-backend-app?noRun=1&group=${u.rndGroup()}&noVideo=1`, 200, '"video":false');161 });162 it('GET /test/yellow/cypress-backend-app/lastReport returns not available', function () {163 cy.postTests('/test/yellow/cypress-backend-app', 'cypress-backend-app.zip', 'v1.3.8');164 cy.httpGet('/test/yellow/cypress-backend-app/lastReport', 404, 'No last mochawesome report available');165 });166 it('GET /test/yellow/cypress-backend-app/lastRunResult returns not available', function () {167 cy.postTests('/test/yellow/cypress-backend-app', 'cypress-backend-app.zip', 'v1.2.8');168 cy.httpGet('/test/yellow/cypress-backend-app/lastRunResult', 404, 'No last run result available');169 });...
task_spec.js
Source:task_spec.js
...5 }, () => {6 beforeEach(() => {7 cy.stub(Cypress, 'backend').callThrough()8 })9 it('calls Cypress.backend(\'task\') with the right options', () => {10 Cypress.backend.resolves(null)11 cy.task('foo').then(() => {12 expect(Cypress.backend).to.be.calledWith('task', {13 task: 'foo',14 timeout: 2500,15 arg: undefined,16 })17 })18 })19 it('passes through arg', () => {20 Cypress.backend.resolves(null)21 cy.task('foo', { foo: 'foo' }).then(() => {22 expect(Cypress.backend).to.be.calledWith('task', {23 task: 'foo',...
fixtures_spec.js
Source:fixtures_spec.js
1const { Promise } = Cypress2describe('src/cy/commands/fixtures', () => {3 beforeEach(() => {4 return Cypress.emit('clear:fixtures:cache')5 })6 // call all of the fixture triggers async to simulate7 // the real browser environment8 context('#fixture', () => {9 beforeEach(() => {10 // call through normally on everything11 cy.stub(Cypress, 'backend').callThrough()12 })13 it('triggers \'fixture\' on Cypress', () => {14 Cypress.backend.withArgs('get:fixture').resolves({ foo: 'bar' })15 cy.fixture('foo').as('f').then((obj) => {16 expect(obj).to.deep.eq({ foo: 'bar' })17 expect(Cypress.backend).to.be.calledWith('get:fixture', 'foo', {})18 })19 })20 it('can support an array of fixtures')21 it('can have encoding as second argument', () => {22 Cypress.backend.withArgs('get:fixture').resolves({ foo: 'bar' })23 cy.fixture('foo', 'ascii').then((obj) => {24 expect(obj).to.deep.eq({ foo: 'bar' })25 expect(Cypress.backend).to.be.calledWith('get:fixture', 'foo', {26 encoding: 'ascii',27 })28 })29 })30 it('can have encoding as second argument and options as third argument', () => {31 Cypress.backend.withArgs('get:fixture').resolves({ foo: 'bar' })32 cy.fixture('foo', 'ascii', { timeout: 1000 }).then((obj) => {33 expect(obj).to.deep.eq({ foo: 'bar' })34 expect(Cypress.backend).to.be.calledWith('get:fixture', 'foo', {35 encoding: 'ascii',36 })37 })38 })39 it('really works', () => {40 cy.fixture('example').should('deep.eq', { example: true })41 })42 it('works with null.json', () => {43 cy.fixture('null.json').should('equal', null)44 })45 it('can read a fixture without extension with multiple dots in the name', () => {46 cy.fixture('foo.bar.baz').should('deep.eq', { quux: 'quuz' })47 })48 it('looks for csv without extension', () => {49 cy.fixture('comma-separated').should('equal', [50 'One,Two,Three\n',51 '1,2,3\n',52 ].join(''))53 })54 it('handles files with unknown extensions, reading them as utf-8', () => {55 cy.fixture('yaml.yaml').should('equal', [56 '- foo\n',57 '- bar\n',58 '- \n',59 ].join(''))60 })61 describe('errors', {62 defaultCommandTimeout: 50,63 }, () => {64 beforeEach(function () {65 this.logs = []66 cy.on('log:added', (attrs, log) => {67 if (attrs.name === 'fixture') {68 this.lastLog = log69 this.logs.push(log)70 }71 })72 return null73 })74 it('throws if fixturesFolder is set to false', {75 fixturesFolder: false,76 }, function (done) {77 cy.on('fail', () => {78 const { lastLog } = this79 expect(this.logs.length).to.eq(1)80 expect(lastLog.get('error').message).to.eq('`cy.fixture()` is not valid because you have configured `fixturesFolder` to `false`.')81 expect(lastLog.get('error').docsUrl).to.eq('https://on.cypress.io/fixture')82 expect(lastLog.get('state')).to.eq('failed')83 expect(lastLog.get('name')).to.eq('fixture')84 done()85 })86 cy.fixture('foo')87 })88 it('throws when fixture cannot be found without extension', function (done) {89 cy.on('fail', (err) => {90 const { lastLog } = this91 expect(this.logs.length).to.eq(1)92 expect(lastLog.get('error')).to.eq(err)93 expect(lastLog.get('state')).to.eq('failed')94 expect(lastLog.get('name')).to.eq('fixture')95 expect(lastLog.get('message')).to.eq('err')96 expect(err.message).to.include('A fixture file could not be found')97 expect(err.message).to.include('cypress/fixtures/err')98 done()99 })100 cy.fixture('err')101 })102 it('throws when fixture cannot be found with extension', function (done) {103 cy.on('fail', (err) => {104 const { lastLog } = this105 expect(this.logs.length).to.eq(1)106 expect(lastLog.get('error')).to.eq(err)107 expect(lastLog.get('state')).to.eq('failed')108 expect(lastLog.get('name')).to.eq('fixture')109 expect(lastLog.get('message')).to.eq('err.txt')110 expect(err.message).to.include('A fixture file could not be found')111 expect(err.message).to.include('cypress/fixtures/err.txt')112 done()113 })114 cy.fixture('err.txt')115 })116 it('throws after timing out', function (done) {117 Cypress.backend.withArgs('get:fixture').resolves(Promise.delay(1000))118 cy.on('fail', (err) => {119 const { lastLog } = this120 expect(this.logs.length).to.eq(1)121 expect(lastLog.get('error')).to.eq(err)122 expect(lastLog.get('state')).to.eq('failed')123 expect(lastLog.get('name')).to.eq('fixture')124 expect(lastLog.get('message')).to.eq('foo, {timeout: 50}')125 expect(err.message).to.eq('`cy.fixture()` timed out waiting `50ms` to receive a fixture. No fixture was ever sent by the server.')126 expect(err.docsUrl).to.eq('https://on.cypress.io/fixture')127 done()128 })129 cy.fixture('foo', { timeout: 50 })130 })131 })132 describe('timeout', () => {133 it('sets timeout to Cypress.config(responseTimeout)', {134 responseTimeout: 2500,135 }, () => {136 Cypress.backend.withArgs('get:fixture').resolves({ foo: 'bar' })137 const timeout = cy.spy(Promise.prototype, 'timeout')138 cy.fixture('foo').then(() => {139 expect(timeout).to.be.calledWith(2500)140 })141 })142 it('can override timeout', () => {143 Cypress.backend.withArgs('get:fixture').resolves({ foo: 'bar' })144 const timeout = cy.spy(Promise.prototype, 'timeout')145 cy.fixture('foobar', { timeout: 1000 }).then(() => {146 expect(timeout).to.be.calledWith(1000)147 })148 })149 it('clears the current timeout and restores after success', () => {150 Cypress.backend.withArgs('get:fixture').resolves({ foo: 'bar' })151 cy.timeout(100)152 cy.spy(cy, 'clearTimeout')153 cy.fixture('foo').then(() => {154 expect(cy.clearTimeout).to.be.calledWith('get:fixture')155 // restores the timeout afterwards156 expect(cy.timeout()).to.eq(100)157 })158 })159 })160 describe('caching', () => {161 beforeEach(() => {162 Cypress.backend163 .withArgs('get:fixture', 'foo')164 .resolves({ foo: 'bar' })165 .withArgs('get:fixture', 'bar')166 .resolves({ bar: 'baz' })167 })168 it('caches fixtures by name', () => {169 cy.fixture('foo').then((obj) => {170 expect(obj).to.deep.eq({ foo: 'bar' })171 cy.fixture('bar').then((obj) => {172 expect(obj).to.deep.eq({ bar: 'baz' })173 cy.fixture('foo').then((obj) => {174 expect(obj).to.deep.eq({ foo: 'bar' })175 })176 })177 })178 .then(() => {179 expect(Cypress.backend).to.be.calledTwice180 })181 })182 it('clones fixtures to prevent accidental mutation', () => {183 cy.fixture('foo').then((obj) => {184 // mutate the object185 obj.baz = 'quux'186 cy.fixture('foo').then((obj2) => {187 obj2.lorem = 'ipsum'188 expect(obj2).not.to.have.property('baz')189 cy.fixture('foo').then((obj3) => {190 expect(obj3).not.to.have.property('lorem')191 })192 })193 .then(() => {194 expect(Cypress.backend).to.be.calledOnce195 })196 })197 })198 })199 })...
tests-parallel.js
Source:tests-parallel.js
1const u = require('../../util/util.js');2describe('Tests', function () {3 beforeEach(() => {4 cy.checkPing();5 });6 it('kicks off all suites in an app to run in parallel', function () {7 const group = u.rndGroup();8 cy.postTests('/test/purple/cypress-backend-app', 'cypress-backend-app.zip', 'v3.3.221');9 cy.httpGet(`/test/purple/cypress-backend-app/parallel?group=${group}&interval=1500&noVideo=1`, 200, 'kicked off');10 cy.httpGetRetry(`/test/purple/cypress-backend-app/summary`, 200, `All tests passed.`);11 cy.httpGet('/test/purple/cypress-backend-app/summary', 200, 'canary');12 cy.httpGet('/test/purple/cypress-backend-app/summary', 200, 'core-api');13 });14 it('returns an error if you try to use the same group twice', function () {15 const group = u.rndGroup();16 cy.postTests('/test/purple/cypress-backend-app', 'cypress-backend-app.zip', 'v3.3.222');17 cy.httpGet(`/test/purple/cypress-backend-app/parallel?group=${group}&interval=1500&noVideo=1`, 200, 'kicked off');18 cy.httpGetRetry(`/test/purple/cypress-backend-app/summary`, 200, `All tests passed.`);19 cy.httpGet(`/test/purple/cypress-backend-app/parallel?group=${group}&interval=150&noVideo=1`, 500, 'with errors');20 });21 it('does not require you to specify a group', function () {22 cy.postTests('/test/purple/cypress-backend-app', 'cypress-backend-app.zip', 'v3.3.223');23 cy.httpGet(`/test/purple/cypress-backend-app/parallel?interval=200&noVideo=1`, 200, 'kicked off');24 cy.httpGetRetry(`/test/purple/cypress-backend-app/summary`, 200, `All tests passed.`);25 });...
Using AI Code Generation
1Cypress.Commands.add('backend', (method, url, body) => {2 return cy.wrap(null, { log: false }).then(() => {3 return Cypress.backend(method, url, body)4 })5})6const { startDevServer } = require('@cypress/webpack-dev-server')7const webpackConfig = require('@vue/cli-service/webpack.config')8 * @type {Cypress.PluginConfig}9module.exports = (on, config) => {10 on('dev-server:start', (options) => {11 return startDevServer({12 })13 })14}15import './commands'16import './custom-commands'17Cypress.Commands.add('login', () => {18 cy.visit('/')19 cy.get('input[type=email]').type('
Using AI Code Generation
1Cypress.Commands.add("backend", (method, url, body) => {2 return cy.request({3 headers: {4 }5 });6});7describe("Test backend", () => {8 it("should return a response", () => {9 cy.backend("GET", "/").then(response => {10 expect(response.status).to.eq(200);11 });12 });13});14const express = require("express");15const app = express();16const port = 3001;17app.get("/", (req, res) => {18 res.send("Hello World!");19});20app.listen(port, () => {21});22{23}24CypressError: cy.request() failed trying to load:25CypressError: cy.request() failed trying to load:
Using AI Code Generation
1Cypress.Commands.add('callApi', () => {2 return cy.request({3 headers: {4 }5 })6})7describe('My First Test', function () {8 it('Gets, sets and asserts', function () {9 cy.callApi().then((response) => {10 expect(response.status).to.eq(200)11 expect(response.body).to.have.property('id', 1)12 expect(response.body).to.have.property('title', 'sunt aut facere repellat provident occaecati excepturi optio reprehenderit')13 expect(response.body).to.have.property('body', 'quia et suscipit\\nsuscipit recusandae consequuntur expedita et cum\\nreprehenderit molestiae ut ut quas totam\\nnostrum rerum est autem sunt rem eveniet architecto')14 })15 })16})17describe('My First Test', function () {18 it('Gets, sets and asserts', function () {19 cy.callApi().then((response) => {20 expect(response.status).to.eq(200)21 expect(response.body).to.have.property('id', 1)22 expect(response.body).to.have.property('title', 'sunt aut facere repellat provident occaecati excepturi optio reprehenderit')23 expect(response.body).to.have.property('body', 'quia et suscipit\\nsuscipit recusandae consequuntur expedita et cum\\nreprehenderit molestiae ut ut quas totam\\nnostrum rerum est autem sunt rem eveniet architecto')24 })25 })26})27describe('My First Test', function () {28 it('Gets, sets and asserts', function () {29 cy.callApi().then((response) => {30 expect(response.status).to.eq(200)31 expect(response.body).to.have.property('
Using AI Code Generation
1Cypress.Commands.add('getBackendResponse', (url, method, body) => {2 cy.request({3 }).then((response) => {4 return response.body;5 });6});7Cypress.Commands.add('getBackendResponse', (url, method, body) => {8 cy.request({9 }).then((response) => {10 return response.body;11 });12});13Cypress.Commands.add('getBackendResponse', (url, method, body) => {14 cy.request({15 }).then((response) => {16 return response.body;17 });18});19Cypress.Commands.add('getBackendResponse', (url, method, body) => {20 cy.request({21 }).then((response) => {22 return response.body;23 });24});25Cypress.Commands.add('getBackendResponse', (url, method, body) => {26 cy.request({27 }).then((response) => {28 return response.body;29 });30});
Using AI Code Generation
1describe("test backend", () => {2 it("test backend", () => {3 console.log(data);4 });5 });6});7const axios = require("axios");8Cypress.Commands.add("backend", (url) => {9 .get(url)10 .then((response) => {11 return response.data;12 })13 .catch((error) => {14 console.log(error);15 });16});17const axios = require("axios");18Cypress.Commands.add("backend", (url) => {19 .get(url)20 .then((response) => {21 return response.data;22 })23 .catch((error) => {24 console.log(error);25 });26});27const axios = require("axios");28Cypress.Commands.add("backend", (url) => {29 .get(url)30 .then((response) => {31 return response.data;32 })33 .catch((error) => {34 console.log(error);35 });36});
Using AI Code Generation
1const { add } = require('./add.js')2Cypress.Commands.add('backend', (fn, ...args) => {3 return cy.task('backend', {4 fn: fn.toString(),5 args: args.map(arg => JSON.stringify(arg))6 })7})8describe('test', () => {9 it('test', () => {10 cy.visit('index.html')11 cy.get('#num1').type(2)12 cy.get('#num2').type(3)13 cy.get('#add').click()14 cy.get('#result').should('have.text', '5')15 cy.backend(add, 2, 3).should('eq', 5)16 })17})18const add = (a, b) => {19}20module.exports = {21}
Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.
You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.
Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.
Get 100 minutes of automation test minutes FREE!!