Showing posts with label 4test. Show all posts
Showing posts with label 4test. Show all posts

Sunday, July 19, 2009

Verifying Email notifications

For long time, I was looking a solution to automate the verification of email contents. It required to verify for few user accounts, attachments like Excel, PowerPoint and PDF docs. We have few critical features, which required to verify email contents and attachments. Silktest does not have any built-in functions for this activity. However I have to find a solution. The solution should supports IE6 and IE7 browsers and Windows 2000, Windows XP and Vista OS. I had four choices in mind. They are,

  1. Using a command line utility
  2. Using MS Office Outlook COM interface
  3. Using Collaboration Data Objects (CDO) Interface with Outlook Express
  4. Worst case - Automate any email client with UI

Automate any email client with UI
This option was last one. Because I do not want to automate with User Interface. We can build the solution in couple of weeks effort. The issue is the changes with that client. I have to look on support for different Operating Systems such as Windows XP and Vista.

Using Collaboration Data Objects (CDO) with Outlook Express
In my first company, I have used CDO with Visual Basic. See my previous post - Checking Mail Notification. I got a surprise, while I was searching information for CDO Help. Microsoft has stopped the updates on Outlook Express. Earlier Internet Explorer Intallation was bundled with Outlook Express.

Using MS Office Outlook COM interface
I am familiar with VB script. I have used Outlook COM interface [CreateObject("Outlook.Application")] earlier. The issue is, the particular user account mailboxes should be opened, while executing VB Script. Also I thought the license and installation costs.

Using a command line utility
I have searched many times and found a utility. GetMail is a command line utility and it is working in all windows OS. It is available at GETMAIL for Windows It is a cheapest and best utility to fit for my requirements.

Different Cmdline switches of GetMail
Getmail has different switches for various purposes. You can opt appropriate switches as per your requirement.
 

GetMail v1.33: WinNT console utility to download a mailbox's mail.
syntax:
Getmail -u <user> -pw <password> -s <server> [optional switches (see below)]
Getmail -install [ see install details below ]
Getmail -profile [-delete | "<default>"] [profile1] [profileN] [-q]
Getmail -h [-q]
Getmail -forceextract filename

-install <server> <userid> <password> [<delete> [<xtract> [<try> [<port> [<profile>]]]]]
: set's POP3 server, login, password, whether to delete or not (Yes/No),
whether to automatically extract base64/7bit/UU encoded files or not (Yes/No),
number of tries and port for profile
(<delete> <xtract> <try> and <port> may be replaced by '-').

-u <userid> : Specify userid on remote pop3 host
-pw <password>: Specify password for userid on remote mail host
-s <server> : Specify mail server (pop3) to contact
-nodelete : Do not delete messages after downloading (default)
-delete : Delete messages after downloading
-noxtract : Do not extract base64/7bit/UU files after downloading (default)
-xtract [defname]: Extract base64/7bit/UU encoded files after downloading messages
defname is an optional default filename for the extracted file
-domainstamp : Prepend sender's domain name to extracted attachments
-headersonly : Download only the headers of the message
-port <port> : port to be used on the server, defaults to POP3 (110)
-p <profile> : send with SMTP server, user and port defined in <profile>.
-q : supresses *all* output.
-n <n> : Only get 'n' messages
-m <n> : Only get message # n
-b <n> : Retrieve messages beginning from # n
-plain : Extract text/plain segments too (usually ignored)
-h : displays this help.
-try <n times>: how many attempts to access mail. from '1' to 'INFINITE'
-ti <n> : Set timeout to 'n' seconds.
-forceextract fn: Attempt to extract any encoded messages in 'fn'

Installing GetMail
You need to follow the belows steps to install it. Assume that getmail.exe is stored under D:\tools.
  1. First open a command prompt.
  2. Go to D:\tools folder.
  3. Install it by executing below commmand
    Getmail -install mailserver script1@auto.com wrongpwd
    Here mailserver means the mail Server name or IP address

Verifying GetMail
To verify the GetMail installation, you can use following steps.
  1. Goto folder D:\tools
  2. Execute the following command for any user.
    For example, D:\tools\getmail.exe -u script1 -pw TestPassword -s mailserver
  3. Check any error exists on command prompt.
  4. Check on that folder, whether all the mails are downloaded or not. You can see mails like msg1.txt,msg2.txt,..etc

4Test code - To Verify the GetMail
 

