How can I package a Silk4Net Test Case to a DLL so that a test can be called from other VB.NET Class file?
First you need to need to perform a Record using the “SilkTest Recorder” and then export the script to a Visual Studio 2010 Silk4NET project (using either the VB.NET or C# language).
A typical exported testcase from the SilkTest Recorder to Silk4Net VB.NET will look like the following:
Where the Class contains two sub procedures, Initialize() and RecordedTest().
Initialize: Defines the browser base state
RecordedTest: Defines the SilkTest Calls against the Application under Test
The above code also contain two methods "TestInitialize" and "TestMethod" which are used to execute the two procedures during runtime.
For the purpose of simplicity I have grouped together the code within the two procures into a single function call. This single function call encapsulates all of the Silk4NET functionality, thus allowing me to call the single function from a main method and avoid the need to call the Initialize procedure and RecordedTest procedure independently when the Class is referenced from another VB.NET Unit class.
For example, see below:
• The base state procedure has been removed; the basestate object is now executed at the beginning of the function.
• A new public object of type Agent.Dekstop has been added to replace the object of Private ReadOnly – so that it can be called by other classes
Once the Class has been executed successfully without error in Visual Studio you should go to: Build | Build as this will build the above class into a DLL. The file will typically be stored in a location similar to:
C:\Documents and Settings\user\My Documents\Visual Studio 2010\Projects\Project Name\bin\Release\Debug.dll
Now you have to create either a new VB.NET Silk4NET or NUnit project, once created you will have to add the DLL (Debug.dll) as a reference to the new project. This can be done by:
• Going to: Class View | References | Add Reference
• Selecting the tab “Browse” and browsing to the location of the DLL
• Instantiating the class contained within the DLL
• Calling the method which executes the test, like so: