QTP loading third-party DLLs (C #) implementation clears IE cache

Source: Internet
Author: User

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?
  1. Using System;
  2. Using System.Collections.Generic;
  3. Using System.Linq;
  4. Using System.Text;
  5. Using System.IO;
  6. Using System.Diagnostics;
  7. Namespace Automation
  8. {
  9. public class Browsermanager
  10. {
  11. /* 
  12. Temporary Internet Files (Temporary Internet file)
  13. RunDll32.exe Inetcpl.cpl,clearmytracksbyprocess 8
  14. Cookies
  15. RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 2
  16. History (historical record)
  17. RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 1
  18. Form. Data (form)
  19. RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 16
  20. Passwords (password)
  21. RunDll32.exe Inetcpl.cpl,clearmytracksbyprocess 32
  22. Delete all (remove all)
  23. RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 255
  24. Delete all-"Also delete files and settings stored by add-ons"
  25. RunDll32.exe inetcpl.cpl,clearmytracksbyprocess 4351
  26. */
  27. public void Cleariecookie ()
  28. {
  29. Process Process = new process ();
  30. Process.  Startinfo.filename = "RunDll32.exe";
  31. Process.  startinfo.arguments = "Inetcpl.cpl,clearmytracksbyprocess 2";
  32. Process.  Startinfo.useshellexecute = false;
  33. Process.  Startinfo.redirectstandardinput = true;
  34. Process.  Startinfo.redirectstandardoutput = true;
  35. Process.  Startinfo.redirectstandarderror = true;
  36. Process.  Startinfo.createnowindow = true;
  37. Process. Start ();
  38. Process. WaitForExit ();
  39. }
  40. public void Cleariecache ()
  41. {
  42. Process Process = new process ();
  43. Process.  Startinfo.filename = "RunDll32.exe";
  44. Process.  startinfo.arguments = "Inetcpl.cpl,clearmytracksbyprocess 8";
  45. Process.  Startinfo.useshellexecute = false;
  46. Process.  Startinfo.redirectstandardinput = true;
  47. Process.  Startinfo.redirectstandardoutput = true;
  48. Process.  Startinfo.redirectstandarderror = true;
  49. Process.  Startinfo.createnowindow = true;
  50. Process. Start ();
  51. Process. WaitForExit ();
  52. }
  53. }
  54. }


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?
      1. Function Cleanie_cache_and_cookie
      2. Dim Browsermanager
      3. Set Browsermanager = Dotnetfactory.createinstance ("Automation.browsermanager","C:\Automation.dll")
      4. Browsermanager.cleariecache ()
      5. Browsermanager.cleariecookie ()
      6. Set Browsermanager = Nothing
      7. End Function

QTP loading third-party DLLs (C #) Implementation clear IE cache (GO)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.