Because the default programming language for QTP is VBS, and VBS is a relatively limited scripting language, there are a number of features that are not well implemented when writing automated test scripts. In contrast, C # is a high-level programming language that enables functionality in most Windows environments. So we can use C # to make it impossible or cumbersome to implement under VBS.
This article explains how QTP integrates with the. Net framework by clearing IE caching as an example.
1. Create a C # DLL.
To create a new project in Visual Studio, select the class library. Named as: Automation
2, create a new class in the project named: Browsermanager, in which 2 methods are defined in this class to implement clean IE cache and cookie respectively. Here is the specific code:
[CSharp]View Plaincopyprint?
- Using System;
- Using System.Collections.Generic;
- Using System.Linq;
- Using System.Text;
- Using System.IO;
- Using System.Diagnostics;
- Namespace Automation
- {
- public class Browsermanager
- {
- /*
- Temporary Internet Files (Temporary Internet file)
- RunDll32.exe Inetcpl.cpl,clearmytracksbyprocess 8
- Cookies
- RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 2
- History (historical record)
- RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 1
- Form. Data (form)
- RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 16
- Passwords (password)
- RunDll32.exe Inetcpl.cpl,clearmytracksbyprocess 32
- Delete all (remove all)
- RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 255
- Delete all-"Also delete files and settings stored by add-ons"
- RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 4351
- */
- public void Cleariecookie ()
- {
- Process Process = new process ();
- Process. Startinfo.filename = "RunDll32.exe";
- Process. startinfo.arguments = "Inetcpl.cpl,clearmytracksbyprocess 2";
- Process. Startinfo.useshellexecute = false;
- Process. Startinfo.redirectstandardinput = true;
- Process. Startinfo.redirectstandardoutput = true;
- Process. Startinfo.redirectstandarderror = true;
- Process. Startinfo.createnowindow = true;
- Process. Start ();
- Process. WaitForExit ();
- }
- public void Cleariecache ()
- {
- Process Process = new process ();
- Process. Startinfo.filename = "RunDll32.exe";
- Process. startinfo.arguments = "Inetcpl.cpl,clearmytracksbyprocess 8";
- Process. Startinfo.useshellexecute = false;
- Process. Startinfo.redirectstandardinput = true;
- Process. Startinfo.redirectstandardoutput = true;
- Process. Startinfo.redirectstandarderror = true;
- Process. Startinfo.createnowindow = true;
- Process. Start ();
- Process. WaitForExit ();
- }
- }
- }
3, the class is compiled, and Automation.dll is found under the Project Engineering folder bin\debug directory. Copy this file to the directory you want to store. such as C:\automation.dll
4, open QTP, implement call:
[VB]View Plaincopyprint?
- Function Cleanie_cache_and_cookie
- Dim Browsermanager
- Set Browsermanager = Dotnetfactory.createinstance ("Automation.browsermanager","C:\Automation.dll")
- Browsermanager.cleariecache ()
- Browsermanager.cleariecookie ()
- Set Browsermanager = Nothing
- End Function
QTP loading third-party DLLs (C #) Implementation clear IE cache (GO)