Testing
What is Silk Test?
SilkTest is •
A powerful tool for running automated test cases on the front end •
A tool for testing Web based applications across different browsers •
Very very stupid – you have to tell it everything in its own language (4test) •
Inflexible when it comes to interpreting your commands It cannot guess at what you mean It requires a certain syntax with certain words • This can be quite maddening
Q1. How do I add steps to DefaultBaseState?
The easiest method is to add a BaseState () method to the main window of the application. That's the one that wMainWindow is set to. If you define this method, it will be executed at the end of DefaultBaseState (). Suggestion: By using GetTestCaseState (), you can make your method behave differently depending on whether the testcase is starting or stopping. This function will tell you whether the testcase is starting or stopping.
Q2. Where can I find all the methods for a class? Use the Library Browser. Its invoked by choosing Help-->Library Browser from the SilkTest menu. Select the class tab, then select the class you want to view. The methods for the class appear in the right panel. You can click on a method and view its syntax. If you check the box marked Show Inherited, all the methods from the ancestor classes will be shown. Its major disadvantage is that you can't copy from it.
Q3. Why don't methods defined in a derived class inherit ? When you create a class using winclass MoveableWin : MoveableWin, you're actually deriving a new class which has the same name as the original class. All objects automatically become instances of the new derived class. However, other derived classes, such as DialogBox in this case, have already been inherited from the original MoveableWin. This happened at startup and can't be changed. Therefore, any methods you added to the inherited MoveableWin class will not be available for use by DialogBox objects. Example: winclass MoveableWin : MoveableWin Close () // Steps to close windows window DialogBox Test tag "Test" parent MyApplication main () Test.Close () Notes: The DialogBox "Test" will not use the new Close method defined above, even though DialogBox inherits from MoveableWin.
Q4. How can I change test frames in the middle of a testplan? First you need to understand optionsets. This feature lets you save your configuration in a file. The configuration includes your Agent Options, Runtime Options and Class Mappings. The feature is very useful when you try to open your test frame on a new machine. The optionset brings all the settings from one machine to another, including the test frame. This is also very useful for a team. Within SilkOrganizer, you can use the optionset command, which changes the current optionset on the fly during execution of a test plan. Syntax: optionset: filename Example: optionset: scriptsgeneralie4_hr11frame.opt
Q5. Can I pass global variables from SilkOrganizer to SilkTest ? Yes, you can just reference them directly. For example, if you have a list of string defined in the test frame, you can pass the variable from SilkOrganizer as testdata or directly in the testcase statement.
Q6. Is the Extension Kit difficult to use ? No, if you have the cooperation of the developer (s). If they understand the value of adding functionality for you and if you're perfectly clear about what you need, you will have very quick success at implementing the EK. This assumes that the technology for them to retrieve the information you want exists within their application. Sometimes with 3rd party controls, there is no exposed API which provides what you need. Unfortunately, sometimes you will need to verify some custom objects manually (visually).
Q7. Can I call Silk Scripts from an external shell program. ? Yes. One way is to just call Silk and pass the name of the script using the command line arguments. The complete list of arguments is shown below. Command Line Options Syntax: optionset: filename -m Machine Name -r Script / Testplan / or Suite Name -q Quit SilkTest after the script or plan completes execution. -query Testplan query to run -p Post error count to calling program -resexport Output results files to rex files partner -m LabMachine13 -q -query FunctionalTests -r InsertNewData.pln Example: This command would execute the query FunctionalTests defined in the testplan InsertNewData,pln on the machine LabMachine13 and exit SilkTest after the testplan completes.
Q8. What's the difference between SilkTest and QA Partner ? Originally there was only one product, QA Partner. In 1996, Silk (later renamed SilkTest), was introduced as the Web Testing tool. It was actually the same executable as QA Partner, but with browser capabilities turned on. This turned out to be confusing for most customers. If you bought Silk, you could just turn off the browser feature and then you'd have QA Partner. However, if you bought QA Partner, you wouldn't have the ability to test browsers. Starting with SilkTest 5.0, there is only one product again. Q9. What is Immediate If? Immediate If is a 4-test operator which is little known. It allows you to do an if-then-else on a single line. The syntax is as follows: boolean ? ReturnValueIfTrue : ReturnValueIfFalse BOOLEAN bFirstTime = FALSE STRING sGreeting = bFirstTime ? "Welcome" : "Welcome back"
Q10. When do you need to use the "this" keyword and when don't you? The "this" keyword is used in window class methods to refer to the instance variable which is calling the method at runtime. The "this" keyword is only required when you want to access a data member which is uniquely defined in the instance. Otherwise its use is optional. Example: winclass DialogBox : DialogBox Close () this.wCloseButton.Click () NewMethod () if (Exists ()) // Perform some steps window DialogBox Test tag "Test" parent MyApplication window wCloseButton = Exit PushButton Exit tag "Exit" main () Test.Close () Notes: In the close method above, the "this" keyword is required because the method needs to reference a data member which is declared in the instance "Test". In the NewMethod above, this.Exists () is not required, because it is referencing a method which is defined at the class level.
Q11. Should I create a function or a method? If the action you are automating is: closely related to a specific window, create a method of that specific window. closely related to a class of objects, create a method of that window class. more of a utility, not related to a window or class of windows, create a function.
Q12. What does the recording statement do? The recording statement set the following Agent Verification options to FALSE o OPT_REQUIRE_ACTIVE o OPT_VERIFY_ACTIVE o OPT_VERIFY_CLOSED o OPT_VERIFY_EXPOSED This can be useful if you specifically want to turn these verifications off for a specific block of code, but usually it is better to remove the recording statement after you record the statements you need (run with these options set to TRUE)
Q13. When and why is the Sleep () statement needed? Sometimes Silk can't tell when an application is busy. When this happens, Silk tries to execute the next step which gets thrown away by the application or causes an error which is usually very difficult to reproduce either manually or under debug mode. When this happens, a well-placed Sleep (2) or Sleep (5) can often solve this annoying problem. A few extra sleep statements to make sure that the application is ready to move forward may be worth the small difference in the time it takes to execute your scripts.
14. What is WinClass? Declares a window class for an application-specific window or control. Note Window class declarations must appear outside of any function. 15. Features in silk 7.5 The list of New features in 7.5 are 1) Support for Infragistics Grid and Toolbar controls 2) Project packaging for relocating and emailing 3) Project Explorer enhancements 4) Java Custom Windows record and playback enhancements 5) Beta support for .NET Framework Version 2 6) Updated technology support JDK 1.5 AOL 9 Security Edition Sybase PowerBuilder 10 Silent Installation Support for Microsoft's Source Code Control Integration FILE HANDLING FILEMODE data type Describes the file mode for a file. The file mode is a required parameter for the FileOpen function. 4Test defines this enumerated data type as follows: type FILEMODE is enum FM_READ FM_WRITE FM_UPDATE FM_APPEND Each field is defined as follows: FM_READ Opens the file for reading. SilkTest raises the exception E_FILE if the file does not exist. FM_WRITE Opens the file for writing. If the file does not exist, it is created. If the file exists, it is truncated to zero (0) bytes. FM_UPDATE Similar to FM_WRITE, except that it does not truncate the file. By default, it denies write access to other users. The file pointer is positioned at the beginning of the file. FM_APPEND Opens the file for appending. If the file does not exist, it is created. If the file exists, the file pointer is positioned at the last line of the file. By default, it does not deny write access to other users. About file handles and remote file input and output SilkTest has several functions such as FileOpen() and SYS_FileOpen() whose only difference is whether the function works on a local machine or on a remote machine. Since these functions are so closely related, it’s important to understand their similarities and differences. This section describes file handles and their relationship to remote file input and output: • Introduction to remote file input and output • Introduction to file handles • Tips on using the remote file functions • Examples of what to do and what not to do • Writing to a file on a target machine • Reading from a file on a target machine Introduction to remote file input and output SilkTest provides file functionality to allow users to read/write data to or from files. The data can be user to drive testing of application, to control application as in the INI file and store testing data or results that does not fit in the result file. File is a resource that is control and referenced by file handle variables. This resource has a scope (life), it is local ore remote and it has attributes or modes. A file can be open as read only, write only and or update (read/write). The file can have attribute as in share or not shared. Introduction to file handles When you use FileOpen() it returns the HANDLE datatype you can use in other functions to read, write, and update the file. SYS_FileOpen() also returns a HANDLE datatype you can use with either local or remote file handles. The only difference between FileOpen() and SYS_FileOpen() is where the file is that is opened. FileOpen() opens a file locally on the "host" (partner.exe). If you are using distributed testing, you may want to open a file on the "target" or remote machine. In that case, you must use SYS_FileOpen() to open the remote file and then use the appropriate file manipulation function to complete the task. If you open a file locally with FileOpen(), you must use local File functions (such as FileReadLine and FileWrite). You cannot use remote functions such as SYS_FileReadValue. However, if you open a file using SYS_FileOpen(), you may edit it with local file functions. Tips on using the remote file functions A file is open and a handle is return to the caller. It is the responsibility of the caller to ensure the proper operation of the file and that the file is closed correctly. The scope of the local files (FileOpen() or IniFileOpen()) is from start of a script to end of script. A script is either the individual test in a TestPlan or the run of a main (implicit or explicit) which can cross multi testCase. The scope of a remote files (SYS_FileOpen() or SYS_IniFileOpen) is from AGENT connect to AGENT disconnect. Most of the time the default of remote is the start of a TestCase to the exit of the TestCase.. The default can be over written by the used of the connect and disconnect 4Test function. Examples of what to do and what not to do This section contains the following examples: • A correctly set up testcase • Testcases with local handles and invalid handles • Testcase with double close Correctly set up testcase The file handle is a user defined variable whose scope is defined by the location of the variable declaration. You must be sure that the file is not closed before the variable goes out of scope. If the variable does goes out of scope, the file is lost until it is closed by the resource going out of scope. On the remote files, you must also keep track as to which file handle belongs to which remote AGENT. The file handle itself has no information as to what remote host it belongs to. It is possible that a file handle for one remote host matches another host file handle. The file handle only know that it is local or remote and whether it’s a generic file, INI file, or another file type. The following testcase is correctly set up for remote file handling. TestCase FileCreate () HANDLE hFile hFile = FileOpen ("c:myfile.txt", FM_WRITE, NULL) FileWriteLine (hFile, "This is a Test File line one.") FileWriteLine(hFile, "This is line two.") FileClose (hFile) // end of TestCase TestCase FileRead () HANDLE hFile STRING sMyData BOOL bDidRead hFile = FileOpen ("c:myfile.txt", FM_READ) bDidRead = FileReadLine (hFile, sMyData) Print (sMyData) FileClose (hFile) // end of TestCase Testcases with local handles and invalid handles Here are two examples of testcases that have not been set up correctly. In the first testcase, the file is not closed, and the handle is not saved because it is only local to the LocalFile testcase. The second testcase raises an exception due to the invalid handle. TestCase LocalFile() HANDLE hLocalHandle hLocalHandle = FileOpen ("c:myfile.txt", FM_WRITE) FileWriteLine (hLocalHandle, "test line"); TestCase LostHandlfile() HANDLE hLocalHandle FileWriteLine (hLocalHandle, "Test Line") FileClose (hLocalHandle) The file operation is not restricted to other type of files (i.e used FileOpen for INI file creation or modification and IniFileOpen to read the file). It is possible to create a INI file by using a generic file function such as FileWriteLine() or even to read the INI file via FileReadLine(). You can create a list file and later read it back by using the ListRead() function. Note that once the file is closed, its handles become invalid so that if you close a file twice, the second attempt raises an exception. The same is true for the other file functions. With this in mind, be careful when you process a file with functions containing do..except and exception handling. A mistake can cause another exception to generate or loss of file handles. Testcase with double close In the testcase below, the second File Close causes an INVALID_FILE_HANDLE exception. TestCase DoubleClose () Handle hFile hFile = FileOpen ("c:myfile.txt", FM_WRITE) do SYS_FileWriteLine (hFile, "This will except because of local vs remote mismatch") except Print ("Some error statement") FileClose (hFile) FileClose (hFile) To correct the testcase above, do one of the following: • remove the "fileClose (hFile)" in the exception block • add either the reraise or the Raise function to continue the exception processing without returning to the main line FileWriteLine function Action Writes a line of text to a file on the host system. Syntax FileWriteLine (hFile, sLine) Variable Description hFile The handle of the file to write to. HFILE. sLine The text to write. STRING. Notes FileWriteLine writes the specified string to the file identified by hFile. It automatically appends the appropriate character or characters (for example, a carriage return/line feed sequence) needed to delimit a line of text on the current platform. You can get a handle to a file (an HFILE) by calling the FileOpen function with the filemode data type set to either FM_WRITE, FM_UPDATE, or FM_APPEND. The File functions that control writing to a file do not test your accessibility to a file. This means that you cannot write information to a file that has been opened in read only mode with FileOpen(). The function will successfully return, but no information is actually written to the file. There is no error message that indicates this. Example HFILE FileHandle // Open file, append line, and close FileHandle = FileOpen ("mydata.txt", FM_APPEND) FileWriteLine (FileHandle, "next line of text") FileClose (FileHandle) FileOpen function Action Opens a file on the host system. Syntax hFile = FileOpen (sPath, fmMode [, fsShare[, ftType]]) Variable Description hFile A handle to the opened file. HFILE. sPath The name of the file to open. STRING. fmMode The mode to open the file with. FILEMODE. fsShare Optional. Specifies file-sharing behavior. FILESHARE. ftType Optional. Specifies the format of the text file to be created. Available only with SilkTest International. Only has an affect when creating a new file. FILETYPE Notes FileOpen opens the file identified by sPath, or creates it, depending on the mode you specify (see below). This function returns a file handle of type HFILE, which you pass to other file functions. Any open local files are automatically closed and saved at the end of a test script. The File functions that control writing to a file (such as FileWriteLine, FileWrite Value, and their SYS_ equivaltents) do not test your accessibility to a file. This means that you cannot write information to a file that has been opened in read only mode with FileOpen(). The function will successfully return, but no information is actually written to the file. There is no error message that indicates this. Example Here’s a simple example which checks a BOOLEAN value presumably passed into the function/testcase) to determine whether or not the file should be shared and then sets the file-sharing behavior accordingly. // output file handle HFILE OutputFileHandle FILESHARE fShare // check to see if file opening should lock out other writers if (bExclusiveWrite == TRUE) fShare = FS_DENY_WRITE else fShare = FS_DENY_NONE // now open the file OutputFileHandle = FileOpen ("mydata.txt", FM_WRITE, fShare) FileReadLine function Action Returns the next line of a file on the host system. Syntax bDidRead = FileReadLine (hFile, sLine) Variable Description bDidRead Whether a line was read. BOOLEAN. hFile The handle of the file to read a line from. HFILE. sLine A variable to hold the line. out STRING. Notes FileReadLine reads the next line of a file and returns the contents of the line in sLine. Typically, you open a file with FileOpen, and then read it line by line with FileReadLine until FALSE is returned. You can get a handle to a file (an HFILE) by calling the FileOpen function with the FM_READ filemode data type. An exception is raised if an invalid file handle is specified. FileReadLine returns TRUE if a line was read, or FALSE if the end of the file was encountered. FileReadLine modifies the sLine variable. Any previous value in sLine is discarded. FileReadLine considers the end-of-line character to be a carriage return (CR), even if it is not combined with a linefeed (LF) character. In other words, both CR and CR-LF are considered line terminators. 4Test recognizes that it has reached the end of a file (EOF) by no longer reading that file – in other words, by receiving a null string. It does not read any special character at the EOF. For SilkTest, EOF is indicated by a FALSE bDidRead return and a null string is indicated by a TRUE bDidRead return and a null string. The SilkTest file read functions can handle line lengths up to 4K characters. This applies to the FileReadLine function, FileReadValue function, SYS_FileReadLine function, and SYS_FileReadValue function. Examples HFILE hFile STRING sLine testcase FileReadExample () hFile = FileOpen ("mydata.txt", FM_READ) while (FileReadLine (hFile, sLine)) // statements to process this line FileClose (hFile) You can also read from a file opened in file mode FM_UPDATE, in order to begin overwriting the file in the middle instead of at the beginning. For example: [ ] STRING s [ ] INTEGER i [ ] HFILE hFile = FileOpen ("{GetProgramDir ()}Sample.txt", FM_UPDATE) [-] for i = 1 to 2 [ ] FileReadLine (hFile, s) [ ] FileWriteLine (hFile, "*New one*") [ ] FileWriteLine (hFile, "*This is new line two*") [ ] FileClose (hFile) // Before: // Line 1 // Line 2 // Line 3 // Line 4 // Line 5 // After: // Line 1 // Line 2 // *New one* // *This is new line two* FileWriteValue function Action Writes structured data (for example, a 4Test record) directly to a file on the host system. Syntax FileWriteValue (hFile, aValue) Variable Description hFile A handle to the file to write to. HFILE. aValue The data to write to the file. ANYTYPE. Notes FileWriteValue writes each piece of data (aValue) on its own line in hFile. For example, if you call FileWriteValue three times on a new file, the resulting file will have three lines. You can get a handle to a file (an HFILE) by calling the SYS_FileOpen function with the filemode data type set to either FM_WRITE, FM_UPDATE, or FM_APPEND. You can specify any 4Test data type as aValue. Note the following about how the data is written to the file: • Strings are enclosed by double quotation marks. • Numbers are not enclosed by quotation marks. • Composite data (such as lists and records) are enclosed by curly braces, with elements separated by commas. FileWriteValue raises an exception if the write operation fails. You can use FileReadValue to read files created with FileWriteValue. The File functions that control writing to a file do not test your accessibility to a file. This means that you cannot write information to a file that has been opened in read only mode with FileOpen(). The function will successfully return, but no information is actually written to the file. There is no error message that indicates this. Example type PERSON is record STRING sName INTEGER iAge STRING sFile = "people.dat" testcase WriteToFile () LIST OF PERSON lPerson = {...} {'Bob', 46} {'Emily', 16} {'Craig', 13} STRING sText = "Number of people:" INTEGER iCount = ListCount (lPerson) HFILE hFile PERSON Person hFile = FileOpen (sFile, FM_WRITE) // Open the file // write header information FileWriteValue (hFile, sText) FileWriteValue (hFile, iCount) // write the data for each Person in lPerson // Write to the file FileWriteValue (hFile, Person) FileClose (hFile) // Close the file // Resulting contents of people.dat: // "Number of people:" // 3 // {"Bob", 46} // {"Emily", 16} // {"Craig", 13} SYS_FileReadValue function Action Reads structured data (for example, a 4Test record) directly from a file on a target machine. Syntax bResult = SYS_FileReadValue (hFile, aValue) Variable Description bResult TRUE if the read operation is successful; FALSE if at end of file. BOOLEAN. hFile A handle to the file. HFILE. aValue The data read from the file. ANYTYPE. Notes Use SYS_FileReadValue to read information from files that are structured the same way that the SYS_FileWriteValue function structures files. The file must have only one value per line. SYS_FileReadValue reads the data in a record or list as a single value, so make sure that all elements of a record or list are on the same line (SYS_FileWriteValue does this automatically when it writes a record or list). Blank lines and lines starting with "//" are ignored. See SYS_FileWriteValue for more information about how to structure files for use with SYS_FileReadValue. SYS_ FileReadValue is executed by the Agent process, not the SilkTest process; but it is essentially the same as FileReadValue. To affect the host process, use the function with the hHost notation or machine handle operator. For more information about the machine handle operator and hHost, see Machine handle operator. SYS_FileReadValue raises an exception if the read operation fails. You can get a handle to a file (an HFILE) by calling the SYS_FileOpen function with the FM_READ filemode data type. An exception is raised if an invalid file handle is specified. You can read from a file opened in file mode FM_UPDATE, in order to begin overwriting the file in the middle instead of at the beginning. See the example under FileReadLine function. 4test recognizes that it has reached the end of a file (EOF) by no longer reading that file –in other words, by receiving a null string. It does not read any special character at the EOF. For SilkTest, EOF is indicated by a FALSE bDidRead return and a null string is indicated by a TRUE bDidRead return and a null string. Example The following example uses the file that was created in the example for SYS_FileWriteValue. type PERSON is record STRING sName INTEGER iAge STRING sFile = "people.dat" testcase ReadFromFile () ANYTYPE Item HFILE hFile hFile = SYS_FileOpen (sFile, FM_READ) // Open the file while (SYS_FileReadValue (hFile, Item)) // Read from file Print (Item) SYS_ FileClose (hFile) // Result: // Number of people: // 3 // {Bob, 46} // {Emily, 16} // {Craig, 13} SYS_FileOpen function Action Opens a file on a target machine. Syntax hFile = SYS_FileOpen (sPath, fmMode [, fsShare[, ftType]]) Variable Description hFile A handle to the opened file. HFILE. sPath The name of the file to open. STRING. fmMode The mode to open the file with. FILEMODE. fsShare Optional. Specifies file-sharing behavior. FILESHARE. ftType Optional. Specifies the format of the text file to be created. Available only with SilkTest International. Only has an effect when creating a new file. FILETYPE Notes SYS_FileOpen is executed by the Agent process, not the SilkTest process; but it is essentially the same as FileOpen. To affect the host process, use the function with the hHost notation or machine handle operator. For more information about the machine handle operator and hHost, see Machine handle operator. The handle can be used by all the SYS_ functions and non SYS_ functions. With the non SYS_ functions SilkTest recognizes the handle and calls the appropriate function. SYS_FileOpen opens the file identified by sPath, or creates it, depending on the mode you specify (see below). This function returns a file handle of type HFILE, which you pass to other file functions. When the Agent disconnects, any open files are closed and saved, but we strongly encourage you to use SYS_FileClose() when you are finished with a file. Any open files are automatically closed and saved at the end of a test script as well. Example Here’s a simple example which checks a BOOLEAN value (presumably passed into the function/testcase) to determine whether or not the file should be shared and then sets the file-sharing behavior accordingly. // output file handle HFILE OutputFileHandle FILESHARE fShare // check to see if file opening should lock out other writers if (bExclusiveWrite == TRUE) fShare = FS_DENY_WRITE else fShare = FS_DENY_NONE // now open the file OutputFileHandle = SYS_FileOpen ("mydata.txt", FM_WRITE, fShare) SYS_FileReadLine function Action Returns the next line of a file from a target machine. Syntax bDidRead = SYS_FileReadLine (hFile, sLine) Variable Description bDidRead Whether a line was read. BOOLEAN. hFile The handle of the file to read a line from. HFILE. sLine A variable to hold the line. out STRING. Notes SYS_ FileReadLine is executed by the Agent process, not the SilkTest process; but it is essentially the same as FileReadLine. To affect the host process, use the function with the hHost notation or machine handle operator. For more information about the machine handle operator and hHost, see Machine handle operator. SYS_FileReadLine reads the next line of a file and returns the contents of the line in sLine. Typically, you open a file with SYS_FileOpen, and then read it line by line with SYS_FileReadLine until FALSE is returned. SYS_FileReadLine returns TRUE if a line was read, or FALSE if the end of the file was encountered. SYS_FileReadLine modifies the sLine variable. Any previous value in sLine is discarded. SYS_FileReadLine automatically handles cross-platform end-of-line differences. You can get a handle to a file (an HFILE) by calling the SYS_FileOpen function with the FM_READ filemode data type. An exception is raised if an invalid file handle is specified. You can read from a file opened in file mode FM_UPDATE, in order to begin overwriting the file in the middle instead of at the beginning. See the example under FileReadLine function. 4test recognizes that it has reached the end of a file (EOF) by no longer reading that file – in other words, by receiving a null string. It does not read any special character at the EOF. For SilkTest, EOF is indicated by a FALSE bDidRead return and a null string is indicated by a TRUE bDidRead return and a null string. The SilkTest file read functions can handle line lengths up to 4K characters. This applies to the SYS_FileReadLine function, FileReadLine function, FileReadValue function, and SYS_FileReadValue function. Example HFILE hFile STRING sLine testcase FileReadExample () hFile = SYS_FileOpen ("mydata.txt", FM_READ) while (SYS_FileReadLine (hFile, sLine)) // statements to process this line SYS_FileClose (hFile) SYS_FileWriteValue function Action Writes structured data (for example, a 4Test record) directly to a file on a target machine. Syntax SYS_FileWriteValue (hFile, aValue) Variable Description hFile A handle to the file to write to. HFILE. aValue The data to write to the file. ANYTYPE. Notes SYS_ FileWriteValue is executed by the Agent process, not the SilkTest process; but it is essentially the same as FileWriteValue. To affect the host process, use the function with the hHost notation or machine handle operator. For more information about the machine handle operator and hHost, see Machine handle operator. You can get a handle to a file (an HFILE) by calling the SYS_FileOpen function with the filemode data type set to either FM_WRITE, FM_UPDATE, or FM_APPEND. SYS_FileWriteValue writes each piece of data (aValue) on its own line in hFile. For example, if you call SYS_FileWriteValue three times on a new file, the resulting file will have three lines. You can specify any 4Test data type as aValue. Note the following about how the data is written to the file: • Strings are enclosed by double quotation marks. • Numbers are not enclosed by quotation marks. • Composite data (such as lists and records) are enclosed by curly braces, with elements separated by commas. You can use SYS_FileReadValue to read files created with SYS_FileWriteValue. The File functions that control writing to a file do not test your accessibility to a file. This means that you cannot write information to a file that has been opened in read only mode with FileOpen(). The function will successfully return, but no information is actually written to the file. There is no error message that indicates this. Example type PERSON is record STRING sName INTEGER iAge STRING sFile = "people.dat" testcase SYS_WriteToFile () LIST OF PERSON lPerson = {...} {'Bob', 46} {'Emily', 16} {'Craig', 13} STRING sText = "Number of people:" INTEGER iCount = ListCount (lPerson) HFILE hFile PERSON Person hFile = SYS_FileOpen (sFile, FM_WRITE) // Open the file // write header information SYS_FileWriteValue (hFile, sText) SYS_FileWriteValue (hFile, iCount) // write the data for each Person in lPerson // Write to the file SYS_FileWriteValue (hFile, Person) SYS_FileClose (hFile) // Close the file // Resulting contents of people.dat: // "Number of people:" // 3 // {"Bob", 46} // {"Emily", 16} // {"Craig", 13} FILEINFO data type Describes a particular file by providing its attributes. 4Test defines this record data type as follows: type FILEINFO is record string sName boolean bIsDir number iSize integer iAttributes datetime dtLastModifyTime datetime dtCreationTime Where: • sName is a string specifying the file name • bIsDir is a boolean indicating whether the file is a true file or a directory • iSize is an number specifying the file’s size • iAttributes is an integer specifying the attributes of the file • dtLastModifyTime is of the datetime data type and specifies the date and time that the file was last modified • dtCreationTime is of the datetime data type and specifies the date and time that the file was created Attributes The file attributes that you can determine with FILEINFO are: FILE_ATTRIBUTE_ARCHIVE FILE_ATTRIBUTE_OFFLINE FILE_ATTRIBUTE_COMPRESSED FILE_ATTRIBUTE_READONLY FILE_ATTRIBUTE_DIRECTORY FILE_ATTRIBUTE_REPARSE_POINT FILE_ATTRIBUTE_HIDDEN FILE_ATTRIBUTE_SPARSE_FILE FILE_ATTRIBUTE_ENCRYPTED FILE_ATTRIBUTE_SYSTEM FILE_ATTRIBUTE_NORMAL FILE_ATTRIBUTE_TEMPORARY FILE_ATTRIBUTE_NOT_CONTENT_INDEXED Note To determine a file attribute, you must use a binary AND comparison with the file attribute. If the comparison returns that same file attribute, then the attribute exists. FILEPOS data type Describes how the FileSetPointer function should set the read/write position in an open file. 4Test defines this enumerated data type as follows: type FILEPOS is enum FP_START FP_END FP_RELATIVE IsFileRemote function Action Tests whether a file handle points to a target (remote) machine. Syntax bRemoteHandle = IsFileRemote (hFileHandle) Variable Description bRemoteHandle TRUE if the file handle points to a target machine. BOOLEAN. hFileHandle The handle of the file retrieved from FileOpen(), SYS_FileOpen(), IniFileOpen(), or SYS_IniFileOpen(). IsFileRemote returns TRUE if the file handle points to a target machine, or FALSE if the file handle does not point to a target machine. The file can be of any sort, including an .ini file. ResOpenList function Action Creates a new hierarchical level in the results file. Syntax ResOpenList (sName) Variable Description sName The name of the level as it will appear in the results file. STRING. Notes Use ResOpenList to start a new hierarchical level. The Print commands that follow it are indented until you close the level with ResCloseList. When you view the results file, the item sName is initially collapsed, indicated by the [+] icon next to it. You can expand sName to reveal the indented items under it. Example testcase ResOpenListExample () ResOpenList ("Level 1") // Create a new level Print ("subitem 1") // Add subitems to the level Print ("subitem 2") Print ("subitem 3") ResCloseList () // Close this level // In Results file, you see // [+] Level 1 // Clicking on the [+] icon reveals // [-] Level 1 // subitem1 // subitem2 // subitem3 ResCloseList function Action Closes a hierarchical level in the results file that was opened with ResOpenList. Syntax ResCloseList ( ) Notes Use ResOpenList to start a new hierarchical level. The Print commands that follow it are indented until you close the level with ResCloseList. When you view the results file, the item sName is initially collapsed, indicated by the [+] icon next to it. You can expand sName to reveal the indented items under it. Example testcase ResCloseListExample () ResOpenList ("Level 1") // Create a new level Print ("subitem 1") // Add subitems to the level Print ("subitem 2") Print ("subitem 3") ResCloseList () // Close this level // In Results file, you see // [+] Level 1 // Clicking on the [+] icon reveals // [-] Level 1 // subitem1 // subitem2 // subitem3 ResExport function Action Exports one or more results sets to a results export (.rex) file. Syntax ResExport (sResultsFile [, sREXFile, iStartIndex, iEndIndex ]) Variable Description sResultsFile The name of the results file containing the results set(s) you want to export. It cannot be the current results file. STRING. sREXFile Optional. Results export file to save the results set(s) to. If not specified, results are saved in a file with the same name as sResultsFile, in the same directory, with the .rex extension. If only a file name is specified, the file is saved in the same directory as sResultsFile. STRING. iStartIndex Optional. Index of the most recent results set to save. 0 represents the most recent results set; 1 the next most recent, and so on. If not specified, saves most recent results set. INTEGER. iEndIndex Optional. Index of oldest results set to save. 0 represents the most recent results set; 1 the next most recent, and so on. If not specified, saves most recent results set. INTEGER. Notes Use ResExport to save one or more results sets to a .rex file, which is a structured (delimited) text file that is suitable for importing into a spreadsheet or other application for further processing. ResExport uses export parameters that are specified in the [ResultsExport] section in partner.ini. These parameters specify which fields are exported and the format of the exported file. You can view and set these parameters in the Results Export dialog. To set the parameters, select Results/Export, specify your preferences, then click OK. The preferences are saved in the [ResultsExport] section in partner.ini (if you changed one or more values from the defaults) and are used the next time you call the ResExport function in a script or select the Results/Export command. Example The following statement exports the most-recent results set from db.res to db.rex. ResExport ("d:mytestsdb.res") The following statement exports the second-most-recent and third-most-recent results sets from db.res to db.rex. ResExport ("d:mytestsdb.res",NULL,1,2) ResExportOnClose function Action Exports the most recent results set from the current results file to a results export (.rex) file when the script/suite/testplan terminates. Syntax ResExportOnClose ( [sREXFile] ) Variable Description sREXFile Optional. Results export file to save the results set to. If not specified, results are saved in a file with the same name as the current results file, in the same directory, with the .rex extension. If only a file name is specified, the file is saved in the same directory as the current results file. STRING. Notes Use ResExportOnClose to save the most recent results set from the current results file to a .rex file, which is a structured (delimited) text file that is suitable for importing into a spreadsheet or other application for further processing. ResExportOnClose uses export parameters that are specified in the [ResultsExport] section in partner.ini. These parameters specify which fields are exported and the format of the exported file. You can view and set these parameters in the Results Export dialog. To set the parameters, select Results/Export, specify your preferences, then click OK. The preferences are saved in the [ResultsExport] section in partner.ini (if you changed one or more values from the defaults) and are used the next time you call the ResExportOnClose function in a script or select the Results/Export command. Example The following statement exports the most-recent results set from the current results file to current.rex file when the script terminates. ResExportOnClose ("current.rex") DATABASE HANDLING DB_ColumnPrivileges function Action Returns the column privileges for the specified table column(s) as a result set on the statement handle. Syntax hstmnt = DB_ColumnPrivileges (hdbc, catalog-name, schema-name, table-name,column-name) Variable Description hstmnt Statement handle returned for the result set. It is an input parameter for other DBTester functions. HSQL. hdbc The handle to a database as returned by DB_Connect. HDATABASE. catalog-name Catalog name. STRING. schema-name Schema name. STRING. table-name Table name. STRING. column-name String search pattern for column names. STRING. Notes DB_ColumnPrivileges corresponds to SQLColumnPrivileges. Please consult your documentation for more information about SQLColumnPrivileges. Wildcard characters are supported: % (percent sign) matches any character sequence, and _ (underscore) matches any single character. To omit a variable argument, specify it as an empty string (""). When you receive a valid statement handle, you can issue a call to DB_FetchNext or DB_FetchPrevious to manipulate the information. Example To retrieve the column privileges for a specific table: STRING cat, sch, table, col, ignore, column-name, privileges hstmnt = DB_ColumnPrivileges (hdbc, cat, sch, table, col) while // retrieve only column and privileges; ignore the rest. (DB_FetchNext (hstmt, ignore, ignore, ignore, column-name, ignore, ignore, privileges) == TRUE) { //print columns and privileges ... } DB_Columns function Action Returns the list of column names in specified tables as a result set on the statement handle. Syntax hstmnt = DB_Columns (hdbc, catalog-name, schema-name, table-name, column-name) Variable Description hstmnt The returned handle to the executed SQL statement. This is an input parameter for other DBTester functions. HSQL. hdbc The handle to a database as returned by DB_Connect. HDATABASE. catalog-name Catalog name. STRING. schema-name String search pattern for schema names. STRING. table-name String search pattern for table names. STRING. column-name String search pattern for column names. STRING. Notes DB_Columns corresponds to SQLColumns. Please consult your documentation for more information about SQLColumns. Wildcard characters are supported: % (percent sign) matches any character sequence _ (underscore) matches any single character To omit a variable argument, specify it as NULL. When you receive a valid statement handle, you can issue a call to DB_FetchNext or DB_FetchPrevious to manipulate the information. Example [+] testcase DBColumnsExample () appstate none [ ] // Retrieve all columns beginning with the letter 'i' (or 'I') for all tables [ ] // beginning with the letter 'p' (or 'P'). [ ] // Assume that hdbc is a valid database handle returned from DB_Connect(). [ ] STRING cat, sch, tbl, col, ignore, table, column, dtype [ ] [ ] tbl = "p%" [ ] cat = NULL [ ] sch = NULL [ ] col = "i%" [ ] [ ] HDATABASE hdbc [ ] HSQL hstmnt [ ] [ ] hdbc = DB_Connect("DSN=