[ ] sMailCommand = "{gsToolsDir}\getmail.exe -u {sUser} -pw {sPass} -s {sServer} {sAdditionalSwitch}"
[ ] Print ("Mail Command: {sMailCommand}")
[+] // if (bDeleteAfterReceive)
[ ] // sMailCommand = "{gsToolsDir}getmail.exe -u {sUser} -pw {sPass} -s {sServer} -delete"
[+] // else
[ ] // sMailCommand = "{gsToolsDir}getmail.exe -u {sUser} -pw {sPass} -s {sServer} -nodelete"
[ ] // Checking any errors on command line output
[+] if( 0 != SYS_Execute( sMailCommand, lsGetmailOut ) )
[ ] ListPrint( lsGetmailOut )
[ ] LogError ( "FAIL. Unable to receive the mail." )
[ ] return FALSE
[ ]

Sunday, July 12, 2009

Top 10 Silktest blogs/forums

Earlier I have seen Dmitry Motevich's post 15 QTP sites/blogs/groups/forums. Similarly I have listed for Silktest.

  1. SQA Forums
    Initially it was QAForums. Many silktest users are participating here. You can find many silktest expertise in this forum. It is having more than 50k posts and sample code.
  2. Borland Support
    Tool vendor's support site. Recently borland made compulsory service contract to access Knowledgebase articles and silktest community. It has plenty of usefull KB articles.
  3. Silktest FAQ & Tips
    Great blog for Silktest FAQ and tips. It has detailed solutions for common silktest issues.
  4. Silktest and Automation Tips
    Here user can find Silktest tips, code and automation tricks. Also covering advanced features of Silktest.
  5. Silktest tips
    One more good blog with limited posts.
  6. Silktest Yahoo groups
    It is the only active Silktest yahoo groups. One can find many expertise here.
  7. Silktest Tutorial
    Having detailed tutorials for Silktest.
  8. Silktest on QACampus
    Few more Silktest information is shared here.
  9. Darshan's blog
    Contains mixed of silktest and python posts.
  10. CSDN blog
    Many posts are in Chinese language. Has covered most of the silktest features.


Also I would like to mention few popular silktest sites, which are not available now. Many of you would have seen Bret Pettichord's Software Testing Hotlist. But most of the Silktest links are not exist today. All of them having fundamental and advanced concepts of Silktest. Also they have shared 4test sample code and white-papers.

Jeff Hemsley-OOPs and Classes concepts
Non-exist Link: http://www.weirdness.org/jeff/articles/a_classes.html
Current Page: Classes, Objects, Dynamic Instantiation and Constructors: Is 4Test Really an Object-Oriented Language?

Tony Venditti's Silk Automation Page
Non-exist Link: http://www.iris.com/web/irisdevs.nsf/c404f3f7c0cc20458525618c00633c15/f41c9c2b9b8dc4508525666700747f56?OpenDocument
Info about him: IBM page

Silktest White Papers - ameliortech
Non-exist Link: http://www.ameliortech.com/stuff/toolkits/ST/st_whpap.htm

4Test Hints and Tips
Non-exist Link: http://www.testmap.com/4test/4test_support.htm

Automation Expertise Tutorials
Non-exist Link: http://www.automationexpertise.com/Tutorials/SilkOrganizer/pages/Parent.htm

Mr. Cluey's Kludge Page
Non-exist Link: http://www.sqa-test.com/mr_cluey/

Automation on Quality Tree website
Non-exist Link: http://www.qualitytree.com/autotest/qapartner.htm

Automation Junkies
Non-exist Link: http://www.automationjunkies.com/resources/experts.shtml

I think that I can put them here, If I am able to retrieve those missed pages from my storage or from others. What do you say?

Sunday, July 5, 2009

Silk4J Overview & Analysis

Silk4j was introduced from Silktest 2008. Hereafter user can use Java as test scripting language with the help of Silk4J Package. It is supported only with Open Agent. I hope that Borland might target developers too. User can write java unit tests as well as GUI tests.

From Silktest Help - Silk4J Eclipse Plugin

Silk4J enables user to create functional tests using the Java programming language. Silk4J provides a Java runtime library that includes test classes for all the classes that Silk4J supports for testing. This runtime library is compatible with JUnit, which means you can leverage the JUnit infrastructure and run and create tests using JUnit. You can also use all available Java libraries in your testcases.

The testing environments that Silk4J supports include:

  • Adobe Flex applications
  • Java SWT applications
  • Windows Presentation Foundation (WPF) applications
  • Windows API-based client/server applications
  • xBrowser applications


Silk4J with Open Agent - Google Search testcase

I have gone through documents such as Silk4J_QuickStartGuide_en.pdf and Silk4J_AdvancedUserGuide_en.pdf. I created the sample code and it works fine.

