AltDriver#
AltDriver is how your tests drive the app. Creating one connects to AltTester® Server, which routes the driver to a connected instrumented app; Stop closes the connection. Create the driver in your set-up and stop it in your tear-down.
Each command shows its signature and an example in every language; pick a language in any tab and the others switch with it.
Commands on this page#
AltDriver#
Connects to AltTester® Server and, through it, to an instrumented app. With one app connected, AltDriver() with no arguments is all you need; the other parameters say where the server is and which app you want.
AltDriver(
string host = "127.0.0.1",
int port = 13000,
string appName = "__default__",
bool enableLogging = false,
int connectTimeout = 60,
string platform = "unknown",
string platformVersion = "unknown",
string deviceInstanceId = "unknown",
string appId = "unknown",
string driverType = "SDK",
bool secureMode = false)
Example
[OneTimeSetUp]
public void SetUp()
{
// AltTester® Desktop runs on another machine; connect to the app named "MyGame".
altDriver = new AltDriver(host: "192.168.0.10", appName: "MyGame");
}
AltDriver()
AltDriver(String host, int port)
AltDriver(String host, int port, boolean secureMode)
AltDriver(
String host,
int port,
Boolean enableLogging,
int connectTimeout,
String appName)
AltDriver(
String host,
int port,
Boolean enableLogging,
int connectTimeout,
String appName,
String platform,
String platformVersion,
String deviceInstanceId,
String appId,
boolean secureMode)
Example
@BeforeClass
public static void setUp() {
// AltTester® Desktop runs on another machine; connect to the app named "MyGame".
altDriver = new AltDriver("192.168.0.10", 13000, false, 60, "MyGame");
}
AltDriver(
host='127.0.0.1',
port=13000,
app_name='__default__',
enable_logging=False,
timeout=60,
platform='unknown',
platform_version='unknown',
device_instance_id='unknown',
app_id='unknown',
secure_mode=False,
driver_type='python')
Example
from alttester import AltDriver
# AltTester® Desktop runs on another machine; connect to the app named "MyGame".
alt_driver = AltDriver(host="192.168.0.10", app_name="MyGame")
Initialize AltDriver host='127.0.0.1' port=13000 app_name='__default__' enable_logging=False timeout=60 platform='unknown' platform_version='unknown' device_instance_id='unknown' app_id='unknown' secure_mode=False
Example
*** Settings ***
Library AltTesterLibrary
# AltTester® Desktop runs on another machine; connect to the app named "MyGame".
Suite Setup Initialize AltDriver host=192.168.0.10 app_name=MyGame
Parameters
Name |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
The host AltTester® Server listens on: the machine running AltTester® Desktop. |
|
|
|
The port AltTester® Server listens on. It must match the port set in the instrumented build. |
|
|
|
The name of the app to connect to, as set in the AltTester® settings of the instrumented build. |
|
|
|
Turns on the driver’s own logs. See Logs of AltDriver. |
|
C#, Java: |
|
Seconds to keep trying to connect before giving up with a connection timeout error. It applies to connecting only; how long each command may take is set with SetCommandResponseTimeout. In Python and Robot Framework, |
|
|
|
Connect only to an app reporting this platform, such as |
|
|
|
Connect only to an app reporting this platform version. |
|
|
|
Connect only to an app running on this device, for when the same build runs on several devices at once. |
|
|
|
Connect only to the app with this id, which the server assigns. Use it when the other criteria still match more than one app. |
|
|
|
Connect over a secure WebSocket ( |
|
|
|
The kind of driver reported to AltTester® Server. Leave it at its default. Only in C#, Python. |
Note
Java has no default values. Its eleven constructors take the parameters in the order host, port, enableLogging, connectTimeout, appName, then platform, platformVersion, deviceInstanceId and appId together. Each stops at a different point, with or without secureMode last; the common ones are shown above.
In Java, new AltDriver(host, port, true) calls the constructor with secureMode, not enableLogging. To turn on logging that way, pass Boolean.TRUE.
See also: Stop
Which app does the driver connect to?#
AltTester® Server can have several instrumented apps connected at once. The driver doesn’t
name one: it sends the criteria appName, platform, platformVersion,
deviceInstanceId and appId when it connects, and the server routes it to an app whose
own details match.
So these parameters are filters that describe the app you want, not values you give it. The values come from elsewhere:
The app reports its own
platform,platformVersionanddeviceInstanceIdwhen it registers with the server. They come from the device it runs on, which is why they have real values you never set, for example on a cloud device farm.The server assigns
appId, to tell each connected app apart.appNameis the one value you control from the app side. It is set in the AltTester® settings of the instrumented build and can be anything; pick something meaningful and use the same name in your tests.
A criterion left at unknown matches any value. With one app connected you can leave them
all alone.
The Connected Apps list in AltTester® Desktop shows these values for every connected app, ready to copy into your tests.
Note
To tell two runs of the same app apart, such as two devices in a matrix or two suites in
parallel, give each instrumented build its own appName, or select on
deviceInstanceId. appName alone can’t tell two identical builds apart.
What it raises#
Creating the driver raises one of these errors when it can’t connect. The names differ by language.
C# and Java |
Python and Robot Framework |
Raised when |
|---|---|---|
|
|
The server couldn’t be reached within the connect timeout. |
|
|
The server was reachable, but no instrumented app matching the criteria connected within the connect timeout. |
|
|
A driver is already connected and your license allows only one. |
|
|
Another driver is connecting at the same time. |
|
|
Your license’s driver limit is already in use, often by a driver from an earlier run that was never stopped. |
See Errors for the full list.
Stop#
Closes the driver’s connection to AltTester® Server. Call it in your tear-down, so the connection is closed even when a test fails; a driver left connected counts against your license’s driver limit.
void Stop()
Example
[OneTimeTearDown]
public void TearDown()
{
altDriver.Stop();
}
void stop()
Example
@AfterClass
public static void tearDown() throws IOException {
altDriver.stop();
}
alt_driver.stop()
Example
import pytest
from alttester import AltDriver
@pytest.fixture(scope="session")
def alt_driver():
alt_driver = AltDriver()
yield alt_driver
alt_driver.stop()
Stop AltDriver
Example
*** Settings ***
Library AltTesterLibrary
Suite Setup Initialize AltDriver
Suite Teardown Stop AltDriver
Returns
Nothing.
Note
In Java, stop() declares throws IOException.
See also: AltDriver
Other driver methods#
A few AltDriver methods exist in only some languages:
GetServerVersion()in C# andgetServerVersion()in Java return the version of the AltTester® Unity SDK the app was built with. The Python driver logs it when it connects.SetLogging(bool enableLogging), in C# only, turns the driver’s logs on or off after it is created. See Logs of AltDriver for the other languages.