The Electron framework is used to create applications with JavaScript. The user interface of such applications is implemented as web pages that the Chromium web browser embedded into the application renders. With TestLeft, you can create automated tests for applications created with Electron.
Supported Electron Versions
TestLeft can test both 32- and 64-bit applications created with Electron. Which Electron versions are supported depends on the approach to exposing Electron applications:
-
Chrome DevTools Protocol - Electron versions 11 - 14 (including minor versions) are supported.
-
Script injection (legacy) - Electron versions 1.8.2 - 11.0.0 are supported.
For detailed information on supported versions and known limitations, see the appropriate sections below.
Requirements
Your tested Electron application must be compiled as a binary executable file. See the Application Distribution section in the Electron documentation.
Exposing Electron applications
To expose web pages that the embedded Chromium web browser renders:
Via the Chrome DevTools Protocol (CDP)
The Chrome DevTools Protocol allows accessing and interacting with web applications running in Chromium-based web browsers. For TestLeft to be able to use the protocol to expose and test Electron applications, the application must be launched with the remote debugging port enabled and with the specified port that the test engine will listen to. To do this, launch the Electron application binary executable in one of the following ways:
-
With the
--remote-debugging-port=<port_1> --inspect=<port_2>
command-line parameters specified, where port_1 and port_2 must belong to the 1024–65535 range and be available.
– or –
-
By using the
ApplicationManager.Run
method and with the-cdpAutoSetPort
command-line parameter specified. TestLeft will assign the remote debugging port and the port to listen to automatically:C#
using SmartBear.TestLeft;
…
string appPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
appPath += @"\Orders\app-1.0.0\orders.exe";
// Runs the Electron-based application
Driver.Applications.Run(appPath, "-cdpAutoSetPort");Visual Basic .NET
Imports SmartBear.TestLeft
…
Dim appPath As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
appPath = appPath & "\Orders\app-1.0.0\orders.exe"
' Runs the Electron-based application Driver.Applications.Run(appPath, "-cdpAutoSetPort")Java
import com.smartbear.testleft.*;
import com.smartbear.testleft.testobjects.*;
…
String appPath = System.getenv("LOCALAPPDATA");
appPath += "\\Orders\\app-1.0.0\\orders.exe";
// Runs the Electron-based application
driver.getApplications().run(appPath, "-cdpAutoSetPort");
Via script injection (Legacy)
This approach has been adopted in TestLeft versions prior to version 4.93. It has several limitations. We do not recommend that you use it.
Run your Electron application by using the ApplicationManager.Run
method, with no extra command-line parameters:
C#
using SmartBear.TestLeft;
…
string appPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
appPath += @"\Orders\app-1.0.0\orders.exe";
// Runs the Electron-based application
Driver.Applications.Run(appPath);
Visual Basic .NET
Imports SmartBear.TestLeft
…
Dim appPath As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
appPath = appPath & "\Orders\app-1.0.0\orders.exe"
' Runs the Electron-based application
Driver.Applications.Run(appPath)
Java
import com.smartbear.testleft.*;
import com.smartbear.testleft.testobjects.*;
…
String appPath = System.getenv("LOCALAPPDATA");
appPath += "\\Orders\\app-1.0.0\\orders.exe";
// Runs the Electron-based application
driver.getApplications().run(appPath);
Known issues and limitations of the legacy Electron support
-
Electron versions later than 11 are not supported.
-
Electron applications created with Electron 9.x are not supported on Windows 7.
-
Electron 9.x and 11.0.0 that have the global sandbox mode enabled (the
app.enableSandbox
method) are not supported. -
If the script injection is restricted by Content Security Policy (CSP) in your tested Electron application, TestLeft will not be able to access internal objects of the application.
-
If you run your tested Electron application created with Electron 9.2.0 x86, from your test, by using the
ApplicationManager.Run
method, on the Windows 7 operating system, and the sandbox renderer is enabled in the application, the application may fail to render its pages.
Best practice - Locating proper binary executable of Electron application
If your Electron application is distributed via installable binaries, several executables can be generated upon the installation. In order for the test engine to be able to access the application internals, use the application’s actual executable rather than the application launcher. Typically, the needed executable is located in the %APPDATA%\Local\<Your_App_Name>\app-N.N.N folder.
To make sure that you use the proper executable, check the Path
property of your Electron application process in the TestLeft UI Spy.
Specifics of testing Electron applications
-
TestLeft identifies applications created with Electron as the
Process
test objects rather than theBrowser
objects. -
TestLeft recognizes the contents the Chromium web browser renders the same way it recognizes any other web application.
Page
objects correspond to rendered web pages. Child objects of thePage
correspond to web elements on the page. WebView controls in your Electron applications are recognized asFrame
objects.
See Also
Identifying Web Objects
Preparing CEF-Based Applications for Testing