package com.palani;
import org.junit.Before;
import org.junit.Test;

import com.borland.silktest.jtf.Desktop;
import com.borland.silktest.jtf.TechDomain;
import com.borland.silktest.jtf.xbrowser.BrowserWindow;
import com.borland.silktest.jtf.xbrowser.DomButton;
import com.borland.silktest.jtf.xbrowser.DomTextField;

public class GoogleSearch {
private Desktop desktop = new Desktop();
private BrowserWindow browser;

@Before
public void setUp() throws Exception {

browser = (BrowserWindow)desktop.executeBaseState(
"C:/Program Files/Internet Explorer/iexplore.exe", null, null,
".//BrowserWindow", TechDomain.XBROWSER);
browser.navigate("http://www.google.co.in/");
}

@Test
public void testSimpleGoogleSearch() throws Exception {

DomTextField searchText = (DomTextField)browser.find (".//DomTextField[@title='Google Search' and @name='q']");
searchText.setText("");
searchText.setText("silk4j tutorial");
DomButton btn = (DomButton)browser.find(
".//DomButton[@type='submit' and @name='btnG']");
btn.click();
}
}


4Test with Open Agent - Google Search testcase
The same case is written in 4Test. SilkTest supports a subset of the XPath query language. It gives dynamic object recognition.

[ ]
[-] testcase GoogleSearch1 () appstate none //DefaultBaseState
[ ] STRING sUrl="http://www.google.co.in/"
[ ]
[-] if (! InternetExplorer.Exists(2))
[ ] InternetExplorer.Invoke ()
[ ] InternetExplorer.SetActive ()
[ ] InternetExplorer.Maximize ()
[ ]
[ ] WINDOW wMain = Desktop.Find(".//BrowserApplication")
[ ] WINDOW wBrowser = wMain.Find(".//BrowserWindow")
[ ]
[ ] wMain.SetActive()
[ ] wBrowser.Navigate (sUrl)
[ ] WINDOW wText1=wBrowser.Find(".//DomTextField[@title='Google Search' and @name='q']")
[ ] wText1.SetText("Silk4j Tutorial")
[ ] wBrowser.Find(".//DomButton[@name='btnG' ]").Click ()
[ ]
[ ] WINDOW wText2=wBrowser.Find(".//DomTextField[@name='q']")
[ ] wText2.SetText("Silktest Extension Kit")
[ ] wBrowser.Find(".//DomButton[@name='btnG' ]").Click ()
[ ]
[ ]


Selenium RC Java format - Google Search testcase

Selenium is a open source tool and can be used only web based applications. But user can choose different languages to develop the suite. Selenium tests can be written with Selenese, PHP, Perl, Python, Ruby, DotNet and Java.

import org.openqa.selenium.server.SeleniumServerTest;
import com.thoughtworks.selenium.*;
import junit.framework.*;
import org.openqa.selenium.server.SeleniumServer;

public class TestSearch extends SeleniumServerTest {
private Selenium browser;
public void setUp() throws Exception {
SeleniumServer seleniumServer = new SeleniumServer();
browser = new DefaultSelenium("localhost", 5555, "*firefox", "http://www.google.com");
seleniumServer.start();
browser.start();
}

public void testGoogle() {
browser.open("/webhp?hl=en");
browser.type("q", "hello world");
browser.click("btnG");
browser.waitForPageToLoad("5000");
assertEquals("hello world - Google Search", browser.getTitle());
}

public void tearDown() {
browser.stop();
}
}


Few Questions

Now Silktest and selenium both supports in Java language. Silktest supports many type of applications. In other end, Selenium supports many Operating Systems and browsers. I have few questions on Silk4J.
  1. Can Silk4J utilize silktest features such as TestcaseEnter,TestcaseExit,scriptEnter and ScriptExit?
  2. Target audience?
  3. Any Success stories (implementations)?

Saturday, December 13, 2008

Close the AUT after certain time

In recent days, I am trying to kill the applications if they are unable to close by the tool (SilkTest). Last month, I was solving one different issue.

We are having ten years old test suite and it was not updated for last two years due to product priorities. The total execution time for this regression suite is around 70 hours. Many times, our AUT is getting hung or the current window focus is unable to shift and suite is unable to continue after that. We endup to stop the suite at that script and re-ran the remaining scripts manually. Also we are unable to use weekends fully for the regression.

I planned to run the scripts as unattended. It is intermittent problem. Often silktest not executed in different testcases and not in one particular case always. So I thought to kill the application if the application is running more than 45 minutes. Few of silktest group members have given a idea and I have implemented it.

