Skip to content

Commit 6ac4c2d

Browse files
author
Archish Thakkar
authored
Merge pull request #659 from browserstack/interactive_session_cypress
Interactive session cypress
2 parents 4b46ccb + df4ab6a commit 6ac4c2d

File tree

6 files changed

+251
-1
lines changed

6 files changed

+251
-1
lines changed

bin/commands/runs.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ module.exports = function run(args, rawArgs) {
184184
// set record feature caps
185185
utils.setRecordCaps(bsConfig, args, cypressConfigFile);
186186

187+
// set the interactive debugging capability
188+
utils.setInteractiveCapability(bsConfig);
189+
187190
// warn if specFiles cross our limit
188191
utils.warnSpecLimit(bsConfig, args, specFiles, rawArgs, buildReportData);
189192
markBlockEnd('preArchiveSteps');

bin/helpers/capabilityHelper.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,23 @@ const validate = (bsConfig, args) => {
242242
addCypressZipStartLocation(bsConfig.run_settings);
243243
}
244244

245+
// check if Interactive Capabilities Caps passed is correct or not
246+
if(!Utils.isUndefined(bsConfig.run_settings.interactive_debugging) && !Utils.isUndefined(bsConfig.run_settings.interactiveDebugging)) {
247+
if(Utils.isConflictingBooleanValues(bsConfig.run_settings.interactive_debugging, bsConfig.run_settings.interactiveDebugging)) {
248+
reject(Constants.userMessages.CYPRESS_INTERACTIVE_SESSION_CONFLICT_VALUES);
249+
} else if(Utils.isNonBooleanValue(bsConfig.run_settings.interactive_debugging) && Utils.isNonBooleanValue(bsConfig.run_settings.interactiveDebugging)) {
250+
logger.warn('You have passed an invalid value to the interactive_debugging capability. Proceeding with the default value (True).');
251+
}
252+
} else if(!Utils.isUndefined(bsConfig.run_settings.interactive_debugging)) {
253+
if(Utils.isNonBooleanValue(bsConfig.run_settings.interactive_debugging)) {
254+
logger.warn('You have passed an invalid value to the interactive_debugging capability. Proceeding with the default value (True).');
255+
}
256+
} else if(!Utils.isUndefined(bsConfig.run_settings.interactiveDebugging)) {
257+
if(Utils.isNonBooleanValue(bsConfig.run_settings.interactiveDebugging)) {
258+
logger.warn('You have passed an invalid value to the interactive_debugging capability. Proceeding with the default value (True).');
259+
}
260+
}
261+
245262
// check if two config files are present at the same location
246263
let cypressFileDirectory = path.dirname(path.resolve(bsConfig.run_settings.cypressConfigFilePath));
247264
let listOfFiles = fs.readdirSync(cypressFileDirectory);

bin/helpers/constants.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ const userMessages = {
117117
NO_CONNECTION_WHILE_UPDATING_UPLOAD_PROGRESS_BAR:
118118
"Unable to determine zip upload progress due to undefined/null connection request",
119119
CYPRESS_PORT_WARNING:
120-
"The requested port number <x> is ignored. The default BrowserStack port will be used for this execution"
120+
"The requested port number <x> is ignored. The default BrowserStack port will be used for this execution",
121+
CYPRESS_INTERACTIVE_SESSION_CONFLICT_VALUES:
122+
"Conflicting values (True & False) were found for the interactive_debugging capability. Please resolve this issue to proceed further."
121123
};
122124

123125
const validationMessages = {

bin/helpers/utils.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,24 @@ exports.setHeaded = (bsConfig, args) => {
10001000
logger.debug(`headless mode set to ${bsConfig.run_settings.headless}`);
10011001
};
10021002

1003+
exports.isConflictingBooleanValues = (value1, value2) => {
1004+
return (value1.toString() === "true" && value2.toString() === "false") || (value1.toString() === "false" && value2.toString() === "true")
1005+
};
1006+
1007+
exports.isNonBooleanValue = (value) => {
1008+
return value.toString() !== "true" && value.toString() !== "false";
1009+
};
1010+
1011+
exports.setInteractiveCapability = (bsConfig) => {
1012+
let interactiveDebuggingTemp = "true";
1013+
let interactive_debugging = bsConfig.run_settings.interactive_debugging;
1014+
let interactiveDebugging = bsConfig.run_settings.interactiveDebugging;
1015+
if(this.isNotUndefined(interactive_debugging) && !this.isNonBooleanValue(interactive_debugging)) interactiveDebuggingTemp = interactive_debugging;
1016+
else if(this.isNotUndefined(interactiveDebugging) && !this.isNonBooleanValue(interactiveDebugging)) interactiveDebuggingTemp = interactiveDebugging;
1017+
logger.debug(`Setting interactiveDebugging flag to ${interactiveDebuggingTemp}`);
1018+
bsConfig.run_settings.interactiveDebugging = interactiveDebuggingTemp;
1019+
}
1020+
10031021
exports.setNoWrap = (_bsConfig, args) => {
10041022
if (args.noWrap === true || this.searchForOption('--no-wrap')) {
10051023
process.env.SYNC_NO_WRAP = true;

test/unit/bin/helpers/capabilityHelper.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,95 @@ describe("capabilityHelper.js", () => {
12291229
});
12301230
});
12311231

1232+
describe("validate interactive caps debugging", () => {
1233+
let loggerWarningSpy;
1234+
beforeEach(() => {
1235+
loggerWarningSpy = sinon.stub(logger, 'warn').returns('You have passed an invalid value to the interactive_debugging capability. Proceeding with the default value (True).');
1236+
});
1237+
1238+
afterEach(function() {
1239+
loggerWarningSpy.restore();
1240+
});
1241+
it("show the warning if interactive_debugging passed is a non boolean value", () => {
1242+
let bsConfig = {
1243+
auth: {},
1244+
browsers: [
1245+
{
1246+
browser: "chrome",
1247+
os: "Windows 10",
1248+
versions: ["78", "77"],
1249+
},
1250+
],
1251+
run_settings: {
1252+
cypress_proj_dir: "random path",
1253+
cypressConfigFilePath: "random path",
1254+
cypressProjectDir: "random path",
1255+
cypress_config_filename: "false",
1256+
interactive_debugging: "abc"
1257+
},
1258+
connection_settings: {}
1259+
}
1260+
return capabilityHelper
1261+
.validate(bsConfig, {})
1262+
.then(function (data) {
1263+
sinon.assert.calledWith(loggerWarningSpy, 'You have passed an invalid value to the interactive_debugging capability. Proceeding with the default value (True).');
1264+
});
1265+
});
1266+
1267+
it("show the warning if interactiveDebugging passed is a non boolean value", () => {
1268+
let bsConfig = {
1269+
auth: {},
1270+
browsers: [
1271+
{
1272+
browser: "chrome",
1273+
os: "Windows 10",
1274+
versions: ["78", "77"],
1275+
},
1276+
],
1277+
run_settings: {
1278+
cypress_proj_dir: "random path",
1279+
cypressConfigFilePath: "random path",
1280+
cypressProjectDir: "random path",
1281+
cypress_config_filename: "false",
1282+
interactiveDebugging: "abc"
1283+
},
1284+
connection_settings: {}
1285+
}
1286+
return capabilityHelper
1287+
.validate(bsConfig, {})
1288+
.then(function (data) {
1289+
sinon.assert.calledWith(loggerWarningSpy, 'You have passed an invalid value to the interactive_debugging capability. Proceeding with the default value (True).');
1290+
});
1291+
});
1292+
1293+
it("show the warning if both the interactive caps are non boolean", () => {
1294+
let bsConfig = {
1295+
auth: {},
1296+
browsers: [
1297+
{
1298+
browser: "chrome",
1299+
os: "Windows 10",
1300+
versions: ["78", "77"],
1301+
},
1302+
],
1303+
run_settings: {
1304+
cypress_proj_dir: "random path",
1305+
cypressConfigFilePath: "random path",
1306+
cypressProjectDir: "random path",
1307+
cypress_config_filename: "false",
1308+
interactiveDebugging: "def",
1309+
interactive_debugging: "abc"
1310+
},
1311+
connection_settings: {}
1312+
}
1313+
return capabilityHelper
1314+
.validate(bsConfig, {})
1315+
.then(function (data) {
1316+
sinon.assert.calledWith(loggerWarningSpy, 'You have passed an invalid value to the interactive_debugging capability. Proceeding with the default value (True).');
1317+
});
1318+
});
1319+
});
1320+
12321321
describe("validate home directory", () => {
12331322
beforeEach(() => {
12341323
bsConfig = {

test/unit/bin/helpers/utils.js

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3938,6 +3938,127 @@ describe('utils', () => {
39383938
});
39393939
});
39403940

3941+
describe('#isNonBooleanValue' , () => {
3942+
it('return true if value passed in empty string', () => {
3943+
expect(utils.isNonBooleanValue('')).to.be.eql(true);
3944+
});
3945+
3946+
it('return true if value passed is abc(non boolean)', () => {
3947+
expect(utils.isNonBooleanValue("abc")).to.be.eql(true);
3948+
});
3949+
3950+
it('return false if value passed is false(boolean)', () => {
3951+
expect(utils.isNonBooleanValue("false")).to.be.eql(false);
3952+
});
3953+
3954+
it('return false if value passed is true(boolean)', () => {
3955+
expect(utils.isNonBooleanValue(true)).to.be.eql(false);
3956+
});
3957+
});
3958+
3959+
describe('#isConflictingBooleanValues' , () => {
3960+
it('return false if value passed is true and true', () => {
3961+
expect(utils.isConflictingBooleanValues(true, true)).to.be.eql(false);
3962+
});
3963+
3964+
it('return false if value passed is false and "false"', () => {
3965+
expect(utils.isConflictingBooleanValues(false, "false")).to.be.eql(false);
3966+
});
3967+
3968+
it('return true if value passed is "true" and "false"', () => {
3969+
expect(utils.isConflictingBooleanValues("true", "false")).to.be.eql(true);
3970+
});
3971+
3972+
it('return true if value passed is true and "false"', () => {
3973+
expect(utils.isConflictingBooleanValues(true, "false")).to.be.eql(true);
3974+
});
3975+
3976+
it('return false if value passed is false and "true"', () => {
3977+
expect(utils.isConflictingBooleanValues(false, "true")).to.be.eql(true);
3978+
});
3979+
3980+
it('return false if value passed is false and "false"', () => {
3981+
expect(utils.isConflictingBooleanValues(false, "false")).to.be.eql(false);
3982+
});
3983+
});
3984+
3985+
describe('#setInteractiveCapability' , () => {
3986+
it('should set true if interactive caps is not passed', () => {
3987+
let bsConfig = {
3988+
run_settings: {}
3989+
}
3990+
let expectedResult = {
3991+
run_settings: {
3992+
interactiveDebugging: "true"
3993+
}
3994+
}
3995+
utils.setInteractiveCapability(bsConfig);
3996+
expect(bsConfig).to.be.eql(expectedResult);
3997+
});
3998+
3999+
it('should set true if interactiveDebugging caps passed is true', () => {
4000+
let bsConfig = {
4001+
run_settings: {
4002+
interactiveDebugging: true
4003+
}
4004+
}
4005+
let expectedResult = {
4006+
run_settings: {
4007+
interactiveDebugging: true
4008+
}
4009+
}
4010+
utils.setInteractiveCapability(bsConfig);
4011+
expect(bsConfig).to.be.eql(expectedResult);
4012+
});
4013+
4014+
it('should set true if interactive_debugging caps passed is true', () => {
4015+
let bsConfig = {
4016+
run_settings: {
4017+
interactive_debugging: true
4018+
}
4019+
}
4020+
let expectedResult = {
4021+
run_settings: {
4022+
interactive_debugging: true,
4023+
interactiveDebugging: true
4024+
}
4025+
}
4026+
utils.setInteractiveCapability(bsConfig);
4027+
expect(bsConfig).to.be.eql(expectedResult);
4028+
});
4029+
4030+
it('should set false if interactive_debugging caps passed is false', () => {
4031+
let bsConfig = {
4032+
run_settings: {
4033+
interactive_debugging: false
4034+
}
4035+
}
4036+
let expectedResult = {
4037+
run_settings: {
4038+
interactive_debugging: false,
4039+
interactiveDebugging: false
4040+
}
4041+
}
4042+
utils.setInteractiveCapability(bsConfig);
4043+
expect(bsConfig).to.be.eql(expectedResult);
4044+
});
4045+
4046+
it('should set false if interactiveDebugging caps passed is false', () => {
4047+
let bsConfig = {
4048+
run_settings: {
4049+
interactiveDebugging: false
4050+
}
4051+
}
4052+
let expectedResult = {
4053+
run_settings: {
4054+
interactiveDebugging: false
4055+
}
4056+
}
4057+
utils.setInteractiveCapability(bsConfig);
4058+
expect(bsConfig).to.be.eql(expectedResult);
4059+
});
4060+
});
4061+
39414062
describe('#setCypressNpmDependency', () => {
39424063

39434064
it('should set cypress as latest for cypress 10 test suite if cypress_version missing', () => {

0 commit comments

Comments
 (0)