Skip to content

Commit 82399ad

Browse files
committed
added changes for record functionality
1 parent 276b070 commit 82399ad

File tree

5 files changed

+66
-2
lines changed

5 files changed

+66
-2
lines changed

bin/commands/runs.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ module.exports = function run(args, rawArgs) {
8383
// set the no-wrap
8484
utils.setNoWrap(bsConfig, args);
8585

86+
// set record feature caps
87+
utils.setRecordCaps(bsConfig, args);
88+
8689
//set browsers
8790
await utils.setBrowsers(bsConfig, args);
8891

bin/helpers/capabilityHelper.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,14 @@ const validate = (bsConfig, args) => {
241241
logger.warn(Constants.validationMessages.SPEC_TIMEOUT_NOT_PASSED_ERROR);
242242
}
243243

244+
if(Utils.isUndefined(bsConfig.run_settings.projectId)) {
245+
reject(Constants.validationMessages.PROJECT_ID_MISSING);
246+
} else if (Utils.isUndefined(bsConfig.run_settings["record"]) || bsConfig.run_settings["record"].toString() == "false") {
247+
logger.warn(Constants.validationMessages.RECORD_MISSING);
248+
} else if (Utils.isUndefined(bsConfig.run_settings["record-key"])) {
249+
logger.warn(Constants.validationMessages.RECORD_KEY_MISSING);
250+
}
251+
244252
resolve(cypressJson);
245253
});
246254
}

bin/helpers/constants.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ const validationMessages = {
101101
HOME_DIRECTORY_NOT_A_DIRECTORY: "Specified home directory is not a directory. The home directory can only be a directory and not a file.",
102102
CYPRESS_CONFIG_FILE_NOT_PART_OF_HOME_DIRECTORY: "Could not find cypress.json within the specified home directory. Please make sure cypress.json resides within the home directory.",
103103
SPEC_TIMEOUT_LIMIT_ERROR: "The maximum allowed value of 'spec_timeout' is 120. Read more on https://browserstack.com/docs/automate/cypress/spec-timeout ",
104-
SPEC_TIMEOUT_NOT_PASSED_ERROR: "'spec_timeout' key not specified. Going ahead with 30 mins as the default spec timeout. Read more about how to specify the option in https://browserstack.com/docs/automate/cypress/spec-timeout "
104+
SPEC_TIMEOUT_NOT_PASSED_ERROR: "'spec_timeout' key not specified. Going ahead with 30 mins as the default spec timeout. Read more about how to specify the option in https://browserstack.com/docs/automate/cypress/spec-timeout ",
105+
PROJECT_ID_MISSING: "You passed the --record flag but this project has not been setup to record. This project is missing the 'projectId' inside of 'cypress.json'. We cannot uniquely identify this project without this id. You need to setup this project to record. This will generate a unique 'projectId'. Alternatively if you omit the --record flag this project will run without recording. https://on.cypress.io/recording-project-runs",
106+
RECORD_KEY_MISSING: "You have specified '--record' flag but you've not provided the '--record-key' and we could not find any value in 'CYPRESS_RECORD_KEY' environment variable. Your record functionality on cypress.io dashboard might not work as it needs the key and projectId",
107+
RECORD_MISSING: "You have not specified '--record' flag. Your record functionality on cypress.io dashboard might not work."
105108
};
106109

107110
const cliMessages = {
@@ -145,7 +148,10 @@ const cliMessages = {
145148
REPORTER: "Specify the custom reporter to use",
146149
REPORTER_OPTIONS: "Specify reporter options for custom reporter",
147150
CYPRESS_GEO_LOCATION: "Enterprise feature to simulate website and mobile behavior from different locations.",
148-
SPEC_TIMEOUT: "Specify a value for a hard timeout for each spec execution in the 1-120 mins range. Read https://browserstack.com/docs/automate/cypress/spec-timeout for more details."
151+
SPEC_TIMEOUT: "Specify a value for a hard timeout for each spec execution in the 1-120 mins range. Read https://browserstack.com/docs/automate/cypress/spec-timeout for more details.",
152+
RECORD: "Run your tests with record functionality on cypress.io dashboard",
153+
RECORD_KEY: "Specify a value for record key.",
154+
PROJECT_ID: "Specify a value for project id."
149155
},
150156
COMMON: {
151157
DISABLE_USAGE_REPORTING: "Disable usage reporting",

bin/helpers/utils.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,38 @@ exports.setSpecTimeout = (bsConfig, args) => {
327327
bsConfig.run_settings.spec_timeout = specTimeout;
328328
}
329329

330+
exports.setRecordFlag = (bsConfig, args) => {
331+
if(!this.isUndefined(args["record"])) {
332+
return true;
333+
}
334+
return bsConfig.run_settings["record"];
335+
}
336+
337+
exports.setRecordKeyFlag = (bsConfig, args) => {
338+
if(!this.isUndefined(args["record-key"])) {
339+
return args["record-key"];
340+
} else if (!this.isUndefined(process.env.CYPRESS_RECORD_KEY)) {
341+
return process.env.CYPRESS_RECORD_KEY;
342+
}
343+
return bsConfig.run_settings["record-key"];
344+
}
345+
346+
exports.setProjectId = (bsConfig, args) => {
347+
if(!this.isUndefined(args["projectId"])) {
348+
return args["projectId"];
349+
} else {
350+
let cypressJson = this.getCypressJSON(bsConfig);
351+
if (!this.isUndefined(cypressJson) && !this.isUndefined(cypressJson["projectId"])) { return cypressJson["projectId"]; }
352+
}
353+
return bsConfig.run_settings["projectId"];
354+
}
355+
356+
exports.setRecordCaps = (bsConfig, args) => {
357+
bsConfig.run_settings["record"] = this.setRecordFlag(bsConfig, args);
358+
bsConfig.run_settings["record-key"] = this.setRecordKeyFlag(bsConfig, args);
359+
bsConfig.run_settings["projectId"] = this.setProjectId(bsConfig, args);
360+
}
361+
330362
// specs can be passed from bstack configuration file
331363
// specs can be passed via command line args as a string
332364
// command line args takes precedence over config

bin/runner.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,21 @@ var argv = yargs
243243
describe: Constants.cliMessages.RUN.REPORTER_OPTIONS,
244244
type: "string"
245245
},
246+
'record': {
247+
default: false,
248+
describe: Constants.cliMessages.RUN.RECORD,
249+
type: "boolean"
250+
},
251+
'record-key': {
252+
default: undefined,
253+
describe: Constants.cliMessages.RUN.RECORD_KEY,
254+
type: "string"
255+
},
256+
'projectId': {
257+
default: undefined,
258+
describe: Constants.cliMessages.RUN.PROJECT_ID,
259+
type: "string"
260+
}
246261
})
247262
.help('help')
248263
.wrap(null)

0 commit comments

Comments
 (0)