Silktest has 'spawn' statement to create a separate thread and it is used to execute MultiTestcase. MultiTestcae helps to run the particular code in multiple systems. Also I used PsList to get the running time of an application. I have tried few scenarios with Notepad and then finally put into our suite. This solution is worked..!!!

I have called in script level and I called 'spawn' statement in ScriptEnter and break the loop, once the execution reached ScriptExit. I have given the code below...

4Test code for ScriptEnter and ScriptExit



[+] void ScriptEnter ()
[ ] // Added for Unattended execution
[ ] gbAppKill = TRUE
[+] spawn
[ ] KillApp_UsedTime ("myAut",2700)
[ ]
[+] void ScriptExit (boolean bException)
[ ]
[ ] // Added to stop kill thread
[ ] gbAppKill = FALSE
[ ]



4Test methods to find the exeuction time and killing it


[ ] // // **** Code written for killing apps if app is running more than 45 mins.
[ ] // Methods
[ ] Boolean gbAppKill
[ ]
[+] Void KillApp_psKill (STRING sApp)
[ ] List of STRING lsOutput
[ ]
[ ] STRING sCommand = "{gcsToolsPath}\pskill {sApp} "
[ ]
[+] do
[ ]
[ ] Print ("Executing command: {sCommand}")
[ ] SYS_Execute (sCommand, lsOutput)
[ ] ResPrintList ("Command Output", lsOutput)
[ ] Print ("echo App {sApp} killed at %DATE%_%TIME% >> d:\kill.txt ")
[ ] SYS_Execute ("echo App {sApp} killed at %DATE%_%TIME% >> d:\kill.txt ")
[ ] Sleep (2)
[+] except
[ ] // Do Nothing
[ ] ExceptLog ()
[ ]
[ ]
[-] VOID KillApp_UsedTime (STRING sApp, INTEGER iKillTimeLimit optional)
[ ] List of STRING lsOutput
[ ] INTEGER iItem, iTotalValue, iTimes, iCount,iSleepTime
[ ] STRING sPartial,sItem,sPID
[ ] STRING sTime, sHour, sMin, sSec
[ ] STRING sCommand = "{gcsToolsPath}\pslist {sApp}"
[ ]
[ ] //sPID = ""
[ ]
[-] do
[ ]
[ ] iSleepTime = 50 //Seconds
[+] if (IsNull (iKillTimeLimit))
[ ] iKillTimeLimit = 6 // Seconds.
[ ]
[ ]
[ ] iCount = (iKillTimeLimit/iSleepTime) * 100 + 1+10
[ ]
[-] for iTimes=1 to iCount
[+] if (! gbAppKill)
[ ] Print ("gbAppKill is FALSE and exiting from Spawn thread..")
[ ] break
[ ]
[ ]
[ ] Sleep (iSleepTime)
[ ]
[ ]
[ ] Print ("Executing command: {sCommand}")
[ ] SYS_Execute (sCommand, lsOutput)
[ ] ResPrintList ("Command Output", lsOutput)
[ ]
[+] for iItem=2 to ListCount (lsOutput)
[ ] sItem = lsOutput[iItem]
[+] if (MatchStr ("{sApp}*",sItem))
[ ]
[ ] sSec = GetField (sItem,":",5)
[ ]
[+] if (IsNull(sSec) || (Trim(sSec) == ""))
[ ] continue
[+] else
[ ] sTime = GetField (sItem,":",3)
[ ] sMin = GetField (sItem,":",4)
[ ] sHour = SubStr (sTime,Len(sTime)-3)
[ ]
[ ] Print ("Hour: {sHour}")
[ ] Print ("Minutes: {sMin}")
[ ] Print ("Seconds: {sSec}")
[ ] iTotalValue = Val (sMin) * 60 + Val(sHour) * 3600
[ ] Print ("App {sApp} - running total time: {iTotalValue} Seconds")
[ ]
[+] if (iKillTimeLimit <= iTotalValue)
[ ] Print ("Application {sApp} is running {iTotalValue} seconds -beyond expected time {iKillTimeLimit} seconds.")
[ ] KillApp_psKill (sApp)
[ ] Print ("Going to kill Application {sApp}")
[ ] // break // It is suitable for testcase level
[+] else
[ ] Print ("Application {sApp} is running {iTotalValue} seconds - not exceeding expected time {iKillTimeLimit} seconds.")
[ ] // return sPID
[ ]
[ ]
[ ]
[+] except
[ ] // Do Nothing
[ ]
[ ]
[ ]

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)

