Preparing CEF-Based Applications for Testing

Applies to TestComplete 12.60, last modified on September 17, 2018

TestComplete can access web pages in applications based on the Chromium Embedded Framework (CEF). Before you can test CEF applications, you need to prepare your TestComplete project or tested application.

Instrument CEF Application

Option 1: Automatic Instrumentation (Recommended)

TestComplete can automatically expose elements in CEF-based applications. To enable this, add your application to the Tested Applications collection and launch it in Simple run mode while one of the following conditions is met:

  • The application’s executable imports the libcef.dll library.

— or —

  • The libcef.dll library and the application’s executable are located in the same folder.

— or —

  • The application has the injectCefHook command-line argument (in any letter case and with any prefix).
    A CEF-based application in TestedApps editor

This is the recommended way to work with CEF-based applications.

Option 2: Compile Application With TestComplete Library

Another way to enable CEF applications for testing is to compile the application with the TestComplete tcCEFHook library. You need to do this, for example, if you start your application outside of TestComplete, or run it in RunAs, Debug, or Profile run mode.

The tcCEFHook library path is:

  • For 32-bit CEF-based applications: <TestComplete>\Bin\Extensions\tcCEFHook.dll

  • For 64-bit CEF-based applications: <TestComplete>\x64\Bin\Extensions\tcCEFHook.dll

You can copy the tcCEFHook library to your application’s folder, or open it from the original location.

Change your application’s code as follows:

  1. Insert instructions that load the tcCEFHook library before the cef_initialize() function that initializes CEF.

    C++

      ...
      // Load the TestComplete automation library
      HMODULE tcHook = LoadLibraryW(L"tcCEFHook.dll");
      ...
      // Initialize CEF
      CefInitialize(settings, app);

    Delphi

      ...
      // Load the TestComplete automation library
      TCDLLHandle := LoadLibrary(PChar('tcCEFHook.dll'));
      ...
      // Initialize CEF
      TChromium.Create(Parent);

    C# CefSharp

      ...
      using System.Runtime.InteropServices;
      ...
      // Import LoadLibrary and FreeLibrary methods from kernel32.dll
      [DllImport("kernel32.dll", CallingConvention = CallingConvention.Winapi)]
      static extern IntPtr LoadLibrary(string lpFileName);
      [DllImport("kernel32.dll", CallingConvention = CallingConvention.Winapi)]
      static extern bool FreeLibrary(IntPtr hModule);
      ...
      // Load the TestComplete automation library
      IntPtr tcModulePtr = LoadLibrary("tcCEFHook.dll");
      ...
      // Initialize CEF
      CEF.Initialize(cefSettings);

    Java

      ...
      // Load the TestComplete automation library
      System.load("tcCEFHook.dll");
      ...
      // Initialize CEF
      c = new Chromium(composite1, SWT.NONE, "google.com");

  2. Add code that unloads the tcCEFHook library after the cef_shutdown() function that shuts down CEF.

    C++

      ...
      // Shut down CEF
      CefShutdown();
      // Release the TestComplete automation library
      if (tcHook)
        FreeLibrary(tcHook);
      ...

    Delphi

    procedure TFormMain.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      //Release the TestComplete automation library
      if TCDLLHandle>=32 then
        FreeLibrary(TCDLLHandle);
    end;

    C# CefSharp

      ...
      // Shut down CEF
      if (CEF.IsInitialized)
        CEF.Shutdown();
      // Release the TestComplete automation library
      if (tcModulePtr != IntPtr.Zero)
        FreeLibrary(tcModulePtr);
      ...

    Java

      // Library is automatically released by garbage collector

Note: The exact names of wrapper functions that correspond to CEF’s cef_initialize() and cef_shutdown() functions may vary depending on the programming language and framework used. For example:

  • C and C++ – CefInitialize() and CefShutdown()
  • Java – CefApp.getInstance() and CefApp.dispose()
  • CefSharp – CEF.Initialize() and CEF.Shutdown()
  • and so on.

Disable Windows (Off-Screen) Rendering

A CEF application can use windowed or windowless (off-screen) rendering. TestComplete supports CEF applications that use windowed rendering. Windowless (off-screen) rendering mode is supported only for WPF components of the CefSharp framework. Other applications that use windowless rendering are not supported. If your application uses windowless rendering, you need to disable it for testing purposes.

The way you disable windowless rendering depends on the programming language and framework used. Refer to the documentation of your CEF framework for details.

Verify CEF Support

Start your tested application (for example, from TestedApps) and switch to the Object Browser. You should see the Page object in your application. You can use it to automate web pages and web page elements in the application’s embedded web browser.

CEF application in Object Browser

See Also

Support for Chromium Embedded Framework
About Support for Chromium Embedded Framework
Web and RIA Testing
Requirements for Web Testing

Highlight search results