SILK TEST A QUICK TOUR BY JAGAN MOHAN JULOORU Sr. Software Engineer Value Labs
Silk Test – A Quick Tour
SILK TEST A QUICK TOUR
1. Silk test software is divided into two parts: silk test host and silk test agent. The host software provides the user with functionality to create plans, test scripts etc, while the agent software interacts directly with the GUI (or drives the application under test). [In short, Agent is required on the machine where u want to run the script. While host is what u see when u start silk test from program manager)
2. There are two kinds of applications you might automate with silk test. a)
Web based
b)
Desktop Application / Client – Server Applications
Here, we are not discussing about automation of web based application. There are lots of similarities, so anyone who understands automating a desktop application can learn web based application automation with a little extra effort.
3. The procedure followed to automate an application is: a. Start by creating a frame file (.inc file). b. Then write (or record) test scripts (.t files) and call these from the plan
file (.pln files).
When the script is run or we do some recording, the agent software is automatically launched (can be observed it in the taskbar) as this is the software which does all the interaction with the GUI.
4. Let us first start with creating the frame file: a) First Click on File -> New, then select “Test Frame” in the file types listed and click ok. b) You shall find the new test frame dialog box, here, you shall find a list of applications that are open, including the program manager. Select the application whose frame you
Silk Test – A Quick Tour
want to create. If the application is not shown, just click on the window corresponding to that application and then switch back to silk test to see it listed in the dialog box.
5. Now, let us create a frame file for notepad. As such when you select the notepad application in the dialog box mentioned in step 4, it automatically creates a frame file for this. But this frame file does not include the class descriptions for the dialog boxes that are invoked when we click on one of the menu items (file->open, for ex). Save the frame file that is automatically created with name X.
6. Now, Let us study this inc file before proceeding any further. The inc file starts with a very simple statement: const wMainWindow = Notepad . wMainWindow is the constant which points to the home page of your application or the main window of the application(to which u have pointed in the dialog box of step 4).When the test fails, this is treated as the base state. [After we run the test, it can be observed in the result file a statement saying: default base state is closing this window etc, this means that silk is trying to bring back the UI to this wMainWindow state to ensure that the next state works fine. Default base state is explained later]
7. The next statement you see would look something like this: window MainWin Notepad This declaration identifies an object in the application under test. This window is a keyword. MainWin is the class and Notepad is the name of the object here. An object is essentially seen as a container for the other objects that are declared in the window: wMainWindow which we discussed in step 6, is essentially pointing to this window as we can see. MainWin is the class for the main window of the application.
8. If we expand this (window MainWin Notepad), we shall find the following statement [-] multitag "*Notepad" [ ] "$C:\WINNT\system32\notepad.exe"
Silk Test – A Quick Tour
A tag or a multitag statement shall be present here. Tag statement is functionally equivalent to a multi tag statement. Other than differences in syntax both are the same. These statements are used by the “Silk Agent” to identify the GUI object at runtime. There are 5 types of tags as in the table below: Tag type
Value
Comment
Caption
Case sensitive
The label for the check box.
Prior text
^Find What:
The closest static text above the check box.
Index
#1
It is the first check box in the dialog.
Window ID
$1,041
GUI-specific tag.
Location
@(57,65)
(x, y) location of the check box in the dialog.
In this particular case, the notepad’s caption and its id (see that id starts with $ and caption is just the string) are used to identify the window. We shall find similar statements for the other objects in the window also. For example see this line: [-] Menu File [ ] tag "File" This statement simply says that there is an object with identifier “File” and which is an object of the class “Menu”. Further it also says that this object is to be identified by the tag “File”, which is the caption is “File”. Also, since this is “inside” the Notepad object, this is contained in it.
9. The sDir constant contains the working directory of the application when it is started and the sCmdLine constant contains the application’s exe. This is used to invoke the application. The wMainwin will identify the main window. And in this main window sCmdLine constant is used to invoke it.
10. The wStartup constant is commented out. This is used if when the application is invoked an additional window appears before the main window’s appearance. For example, for some
Silk Test – A Quick Tour
applications, when the application is invoked, a logon window appears before the actual main window. This logon window needs to be handled. In such cases we record the logon window separately and assign the identifier of this window object to wStartup. Let us discuss what shall be done next, a little later.
11. The lwLeaveopen constant is commented too. This is a set of windows we do not want the recovery system to close when arriving at the default base state. Usually when a test case fails (or ends), the silk recovery system comes into play.There is an inc file with name defaults.inc in the silk test program directory. This contains the routines for recovery system. That is it contains the DefaultBaseState function which does the clean up in recovery process. There are other scripts like DefaultScriptEntry, DefaultScriptExit etc . These functions are called before a test script entry, and at exit etc. lwLeaveOpen constant stops the default base state from closing specific windows while trying to arrive at the default base state.
12. What is default base state? Default base state is an application state. That is , suppose u do some operations and at the end of those operations you are in an application state. We can define application states (by specifying how to arrive at them) and make specific test cases start from such application states. Default base state is the application state where the test cases start by default. By default this is the main window. But, this may be modified, as we shall see soon.
13. The rest of the statements are simply Menu object declarations. Each Menu object declaration contains the declarations for MenuItems. If you look into each of these statements you shall find those “tag” and “multitag” statements.
14. We also have one MessageBox object declaration of MessageBoxClass. This is for message Boxes. This is included by default, as message boxes may pop up any time while a windows application is running.
Silk Test – A Quick Tour
15. Let us now proceed to write this small “.t” file. Before creating this make sure the inc file is listed in the use files text box in Options Runtime Options. If you are using web based applications make sure to select the correct browser type in this runtime options dialog box. If you are not using any browser, make sure to set the browser in runtime options dialog to none.
16. The .t file should contain the following code: [-] testcase t() [ ] wMainWindow.File.Open.Pick()
Now. Open is an object of MenuItem type. This MenuItem class will have lots of functions. See the help for the list. You can use these functions on it. Also, in order to navigate in the editor of these .t files, we will have to use Alt + Left arrow to “go in” and Alt + Right Arrow to move out. Note this since we do not have { and } as in c++ to state what all is inside an if statement, say. The only way we can ensure this, therefore is by indenting the lines accordingly. For example, in the above code, the statement is inside testcase t(), statement.
17. If you have run this particular program the result file automatically appears. This is the listing I am getting in the result file: [ ] *** DefaultBaseState is invoking Notepad [ ] *** Warning: DefaultBaseState is closing Notepad windows [ ] Closing Notepad.DialogBox("Open") Default base state is invoked and finally restored, so that the next test case may run. As I already mentioned, default base state is defined in the defaults.inc file.
18. When in Results mode, the silk test menu is different. There is a menu item Results that is added. The .res file is by default saved in the program directory of silk. This path may be changed through runtime options. Options RuntimeOptions, Results, enter the directory in the text box here. There is also an option to mention the history size. This may be varied too. This is the
Silk Test – A Quick Tour
number of past results to be saved. Through Results Merge option you may merge the past results with the current ones. You can try this after creating the plan fine and calling this .t file from there.
19. We could have recorded the test case using the Record Actions or Record TestCase options. But we chose to write it manually, coz we think we are good programmers ;).
20. Let us now proceed to record the File open dialog box also. To record the File open dialog box and add it to the .inc file. Open the .inc file, Invoke the notepad and the Fileopen dialog box and select Record WindowDeclaration. Point to the Open DialogBox and press “Alt + Ctrl” to stop recording. Copy it to clip board and paste it to the .inc file. Now the dialogbox is recognized.
21. Let us now rerun the .t file. We get the following result: [ ] *** DefaultBaseState is invoking Notepad [ ] *** Warning: DefaultBaseState is closing Notepad windows [ ] Closing Open
Just see that the last statement is no more Closing Notepad.DialogBox(“Open”) ! This is coz silk is now recognizing the Open dialog box. You wont get this this way if you either do not include the correct frame file in Runtime Options, or if you have not compiled (using Run Compile all).
22. Let us now get back to the .inc file for a moment. We have an additional statement: window DialogBox Open. This appeared when we recorded the window declarations. You might have straight away recognized what this means. It is simply the declaration for this object whose identifier is “Open” and whose class is “dialogbox”. Classes are created much the same way as we do in c++. We may write our own classes. Let us try this one. Let us write a class called Dialogbox1. The syntax for writing classes is as below:
Silk Test – A Quick Tour
[scope] winclass wclass-id [ : derived-class] statements So, that means, we can create a class by simply writing this: winclass DialogBox1 : DialogBox which means we are deriving our new class from the previous one. Then we may add functions to this class in place of the “statements” . So, here is the piece of code I have added to create a new class called DialogBox1 [-] winclass DialogBox1 : DialogBox [-] void validateme() [ ] print ("Jagans : Validation")
As you see, I have also added a function validateme() to this class which prints “Jagan: Validation” to the output screen. Also this particular class inherits all the methods and objects of the “DialogBox” class.
23. I have included the above definition of DialogBox1 class in the .inc file just after the wMainwin statement. Let us now try this. Instead of having Open as an object of DialogBox , we may make it an object of Dialogbox1. This is pretty simple, just modify the window statement of Open as below: window DialogBox1 Open The remaining statements remain as they were, unchanged.
24. Having done this, let also modify the .t file to call this validateme function as below: [-] testcase t() [ ] wMainWindow.File.Open.Pick() [ ] Open.validateme()
25. When we run this, we get the following output:
Silk Test – A Quick Tour
[ ] *** DefaultBaseState is invoking Notepad [ ] Jagans : Validation [ ] *** Warning: DefaultBaseState is closing Notepad windows [ ] Closing Open
Note the second line; it is printing the statement in validateme function. So that serves our purpose.
26. Let us now add this test case to a test plan . This is very simple too. First create a plan file , by file New option and selecting a TestPlan in the file types. Here is what I wrote in the test plan file: [ ] script: test.t [] [-] this is my test case [ ] testcase: t()
Now when I select and run this, the result is obvious.
27. We can also pass parameters to my scripts from here.: [-] testcase t(int param) [ ] wMainWindow.File.Open.Pick() [ ] print(param) [ ] Open.validateme() Then, I modify my test plan as below and run it : [ ] script: test.t [] [-] this is my test case [ ] $param = 5
Silk Test – A Quick Tour
[ ] testcase: t($param) Observe the syntax here.
28.
We can create a new appstate. This means, our test case can be made to start from a
different state than the default base state. The following change in the .t file would do it for us: [-] appstate NewState() basedon DefaultBaseState [ ] wMainWindow.File.Open.Pick() [] [] [-] testcase t(int param) appstate NewState [ ] //wMainWindow.File.Open.Pick() [ ] print(param) [ ] Open.validateme()
If we run this, it runs just like the previous program! That is despite the fact that the first statement in the test case is now commented!
Silk Test – A Quick Tour
SILK TEST FEATURES
Platform Independent
Silk Test doesn’t care about how the application is created, in which software the application is written, what kind of design is used, which browser it is being worked, in which operating system the application is running.
All that needs for an application to be tested using silktest is that it needs a frame (like window) Browser Independent
There are various kinds of browsers used by various people for running their applications. The user may use any browser of his choice to test the standard application. Each and every browser acts differently with different applications. They show the same page differently. The web objects they display can also be aligned or displayed in different manner.
SilkTest just looks at these browser contents as objects and hence they cannot avoid any images, texts, that they are not identifiable. Also we can write a test in one browser and run it in any other browser (to some extend). i.e, using SilkTest, we can do cross browser testing.
With minor modifications, your tests are robust enough to support different browsers and different versions of these browsers.
Technology Independent
Silktest does not care how the application was built. It seamlessly works with the different web technologies commonly used today.
How to use the same code for multiple browsers:
Start writing the silk scripts. Capture the window declarations (.inc file) and write the .t file. Say if you are capturing the declarations from Internet Explorer & run successfully on it. As we captured
Silk Test – A Quick Tour
the declarations from I.E., we now have to make the same test case run on Netscape since the tag value changes from multiple browsers.
Testing the Windows based applications
Before start writing scripts, enable the settings given below.
1. Declare all the window names and its objects (used in writing scripts) starting from the first window. 2. In the File-> New option in the menu bar, select the test frame.
3. In the resulting ‘new Test Frame’ dialog box, specify the path of the executable file of your application. 4. After submitting that dialog box, the silktest will automatically create a declaration file with the default window declared.
5. Use that file to create your testscripts.
Testing the Java based applications
Before you start testing the java applications or applets, you have to set the java classpath. •
Point to a Java archive (.jar file) that contains the software the powers SilkTest’s Java support for JDK 1.2 and JRE 1.2. This file is called SilkTest_Java2.jar.)
•
When you install SilkTest_Java2.jar is installed in this directory:\JavaEx
•
If you will use only JDK 1.2 for testing, you can activate Java support for JDK 1.2 by copying SilkTest_Java2.jar from \JavaEx to \jre/lib/ext.
If you do not copy SilkTest_Java2.jar to your JDK 1.2 install directory, you must point to it from your CLASSPATH.
Silk Test – A Quick Tour