Wednesday, August 27, 2008

Restart Silktest Agent at Runtime

Last few months, I faced one issue and solved it by restarting silktest Agent.
Problem
We have a silktest suite for our Excel AddIn. It is developed by DotNet Framework. Silktest DotNet extension goes off after running 75-200 tests. Also facing this issue differently for both Excel 2003 and Excel 2007. Already I raised one post 'Application not responding" for this.



[ ] *** Error: Application is not responding
[ ] Occurred in Exists
[ ] Called from MSExcelAddIns at ExcelRecoverySystem.inc(573)
[ ] Called from ASCS_EAIBaseState at ExcelRecoverySystem.inc(684)
[ ] Called from SymmetricReport at ExcelRecoverySystem.inc(714)
[ ] Called from TestcaseEnter at ExcelRecoverySystem.inc(255)
[ ] Called from PreservingFunctions_ReplaceWithUpper at PreservingFunctions.t(238)
[ ] Error E_APP_NOT_RESPONDING) raised. Closing all applications
[ ] *** Error: Application is not responding
[ ] Occurred in Exists
[ ] Called from KillExcelApp at ExcelRecoverySystem.inc(395)
[ ] Called from CloseAllApps at ExcelRecoverySystem.inc(386)



Solution:
Later selected cases are executed fine, If I close silktest agent and re-run few cases. I am able to figure out, where/when it is not able to identify. Then I tried to restart the agent in that machine, while scripts are executing continuously.

4Test code: To restart Silktest Agent


[-] void RestartSilkAgent ()
[ ] // To Restart Silktest Agent
[ ]
[ ] STRING sAgent
[ ]
[ ]
[ ] sAgent = GetMachineName ()
[ ] Print ("Agent name: {sAgent}")
[ ] Print (Desktop.GetActive ())
[ ] Disconnect (sAgent)
[ ]
[ ] Print ("**** Restarting Silktest Agent ...")
[ ] SYS_Execute ("D:\SampleDotNet\RestartAgent.bat")
[ ] Print ("**** Restarted Silktest Agent @@@@@@")
[ ]
[ ] Connect (sAgent)
[ ] Print (Desktop.GetActive ())
[ ]
[ ]

Sunday, August 17, 2008

Comparison between 4Test and C language Keywords

Few months back, I was going through 4Test Language Reference (Silktest 5.01) PDF document. There I have seen the comparison of C Language and 4Test. Then I searched the same table in Silktest8.5 Help documentation. It is available under 4Test Reference -> About the 4Test Language -> Comparison of 4Test and C.

Comparison Table: 4Test and C language Keywords

Data type / Feature

C Language

4Test Script

Any type: Stores data of any typeNo datatype available.ANYTYPE aName
Array int ai[10];
  • array [10] of integer ai
  • integer ai[10]
  • Arrays in 4Test can be dynamically resized.
Boolean: Stores either TRUE or FALSEint b;boolean b
Characterchar c;string c. 4Test has no seperate data type for single character.
Enumeratedenum COLOR{red, white, blue};type COLOR is enum red white blue
Floating-point float f; double d;
  • real f
  • real d
Integerint i; long, short, unsignedinteger i
ListSimilar datatype is not available.list of integer li. 4Test has dynamic lists.
NumericSimilar datatype is not available.number n.4Test NUMBER type stores either integers or floating point numbers.
Pointerchar *p; 4Test does not have pointers; however, data can be indirectly referenced using the @ operator.
Pointer to function int (*func) (); @(sFunc) ()
Stringchar s[5]; STRING s. 4Test strings are dynamically allocated; you do not need to declare their lengths.
Structure struct Person { char name[8]; int age; } type Person is record { string name integer age}
User-defined type typedef struct Person PERSON_INFO;type PERSON_INFO is Person
Type cast operator (typename) expression [typename] expression
Equality (==) operator differences if ((i=5) == TRUE) --> This code compiles in C if ((i=5) == TRUE) --> Ths code does not compile in 4Test:This difference is intentional. Because this construct can lead to unreadable code, 4Test does not allow it.

Friday, August 15, 2008

SilkTest - Convert String to List of String

Last month, my friend asked a silktest function similar to Split in QTP. Silktest does not have any built-in function. I thought to develop a function for this need. See the 4test code below:

4Test Code - Convert STRING contents as List of STRING

[+] List of STRING SplitToList (String sInput, String sDelimiter) [ ] List of STRING lsReturn = {} [ ] Integer iIndex =1 [ ] [+] while (GetField (sInput,sDelimiter,iIndex) != "") [ ] ListAppend (lsReturn, GetField (sInput,sDelimiter,iIndex)) [ ] iIndex++ [ ] [ ] return lsReturn

