Showing posts with label testplan. Show all posts
Showing posts with label testplan. Show all posts

Wednesday, September 3, 2008

Convert failed testcases as a testplan

We have few silktest automation projects. One project is used to execute by suite. Another one is ran by batch (*.bat) file, which has few sub-plans. I am not able to run the failed cases from all results at one shot. I was looking an utility, similar to 'Mark failures in Plan' in the results menu. I thought to implement a 4test script to convert failed testcases as a testplan and I did it.

4Test code - Create testplan for failed cases only

[ ] LIST OF STRING glsFailedScripts = {} [ ] [+] testcase ConvertTestPlan_SingleFile () appstate none [ ] [ ] STRING sResFile = "D:\Auto_Scripts\Results\MyStuff_MasterPlan.res " [ ] STRING sRexFile = "D:\Auto_Scripts\Results\MyStuff_MasterPlan1.rex " [ ] STRING sMyPlanFile = "D:\Auto_Scripts\Results\zSingleFailed.pln " [ ] [ ] glsFailedScripts = {} [ ] CreateFileFromTemplate(sPlanTemplate,sMyPlanFile) [ ] ResExport (sResFile,sRexFile) [ ] ProcessSingleREXFile (sRexFile,sMyPlanFile) [ ] [ ] Agent.DisplayMessage ("test","Completed.") [ ] [-] // functions [+] Boolean GetFailedTestInfo (STRING sRexLine, out LIST OF STRING lsPlanInfo) [ ] [ ] // Title [ ] //TestPlan Script TestCase TestData ErrorCount ErrorText DateTime Elapsed [ ] [ ] // Samples [ ] // "D:\Auto_Scripts\PlanFiles\MyStuff_MasterPlan.pln","D:\Auto_Scripts\Scripts\FamilyFunctions.t","FamilyFunctions_DimensionFunctions_5", [ ] // "Verify user sees a proper error message by clicking OK button.",0,"","2008-08-18 21.52.06","0:00:00" [ ] [ ] STRING sScript [ ] STRING sTestCase [ ] STRING sTestData,sFormattedData [ ] STRING sTestTime [ ] STRING sErrCount, sErrCount1 [ ] INTEGER iPos [ ] [ ] // Initialization [ ] STRING sIndentation = " " [ ] STRING sIndentation1 = "[+] " // Level1 [ ] STRING sIndentation2 = " [ ] " // Level2 [ ] [ ] STRING sSeperator = """,""" [ ] STRING sErrSeperator = ",""" //",""***" [ ] STRING sDataSeperator = """,0,""" [ ] STRING sErrSeperator1 = """" [ ] Boolean bResult = FALSE [ ] lsPlanInfo = {} [ ] [ ] sErrCount1 = GetField (sRexLine,sSeperator,4) [ ] sErrCount = GetField (sRexLine,sDataSeperator, 2) [ ] //if ((Trim(sErrCount) != "") && (Val(sErrCount) > 0)) [+] if ((Trim(sErrCount) == "") && (Trim(sErrCount1) != "") ) [ ] Print ("Considering line: {sRexLine}") [ ] bResult = TRUE [ ] sScript = GetField (sRexLine,sSeperator,2) [ ] sTestCase = GetField (sRexLine,sSeperator,3) [ ] sTestTime = GetField (sRexLine,sSeperator,6) [ ] Print ("Elapsed: {sTestTime}") [+] if (sTestTime == "") [+] sFormattedData = "" [ ] iPos = StrPos (sErrSeperator, sTestCase,TRUE) [+] if (iPos > 0) [ ] Print ("sTestCase:{sTestCase}: iPos:{iPos}") [ ] sTestCase = SubStr (sTestCase, 1,iPos - 4) [ ] Print ("Before formatting, sTestCase:{sTestCase}") [ ] //sTestCase = StrTran (sTestCase,"\","") [ ] Print ("After formatting, sTestCase:{sTestCase}") [ ] [+] else [ ] sTestData = GetField (sRexLine,sSeperator,4) [+] if (MatchStr ("*,?,""*",sTestData)) [ ] iPos = StrPos (sErrSeperator, sTestData,TRUE) [+] if (iPos > 0) [ ] Print ("TestData:{sTestData}: iPos:{iPos}") [ ] sTestData = SubStr (sTestData, 1,iPos - 4) [ ] Print ("Before formatting, TestData:{sTestData}") [ ] sFormattedData = StrTran (sTestData,"\","") [ ] Print ("After formatting, TestData:{sTestData}") [ ] [ ] Print ("TestCase: {sTestCase}") [ ] Print ("TestData: {sFormattedData}") [ ] [+] if ( (glsFailedScripts == {}) || (glsFailedScripts[ListCount(glsFailedScripts)] != sScript) ) [ ] ListAppend (glsFailedScripts,sScript) [ ] ListAppend (lsPlanInfo,"{sIndentation1}#script: {sScript}") [+] // if (Trim (sTestData) != "") [ ] // ListAppend (lsPlanInfo,"{sIndentation2}#testdata: {sFormattedData}") [ ] ListAppend (lsPlanInfo,"{sIndentation2}#testcase: {sTestCase}({sFormattedData})") [ ] [+] else [ ] Print ("Not Considering line: {sRexLine}") [ ] [ ] return bResult [+] public void TestPlanWrite(STRING sPlanFile, ANYTYPE aMsg) [ ] // To write content into log file [ ] HFILE hFile [ ] STRING sItem [ ] [ ] hFile = FileOpen (sPlanFile, FM_APPEND) [+] switch TypeOf (aMsg) [+] case STRING [ ] FileWriteLine(hFile,"{aMsg}") [+] case LIST OF STRING [+] for each sItem in aMsg [ ] FileWriteLine(hFile,"{sItem}") [+] default [ ] Print ("Non supported element for TestPlanWrite: {TypeOf (aMsg)}") [ ] FileWriteLine(hFile,"{aMsg}") [ ] [ ] FileClose (hFile) [ ] [ ] [+] VOID ProcessSingleREXFile (String sRexFile, STRING sPlanFile) [ ] // To create a testplan [ ] // Implemented for Auto Scripts [ ] // It will read the text file [ ] [+] // Parsing REX file and then writing into plan file [ ] HFILE hInFile [ ] STRING sLine [ ] LIST OF STRING lsPlan [ ] [ ] hInFile = FileOpen (sRexFile,FM_READ) [ ] [+] while (FileReadLine (hInFile, sLine)) [+] if (GetFailedTestInfo (sLine,lsPlan)) [ ] TestPlanWrite (sPlanFile,lsPlan) [ ] [ ] FileClose (hInFile)

Friday, July 25, 2008

Silktest - TestPlan solutions

TestPlan is one of the good features in Silktest. You can query to execute certain testcases from Testplan. Also you can mark only failures from the silktest results. Below I have given the two test plan issues and solutions for them.

1. How to pass Dollar ($) sign in TestPlan?
TestPlan is using $ symbol to represent the variables. Silktest will through the error, if any testdata contains dollar ($) character explicitly.
Solution:
Replace symbol $ by {Chr(36)}


2. Running Main() from TestPlan
Few weeks back, I wanted to run the Main() function from Testplan. It is very old suite ( 10 years old). I thought, Silktest does not have any provision to call Main () function. I put the query into Borland forum and I got the answer.
Solution:
We have to represent the Main() as testcase. We should not change the hierarchy/indentation for script and testcase statements. See the sample plan below.



[-] SilkTest Issues
[ ] Developer: Palani Selvam
[ ] script: silkIssues.t
[ ] testcase: main()
[ ]



By this way, we can run the functions too..


[-] SilkTest Issues
[ ] Developer: Palani Selvam
[ ] script: silkIssues.t
[ ] // testcase: main()
[ ] testcase: MyTestCalls5 ()