Forum Discussion
mmkumaram
14 years agoOccasional Contributor
Well, these are custom files that we create manually while running the test. We have a framework that creates these files. Below is an example of a simple test that ouputs test summary file with pass count and fail count;
Assume, you have a function called Login(username,password) and you want to call this five time with different values and report results.
First i would create a data file called LoginTest.txt which contains below test data.
Login("user1","pwd1")
Login("user2","pwd1")
Login("user3","pwd1")
Login("user4","pwd1")
Login("user5","pwd1")
In testcomplete I would create test function called Login(username,password) and a main function to call this.
function Login(username,password){
...<your test here>
if ("passed"){
return true
}
return false
}
function main(){
var TestsFileName ="LoginTest.txt"; #provide full path
var FailedTests=0;
var PassedTests=0;
var ForReading = 1;
var ForWriting = 8;
var fso = new ActiveXObject("Scripting.FileSystemObject");
if (fso.FileExists(TestsFileName) == true) {
var TestNameFromFile = TestsFileName.split("\\");
TestNameFromFile = TestNameFromFile[TestNameFromFile.length - 1];
var TestName=TestNameFromFile ;
TestsFileName = fso.OpenTextFile(TestsFileName, ForReading);
var TestFunction,result,TestCount ;
TestCount =0;
while (!TestsFileName.AtEndOfStream) {
TestFunction = TestsFileName.ReadLine();
result = eval(TestFunction);
if ((result == "Failed") || (result == false) ) {
FailedTests++;
result = "Failed";
}
else{
PassedTests++;
result = "Passed";
}
TestCount++;
}
var TestSetResultFile = "TestSummaryResults.txt";
TestSetResultFile = fso.OpenTextFile(TestSetResultFile,ForWriting,true);
TestSetResultFile.WriteLine(TestName+","+PassedTests+","+FailedTests+","+TestCount);
TestSetResultFile.Close();
}
}
here running the main function would create summary result file with test name, passed count, fail count etc of the test.. similarly you could create html and other files as well.
Thanks,
Muthu
Assume, you have a function called Login(username,password) and you want to call this five time with different values and report results.
First i would create a data file called LoginTest.txt which contains below test data.
Login("user1","pwd1")
Login("user2","pwd1")
Login("user3","pwd1")
Login("user4","pwd1")
Login("user5","pwd1")
In testcomplete I would create test function called Login(username,password) and a main function to call this.
function Login(username,password){
...<your test here>
if ("passed"){
return true
}
return false
}
function main(){
var TestsFileName ="LoginTest.txt"; #provide full path
var FailedTests=0;
var PassedTests=0;
var ForReading = 1;
var ForWriting = 8;
var fso = new ActiveXObject("Scripting.FileSystemObject");
if (fso.FileExists(TestsFileName) == true) {
var TestNameFromFile = TestsFileName.split("\\");
TestNameFromFile = TestNameFromFile[TestNameFromFile.length - 1];
var TestName=TestNameFromFile ;
TestsFileName = fso.OpenTextFile(TestsFileName, ForReading);
var TestFunction,result,TestCount ;
TestCount =0;
while (!TestsFileName.AtEndOfStream) {
TestFunction = TestsFileName.ReadLine();
result = eval(TestFunction);
if ((result == "Failed") || (result == false) ) {
FailedTests++;
result = "Failed";
}
else{
PassedTests++;
result = "Passed";
}
TestCount++;
}
var TestSetResultFile = "TestSummaryResults.txt";
TestSetResultFile = fso.OpenTextFile(TestSetResultFile,ForWriting,true);
TestSetResultFile.WriteLine(TestName+","+PassedTests+","+FailedTests+","+TestCount);
TestSetResultFile.Close();
}
}
here running the main function would create summary result file with test name, passed count, fail count etc of the test.. similarly you could create html and other files as well.
Thanks,
Muthu
Related Content
- 4 years ago
- 8 years ago
- 9 years ago
- 14 years ago
Recent Discussions
- 4 days ago
- 4 days ago