Tuesday, July 15, 2008

Silktest - File Download window

Sometimes Silktest is not identifying FileDownload objects properly. To save it, we need to use TypeKeys. I used following code snippet to save a file from Browser.

Sample 4Test code



[+] Boolean SaveFile (String sFile)
[ ] Boolean bResult = FALSE
[+] do
[+] if (FileDownload.Exists(1))
[ ] Print ("FileDownload exists.")
[ ] FileDownload.SetActive ()
[ ] Sleep (1)
[ ] FileDownload.Save.Click (1,10,3)
[ ] Sleep (3)
[ ]
[ ] Window wActive = Desktop.GetActive ()
[ ] Print ("Window: {wActive}")
[ ] // DialogBox("File Download").DialogBox("Save As")
[ ] wActive.TypeKeys (sFile)
[ ] wActive.TypeKeys ("", 1)
[ ] wActive.TypeKeys ("", 1)
[ ] wActive.TypeKeys ("S",1)
[ ]
[ ] bResult = TRUE

[+] else
[ ] Print ("BrowserFileDownload does not exist.")
[+] except
[ ] ExceptLog ()
[ ]
[ ] return bResult
[ ]

Monday, June 16, 2008

4Test - Getting IP address

In automation, sometimes we need to find the tricks to achieve it. Like that I have done to find the IP address of a machine. You can see the following code snippet.

Silktest code - To find IP address of a system

[+] public String GetIpAddress(String sMachineName) [ ] //To get IP Address for the particular machine in Network [ ] List of String lsOutput [ ] String sCommand [ ] String sTemp, sItem [ ] String sResult = NULL [ ] Boolean bResult = FALSE [ ] Integer iPos1, iPos2 [ ] [ ] sCommand = "ping -a {sMachineName}" [ ] Sys_Execute (sCommand,lsOutput) [ ] [ ] //ListPrint (lsOutput) [-] for each sItem in lsOutput [-] if (MatchStr("*pinging*", sItem)) [ ] bResult = TRUE [ ] break [ ] [-] if (bResult) [ ] iPos1 = StrPos ("[", sItem) [ ] iPos2 = StrPos ("]", sItem) [-] if ((iPos1 > 0) && (iPos2 > 0)) [ ] sResult = SubStr(sItem,iPos1+1, iPos2-iPos1-1) [ ] Print ("Found IP Address: {sResult}") [ ] return sResult

Monday, June 9, 2008

SilkTest - Make sublist from a list

I have written a function to get sublist from a list of items. I have done for STRING type. You can try for ANYTYPE data type.Its usage is similar to SubString. See the following code snippet.

Silktest code sample: GetSubList

[+] public LIST OF STRING GetSubList(LIST OF STRING lsInput, STRING sFirst optional, STRING sLast optional, Boolean bMatch optional) [ ] //To get String list between sFirst and sLast [ ] //If sFirst is NULL or "", SubList will be taken from first item of list [ ] //If sSecond is Null or "", SubList will be taken upto last item of list [ ] //bMatch - FALSE means exact match, TRUE means Partial Match [ ] Integer iCount, iItem [ ] Boolean bFirst = FALSE [ ] Boolean bLast = FALSE [ ] LIST OF STRING lsReturn = {} [ ] [-] if (IsNull(bMatch)) [ ] bMatch = FALSE [-] if (IsNull(sFirst) || (sFirst == "")) [ ] bFirst = TRUE [ ] [ ] iCount = ListCount(lsInput) [-] for iItem=1 to iCount [-] if !(bFirst) [-] if !(bMatch) [-] if (sFirst == lsInput[iItem]) [ ] bFirst = TRUE [ ] ListAppend(lsReturn,lsInput[iItem]) [-] else [-] if (Len(sFirst) <= Len(lsInput[iItem])) [-] if (MatchStr("*{sFirst}*",lsInput[iItem])) [ ] bFirst = TRUE [ ] ListAppend(lsReturn,lsInput[iItem]) [+] else [-] if !(bLast) [ ] ListAppend(lsReturn,lsInput[iItem]) [-] if !(IsNull(sLast)) [-] if !(bMatch) [-] if (sLast == lsInput[iItem]) [ ] bLast = TRUE [-] else [-] if (MatchStr("*{sLast}*",lsInput[iItem])) [ ] bLast = TRUE [-] else [ ] break //Exit from for loop [ ] [ ] return lsReturn [ ]

