Best JavaScript code snippet using redwood
executionengine.js
Source:executionengine.js
...738 //result.result = testcase.dbTestCase.status;739 result.result = error;740 updateResult(result);741 //executions[executionID].testcases[id].result = result;742 finishTestCaseExecution(executions[executionID],executionID,executions[executionID].testcases[id]._id,executions[executionID].currentTestCases[id]);743 callback();744 return;745 }746 //if there is nothing to execute just finish the TC747 if (((testcase.dbTestCase.type === "collection")&&(testcase.actions.length == 0)) || ((testcase.dbTestCase.type === "script")&&(testcase.dbTestCase.script == ""))){748 //if (callback){749 // callback();750 //}751 result.status = "Finished";752 result.result = "Passed";753 updateResult(result);754 finishTestCaseExecution(executions[executionID],executionID,executions[executionID].testcases[id]._id,executions[executionID].currentTestCases[id]);755 callback();756 return;757 }758 //updateExecutionTestCase({_id:testcases[0]._id.executionTestCaseID},{$set:{"status":"Running"}});759 var machines = executions[executionID].machines;760 machines.sort(function(a,b){761 return a.roles.length - b.roles.length;762 });763 /*764 var reservedHosts = [];765 testcase.machines = [];766 testcase.machineVars = [];767 machines.forEach(function(machine,index){768 hosts.forEach(function(host){769 if((machine.roles.indexOf(host) != -1)&& (reservedHosts.indexOf(host) == -1) &&((machine.runningTC == undefined)||(machine.runningTC == testcase))){770 machine.runningTC = testcase;771 reservedHosts.push(host);772 testcase.machines.push(machine);773 machine.roles.forEach(function(role){774 if (machine.machineVars){775 machine.machineVars.forEach(function(variable){776 testcase.machineVars["Machine."+role+"."+variable.name] = variable.value777 });778 }779 testcase.machineVars["Machine."+role+".Host"] = machine.host;780 testcase.machineVars["Machine."+role+".Port"] = machine.port;781 })782 }783 });784 });785 */786 if ((testcase.machines.length == 0) || (reservedHosts.length != hosts.length)){787 //if (callback){788 // callback({error:"Unable to find matching machine for this test case. Roles required are:"+hosts.join()});789 //}790 //updateExecutionTestCase({_id:executions[executionID].testcases[id]._id},{$set:{"status":"Finished",result:"Failed",resultID:result._id,error:"Unable to find matching machine for this test case. Roles required are:"+hosts.join()}});791 result.error = "Unable to find matching machine for this test case. Roles required are:"+hosts.join();792 result.status = "Finished";793 result.result = "Failed";794 updateResult(result);795 finishTestCaseExecution(executions[executionID],executionID,executions[executionID].testcases[id]._id,executions[executionID].currentTestCases[id]);796 callback();797 return;798 }799 var count = 0;800 var errorFound = false;801 //var startTC = function(){802 //var agentInstructions = {command:"run action",executionID:executionID,testcaseID:testcase.dbTestCase._id,variables:executions[executionID].variables};803 var agentInstructions = {command:"run action",executionID:executionID,testcaseID:id,variables:executions[executionID].variables};804 var foundMachine = null;805 var runBaseState = function(){806 agentBaseState(executions[executionID].project+"/"+executions[executionID].username,executionID,foundMachine.host,foundMachine.port,foundMachine.threadID,function(err){807 if (err){808 result.error = err.error;809 result.status = "Finished";810 result.result = "Failed";811 updateResult(result);812 if (executions[executionID] && executions[executionID].currentTestCases[id]){813 executions[executionID].currentTestCases[id].result = result;814 finishTestCaseExecution(executions[executionID],executionID,executions[executionID].testcases[id]._id,executions[executionID].currentTestCases[id]);815 }816 }817 else{818 foundMachine.runBaseState = true;819 sendAgentCommand(foundMachine.host,foundMachine.port,agentInstructions,3);820 }821 });822 };823 //if test case is a script and NOT an action collection824 if (testcase.dbTestCase.type !== "collection"){825 if ((testcase.script == "") || (!testcase.script)){826 result.error = "Test Case does not have a script assigned";827 result.status = "Finished";828 result.result = "Failed";829 updateResult(result);830 //executions[executionID].testcases[id].result = result;831 finishTestCaseExecution(executions[executionID],executionID,executions[executionID].testcases[id]._id,executions[executionID].currentTestCases[id]);832 return;833 }834 agentInstructions.name = testcase.name;835 agentInstructions.ignoreScreenshots = executions[executionID].ignoreScreenshots;836 agentInstructions.allScreenshots = executions[executionID].allScreenshots;837 agentInstructions.executionID = executionID;838 agentInstructions.testcaseName = testcase.name;839 agentInstructions.script = testcase.script;840 agentInstructions.scriptLang = testcase.scriptLang;841 agentInstructions.resultID = result._id.toString();842 agentInstructions.parameters = [];843 agentInstructions.type = testcase.dbTestCase.type;844 var actionHost = "Default";845 //if(action.dbAction.host != "") actionHost = action.dbAction.host;846 testcase.machines.forEach(function(machine){847 if ((machine.roles.indexOf(actionHost) != -1)&&(foundMachine == null)){848 foundMachine = machine;849 }850 });851 agentInstructions.threadID = foundMachine.threadID;852 updateExecutionTestCase({_id:executions[executionID].testcases[id]._id},{$set:{"status":"Running","result":"",error:"",trace:"",resultID:result._id,startdate:testcase.startDate,enddate:"",runtime:"",host:foundMachine.host,vncport:foundMachine.vncport}},foundMachine.host,foundMachine.vncport);853 executionsRoute.updateExecutionTotals(executionID);854 if (foundMachine.runBaseState === true){855 if (foundMachine.multiThreaded == true){856 sendAgentCommand(foundMachine.host,foundMachine.port,agentInstructions,30);857 }858 else{859 //make sure the files are actually there, in case of revert to snapshot or not persistent VMs files860 //could have changed while test case was running861 sendAgentCommand(foundMachine.host,foundMachine.port,{command:"files loaded",executionID:executionID},30,function(message){862 if (message.loaded == true){863 sendAgentCommand(foundMachine.host,foundMachine.port,agentInstructions,30);864 }865 else{866 runBaseState();867 }868 });869 }870 }871 else{872 runBaseState();873 }874 callback();875 return;876 }877 findNextAction(testcase.actions,testcase.variables,function(action){878 if (!executions[executionID]) return;879 if(!executions[executionID].currentTestCases[id]) return;880 if(action == null){881 finishTestCaseExecution(executions[executionID],executionID,executions[executionID].testcases[id]._id,executions[executionID].currentTestCases[id]);882 return;883 }884 executions[executionID].currentTestCases[id].currentAction = action;885 agentInstructions.name = action.name;886 agentInstructions.executionflow = action.dbAction.executionflow;887 agentInstructions.executionID = executionID;888 agentInstructions.ignoreScreenshots = executions[executionID].ignoreScreenshots;889 agentInstructions.allScreenshots = executions[executionID].allScreenshots;890 agentInstructions.returnValueName = action.dbAction.returnvalue;891 agentInstructions.testcaseName = testcase.dbTestCase.name;892 agentInstructions.script = action.script;893 agentInstructions.scriptLang = action.scriptLang;894 agentInstructions.resultID = result._id.toString();895 agentInstructions.parameters = [];896 action.dbAction.parameters.forEach(function(parameter){897 agentInstructions.parameters.push({name:parameter.paramname,value:parameter.paramvalue});898 });899 var actionHost = "Default";900 if(action.dbAction.host != "") actionHost = action.dbAction.host;901 testcase.machines.forEach(function(machine){902 if ((machine.roles.indexOf(actionHost) != -1)&&(foundMachine == null)){903 foundMachine = machine;904 }905 });906 callback();907 agentInstructions.threadID = foundMachine.threadID;908 updateExecutionTestCase({_id:executions[executionID].testcases[id]._id},{$set:{"status":"Running","result":"",error:"",trace:"",resultID:result._id,startdate:testcase.startDate,enddate:"",runtime:"",host:foundMachine.host,vncport:foundMachine.vncport}},foundMachine.host,foundMachine.vncport);909 if ((testcase.machines.length > 0) &&((testcase.machines[0].baseState))){910 updateExecutionMachine(executionID,testcase.machines[0]._id,"",result._id.toString());911 }912 executionsRoute.updateExecutionTotals(executionID);913 if (foundMachine.runBaseState === true){914 if (foundMachine.multiThreaded == true){915 sendAgentCommand(foundMachine.host,foundMachine.port,agentInstructions,30);916 }917 else{918 //make sure the files are actually there, in case of revert to snapshot or not persistent VMs files919 //could have changed while test case was running920 sendAgentCommand(foundMachine.host,foundMachine.port,{command:"files loaded",executionID:executionID},30,function(message){921 if (message.loaded == true){922 sendAgentCommand(foundMachine.host,foundMachine.port,agentInstructions,30);923 }924 else{925 runBaseState();926 }927 });928 }929 }930 else{931 runBaseState();932 }933 });934 })935 });936}937exports.logPost = function(req,res){938 var insertLogMessage = function(record){939 var executionID = record.executionID.replace(/-/g, '');940 delete record.command;941 delete record.executionID;942 db.collection('executionlogs'+executionID, function(err, collection) {943 collection.insert(record, {safe:true},function(err,returnData){944 });945 });946 };947 if(Array.isArray(req.body) == true){948 req.body.forEach(function(record){949 insertLogMessage(record);950 });951 realtime.emitMessage("AddExecutionLog",req.body);952 }953 else{954 insertLogMessage(req.body);955 realtime.emitMessage("AddExecutionLog",[req.body]);956 }957 res.contentType('json');958 res.set('Connection','Close');959 res.json({success:true});960};961exports.actionresultPost = function(req, res){962 res.contentType('json');963 res.set('Connection','Close');964 res.json({success:true});965 var execution = executions[req.body.executionID];966 if (!execution) return;967 var testcase = execution.currentTestCases[req.body.testcaseID];968 if (testcase == undefined) return;969 if (testcase.testcase.script){970 testcase.result.status = "Finished";971 testcase.result.result = req.body.result;972 if (req.body.error){973 testcase.result.error = req.body.error;974 }975 else{976 testcase.result.error = "";977 }978 if (req.body.trace){979 formatTrace(req.body.trace,execution.sourceCache,function(trace){980 testcase.result.trace = trace;981 testcase.trace = trace;982 if(trace == "") testcase.result.trace = req.body.trace;983 updateResult(testcase.result);984 });985 }986 else{987 updateResult(testcase.result);988 }989 finishTestCaseExecution(execution,req.body.executionID,execution.testcases[testcase.executionTestCaseID]._id,testcase);990 return;991 }992 var actionFlow = testcase.currentAction.dbAction.executionflow;993 testcase.currentAction.result.status = "Finished";994 testcase.currentAction.result.result = req.body.result;995 if (req.body.error && actionFlow != "Ignore Error Continue Test Case"){996 testcase.result.error = req.body.error;997 testcase.currentAction.result.error = req.body.error;998 }999 if(!testcase.result.error){1000 testcase.result.error = "";1001 }1002 if (req.body.trace && actionFlow != "Ignore Error Continue Test Case"){1003 testcase.result.trace = req.body.trace;1004 testcase.currentAction.result.trace = req.body.trace;1005 testcase.trace = req.body.trace;1006 }1007 if (req.body.screenshot){1008 testcase.result.screenshot = req.body.screenshot;1009 testcase.currentAction.result.screenshot = req.body.screenshot;1010 }1011 if ((req.body.returnValue)&&(testcase.currentAction.dbAction.returnvalue != "")){1012 if(!execution.returnVars[req.body.testcaseID]){1013 execution.returnVars[req.body.testcaseID] = {};1014 }1015 execution.returnVars[req.body.testcaseID][testcase.currentAction.dbAction.returnvalue] = req.body.returnValue;1016 //.[testcase.currentAction.dbAction.returnvalue] = req.body.returnValue;1017 //execution.variables[testcase.currentAction.dbAction.returnvalue] = req.body.returnValue;1018 }1019 if (req.body.result == "Failed"){1020 if (actionFlow == "Record Error Stop Test Case"){1021 testcase.result.status = "Finished";1022 testcase.result.result = "Failed";1023 testcase.runAfterState = true;1024 testcase.testcase.actions.forEach(function(action){1025 if(!action.dbAction.afterState == true){1026 action.runAction = false;1027 }1028 });1029 //updateExecutionTestCase({_id:execution.testcases[testcase.executionTestCaseID]._id},{$set:{error:testcase.result.error,trace:testcase.trace}});1030 /*1031 markFinishedResults(testcase.result.children,execution.sourceCache,function(){1032 updateResult(testcase.result);1033 });1034 finishTestCaseExecution(execution,req.body.executionID,execution.testcases[testcase.executionTestCaseID]._id,testcase);1035 return;1036 */1037 }1038 else if (actionFlow == "Record Error Continue Test Case"){1039 testcase.result.result = "Failed";1040 updateExecutionTestCase({_id:execution.testcases[testcase.executionTestCaseID]._id},{$set:{result:"Failed",trace:testcase.trace}});1041 }1042 else{1043 testcase.currentAction.result.result = "";1044 testcase.currentAction.result.trace = "";1045 testcase.currentAction.result.error = "";1046 //testcase.result.result = "";1047 //testcase.result.error = "";1048 }1049 }1050 var actionVariables = {};1051 for (var attrname in testcase.testcase.variables) { actionVariables[attrname] = testcase.testcase.variables[attrname]; }1052 for (var attrname in testcase.machineVars) { actionVariables[attrname] = testcase.machineVars[attrname]; }1053 if(execution.returnVars[testcase.executionTestCaseID]){1054 for (var attrname in execution.returnVars[testcase.executionTestCaseID]) { actionVariables[attrname] = execution.returnVars[testcase.executionTestCaseID][attrname]; }1055 }1056 findNextAction(testcase.testcase.actions,actionVariables,function(action){1057 if(action == null){1058 testcase.result.status = "Finished";1059 if(testcase.result.result != "Failed") testcase.result.result = "Passed";1060 markFinishedResults(testcase.result.children,execution.sourceCache,function(){1061 updateResult(testcase.result);1062 });1063 finishTestCaseExecution(execution,req.body.executionID,execution.testcases[testcase.executionTestCaseID]._id,testcase);1064 return;1065 }1066 else{1067 markFinishedResults(testcase.result.children,execution.sourceCache,function(){1068 updateResult(testcase.result);1069 });1070 }1071 var foundMachine = null;1072 var actionHost = "Default";1073 if(action.dbAction.host != "") actionHost = action.dbAction.host;1074 testcase.testcase.machines.forEach(function(machine){1075 if ((machine.roles.indexOf(actionHost) != -1)&&(foundMachine == null)){1076 foundMachine = machine;1077 }1078 });1079 updateExecutionTestCase({_id:execution.testcases[testcase.executionTestCaseID]._id},{$set:{"status":"Running","result":"",host:foundMachine.host,vncport:foundMachine.vncport}},foundMachine.host,foundMachine.vncport);1080 testcase.result.status = "Running";1081 var agentInstructions = {command:"run action",executionID:req.body.executionID,threadID:foundMachine.threadID,testcaseID:testcase.executionTestCaseID,variables:testcase.testcase.variables};1082 execution.currentTestCases[testcase.executionTestCaseID].currentAction = action;1083 agentInstructions.name = action.name;1084 agentInstructions.executionflow = action.dbAction.executionflow;1085 agentInstructions.executionID = req.body.executionID;1086 agentInstructions.ignoreScreenshots = executions[req.body.executionID].ignoreScreenshots;1087 agentInstructions.allScreenshots = executions[req.body.executionID].allScreenshots;1088 agentInstructions.returnValueName = action.dbAction.returnvalue;1089 agentInstructions.testcaseName = testcase.testcase.dbTestCase.name;1090 agentInstructions.script = action.script;1091 agentInstructions.scriptLang = action.scriptLang;1092 agentInstructions.resultID = testcase.result._id.toString();1093 agentInstructions.parameters = [];1094 action.dbAction.parameters.forEach(function(parameter){1095 agentInstructions.parameters.push({name:parameter.paramname,value:parameter.paramvalue});1096 });1097 var runBaseState = function(){1098 agentBaseState(execution.project+"/"+execution.username,req.body.executionID,foundMachine.host,foundMachine.port,foundMachine.threadID,function(err){1099 if (err){1100 testcase.result.error = err.error;1101 testcase.result.status = "Finished";1102 testcase.result.result = "Failed";1103 updateResult(testcase.result);1104 if (execution && testcase.dbTestCase){1105 execution.currentTestCases[testcase.executionTestCaseID].result = "Failed";1106 finishTestCaseExecution(execution,req.body.executionID,execution.testcases[id]._id,execution.currentTestCases[testcase.executionTestCaseID]);1107 }1108 }1109 else{1110 foundMachine.runBaseState = true;1111 sendAgentCommand(foundMachine.host,foundMachine.port,agentInstructions,3);1112 }1113 });1114 };1115 if (foundMachine.runBaseState === true){1116 if (foundMachine.multiThreaded == true){1117 sendAgentCommand(foundMachine.host,foundMachine.port,agentInstructions,3);1118 }1119 else{1120 //make sure the files are actually there, in case of revert to snapshot or not persistent VMs files1121 //could have changed while test case was running1122 sendAgentCommand(foundMachine.host,foundMachine.port,{command:"files loaded",executionID:req.body.executionID},3,function(message){1123 if (message.loaded == true){1124 sendAgentCommand(foundMachine.host,foundMachine.port,agentInstructions,3);1125 }1126 else{1127 runBaseState();1128 }1129 });1130 }1131 }1132 else{1133 runBaseState();1134 }1135 });1136};1137//last action or we are done with the TC1138//start next test case if there is one1139function finishTestCaseExecution(execution,executionID,testcaseId,testcase){1140 //updateExecutionTestCase({_id:execution.testcases[testcase.executionTestCaseID]._id},{$set:{"status":"Finished",result:testcase.result.result}});1141 var date = new Date();1142 var status = "Finished";1143 if((testcase.result.result != "Passed") && (testcase.result.result != "Failed")){1144 status = "Not Run";1145 }1146 var updateTC = function(){1147 updateExecutionTestCase({_id:testcaseId},{$set:{trace:testcase.trace,"status":status,resultID:testcase.result._id.toString(),result:testcase.result.result,error:testcase.result.error,enddate:date,runtime:date-testcase.testcase.startDate,host:"",vncport:""}});1148 executionsRoute.updateExecutionTotals(executionID);1149 };1150 //update machine base state result1151 if(execution.cachedTCs){1152 if (testcase.testcase.machines.length > 0){1153 updateExecutionMachine(executionID,testcase.testcase.machines[0]._id,testcase.result.result,testcase.result._id.toString(),function(){...
executionengine original.js
Source:executionengine original.js
...664 //result.result = testcase.dbTestCase.status;665 result.result = error;666 updateResult(result);667 //executions[executionID].testcases[id].result = result;668 finishTestCaseExecution(executions[executionID],executionID,executions[executionID].testcases[id]._id,executions[executionID].currentTestCases[testcase.dbTestCase._id]);669 callback();670 return;671 }672 //if there is nothing to execute just finish the TC673 if (((testcase.dbTestCase.type === "collection")&&(testcase.actions.length == 0)) || ((testcase.dbTestCase.type === "script")&&(testcase.dbTestCase.script == ""))){674 //if (callback){675 // callback();676 //}677 result.status = "Finished";678 result.result = "Passed";679 updateResult(result);680 finishTestCaseExecution(executions[executionID],executionID,executions[executionID].testcases[id]._id,executions[executionID].currentTestCases[testcase.dbTestCase._id]);681 callback();682 return;683 }684 //updateExecutionTestCase({_id:testcases[0]._id.executionTestCaseID},{$set:{"status":"Running"}});685 var machines = executions[executionID].machines;686 machines.sort(function(a,b){687 return a.roles.length - b.roles.length;688 });689 /*690 var reservedHosts = [];691 testcase.machines = [];692 testcase.machineVars = [];693 machines.forEach(function(machine,index){694 hosts.forEach(function(host){695 if((machine.roles.indexOf(host) != -1)&& (reservedHosts.indexOf(host) == -1) &&((machine.runningTC == undefined)||(machine.runningTC == testcase))){696 machine.runningTC = testcase;697 reservedHosts.push(host);698 testcase.machines.push(machine);699 machine.roles.forEach(function(role){700 if (machine.machineVars){701 machine.machineVars.forEach(function(variable){702 testcase.machineVars["Machine."+role+"."+variable.name] = variable.value703 });704 }705 testcase.machineVars["Machine."+role+".Host"] = machine.host;706 testcase.machineVars["Machine."+role+".Port"] = machine.port;707 })708 }709 });710 });711 */712 if ((testcase.machines.length == 0) || (reservedHosts.length != hosts.length)){713 //if (callback){714 // callback({error:"Unable to find matching machine for this test case. Roles required are:"+hosts.join()});715 //}716 //updateExecutionTestCase({_id:executions[executionID].testcases[id]._id},{$set:{"status":"Finished",result:"Failed",resultID:result._id,error:"Unable to find matching machine for this test case. Roles required are:"+hosts.join()}});717 result.error = "Unable to find matching machine for this test case. Roles required are:"+hosts.join();718 result.status = "Finished";719 result.result = "Failed";720 updateResult(result);721 finishTestCaseExecution(executions[executionID],executionID,executions[executionID].testcases[id]._id,executions[executionID].currentTestCases[testcase.dbTestCase._id]);722 callback();723 return;724 }725 var count = 0;726 var errorFound = false;727 //var startTC = function(){728 var agentInstructions = {command:"run action",executionID:executionID,testcaseID:testcase.dbTestCase._id,variables:executions[executionID].variables};729 var foundMachine = null;730 var runBaseState = function(){731 agentBaseState(executions[executionID].project+"/"+executions[executionID].username,executionID,foundMachine.host,foundMachine.port,foundMachine.threadID,function(err){732 if (err){733 result.error = err.error;734 result.status = "Finished";735 result.result = "Failed";736 updateResult(result);737 if (executions[executionID]){738 executions[executionID].currentTestCases[testcase.dbTestCase._id].result = result;739 finishTestCaseExecution(executions[executionID],executionID,executions[executionID].testcases[id]._id,executions[executionID].currentTestCases[testcase.dbTestCase._id]);740 }741 }742 else{743 foundMachine.runBaseState = true;744 sendAgentCommand(foundMachine.host,foundMachine.port,agentInstructions,3);745 }746 });747 };748 //if test case is a script and NOT an action collection749 if (testcase.dbTestCase.type !== "collection"){750 if ((testcase.script == "") || (!testcase.script)){751 result.error = "Test Case does not have a script assigned";752 result.status = "Finished";753 result.result = "Failed";754 updateResult(result);755 //executions[executionID].testcases[id].result = result;756 finishTestCaseExecution(executions[executionID],executionID,executions[executionID].testcases[id]._id,executions[executionID].currentTestCases[testcase.dbTestCase._id]);757 return;758 }759 agentInstructions.name = testcase.name;760 agentInstructions.ignoreScreenshots = executions[executionID].ignoreScreenshots;761 agentInstructions.allScreenshots = executions[executionID].allScreenshots;762 agentInstructions.executionID = executionID;763 agentInstructions.testcaseName = testcase.name;764 agentInstructions.script = testcase.script;765 agentInstructions.scriptLang = testcase.scriptLang;766 agentInstructions.resultID = result._id.__id;767 agentInstructions.parameters = [];768 agentInstructions.type = testcase.dbTestCase.type;769 var actionHost = "Default";770 //if(action.dbAction.host != "") actionHost = action.dbAction.host;771 testcase.machines.forEach(function(machine){772 if ((machine.roles.indexOf(actionHost) != -1)&&(foundMachine == null)){773 foundMachine = machine;774 }775 });776 agentInstructions.threadID = foundMachine.threadID;777 updateExecutionTestCase({_id:executions[executionID].testcases[id]._id},{$set:{"status":"Running","result":"",error:"",trace:"",resultID:result._id,startdate:testcase.startDate,enddate:"",runtime:"",host:foundMachine.host,vncport:foundMachine.vncport}},foundMachine.host,foundMachine.vncport);778 executionsRoute.updateExecutionTotals(executionID);779 if (foundMachine.runBaseState === true){780 if (foundMachine.multiThreaded == true){781 sendAgentCommand(foundMachine.host,foundMachine.port,agentInstructions,3);782 }783 else{784 //make sure the files are actually there, in case of revert to snapshot or not persistent VMs files785 //could have changed while test case was running786 sendAgentCommand(foundMachine.host,foundMachine.port,{command:"files loaded",executionID:executionID},3,function(message){787 if (message.loaded == true){788 sendAgentCommand(foundMachine.host,foundMachine.port,agentInstructions,3);789 }790 else{791 runBaseState();792 }793 });794 }795 }796 else{797 runBaseState();798 }799 callback();800 return;801 }802 callback();803 for (var attrname in testcase.machineVars) { variables[attrname] = testcase.machineVars[attrname]; }804 variables["Framework.TestCaseName"] = testcase.dbTestCase.name;805 findNextAction(testcase.actions,variables,function(action){806 if (!executions[executionID]) return;807 if(!executions[executionID].currentTestCases[testcase.dbTestCase._id]) return;808 if(action == null){809 finishTestCaseExecution(executions[executionID],executionID,executions[executionID].testcases[id]._id,executions[executionID].currentTestCases[testcase.dbTestCase._id]);810 return;811 }812 executions[executionID].currentTestCases[testcase.dbTestCase._id].currentAction = action;813 agentInstructions.name = action.name;814 agentInstructions.executionflow = action.dbAction.executionflow;815 agentInstructions.executionID = executionID;816 agentInstructions.ignoreScreenshots = executions[executionID].ignoreScreenshots;817 agentInstructions.allScreenshots = executions[executionID].allScreenshots;818 agentInstructions.returnValueName = action.dbAction.returnvalue;819 agentInstructions.testcaseName = testcase.dbTestCase.name;820 agentInstructions.script = action.script;821 agentInstructions.scriptLang = action.scriptLang;822 agentInstructions.resultID = result._id.__id;823 agentInstructions.parameters = [];824 action.dbAction.parameters.forEach(function(parameter){825 agentInstructions.parameters.push({name:parameter.paramname,value:parameter.paramvalue});826 });827 var actionHost = "Default";828 if(action.dbAction.host != "") actionHost = action.dbAction.host;829 testcase.machines.forEach(function(machine){830 if ((machine.roles.indexOf(actionHost) != -1)&&(foundMachine == null)){831 foundMachine = machine;832 }833 });834 agentInstructions.threadID = foundMachine.threadID;835 updateExecutionTestCase({_id:executions[executionID].testcases[id]._id},{$set:{"status":"Running","result":"",error:"",trace:"",resultID:result._id,startdate:testcase.startDate,enddate:"",runtime:"",host:foundMachine.host,vncport:foundMachine.vncport}},foundMachine.host,foundMachine.vncport);836 if ((testcase.machines.length > 0) &&((testcase.machines[0].baseState))){837 updateExecutionMachine(executionID,testcase.machines[0]._id,"",result._id.__id);838 }839 executionsRoute.updateExecutionTotals(executionID);840 if (foundMachine.runBaseState === true){841 if (foundMachine.multiThreaded == true){842 sendAgentCommand(foundMachine.host,foundMachine.port,agentInstructions,3);843 }844 else{845 //make sure the files are actually there, in case of revert to snapshot or not persistent VMs files846 //could have changed while test case was running847 sendAgentCommand(foundMachine.host,foundMachine.port,{command:"files loaded",executionID:executionID},3,function(message){848 if (message.loaded == true){849 sendAgentCommand(foundMachine.host,foundMachine.port,agentInstructions,3);850 }851 else{852 runBaseState();853 }854 });855 }856 }857 else{858 runBaseState();859 }860 });861 })862 });863}864exports.logPost = function(req,res){865 var record = req.body;866 var executionID = record.executionID.replace(/-/g, '');867 delete record.command;868 delete record.executionID;869 db.collection('executionlogs'+executionID, function(err, collection) {870 collection.insert(record, {safe:true},function(err,returnData){871 res.contentType('json');872 res.json({success:true});873 realtime.emitMessage("AddExecutionLog",record);874 });875 });876};877exports.actionresultPost = function(req, res){878 res.contentType('json');879 res.json({success:true});880 var execution = executions[req.body.executionID];881 if (!execution) return;882 var testcase = execution.currentTestCases[req.body.testcaseID];883 if (testcase == undefined) return;884 if (testcase.testcase.script){885 testcase.result.status = "Finished";886 testcase.result.result = req.body.result;887 if (req.body.error){888 testcase.result.error = req.body.error;889 }890 else{891 testcase.result.error = "";892 }893 if (req.body.trace){894 formatTrace(req.body.trace,execution.sourceCache,function(trace){895 testcase.result.trace = trace;896 if(trace == "") testcase.result.trace = req.body.trace;897 updateResult(testcase.result);898 });899 }900 else{901 updateResult(testcase.result);902 }903 finishTestCaseExecution(execution,req.body.executionID,execution.testcases[testcase.executionTestCaseID]._id,testcase);904 return;905 }906 testcase.currentAction.result.status = "Finished";907 testcase.currentAction.result.result = req.body.result;908 if(!testcase.result.error){909 testcase.result.error = "";910 }911 if (req.body.error){912 testcase.result.error = req.body.error;913 testcase.currentAction.result.error = req.body.error;914 }915 if (req.body.trace){916 testcase.result.trace = req.body.trace;917 testcase.currentAction.result.trace = req.body.trace;918 testcase.trace = req.body.trace;919 }920 if (req.body.screenshot){921 testcase.result.screenshot = req.body.screenshot;922 testcase.currentAction.result.screenshot = req.body.screenshot;923 }924 if ((req.body.returnValue)&&(testcase.currentAction.dbAction.returnvalue != "")){925 if(!execution.returnVars[req.body.testcaseID]){926 execution.returnVars[req.body.testcaseID] = {};927 }928 execution.returnVars[req.body.testcaseID][testcase.currentAction.dbAction.returnvalue] = req.body.returnValue;929 //.[testcase.currentAction.dbAction.returnvalue] = req.body.returnValue;930 //execution.variables[testcase.currentAction.dbAction.returnvalue] = req.body.returnValue;931 }932 var actionFlow = testcase.currentAction.dbAction.executionflow;933 if (req.body.result == "Failed"){934 if (actionFlow == "Record Error Stop Test Case"){935 testcase.result.status = "Finished";936 testcase.result.result = "Failed";937 testcase.runAfterState = true;938 testcase.testcase.actions.forEach(function(action){939 if(!action.dbAction.afterState == true){940 action.runAction = false;941 }942 });943 //updateExecutionTestCase({_id:execution.testcases[testcase.executionTestCaseID]._id},{$set:{error:testcase.result.error,trace:testcase.trace}});944 /*945 markFinishedResults(testcase.result.children,execution.sourceCache,function(){946 updateResult(testcase.result);947 });948 finishTestCaseExecution(execution,req.body.executionID,execution.testcases[testcase.executionTestCaseID]._id,testcase);949 return;950 */951 }952 else if (actionFlow == "Record Error Continue Test Case"){953 testcase.result.result = "Failed";954 updateExecutionTestCase({_id:execution.testcases[testcase.executionTestCaseID]._id},{$set:{result:"Failed",trace:testcase.trace}});955 }956 else{957 testcase.currentAction.result.result = "";958 testcase.currentAction.result.trace = "";959 testcase.currentAction.result.error = "";960 testcase.result.result = "";961 testcase.result.error = "";962 }963 }964 markFinishedResults(testcase.result.children,execution.sourceCache,function(){965 updateResult(testcase.result);966 });967 var actionVariables = {};968 for (var attrname in execution.variables) { actionVariables[attrname] = execution.variables[attrname]; }969 for (var attrname in testcase.machineVars) { actionVariables[attrname] = testcase.machineVars[attrname]; }970 if(execution.returnVars[testcase.executionTestCaseID]){971 for (var attrname in execution.returnVars[testcase.executionTestCaseID]) { actionVariables[attrname] = execution.returnVars[testcase.executionTestCaseID][attrname]; }972 }973 findNextAction(testcase.testcase.actions,actionVariables,function(action){974 if(action == null){975 testcase.result.status = "Finished";976 if(testcase.result.result != "Failed") testcase.result.result = "Passed";977 updateResult(testcase.result);978 finishTestCaseExecution(execution,req.body.executionID,execution.testcases[testcase.executionTestCaseID]._id,testcase);979 return;980 }981 var foundMachine = null;982 var actionHost = "Default";983 if(action.dbAction.host != "") actionHost = action.dbAction.host;984 testcase.testcase.machines.forEach(function(machine){985 if ((machine.roles.indexOf(actionHost) != -1)&&(foundMachine == null)){986 foundMachine = machine;987 }988 });989 updateExecutionTestCase({_id:execution.testcases[testcase.executionTestCaseID]._id},{$set:{"status":"Running","result":"",host:foundMachine.host,vncport:foundMachine.vncport}},foundMachine.host,foundMachine.vncport);990 testcase.result.status = "Running";991 var agentInstructions = {command:"run action",executionID:req.body.executionID,threadID:foundMachine.threadID,testcaseID:testcase.testcase.dbTestCase._id,variables:execution.variables};992 execution.currentTestCases[testcase.testcase.dbTestCase._id].currentAction = action;993 agentInstructions.name = action.name;994 agentInstructions.executionflow = action.dbAction.executionflow;995 agentInstructions.executionID = req.body.executionID;996 agentInstructions.ignoreScreenshots = executions[req.body.executionID].ignoreScreenshots;997 agentInstructions.allScreenshots = executions[req.body.executionID].allScreenshots;998 agentInstructions.returnValueName = action.dbAction.returnvalue;999 agentInstructions.testcaseName = testcase.testcase.dbTestCase.name;1000 agentInstructions.script = action.script;1001 agentInstructions.scriptLang = action.scriptLang;1002 agentInstructions.resultID = testcase.result._id.__id;1003 agentInstructions.parameters = [];1004 action.dbAction.parameters.forEach(function(parameter){1005 agentInstructions.parameters.push({name:parameter.paramname,value:parameter.paramvalue});1006 });1007 var runBaseState = function(){1008 agentBaseState(execution.project+"/"+execution.username,req.body.executionID,foundMachine.host,foundMachine.port,foundMachine.threadID,function(err){1009 if (err){1010 testcase.result.error = err.error;1011 testcase.result.status = "Finished";1012 testcase.result.result = "Failed";1013 updateResult(testcase.result);1014 if (execution){1015 execution.currentTestCases[testcase.dbTestCase._id].result = "Failed";1016 finishTestCaseExecution(execution,req.body.executionID,execution.testcases[id]._id,execution.currentTestCases[testcase.dbTestCase._id]);1017 }1018 }1019 else{1020 foundMachine.runBaseState = true;1021 sendAgentCommand(foundMachine.host,foundMachine.port,agentInstructions,3);1022 }1023 });1024 };1025 if (foundMachine.runBaseState === true){1026 if (foundMachine.multiThreaded == true){1027 sendAgentCommand(foundMachine.host,foundMachine.port,agentInstructions,3);1028 }1029 else{1030 //make sure the files are actually there, in case of revert to snapshot or not persistent VMs files1031 //could have changed while test case was running1032 sendAgentCommand(foundMachine.host,foundMachine.port,{command:"files loaded",executionID:req.body.executionID},3,function(message){1033 if (message.loaded == true){1034 sendAgentCommand(foundMachine.host,foundMachine.port,agentInstructions,3);1035 }1036 else{1037 runBaseState();1038 }1039 });1040 }1041 }1042 else{1043 runBaseState();1044 }1045 });1046};1047//last action or we are done with the TC1048//start next test case if there is one1049function finishTestCaseExecution(execution,executionID,testcaseId,testcase){1050 //updateExecutionTestCase({_id:execution.testcases[testcase.executionTestCaseID]._id},{$set:{"status":"Finished",result:testcase.result.result}});1051 var date = new Date();1052 var status = "Finished";1053 if((testcase.result.result != "Passed") && (testcase.result.result != "Failed")){1054 status = "Not Run";1055 }1056 var updateTC = function(){1057 updateExecutionTestCase({_id:testcaseId},{$set:{trace:testcase.trace,"status":status,resultID:testcase.result._id.__id,result:testcase.result.result,error:testcase.result.error,enddate:date,runtime:date-testcase.testcase.startDate,host:"",vncport:""}});1058 executionsRoute.updateExecutionTotals(executionID);1059 };1060 //update machine base state result1061 if(execution.cachedTCs){1062 if (testcase.testcase.machines.length > 0){1063 updateExecutionMachine(executionID,testcase.testcase.machines[0]._id,testcase.result.result,testcase.result._id.__id,function(){...
Using AI Code Generation
1var redwood = require('redwoodhq');2var finishTestCaseExecution = redwood.finishTestCaseExecution;3finishTestCaseExecution('Test Case Name', 'Test Case Status', 'Test Case Execution Time', 'Test Case Error Message', 'Test Case Error Stack', 'Test Case Log File Path', 'Test Case Screenshot File Path', 'Test Case Report File Path', 'Test Case Video File Path', 'Test Case Attachments File Path', 'Test Case Step Name', 'Test Case Step Status', 'Test Case Step Execution Time', 'Test Case Step Error Message', 'Test Case Step Error Stack', 'Test Case Step Log File Path', 'Test Case Step Screenshot File Path', 'Test Case Step Report File Path', 'Test Case Step Video File Path', 'Test Case Step Attachments File Path');4finishTestCaseExecution('Test Case Name', 'Test Case Status', 'Test Case Execution Time', 'Test Case Error Message', 'Test Case Error Stack', 'Test Case Log File Path', 'Test Case Screenshot File Path', 'Test Case Report File Path', 'Test Case Video File Path', 'Test Case Attachments File Path');5finishTestCaseExecution('Test Case Name', 'Test Case Status', 'Test Case Execution Time', 'Test Case Error Message', 'Test Case Error Stack');6finishTestCaseExecution('Test Case Name', 'Test Case Status', 'Test Case Execution Time');7finishTestCaseExecution('Test Case Name', 'Test Case Status');8finishTestCaseExecution('Test Case Name');9finishTestCaseExecution();10finishTestCaseExecution('Test Case Name', 'Test Case Status', 'Test Case Execution Time', 'Test Case Error Message', 'Test Case Error Stack', 'Test Case Log File Path', 'Test Case Screenshot File Path', 'Test Case Report File Path', 'Test Case Video File Path', 'Test Case Attachments File Path', 'Test Case Step Name', 'Test Case Step Status', 'Test
Using AI Code Generation
1var finishTestCaseExecution = require('redwoodhq');2finishTestCaseExecution("Pass", "TestCase Passed", "TestCase Passed");3var finishTestCaseExecution = require('redwoodhq');4finishTestCaseExecution("Fail", "TestCase Failed", "TestCase Failed");5var finishTestCaseExecution = require('redwoodhq');6finishTestCaseExecution("Fail", "TestCase Failed", "TestCase Failed", "Error");7var finishTestCaseExecution = require('redwoodhq');8finishTestCaseExecution("Fail", "TestCase Failed", "TestCase Failed", "Error", "Error");9var finishTestCaseExecution = require('redwoodhq');10finishTestCaseExecution("Fail", "TestCase Failed", "TestCase Failed", "Error", "Error", "Error");11var finishTestCaseExecution = require('redwoodhq');12finishTestCaseExecution("Fail", "TestCase Failed", "TestCase Failed", "Error", "Error", "Error", "Error");13var finishTestCaseExecution = require('redwoodhq');14finishTestCaseExecution("Fail", "TestCase Failed", "TestCase Failed", "Error", "Error", "Error", "Error", "Error");15var finishTestCaseExecution = require('redwoodhq');16finishTestCaseExecution("Fail", "TestCase Failed", "TestCase Failed", "Error", "Error", "Error", "Error", "Error", "Error");17var finishTestCaseExecution = require('redwoodhq');18finishTestCaseExecution("Fail", "TestCase Failed", "TestCase Failed", "Error", "Error", "Error", "Error", "Error", "Error", "Error");19var finishTestCaseExecution = require('redwoodhq');20finishTestCaseExecution("Fail",
Using AI Code Generation
1var redwoodHQ = require('redwoodHQ');2redwoodHQ.finishTestCaseExecution("Passed", "Test case passed successfully", "TestCaseName", "TestSuiteName", "TestProjectName");3redwoodHQ.finishTestCaseExecution("Passed", "Test case passed successfully", "TestCaseName", "TestSuiteName", "TestProjectName", "Attachment1", "Attachment2");4import redwoodHQ;5redwoodHQ.finishTestCaseExecution("Passed", "Test case passed successfully", "TestCaseName", "TestSuiteName", "TestProjectName");6redwoodHQ.finishTestCaseExecution("Passed", "Test case passed successfully", "TestCaseName", "TestSuiteName", "TestProjectName", "Attachment1", "Attachment2");7using redwoodHQ;8redwoodHQ.finishTestCaseExecution("Passed", "Test case passed successfully", "TestCaseName", "TestSuiteName", "TestProjectName");9redwoodHQ.finishTestCaseExecution("Passed", "Test case passed successfully", "TestCaseName", "TestSuiteName", "TestProjectName", "Attachment1", "Attachment2");10redwoodHQ.finishTestCaseExecution("Passed", "Test case passed successfully", "TestCaseName", "TestSuiteName", "TestProjectName")
Using AI Code Generation
1var redwood = require('redwoodhq');2var test = new redwood.TestCase('Test Case Name', 'Test Case Description');3var step = new redwood.Step();4test.addStep(step);5test.finishTestCaseExecution("Passed", "Test Case Passed");6test.finishTestCaseExecution("Failed", "Test Case Failed");7test.finishTestCaseExecution("Blocked", "Test Case Blocked");8test.finishTestCaseExecution("Not Executed", "Test Case Not Executed");9test.finishTestCaseExecution("Passed", "Test Case Passed", "teststep", "Test Step Name");10test.finishTestCaseExecution("Failed", "Test Case Failed", "teststep", "Test Step Name");11test.finishTestCaseExecution("Blocked", "Test Case Blocked", "teststep", "Test Step Name");12test.finishTestCaseExecution("Not Executed", "Test Case Not Executed", "teststep", "Test Step Name");
Using AI Code Generation
1var redwood = require('redwoodhq');2var testCaseId = "5a6b1f6c-8e8b-4a78-b6f2-6a0a1d2e9b9f";3var testRunId = "5a6b1f6c-8e8b-4a78-b6f2-6a0a1d2e9b9f";4var status = "Passed";5var errorMessage = "Error Message";6var logs = "Logs";7var screenshot = "Screenshot";8var timeTaken = "100";9var result = redwood.finishTestCaseExecution(testCaseId, testRunId, status, errorMessage, logs, screenshot, timeTaken);10var redwood = require('redwoodhq');11var testRunId = "5a6b1f6c-8e8b-4a78-b6f2-6a0a1d2e9b9f";12var status = "Passed";13var errorMessage = "Error Message";14var logs = "Logs";15var screenshot = "Screenshot";16var timeTaken = "100";17var result = redwood.finishTestRun(testRunId, status, errorMessage, logs, screenshot, timeTaken);18var redwood = require('redwoodhq');19var testSuiteId = "5a6b1f6c-8e8b-4a78-b6f2-6a0a1d2e9b9f";20var testRunId = "5a6b1f6c-8e8b-4a78-b6f2-6a0a1d2e9b9f";21var status = "Passed";22var errorMessage = "Error Message";23var logs = "Logs";24var screenshot = "Screenshot";25var timeTaken = "100";26var result = redwood.finishTestSuiteExecution(testSuiteId, testRunId, status, errorMessage, logs, screenshot, timeTaken);27var redwood = require('
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!