You can use the ApplicationManager
object to run tested applications from TestLeft tests.
Run a Desktop Application
Use the ApplicationManager.run
method and specify the path to the executable. This method returns the object that corresponds to the launched application instance. Store the method result to a variable to have a reference to your tested application for subsequent operations:
C#
using SmartBear.TestLeft;
…
IProcess process = Driver.Applications.Run(@"C:\Orders\Orders.exe");
Visual Basic .NET
Imports SmartBear.TestLeft
…
Dim process As IProcess = Driver.Applications.Run("C:\Orders\Orders.exe")
Java
import com.smartbear.testleft.*;
import com.smartbear.testleft.testobjects.*;
…
TestProcess process = driver.getApplications().run("C:\\Orders\\Orders.exe");
In the example above, we specified the fully-qualified name of the application executable. If you run tests on different computers, the application path can differ from one machine to another. To make your test code portable, use environment variables (like %PROGRAMFILES%
, %APPDATA%
and others) in the path to the executable file, or include the application folder in the PATH environment variable and specify the executable name and extension.
Run a Web Browser
TestLeft supports the following browsers:
-
Microsoft Edge (Chromium-based, 32-bit and 64-bit editions)
-
Microsoft Internet Explorer 11 (32-bit and 64-bit editions)
-
Google Chrome 99 (32-bit and 64-bit editions)
-
Mozilla Firefox 91 ESR, 94 - 98 (32-bit only)
To run a web browser and, optionally, navigate to a web page, use the ApplicationManager.runBrowser
method. Specify the web browser to run by using the appropriate constant (the browser type constants are enumerated by the BrowserType
type). This method returns the object that corresponds to the launched browser instance. Store the method result to a variable to have a reference to the browser for subsequent operations:
C#
using SmartBear.TestLeft;
…
IWebBrowser browser = Driver.Applications.RunBrowser(BrowserType.Chrome, "https://smartbear.com");
Visual Basic .NET
Imports SmartBear.TestLeft
…
Dim browser As IWebBrowser = Driver.Applications.RunBrowser(BrowserType.Chrome, "https://smartbear.com")
Java
import com.smartbear.testleft.*;
import com.smartbear.testleft.testobjects.web.*;
import com.smartbear.testleft.testobjects.BrowserType;
…
WebBrowser browser = driver.getApplications().runBrowser(BrowserType.Chrome, "https://smartbear.com");
To improve the Firefox performance, the method automatically configures some of Firefox settings before launching the web browser. These settings will not be restored to their initial values after the test run is over.
You can also iterate through all the browsers installed on your computer to simulate user actions in them. Get a list of BrowserInfo
objects that contain information on installed web browsers (the browser type, platform and version). Then, use the BrowserInfo
object to launch the needed web browser:
C#
foreach (BrowserInfo browserInf in Driver.Applications.Browsers)
{
IWebBrowser browser = Driver.Applications.RunBrowser(browserInf, "https://smartbear.com");
// Do something
…
}
Visual Basic .NET
For Each browserInf As BrowserInfo In Driver.Applications.Browsers
Dim browser As IWebBrowser = Driver.Applications.RunBrowser(browserInf, "https://smartbear.com")
' Do something
…
Next
Java
for (BrowserInfo browserInf : driver.getApplications().getBrowsers())
{
WebBrowser browser = driver.getApplications().runBrowser(browserInf, "https://smartbear.com");
// Do something
…
}
Run an Application Under Another Account
Use the ApplicationManager.RunAs
method. Specify the username (in the DomainName\UserName format) and password. This method returns the object that corresponds to the launched application instance. Store the method result to a variable to have a reference to your tested application for subsequent operations:
C#
using SmartBear.TestLeft;
…
IProcess process = Driver.Applications.RunAs(@"C:\Orders\Orders.exe", @"domain\user", "password");
Visual Basic .NET
Imports SmartBear.TestLeft
…
Dim process As IProcess = Driver.Applications.RunAs("C:\Orders\Orders.exe", "domain\user", "password")
Java
import com.smartbear.testleft.*;
import com.smartbear.testleft.testobjects.*;
…
TestProcess process = driver.getApplications().runAs("C:\\Orders\\Orders.exe", "domain\\user", "password");
Notes:
-
The specified user account must have a non-empty password.
-
If the domain name is not specified, the computer name is used by default.
-
The Secondary Logon service must be running on the computer.
-
The account the test is running under must have the Default Access Permissions on the computer.
Run a Windows Store Application
Windows Store applications run under Windows 8.1, Windows 10 and later operating systems, and are distributed via Windows Store. These applications use the Modern UI style (formerly known as Metro Style).
To run a Windows Store application, use the ApplicationManager.RunPackage
method and specify the application’s package name (the name configured in the application’s manifest).
This method returns the object that corresponds to the launched application instance. Store the method result to a variable to have a reference to your tested application for subsequent operations:
C#
using SmartBear.TestLeft;
…
IImmersiveProcess process = Driver.Applications.RunPackage("Microsoft.SDKSamples.Hilo.JS");
Visual Basic .NET
Imports SmartBear.TestLeft
…
Dim process As IImmersiveProcess = Driver.Applications.RunPackage("Microsoft.SDKSamples.Hilo.JS")
Java
import com.smartbear.testleft.*;
import com.smartbear.testleft.testobjects*;
…
WinRTProcess process = driver.getApplications().runPackage("Microsoft.SDKSamples.Hilo.JS");
Close an Application
To close the application you launched as described above, just call the close
or terminate
method of the corresponding program object.
C#
process.Close();
Visual Basic .NET
process.Close()
Java
process.close();
To close some other application, first, you need to obtain the object that corresponds to the desired application and then call its appropriate method.
C#
using SmartBear.TestLeft;
using SmartBear.TestLeft.TestObjects;
…
Driver.Find<IProcess>(new ProcessPattern()
{
ProcessName = "orders"
}).Close();
Visual Basic .NET
Imports SmartBear.TestLeft
Imports SmartBear.TestLeft.TestObjects
…
Driver.Find(Of IProcess)(New ProcessPattern With {
.ProcessName = "orders"
}).Close()
Java
import com.smartbear.testleft.*;
import com.smartbear.testleft.testobjects*;
import com.smartbear.testleft.testobjects.ProcessPattern;
…
((TestProcess) driver.find(TestProcess.class, new ProcessPattern() {{
ProcessName = "orders";
}})).close();
See Also
Creating TestLeft Tests
About Driver Objects
Preparing Desktop Applications for Testing
Preparing Web Applications for Testing