Wednesday, June 4, 2008

Silktest - File Handling

Any automation suite must have file handling functions for various scenarios. It may be just text files or any data files. Silktest also has few methods for file handling.

SYS_FileOpen is executed by the Agent process and not by the SilkTest host process. But it is essentially the same as FileOpen. SYS_FileOpen and SYS_FileClose should be used to do file operations in other machines (while the agents are running from other machines ), not in the host machine. Below few 4test code samples are given.

4Test Sample Code: To Read a text file.

[+] public void ReadTxtFile(STRING sFile) [ ] // Purpose: Read contents of a file. [ ] HFILE hFile [ ] String sLine [ ] [ ] hFile = FileOpen (sFile, FM_READ) [ ] Print ("File: {sFile}") [ ] [-] while (FileReadLine (hFile, sLine)) [ ] Print (sLine) [ ] [ ] FileClose (hFile) [ ]

4Test Sample Code: To Create a text file.
[+] public void CreateTxtFile(STRING sFile, STRING sMsg) [ ] // Purpose: Create a txt file. All contents will be removed [ ] // from that file, if that file exists already. [ ] HFILE hFile [ ] String sLine [ ] [ ] hFile = FileOpen (sFile, FM_WRITE) [ ] FileWriteLine (hFile, sMsg) [ ] FileClose (hFile)

SilkTest Sample Code: To append a text file.
[+] public void AppendTxtFile(STRING sFile, STRING sMsg) [ ] // Purpose: Create a txt file. Given string will be appended [ ] // from last line of the file, if that file exists already. [ ] HFILE hFile [ ] String sLine [ ] [ ] hFile = FileOpen (sFile, FM_APPEND) [ ] FileWriteLine (hFile, sMsg) [ ] FileClose (hFile) [ ]

Silk Test Sample Code: To Delete a text file.
[-] void DeleteFile (String sFileName) [ ] // To delete given file, if it exists [-] if (Sys_FileExists(sFileName)) [ ] Print ("Existing file - {sFileName}") [ ] Sys_RemoveFile (sFileName) [ ] Sleep (0.1) [-] if (Sys_FileExists(sFileName)) [ ] Print ("Could not delete file - {sFileName}") [-] else [ ] Print ("Deleted file - {sFileName}") [-] else [ ] Print ("File {sFileName} does not exist.")

Silktest Sample Code: To Separate filename and path.
[+] public void GetFileNameAndPath (String sFileWithPath, inout String sFileName null optional, inout String sFilePath null optional) [ ] // Purpose: To separate filname and path. [ ] String sTmpFile, sTmpPath, sTemp [ ] Integer iPos,iCount = 0 [ ] [ ] sTemp = sFileWithPath [ ] iPos = strPos ("\",sTemp, TRUE) [-] if (iPos > 0) [ ] sFileName = Substr (sTemp,iPos + 1) [ ] sFilePath = Left (sTemp,iPos -1) [-] else [ ] Print (" File {sFileWithPath} does not have File Separator")

Friday, May 30, 2008

Silktest - String Match against a List

Silktest has MatchStr function to compare one string with another. Here you can use pattern. But Silktest does not have a built-in function to match a item by a pattern with a List of items. I have used this scenario in many places of the code. Code snippet is given below.

4Test Code: To Match a string against List

[-] public Integer MatchList(String sPattern, LIST OF STRING lsInput) [ ] //To match one string with any item in list of strings [ ] //Returns the item value(integer) [ ] Integer iCount, iItem [ ] String sData, sTemp [ ] Integer iReturn = 0 [ ] [ ] iCount = ListCount(lsInput) [-] for iItem=1 to iCount [-] if (MatchStr(sPattern,lsInput[iItem])) [ ] iReturn = iItem [ ] break [ ] [ ] return iReturn

Thursday, May 29, 2008

Silktest - Classic 4Test and Visual 4Test

I think that many of the silktest automation engineers do not know, Silkest has two outline editors. Visual 4Test, enabled by default, is similar to Visual C++ and contains colors.

Classic 4Test is one of the two outline editors you can use with SilkTest. Classic 4Test is similar to C and does not contain colors.

Below I have given the samples for both type of modes. To change editor modes, click Edit Menu -> "Visual 4Test" to select or clear the check mark. You can also specify your editor mode on the General Options dialog.

Sample Classic 4Test - Silktest Code



public LIST OF WINDOW GetChildObjects(Window wContainer, DATACLASS dcObject)
{
// To get All child objects.
// Used recursive method.
LIST OF WINDOW lwndObjects, lwTemp1, lwTemp2;
LIST OF WINDOW lwndChildren =
{
};
WINDOW wParent, wChild, wTemp;

do
{
if (wContainer.Exists (10))
{
lwndChildren = wContainer.GetChildren (TRUE, FALSE);

for each wChild in lwndChildren
{
if wChild.IsOfClass(dcObject)
{
ListAppend (lwndObjects,wChild);
}
else
{
lwTemp1 = wChild.GetChildren(TRUE, FALSE);
if (ListCount(lwTemp1) > 1)
{
lwTemp2 = GetChildObjects(wChild,dcObject); //To get particular objects
if (ListCount(lwTemp2) > 0)
{
ListMerge (lwndObjects, lwTemp2);
}
}
}
}
}
else
{
Print ("Container {[STRING]wContainer} window is not available.");
}
}
except
{
ExceptLog ();
}

return lwndChildren;
}


Sample Visual 4Test - Silktest Code


[+] public LIST OF WINDOW GetChildObjects(Window wContainer, DATACLASS dcObject)
[ ] // To get All child objects.
[ ] // Used recursive method.
[ ] LIST OF WINDOW lwndObjects, lwTemp1, lwTemp2
[ ] LIST OF WINDOW lwndChildren = {...}
[ ] WINDOW wParent, wChild, wTemp
[ ]
[-] do
[-] if (wContainer.Exists (10))
[ ] lwndChildren = wContainer.GetChildren (TRUE, FALSE)
[ ]
[-] for each wChild in lwndChildren
[-] if wChild.IsOfClass(dcObject)
[ ] ListAppend (lwndObjects,wChild)
[-] else
[ ] lwTemp1 = wChild.GetChildren(TRUE, FALSE)
[-] if (ListCount(lwTemp1) > 1)
[ ] lwTemp2 = GetChildObjects(wChild,dcObject) //To get particular objects
[-] if (ListCount(lwTemp2) > 0)
[ ] ListMerge (lwndObjects, lwTemp2)
[-] else
[ ] Print ("Container {[STRING]wContainer} window is not available.")
[+] except
[ ] ExceptLog ()
[ ]
[ ] return lwndChildren

Wednesday, March 12, 2008

4test - Search and Replace

One project required to replace certain tags at every build. I written this function SearchAndReplaceInFile. This code snippet to search and replace strings in a file.

Code:



[+] public void SearchAndReplaceInFile (STRING sFileInput, STRING sFileOutput, STRING sSearch, STRING sReplace )
HFILE hInFile, hOutFile
STRING sTemp, sLine, sValue
INTEGER iPos1, iPos2

hInFile = FileOpen (sFileInput,FM_READ)
hOutFile = FileOpen (sFileOutput, FM_WRITE)

[-] while (FileReadLine (hInFile, sLine))
sTemp = sLine
[-] if !(Trim(sSearch) == Trim (sReplace))
ReadLine:
iPos1 = StrPos (sSearch,sTemp)
//Print ("Position {sTemp} - {sSearch} : {iPos1}")
[-] if (iPos1 > 0)
sValue = StrTran (sTemp, sSearch, sReplace)
//Print ("got value: {sValue}")
sTemp = sValue
goto ReadLine
FileWriteLine(hOutFile,sTemp)
FileClose (hInFile)
FileClose (hOutFile)

Friday, March 7, 2008

Recursive technique

I am very much interested to include the recursive technique. It is simplifying the code and reduce the number of lines. You can get the definition on Wiki. Below I have given the sample 4test code. This code snippet will get child objects from the given container object.



[+] public LIST OF WINDOW GetChildObjects(Window wContainer, DATACLASS dcObject)
// To get All child objects.
// Used recursive method.
LIST OF WINDOW lwndObjects, lwTemp1, lwTemp2
LIST OF WINDOW lwndChildren = {...}
WINDOW wParent, wChild, wTemp

[+] do
[+] if (wContainer.Exists (10))
lwndChildren = wContainer.GetChildren (TRUE, FALSE)

[+] for each wChild in lwndChildren
[+] if wChild.IsOfClass(dcObject)
ListAppend (lwndObjects,wChild)
[+] else
lwTemp1 = wChild.GetChildren(TRUE, FALSE)
[+] if (ListCount(lwTemp1) > 1)
lwTemp2 = GetChildObjects(wChild,dcObject) //To get particular objects
[+] if (ListCount(lwTemp2) > 0)
ListMerge (lwndObjects, lwTemp2)
[+] else
Print ("Container {[STRING]wContainer} window is not available.")
[+] except
ExceptLog ()

return lwndChildren