API
If you are looking for information on a specific function, class or method, this part of the documentation is for you.
AltDriver
The AltDriver class represents the main app driver component. When you instantiate an AltDriver in your tests, you can use it to “drive” your app like one of your users would, by interacting with all the app objects, their properties and methods.
An AltDriver instance will connect to the running instrumented Unity application. In the constructor, we need to tell the driver where (on what IP and on what port) the instrumented Unity App with a specific name is running and for how many seconds to let the communication opened.
Parameters
Name | Type | Required | Description |
---|---|---|---|
host | string | No | The IP or hostname AltTester Unity SDK is listening on. The default value is "127.0.0.1". |
port | int | No | The default value is 13000. |
enableLogging | boolean | No | The default value is false. |
connectTimeout | int | No | The connect timeout in seconds.The default value is 60. |
appName | string | No | The name of the Unity application.The default value is __default__ . |
Once you have an instance of the AltDriver, you can use all the available commands to interact with the app. The available methods are the following:
Find Objects
FindObject
Finds the first object in the scene that respects the given criteria. Check By for more information about criteria.
Parameters
Name | Type | Required | Description |
---|---|---|---|
by | By | Yes | Set what criteria to use in order to find the object. |
value | string | Yes | The value to which object will be compared to see if they respect the criteria or not. |
cameraBy | By | No | Set what criteria to use in order to find the camera. |
cameraValue | string | No | The value to which all the cameras in the scene will be compared to see if they respect the criteria or not to get the camera for which the screen coordinate of the object will be calculated. If no camera is given It will search through all camera that are in the scene until some camera sees the object or return the screen coordinate of the object calculated to the last camera in the scene. |
enabled | boolean | No | If true will match only objects that are active in hierarchy. If false will match all objects. |
Returns
AltObject
Examples
[Test]
public void TestFindAltObject()
{
const string name = "Capsule";
var altObject = altDriver.FindObject(By.NAME,name);
Assert.NotNull(altObject);
Assert.AreEqual(name, altObject.name);
}
@Test
public void testfindObject() throws Exception
{
String name = "Capsule";
AltFindObjectsParams altFindObjectsParams = new AltFindObjectsParams.Builder(AltDriver.By.NAME,
name).isEnabled(true).withCamera(AltDriver.By.NAME, "Main Camera").build();
AltObject altObject = altDriver.findObject(altFindObjectsParams);
assertNotNull(altObject);
assertEquals(name, altObject.name);
}
def test_find_object(self):
altObject = self.altDriver.find_object(By.NAME, "Capsule")
self.assertEqual(altObject.name, "Capsule")
FindObjects
Finds all objects in the scene that respects the given criteria. Check By for more information about criteria.
Parameters
Name | Type | Required | Description |
---|---|---|---|
by | By | Yes | Set what criteria to use in order to find the object. |
value | string | Yes | The value to which object will be compared to see if they respect the criteria or not. |
cameraBy | By | No | Set what criteria to use in order to find the camera. |
cameraValue | string | No | The value to which all the cameras in the scene will be compared to see if they respect the criteria or not to get the camera for which the screen coordinate of the object will be calculated. If no camera is given It will search through all camera that are in the scene until some camera sees the object or return the screen coordinate of the object calculated to the last camera in the scene. |
enabled | boolean | No | If true will match only objects that are active in hierarchy. If false will match all objects. |
Returns
List of AltObjects or an empty list if no objects were found.
Examples
[Test]
public void TestFindObjectsByTag()
{
var altObjects = altDriver.FindObjects(By.TAG,"plane");
Assert.AreEqual(2, altObjects.Count);
foreach(var altObject in altObjects)
{
Assert.AreEqual("Plane", altObject.name);
}
}
@Test
public void testFindAltObjects() throws Exception
{
String name = "Plane";
AltFindObjectsParams altFindObjectsParams = new AltFindObjectsParams.Builder(AltDriver.By.NAME,
name).isEnabled(true).withCamera(AltDriver.By.NAME, "Main Camera").build();
AltObject[] altObjects = altDriver.findObjects(altFindObjectsParams);
assertNotNull(altObjects);
assertEquals(altObjects[0].name, name);
}
def test_find_objects_by_layer(self):
self.altDriver.load_scene('Scene 1 AltDriverTestScene')
altObjects = self.altDriver.find_objects(By.LAYER,"Default")
self.assertEquals(8, len(altObjects))
FindObjectWhichContains
Finds the first object in the scene that respects the given criteria. Check By for more information about criteria.
Parameters
Name | Type | Required | Description |
---|---|---|---|
by | By | Yes | Set what criteria to use in order to find the object. |
value | string | Yes | The value to which object will be compared to see if they respect the criteria or not. |
cameraBy | By | No | Set what criteria to use in order to find the camera. |
cameraValue | string | No | The value to which all the cameras in the scene will be compared to see if they respect the criteria or not to get the camera for which the screen coordinate of the object will be calculated. If no camera is given It will search through all camera that are in the scene until some camera sees the object or return the screen coordinate of the object calculated to the last camera in the scene. |
enabled | boolean | No | If true will match only objects that are active in hierarchy. If false will match all objects. |
Returns
AltObject
Examples
[Test]
public void TestFindObjectWhichContains()
{
var altObject = altDriver.FindObjectWhichContains(By.NAME, "Event");
Assert.AreEqual("EventSystem", altObject.name);
}
@Test
public void TestFindObjectWhichContains()
{
String name = "Event";
AltFindObjectsParams altFindObjectsParams = new AltFindObjectsParams.Builder(AltDriver.By.NAME,
name).isEnabled(true).withCamera(AltDriver.By.NAME, "Main Camera").build();
AltObject altObject = altDriver.findObjectWhichContains(altFindObjectsParams);
assertEquals("EventSystem", altObject.name);
}
def test_find_object_which_contains(self):
altObject = self.altDriver.find_object_which_contains(By.NAME, "Event");
self.assertEqual("EventSystem", altObject.name)
FindObjectsWhichContain
Finds all objects in the scene that respects the given criteria. Check By for more information about criteria.
Parameters
Name | Type | Required | Description |
---|---|---|---|
by | By | Yes | Set what criteria to use in order to find the object. |
value | string | Yes | The value to which object will be compared to see if they respect the criteria or not. |
cameraBy | By | No | Set what criteria to use in order to find the camera. |
cameraValue | string | No | The value to which all the cameras in the scene will be compared to see if they respect the criteria or not to get the camera for which the screen coordinate of the object will be calculated. If no camera is given It will search through all camera that are in the scene until some camera sees the object or return the screen coordinate of the object calculated to the last camera in the scene. |
enabled | boolean | No | If true will match only objects that are active in hierarchy. If false will match all objects. |
Returns
List of AltObjects or an empty list if no objects were found.
Examples
[Test]
public void TestFindObjects()
{
var planes = altDriver.FindObjectsWhichContain(By.NAME, "Plane");
Assert.AreEqual(3, planes.Count);
}
@Test
public void testFindObjectsWhereNameContains() throws Exception
{
String name = "Pla";
AltFindObjectsParams altFindObjectsParams = new AltFindObjectsParams.Builder(AltDriver.By.NAME,
name).isEnabled(true).withCamera("Main Camera").build();
AltObject[] altObjects = altDriver.findObjectsWhichContain(altFindObjectsParams);
assertNotNull(altObjects);
assertTrue(altObjects[0].name.contains(name));
}
def test_creating_stars(self):
self.altDriver.load_scene("Scene 5 Keyboard Input")
stars = self.altDriver.find_objects_which_contain(By.NAME, "Star", "Player2")
self.assertEqual(1, len(stars))
player = self.altDriver.find_objects_which_contain(By.NAME, "Player", "Player2")
self.altDriver.move_mouse(int(stars[0].x), int(player[0].y) + 500, 1)
time.sleep(1.5)
self.altDriver.press_key(AltKeyCode.Mouse0, 1,0)
self.altDriver.move_mouse_and_wait(int(stars[0].x), int(player[0].y) - 500, 1)
self.altDriver.press_key(AltKeyCode.Mouse0, 1,0)
stars = self.altDriver.find_objects_which_contain(By.NAME, "Star")
self.assertEqual(3, len(stars))
FindObjectAtCoordinates
Retrieves the Unity object at given coordinates.
Uses EventSystem.RaycastAll
to find object. If no object is found then it uses UnityEngine.Physics.Raycast
and UnityEngine.Physics2D.Raycast
and returns the one closer to the camera.
Parameters
Name | Type | Required | Description |
---|---|---|---|
coordinates | Vector2 | Yes | The screen coordinates. |
Returns
AltObject - The UI object hit by event system Raycast, nothing otherwise.
Examples
[Test]
public void TestFindElementAtCoordinates()
{
var counterButton = altDriver.FindObject(By.NAME, "ButtonCounter");
var element = altDriver.FindObjectAtCoordinates(new AltVector2(80 + counterButton.x, 15 + counterButton.y));
Assert.AreEqual("Text", element.name);
}
@Test
public void testFindElementAtCoordinates() {
AltObject counterButton = altDriver.findObject(new AltFindObjectsParams.Builder(
AltDriver.By.NAME, "ButtonCounter").build());
AltObject element = altDriver.findObjectAtCoordinates(
new AltFindObjectAtCoordinatesParams.Builder(new Vector2(80 + counterButton.x, 15 + counterButton.y))
.build());
assertEquals("Text", element.name);
}
def test_find_object_by_coordinates(self):
self.altdriver.load_scene("Scene 1 AltDriverTestScene")
counter_button = self.altdriver.find_object(By.NAME, "ButtonCounter")
element = self.altdriver.find_object_at_coordinates([80 + counter_button.x, 15 + counter_button.y])
assert "Text" == element.name
GetAllElements
Returns information about every objects loaded in the currently loaded scenes. This also means objects that are set as DontDestroyOnLoad.
Parameters
Name | Type | Required | Description |
---|---|---|---|
cameraBy | By | No | Set what criteria to use in order to find the camera. |
cameraValue | string | No | The value to which all the cameras in the scene will be compared to see if they respect the criteria or not to get the camera for which the screen coordinate of the object will be calculated. If no camera is given It will search through all camera that are in the scene until some camera sees the object or return the screen coordinate of the object calculated to the last camera in the scene. |
enabled | boolean | No | If true will match only objects that are active in hierarchy. If false will match all objects. |
Returns
List of AltObjects or an empty list if no objects were found.
Examples
[Test]
public void TestGetAllEnabledObjects()
{
var altObjects = altDriver.GetAllElements(enabled: true);
Assert.IsNotEmpty(altObjects);
}
@Test
public void testGetAllElements() throws Exception {
AltGetAllElementsParams altGetAllElementsParams = new AltGetAllElementsParams.Builder().withCamera(AltDriver.By.NAME, "Main Camera").isEnabled(true).build();
AltObject[] altObjects = altDriver.getAllElements(altGetAllElementsParams);
assertFalse(altObjects.isEmpty());
}
def test_get_all_elements(self):
alt_elements = self.altDriver.get_all_elements(enabled=False)
assert alt_elements
WaitForObject
Waits until it finds an object that respects the given criteria or until timeout limit is reached. Check By for more information about criteria.
Parameters
Name | Type | Required | Description |
---|---|---|---|
by | By | Yes | Set what criteria to use in order to find the object. |
value | string | Yes | The value to which object will be compared to see if they respect the criteria or not. |
cameraBy | By | No | Set what criteria to use in order to find the camera. |
cameraValue | string | No | The value to which all the cameras in the scene will be compared to see if they respect the criteria or not to get the camera for which the screen coordinate of the object will be calculated. If no camera is given It will search through all camera that are in the scene until some camera sees the object or return the screen coordinate of the object calculated to the last camera in the scene. |
enabled | boolean | No | If true will match only objects that are active in hierarchy. If false will match all objects. |
timeout | double | No | The number of seconds that it will wait for object. |
interval | double | No | The number of seconds after which it will try to find the object again. The interval should be smaller than timeout. |
Returns
AltObject
Examples
[Test]
public void TestWaitForExistingElement()
{
const string name = "Capsule";
var timeStart = DateTime.Now;
var altElement = altDriver.WaitForObject(By.NAME, name);
var timeEnd = DateTime.Now;
var time = timeEnd - timeStart;
Assert.Less(time.TotalSeconds, 20);
Assert.NotNull(altElement);
Assert.AreEqual(altElement.name, name);
}
@Test
public void testWaitForExistingElement() {
String name = "Capsule";
long timeStart = System.currentTimeMillis();
AltFindObjectsParams altFindObjectsParams = new AltFindObjectsParams.Builder(AltDriver.By.NAME,
name).build();
AltWaitForObjectsParams altWaitForObjectsParams = new AltWaitForObjectsParams.Builder(
altFindObjectsParams).build();
AltObject altElement = altDriver.waitForObject(altWaitForObjectsParams);
long timeEnd = System.currentTimeMillis();
long time = timeEnd - timeStart;
assertTrue(time / 1000 < 20);
assertNotNull(altElement);
assertEquals(altElement.name, name);
}
def test_wait_for_object(self):
alt_object = self.altDriver.wait_for_object(By.NAME, "Capsule")
assert alt_object.name == "Capsule"
WaitForObjectWhichContains
Waits until it finds an object that respects the given criteria or time runs out and will throw an error. Check By for more information about criteria.
Parameters
Name | Type | Required | Description |
---|---|---|---|
by | By | Yes | Set what criteria to use in order to find the object. |
value | string | Yes | The value to which object will be compared to see if they respect the criteria or not. |
cameraBy | By | No | Set what criteria to use in order to find the camera. |
cameraValue | string | No | The value to which all the cameras in the scene will be compared to see if they respect the criteria or not to get the camera for which the screen coordinate of the object will be calculated. If no camera is given It will search through all camera that are in the scene until some camera sees the object or return the screen coordinate of the object calculated to the last camera in the scene. |
enabled | boolean | No | If true will match only objects that are active in hierarchy. If false will match all objects. |
timeout | double | No | The number of seconds that it will wait for object |
interval | double | No | The number of seconds after which it will try to find the object again. interval should be smaller than timeout |
Returns
AltObject
Examples
[Test]
public void TestWaitForObjectWhichContains()
{
var altObject = altDriver.WaitForObjectWhichContains(By.NAME, "Canva");
Assert.AreEqual("Canvas", altObject.name);
}
@Test
public void TestWaitForObjectWhichContainsWithCameraId() {
AltFindObjectsParams altFindObjectsParametersCamera = new AltFindObjectsParams.Builder(By.PATH,
"//Main Camera").build();
AltObject camera = altDriver.findObject(altFindObjectsParametersCamera);
AltFindObjectsParams altFindObjectsParametersObject = new AltFindObjectsParams.Builder(By.NAME, "Canva")
.withCamera(By.ID, String.valueOf(camera.id)).build();
AltWaitForObjectsParams altWaitForObjectsParams = new AltWaitForObjectsParams.Builder(
altFindObjectsParametersObject).build();
AltObject altObject = altDriver.waitForObjectWhichContains(altWaitForObjectsParams);
assertEquals("Canvas", altObject.name);
}
def test_wait_for_object_which_contains(self):
alt_object = self.altDriver.wait_for_object_which_contains(By.NAME, "Main")
assert alt_object.name == "Main Camera"
WaitForObjectNotBePresent
Waits until the object in the scene that respects the given criteria is no longer in the scene or until timeout limit is reached. Check By for more information about criteria.
Parameters
Name | Type | Required | Description |
---|---|---|---|
by | By | Yes | Set what criteria to use in order to find the object. |
value | string | Yes | The value to which object will be compared to see if they respect the criteria or not. |
cameraBy | By | No | Set what criteria to use in order to find the camera. |
cameraValue | string | No | The value to which all the cameras in the scene will be compared to see if they respect the criteria or not to get the camera for which the screen coordinate of the object will be calculated. If no camera is given It will search through all camera that are in the scene until some camera sees the object or return the screen coordinate of the object calculated to the last camera in the scene. |
enabled | boolean | No | If true will match only objects that are active in hierarchy. If false will match all objects. |
timeout | double | No | The number of seconds that it will wait for object. |
interval | double | No | The number of seconds after which it will try to find the object again. interval should be smaller than timeout. |
Returns
Nothing
Examples
[Test]
public void TestWaitForObjectToNotExist()
{
altDriver.WaitForObjectNotBePresent(By.NAME, "Capsulee", timeout: 1, interval: 0.5f);
}
@Test
public void TestWaitForObjectToNotBePresent(){
AltFindObjectsParams altFindObjectsParameters = new AltFindObjectsParams.Builder(AltDriver.By.NAME, "Capsulee").build();
AltWaitForObjectsParams altWaitForObjectsParameters = new AltWaitForObjectsParams.Builder(altFindObjectsParams).build();
altDriver.waitForObjectToNotBePresent(altWaitForObjectsParams);
}
def test_wait_for_object_to_not_be_present(self):
self.altDriver.wait_for_object_to_not_be_present(By.NAME, "Capsuule")
SetCommandResponseTimeout
Sets the value for the command response timeout.
Parameters
Name | Type | Required | Description |
---|---|---|---|
commandTimeout | int | Yes | The duration for a command response from the driver. |
Returns
Nothing
Examples
altDriver.SetCommandResponseTimeout(commandTimeout);
altDriver.setCommandResponseTimeout(commandTimeout);
altDriver.set_command_response_timeout(command_timeout)
GetDelayAfterCommand
Gets the current delay after a command.
Parameters
None
Returns
The current delay after a command.
Examples
altDriver.GetDelayAfterCommand();
altDriver.getDelayAfterCommand();
altDriver.get_delay_after_command()
SetDelayAfterCommand
Set the delay after a command.
Parameters
Name | Type | Required | Description |
---|---|---|---|
delay | int | Yes | The new delay a after a command. |
Returns
Nothing
Examples
altDriver.SetDelayAfterCommand(5);
altDriver.setDelayAfterCommand(5);
altDriver.set_delay_after_command(5)
Input Actions
KeyDown
Simulates a key down.
Parameters
Name | Type | Required | Description |
---|---|---|---|
keyCode | AltKeyCode | Yes | The keyCode of the key simulated to be pressed. |
power | int | Yes | A value between [-1,1] used for joysticks to indicate how hard the button was pressed. |
Returns
Nothing
Examples
[Test]
public void TestKeyDownAndKeyUp()
{
altDriver.LoadScene("Scene 5 Keyboard Input");
AltKeyCode kcode = AltKeyCode.A;
altDriver.KeyDown(kcode, 1);
var lastKeyDown = altDriver.FindObject(By.NAME, "LastKeyDownValue");
var lastKeyPress = altDriver.FindObject(By.NAME, "LastKeyPressedValue");
Assert.AreEqual((int)kcode, (int)Enum.Parse(typeof(AltKeyCode), lastKeyDown.GetText(), true));
Assert.AreEqual((int)kcode, (int)Enum.Parse(typeof(AltKeyCode), lastKeyPress.GetText(), true));
altDriver.KeyUp(kcode);
var lastKeyUp = altDriver.FindObject(By.NAME, "LastKeyUpValue");
Assert.AreEqual((int)kcode, (int)Enum.Parse(typeof(AltKeyCode), lastKeyUp.GetText(), true));
}
@Test
public void TestKeyDownAndKeyUp() throws Exception {
AltFindObjectsParams altFindObjectsParameters1 = new AltFindObjectsParams.Builder(
AltDriver.By.NAME, "LastKeyDownValue").build();
AltFindObjectsParams altFindObjectsParameters2 = new AltFindObjectsParams.Builder(
AltDriver.By.NAME, "LastKeyUpValue").build();
AltFindObjectsParams altFindObjectsParameters3 = new AltFindObjectsParams.Builder(
AltDriver.By.NAME, "LastKeyPressedValue").build();
AltKeyCode kcode = AltKeyCode.A;
AltKeyParams altKeyParams = new AltKeyParams.Builder(kcode).build();
altDriver.KeyDown(altKeyParams);
Thread.sleep(2000);
AltObject lastKeyDown = altDriver.findObject(altFindObjectsParameters1);
AltObject lastKeyPress = altDriver.findObject(altFindObjectsParameters3);
assertEquals("A", AltKeyCode.valueOf(lastKeyDown.getText()).name());
assertEquals("A", AltKeyCode.valueOf(lastKeyPress.getText()).name());
altDriver.KeyUp(kcode);
Thread.sleep(2000);
AltObject lastKeyUp = altDriver.findObject(altFindObjectsParameters2);
assertEquals("A", AltKeyCode.valueOf(lastKeyUp.getText()).name());
}
def test_key_down_and_key_up(self):
self.altDriver.load_scene('Scene 5 Keyboard Input')
self.altDriver.key_down(AltKeyCode.A)
time.sleep(5)
lastKeyDown = self.altDriver.find_object(By.NAME, 'LastKeyDownValue')
lastKeyPress = self.altDriver.find_object(By.NAME, 'LastKeyPressedValue')
self.assertEqual("A", lastKeyDown.get_text())
self.assertEqual("A", lastKeyPress.get_text())
self.altDriver.key_up(AltKeyCode.A)
time.sleep(5)
lastKeyUp = self.altDriver.find_object(By.NAME, 'LastKeyUpValue')
self.assertEqual("A", lastKeyUp.get_text())
KeyUp
Simulates a key up.
Parameters
Name | Type | Required | Description |
---|---|---|---|
keyCode | AltKeyCode | Yes | The keyCode of the key simulated to be released. |
Returns
Nothing
Examples
[Test]
public void TestKeyDownAndKeyUp()
{
altDriver.LoadScene("Scene 5 Keyboard Input");
AltKeyCode kcode = AltKeyCode.A;
altDriver.KeyDown(kcode, 1);
var lastKeyDown = altDriver.FindObject(By.NAME, "LastKeyDownValue");
var lastKeyPress = altDriver.FindObject(By.NAME, "LastKeyPressedValue");
Assert.AreEqual((int)kcode, (int)Enum.Parse(typeof(AltKeyCode), lastKeyDown.GetText(), true));
Assert.AreEqual((int)kcode, (int)Enum.Parse(typeof(AltKeyCode), lastKeyPress.GetText(), true));
altDriver.KeyUp(kcode);
var lastKeyUp = altDriver.FindObject(By.NAME, "LastKeyUpValue");
Assert.AreEqual((int)kcode, (int)Enum.Parse(typeof(AltKeyCode), lastKeyUp.GetText(), true));
}
@Test
public void TestKeyDownAndKeyUp() throws Exception {
AltFindObjectsParams altFindObjectsParameters1 = new AltFindObjectsParams.Builder(
AltDriver.By.NAME, "LastKeyDownValue").build();
AltFindObjectsParams altFindObjectsParameters2 = new AltFindObjectsParams.Builder(
AltDriver.By.NAME, "LastKeyUpValue").build();
AltFindObjectsParams altFindObjectsParameters3 = new AltFindObjectsParams.Builder(
AltDriver.By.NAME, "LastKeyPressedValue").build();
AltKeyCode kcode = AltKeyCode.A;
AltKeyParams altKeyParams = new AltKeyParams.Builder(kcode).build();
altDriver.KeyDown(altKeyParams);
Thread.sleep(2000);
AltObject lastKeyDown = altDriver.findObject(altFindObjectsParameters1);
AltObject lastKeyPress = altDriver.findObject(altFindObjectsParameters3);
assertEquals("A", AltKeyCode.valueOf(lastKeyDown.getText()).name());
assertEquals("A", AltKeyCode.valueOf(lastKeyPress.getText()).name());
altDriver.KeyUp(kcode);
Thread.sleep(2000);
AltObject lastKeyUp = altDriver.findObject(altFindObjectsParameters2);
assertEquals("A", AltKeyCode.valueOf(lastKeyUp.getText()).name());
}
def test_key_down_and_key_up(self):
self.altDriver.load_scene('Scene 5 Keyboard Input')
self.altDriver.key_down(AltKeyCode.A)
time.sleep(5)
lastKeyDown = self.altDriver.find_object(By.NAME, 'LastKeyDownValue')
lastKeyPress = self.altDriver.find_object(By.NAME, 'LastKeyPressedValue')
self.assertEqual("A", lastKeyDown.get_text())
self.assertEqual("A", lastKeyPress.get_text())
self.altDriver.key_up(AltKeyCode.A)
time.sleep(5)
lastKeyUp = self.altDriver.find_object(By.NAME, 'LastKeyUpValue')
self.assertEqual("A", lastKeyUp.get_text())
HoldButton
Simulates holding left click button down for a specified amount of time at given coordinates.
Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
coordinates | Vector2 | Yes | The coordinates where the button is held down. | |
duration | float | No | 0.1 | The time measured in seconds to keep the button down. |
wait | boolean | No | true | If set wait for command to finish. |
Returns
Nothing
Examples
[Test]
public void TestHoldButton()
{
var button = altDriver.FindObject(By.NAME, "UIButton");
altDriver.HoldButton(button.GetScreenPosition(), 1);
var capsuleInfo = altDriver.FindObject(By.NAME, "CapsuleInfo");
var text = capsuleInfo.GetText();
Assert.AreEqual(text, "UIButton clicked to jump capsule!");
}
@Test
public void testHoldButton() throws Exception {
AltObject button = altDriver
.findObject(new AltFindObjectsParams.Builder(AltDriver.By.NAME, "UIButton").build());
altDriver.holdButton(new AltHoldParams.Builder(button.getScreenPosition()).withDuration(1).build());
AltObject capsuleInfo = altDriver
.findObject(new AltFindObjectsParams.Builder(AltDriver.By.NAME, "CapsuleInfo").build());
String text = capsuleInfo.getText();
assertEquals(text, "UIButton clicked to jump capsule!");
}
def test_hold_button(self):
self.altdriver.load_scene("Scene 1 AltDriverTestScene")
button = self.altdriver.find_object(By.NAME, "UIButton")
self.altdriver.hold_button(button.get_screen_position(), 1)
capsule_info = self.altdriver.find_object(By.NAME, "CapsuleInfo")
text = capsule_info.get_text()
assert text == "UIButton clicked to jump capsule!"
MoveMouse
Simulate mouse movement in your app.
Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
coordinates | Vector2 | Yes | The screen coordinates. | |
duration | float | No | 0.1 | The time measured in seconds to move the mouse from the current mouse position to the set coordinates. |
wait | boolean | No | true | If set wait for command to finish. |
Returns
Nothing
Examples
[Test]
public void TestCreatingStars()
{
altDriver.LoadScene("Scene 5 Keyboard Input");
var stars = altDriver.FindObjectsWhichContain(By.NAME, "Star", cameraValue: "Player2");
var pressingpoint1 = altDriver.FindObjectWhichContains(By.NAME, "PressingPoint1", cameraValue: "Player2");
Assert.AreEqual(1, stars.Count);
altDriver.MoveMouse(new AltVector2(pressingpoint1.x, pressingpoint1.y), 1);
altDriver.PressKey(AltKeyCode.Mouse0, 0.1f);
var pressingpoint2 = altDriver.FindObjectWhichContains(By.NAME, "PressingPoint2", cameraValue: "Player2");
altDriver.MoveMouse(new AltVector2(pressingpoint2.x, pressingpoint2.y), 1);
altDriver.PressKey(AltKeyCode.Mouse0, 0.1f);
stars = altDriver.FindObjectsWhichContain(By.NAME, "Star");
Assert.AreEqual(3, stars.Count);
}
@Test
public void TestCreatingStars2() throws InterruptedException {
AltObject[] stars = altDriver.findObjectsWhichContain(new AltFindObjectsParams.Builder(By.NAME, "Star").build());
assertEquals(1, stars.length);
AltObject pressingPoint1 = altDriver.findObject(new AltFindObjectsParams.Builder(By.NAME, "PressingPoint1").withCamera(By.NAME, "Player2").build());
altDriver.moveMouse(new AltMoveMouseParams.Builder(pressingPoint1.getScreenPosition()).build());
altDriver.pressKey(new AltPressKeyParams.Builder(AltKeyCode.Mouse0).build());
AltObject pressingPoint2 = altDriver.findObject(new AltFindObjectsParams.Builder(AltDriver.By.NAME, "PressingPoint2").withCamera(AltDriver.By.NAME, "Player2").build());
altDriver.moveMouse(new AltMoveMouseParams.Builder(pressingPoint2.getScreenPosition()).build());
altDriver.pressKey(new AltPressKeyParams.Builder(AltKeyCode.Mouse0).build());
stars = altDriver.findObjectsWhichContain(new AltFindObjectsParams.Builder(By.NAME, "Star").build());
assertEquals(3, stars.length);
}
def test_creating_stars(self):
self.altdriver.load_scene("Scene 5 Keyboard Input")
stars = self.altdriver.find_objects_which_contain(By.NAME, "Star", By.NAME, "Player2")
assert len(stars) == 1
self.altdriver.find_objects_which_contain(By.NAME, "Player", By.NAME, "Player2")
pressing_point_1 = self.altdriver.find_object(By.NAME, "PressingPoint1", By.NAME, "Player2")
self.altdriver.move_mouse(pressing_point_1.get_screen_position(), duration=1)
self.altdriver.press_key(AltKeyCode.Mouse0, 1, 1)
pressing_point_2 = self.altdriver.find_object(By.NAME, "PressingPoint2", By.NAME, "Player2")
self.altdriver.move_mouse(pressing_point_2.get_screen_position(), duration=1)
self.altdriver.press_key(AltKeyCode.Mouse0, power=1, duration=1)
stars = self.altdriver.find_objects_which_contain(By.NAME, "Star")
assert len(stars) == 3
PressKey
Simulates key press action in your app.
Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
keycode | AltKeyCode | Yes | The key code of the key simulated to be pressed. | |
power | float | No | 1 | A value between [-1,1] used for joysticks to indicate how hard the button was pressed. |
duration | float | No | 0.1 | The time measured in seconds from the key press to the key release. |
wait | boolean | No | true | If set wait for command to finish. |
Returns
Nothing
Examples
[Test]
public void TestCreatingStars()
{
altDriver.LoadScene("Scene 5 Keyboard Input");
var stars = altDriver.FindObjectsWhichContain(By.NAME, "Star", cameraValue: "Player2");
var pressingpoint1 = altDriver.FindObjectWhichContains(By.NAME, "PressingPoint1", cameraValue: "Player2");
Assert.AreEqual(1, stars.Count);
altDriver.MoveMouse(new AltVector2(pressingpoint1.x, pressingpoint1.y), 1);
altDriver.PressKey(AltKeyCode.Mouse0, 0.1f);
var pressingpoint2 = altDriver.FindObjectWhichContains(By.NAME, "PressingPoint2", cameraValue: "Player2");
altDriver.MoveMouse(new AltVector2(pressingpoint2.x, pressingpoint2.y), 1);
altDriver.PressKey(AltKeyCode.Mouse0, 0.1f);
stars = altDriver.FindObjectsWhichContain(By.NAME, "Star");
Assert.AreEqual(3, stars.Count);
}
@Test
public void TestCreatingStars2() throws InterruptedException {
AltObject[] stars = altDriver.findObjectsWhichContain(new AltFindObjectsParams.Builder(By.NAME, "Star").build());
assertEquals(1, stars.length);
AltObject pressingPoint1 = altDriver.findObject(new AltFindObjectsParams.Builder(By.NAME, "PressingPoint1").withCamera(By.NAME, "Player2").build());
altDriver.moveMouse(new AltMoveMouseParams.Builder(pressingPoint1.getScreenPosition()).build());
altDriver.pressKey(new AltPressKeyParams.Builder(AltKeyCode.Mouse0).build());
AltObject pressingPoint2 = altDriver.findObject(new AltFindObjectsParams.Builder(AltDriver.By.NAME, "PressingPoint2").withCamera(AltDriver.By.NAME, "Player2").build());
altDriver.moveMouse(new AltMoveMouseParams.Builder(pressingPoint2.getScreenPosition()).build());
altDriver.pressKey(new AltPressKeyParams.Builder(AltKeyCode.Mouse0).build());
stars = altDriver.findObjectsWhichContain(new AltFindObjectsParams.Builder(By.NAME, "Star").build());
assertEquals(3, stars.length);
}
def test_creating_stars(self):
self.altdriver.load_scene("Scene 5 Keyboard Input")
stars = self.altdriver.find_objects_which_contain(By.NAME, "Star", By.NAME, "Player2")
assert len(stars) == 1
self.altdriver.find_objects_which_contain(By.NAME, "Player", By.NAME, "Player2")
pressing_point_1 = self.altdriver.find_object(By.NAME, "PressingPoint1", By.NAME, "Player2")
self.altdriver.move_mouse(pressing_point_1.get_screen_position(), duration=1)
self.altdriver.press_key(AltKeyCode.Mouse0, 1, 1)
pressing_point_2 = self.altdriver.find_object(By.NAME, "PressingPoint2", By.NAME, "Player2")
self.altdriver.move_mouse(pressing_point_2.get_screen_position(), duration=1)
self.altdriver.press_key(AltKeyCode.Mouse0, power=1, duration=1)
stars = self.altdriver.find_objects_which_contain(By.NAME, "Star")
assert len(stars) == 3
PressKeys
Simulates multiple key press action in your app.
Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
keycodes | List[AltKeyCode] | Yes | The list of keycodes simulated to be pressed simultaneously. | |
power | float | No | 1 | A value between [-1,1] used for joysticks to indicate how hard the buttons were pressed. |
duration | float | No | 0.1 | The time measured in seconds from the multiple key press to the multiple key release. |
wait | boolean | No | true | If set, wait for command to finish. |
Returns
Nothing
Examples
[Test]
public void TestPressKeys()
{
AltKeyCode[] keys = { AltKeyCode.K, AltKeyCode.L };
altDriver.PressKeys(keys);
var altObject = altDriver.FindObject(By.NAME, "Capsule");
var finalPropertyValue = altObject.GetComponentProperty<string>("AltExampleScriptCapsule", "stringToSetFromTests", "Assembly-CSharp");
Assert.AreEqual("multiple keys pressed", finalPropertyValue);
}
@Test
public void testPressKeys()
{
AltKeyCode[] keys = {AltKeyCode.K, AltKeyCode.L};
altDriver.pressKeys(new AltPressKeysParams.Builder(keys).build());
AltFindObjectsParams altFindObjectsParams = new AltFindObjectsParams.Builder(
AltDriver.By.NAME, "Capsule").build();
AltObject altObject = altDriver.findObject(altFindObjectsParams);
AltGetComponentPropertyParams altGetComponentPropertyParams = new AltGetComponentPropertyParams.Builder(
"AltExampleScriptCapsule",
"stringToSetFromTests", "Assembly-CSharp").build();
String finalPropertyValue = altObject.getComponentProperty(altGetComponentPropertyParams, String.class);
assertEquals(finalPropertyValue, "multiple keys pressed");
}
def test_press_keys(self):
keys = [AltKeyCode.K, AltKeyCode.L]
self.altdriver.press_keys(keys)
alt_unity_object = self.altdriver.find_object(By.NAME, "Capsule")
property_value = alt_unity_object.get_component_property(
"AltExampleScriptCapsule",
"stringToSetFromTests",
"Assembly-CSharp"
)
assert property_value == "multiple keys pressed"
Scroll
Simulate scroll action in your app.
Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
speed | float | No | 1 | Set how fast to scroll. Positive values will scroll up and negative values will scroll down. |
duration | float | No | 0.1 | The duration of the scroll in seconds. |
wait | boolean | No | true | If set wait for command to finish. |
speedHorizontal | float | No | 1 | Set how fast to scroll right or left. |
Returns
Nothing
Examples
[Test]
public void TestScroll()
{
altDriver.LoadScene("Scene 5 Keyboard Input");
var player2 = altDriver.FindObject(By.NAME, "Player2");
AltVector3 cubeInitialPosition = new AltVector3(player2.worldX, player2.worldY, player2.worldY);
altDriver.Scroll(4, 2);
player2 = altDriver.FindObject(By.NAME, "Player2");
AltVector3 cubeFinalPosition = new AltVector3(player2.worldX, player2.worldY, player2.worldY);
Assert.AreNotEqual(cubeInitialPosition, cubeFinalPosition);
}
@Test
public void TestScroll() throws InterruptedException {
AltFindObjectsParams altFindObjectsParams = new AltFindObjectsParams.Builder(AltDriver.By.NAME,
"Player2").build();
AltObject player2 = altDriver.findObject(altFindObjectsParams);
Vector3 cubeInitialPosition = new Vector3(player2.worldX, player2.worldY, player2.worldY);
altDriver.scroll(new AltScrollParams.Builder().withSpeed(4).withDuration(2).build());
player2 = altDriver.findObject(altFindObjectsParams);
Vector3 cubeFinalPosition = new Vector3(player2.worldX, player2.worldY, player2.worldY);
assertNotEquals(cubeInitialPosition, cubeFinalPosition);
}
def test_scroll(self):
self.altdriver.load_scene("Scene 5 Keyboard Input")
player2 = self.altdriver.find_object(By.NAME, "Player2")
cube_initial_position = [player2.worldX, player2.worldY, player2.worldY]
self.altdriver.scroll(4, 2)
player2 = self.altdriver.find_object(By.NAME, "Player2")
cubeFinalPosition = [player2.worldX, player2.worldY, player2.worldY]
assert cube_initial_position != cubeFinalPosition
Swipe
Simulates a swipe action between two points.
Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
start | Vector2 | Yes | Starting location of the swipe. | |
end | Vector2 | Yes | Ending location of the swipe. | |
duration | float | No | 0.1 | The time measured in seconds to move the mouse from start to end location. |
wait | boolean | No | true | If set wait for command to finish. |
Returns
Nothing
Examples
[Test]
public void MultipleDragAndDrop()
{
var altElement1 = altDriver.FindObject(By.NAME, "Drag Image1");
var altElement2 = altDriver.FindObject(By.NAME, "Drop Box1");
altDriver.Swipe(new AltVector2(altElement1.x, altElement1.y), new AltVector2(altElement2.x, altElement2.y), 1);
altElement1 = altDriver.FindObject(By.NAME, "Drag Image2");
altElement2 = altDriver.FindObject(By.NAME, "Drop Box2");
altDriver.Swipe(new AltVector2(altElement1.x, altElement1.y), new AltVector2(altElement2.x, altElement2.y), 1);
altElement1 = altDriver.FindObject(By.NAME, "Drag Image3");
altElement2 = altDriver.FindObject(By.NAME, "Drop Box1");
altDriver.Swipe(new AltVector2(altElement1.x, altElement1.y), new AltVector2(altElement2.x, altElement2.y), 1);
altElement1 = altDriver.FindObject(By.NAME, "Drag Image1");
altElement2 = altDriver.FindObject(By.NAME, "Drop Box1");
altDriver.Swipe(new AltVector2(altElement1.x, altElement1.y), new AltVector2(altElement2.x, altElement2.y), 1);
var imageSource = altDriver.FindObject(By.NAME, "Drag Image1").GetComponentProperty("UnityEngine.UI.Image", "sprite", "UnityEngine.UI");
var imageSourceDropZone = altDriver.FindObject(By.NAME, "Drop Image").GetComponentProperty("UnityEngine.UI.Image", "sprite", "UnityEngine.UI");
Assert.AreNotEqual(imageSource, imageSourceDropZone);
imageSource = altDriver.FindObject(By.NAME, "Drag Image2").GetComponentProperty("UnityEngine.UI.Image", "sprite", "UnityEngine.UI");
imageSourceDropZone = altDriver.FindObject(By.NAME, "Drop").GetComponentProperty("UnityEngine.UI.Image", "sprite", "UnityEngine.UI");
Assert.AreNotEqual(imageSource, imageSourceDropZone);
}
@Test
public void testMultipleDragAndDrop() throws Exception {
AltFindObjectsParams altFindObjectsParameters1 = new AltFindObjectsParams.Builder(
AltDriver.By.NAME, "Drag Image1").build();
AltFindObjectsParams altFindObjectsParameters2 = new AltFindObjectsParams.Builder(
AltDriver.By.NAME, "Drop Box1").build();
AltFindObjectsParams altFindObjectsParameters3 = new AltFindObjectsParams.Builder(
AltDriver.By.NAME, "Drag Image2").build();
AltFindObjectsParams altFindObjectsParameters4 = new AltFindObjectsParams.Builder(
AltDriver.By.NAME, "Drag Image3").build();
AltFindObjectsParams altFindObjectsParameters5 = new AltFindObjectsParams.Builder(
AltDriver.By.NAME, "Drop Box2").build();
AltFindObjectsParams altFindObjectsParameters6 = new AltFindObjectsParams.Builder(
AltDriver.By.NAME, "Drop Image").build();
AltFindObjectsParams altFindObjectsParameters7 = new AltFindObjectsParams.Builder(
AltDriver.By.NAME, "Drop Image").build();
AltObject altElement1 = altDriver.findObject(altFindObjectsParameters1);
AltObject altElement2 = altDriver.findObject(altFindObjectsParameters2);
altDriver
.swipe(new AltSwipeParams.Builder(altElement1.getScreenPosition(), altElement2.getScreenPosition())
.withDuration(2).build());
altElement1 = altDriver.findObject(altFindObjectsParameters3);
altElement2 = altDriver.findObject(altFindObjectsParameters5);
altDriver
.swipe(new AltSwipeParams.Builder(altElement1.getScreenPosition(), altElement2.getScreenPosition())
.withDuration(2).build());
altElement1 = altDriver.findObject(altFindObjectsParameters4);
altElement2 = altDriver.findObject(altFindObjectsParameters2);
altDriver
.swipe(new AltSwipeParams.Builder(altElement1.getScreenPosition(), altElement2.getScreenPosition())
.withDuration(3).build());
altElement1 = altDriver.findObject(altFindObjectsParameters1);
altElement2 = altDriver.findObject(altFindObjectsParameters2);
altDriver
.swipe(new AltSwipeParams.Builder(altElement1.getScreenPosition(), altElement2.getScreenPosition())
.withDuration(1).build());
AltSprite imageSource = altDriver.findObject(altFindObjectsParameters1)
.getComponentProperty(new AltGetComponentPropertyParams.Builder("UnityEngine.UI.Image", "sprite", "UnityEngine.UI").build(), AltSprite.class);
AltSprite imageSourceDropZone = altDriver.findObject(altFindObjectsParameters6)
.getComponentProperty(new AltGetComponentPropertyParams.Builder("UnityEngine.UI.Image", "sprite", "UnityEngine.UI").build(), AltSprite.class);
assertNotSame(imageSource, imageSourceDropZone);
imageSource = altDriver.findObject(altFindObjectsParameters3)
.getComponentProperty(new AltGetComponentPropertyParams.Builder("UnityEngine.UI.Image", "sprite", "UnityEngine.UI").build(), AltSprite.class);
imageSourceDropZone = altDriver.findObject(altFindObjectsParameters7)
.getComponentProperty(new AltGetComponentPropertyParams.Builder("UnityEngine.UI.Image", "sprite", "UnityEngine.UI").build(), AltSprite.class);
assertNotSame(imageSource, imageSourceDropZone);
}
def test_multiple_swipes(self):
self.altdriver.load_scene("Scene 3 Drag And Drop")
image2 = self.altdriver.find_object(By.NAME, "Drag Image2")
box2 = self.altdriver.find_object(By.NAME, "Drop Box2")
self.altdriver.swipe(image2.get_screen_position(), box2.get_screen_position(), 2)
image3 = self.altdriver.find_object(By.NAME, "Drag Image3")
box1 = self.altdriver.find_object(By.NAME, "Drop Box1")
self.altdriver.swipe(image3.get_screen_position(), box1.get_screen_position(), 1)
image1 = self.altdriver.find_object(By.NAME, "Drag Image1")
box1 = self.altdriver.find_object(By.NAME, "Drop Box1")
self.altdriver.swipe(image1.get_screen_position(), box1.get_screen_position(), 3)
image_source = image1.get_component_property("UnityEngine.UI.Image", "sprite", "UnityEngine.UI")
image_source_drop_zone = self.altdriver.find_object(
By.NAME, "Drop Image").get_component_property("UnityEngine.UI.Image", "sprite", "UnityEngine.UI")
assert image_source != image_source_drop_zone
image_source = image2.get_component_property("UnityEngine.UI.Image", "sprite", "UnityEngine.UI")
image_source_drop_zone = self.altdriver.find_object(
By.NAME, "Drop").get_component_property("UnityEngine.UI.Image", "sprite", "UnityEngine.UI")
assert image_source != image_source_drop_zone
MultipointSwipe
Simulates a multipoint swipe action.
Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
positions | List[AltVector2] | Yes | A list of positions on the screen where the swipe be made. | |
duration | float | No | 0.1 | The time measured in seconds to swipe from first position to the last position. |
wait | boolean | No | true | If set wait for command to finish. |
Returns
Nothing
Examples
[Test]
public void TestResizePanelWithMultipointSwipe()
{
var altElement = altDriver.FindObject(By.NAME, "Resize Zone");
var position = new AltVector2(altElement.x, altElement.y);
var pos = new[]
{
altElement.GetScreenPosition(),
new AltVector2(altElement.x - 200, altElement.y - 200),
new AltVector2(altElement.x - 300, altElement.y - 100),
new AltVector2(altElement.x - 50, altElement.y - 100),
new AltVector2(altElement.x - 100, altElement.y - 100)
};
altDriver.MultipointSwipe(pos, 4);
altElement = altDriver.FindObject(By.NAME, "Resize Zone");
var position2 = new AltVector2(altElement.x, altElement.y);
Assert.AreNotEqual(position, position2);
}
@Test
public void testResizePanelWithMultipointSwipe() throws Exception {
AltFindObjectsParams altFindObjectsParameters1 = new AltFindObjectsParams.Builder(
AltDriver.By.NAME, "Resize Zone").build();
AltObject altElement = altDriver.findObject(altFindObjectsParameters1);
List<Vector2> positions = Arrays.asList(altElement.getScreenPosition(),
new Vector2(altElement.x + 100, altElement.y + 100),
new Vector2(altElement.x + 100, altElement.y + 200));
altDriver.multipointSwipe(new AltMultipointSwipeParams.Builder(positions).withDuration(3).build());
AltObject altElementAfterResize = altDriver.findObject(altFindObjectsParameters1);
assertNotSame(altElement.x, altElementAfterResize.x);
assertNotSame(altElement.y, altElementAfterResize.y);
}
def test_resize_panel_with_multipoint_swipe(self):
self.altdriver.load_scene("Scene 2 Draggable Panel")
alt_unity_object = self.altdriver.find_object(By.NAME, "Resize Zone")
position_init = (alt_unity_object.x, alt_unity_object.y)
positions = [
alt_unity_object.get_screen_position(),
[alt_unity_object.x - 200, alt_unity_object.y - 200],
[alt_unity_object.x - 300, alt_unity_object.y - 100],
[alt_unity_object.x - 50, alt_unity_object.y - 100],
[alt_unity_object.x - 100, alt_unity_object.y - 100]
]
self.altdriver.multipoint_swipe(positions, duration=4)
alt_unity_object = self.altdriver.find_object(By.NAME, "Resize Zone")
position_final = (alt_unity_object.x, alt_unity_object.y)
assert position_init != position_final
BeginTouch
Simulates starting of a touch on the screen. To further interact with the touch use MoveTouch and EndTouch
Parameters
Name | Type | Required | Description |
---|---|---|---|
coordinates | Vector2 | Yes | Screen coordinates. |
Returns
int - the fingerId.
Examples
[Test]
public void TestNewTouchCommands()
{
var draggableArea = altDriver.FindObject(By.NAME, "Drag Zone");
var initialPosition = draggableArea.GetScreenPosition();
int fingerId = altDriver.BeginTouch(draggableArea.GetScreenPosition());
AltVector2 newPosition = new AltVector2(draggableArea.x + 20, draggableArea.y + 10);
altDriver.MoveTouch(fingerId, newPosition);
altDriver.EndTouch(fingerId);
draggableArea = altDriver.FindObject(By.NAME, "Drag Zone");
Assert.AreNotEqual(initialPosition, draggableArea.GetScreenPosition());
}
@Test
public void testNewTouchCommands() throws InterruptedException {
AltFindObjectsParams altFindObjectsParameters1 = new AltFindObjectsParams.Builder(
AltDriver.By.NAME, "Drag Zone").build();
AltObject draggableArea = altDriver.findObject(altFindObjectsParameters1);
Vector2 initialPosition = draggableArea.getScreenPosition();
int fingerId = altDriver.beginTouch(new AltBeginTouchParams.Builder(initialPosition).build());
Vector2 newPosition = new Vector2(draggableArea.x + 20, draggableArea.y + 10);
altDriver.moveTouch(new AltMoveTouchParams.Builder(fingerId, newPosition).build());
altDriver.endTouch(new AltEndTouchParams.Builder(fingerId).build());
draggableArea = altDriver.findObject(altFindObjectsParameters1);
assertNotEquals(initialPosition.x, draggableArea.getScreenPosition().x);
assertNotEquals(initialPosition.y, draggableArea.getScreenPosition().y);
}
def test_new_touch_commands(self):
self.altDriver.load_scene('Scene 2 Draggable Panel')
draggable_area = self.altDriver.find_object(By.NAME, 'Drag Zone')
initial_position = draggable_area.get_screen_position()
finger_id = self.altDriver.begin_touch(draggable_area.get_screen_position())
self.altDriver.move_touch(finger_id, [int(draggable_area.x) + 10, int(draggable_area.y) + 10])
self.altDriver.end_touch(finger_id)
draggable_area = self.altDriver.find_object(By.NAME, 'Drag Zone')
self.assertNotEqual(initial_position, draggable_area)
MoveTouch
Simulates a touch movement on the screen. Move the touch created with BeginTouch from the previous position to the position given as parameters.
Parameters
Name | Type | Required | Description |
---|---|---|---|
fingerId | int | Yes | Identifier returned by BeginTouch command. |
coordinates | Vector2 | Yes | Screen coordinates where the touch will be moved. |
Returns
Nothing
Examples
[Test]
public void TestNewTouchCommands()
{
var draggableArea = altDriver.FindObject(By.NAME, "Drag Zone");
var initialPosition = draggableArea.GetScreenPosition();
int fingerId = altDriver.BeginTouch(draggableArea.GetScreenPosition());
AltVector2 newPosition = new AltVector2(draggableArea.x + 20, draggableArea.y + 10);
altDriver.MoveTouch(fingerId, newPosition);
altDriver.EndTouch(fingerId);
draggableArea = altDriver.FindObject(By.NAME, "Drag Zone");
Assert.AreNotEqual(initialPosition, draggableArea.GetScreenPosition());
}
@Test
public void testNewTouchCommands() throws InterruptedException {
AltFindObjectsParams altFindObjectsParameters1 = new AltFindObjectsParams.Builder(
AltDriver.By.NAME, "Drag Zone").build();
AltObject draggableArea = altDriver.findObject(altFindObjectsParameters1);
Vector2 initialPosition = draggableArea.getScreenPosition();
int fingerId = altDriver.beginTouch(new AltBeginTouchParams.Builder(initialPosition).build());
Vector2 newPosition = new Vector2(draggableArea.x + 20, draggableArea.y + 10);
altDriver.moveTouch(new AltMoveTouchParams.Builder(fingerId, newPosition).build());
altDriver.endTouch(new AltEndTouchParams.Builder(fingerId).build());
draggableArea = altDriver.findObject(altFindObjectsParameters1);
assertNotEquals(initialPosition.x, draggableArea.getScreenPosition().x);
assertNotEquals(initialPosition.y, draggableArea.getScreenPosition().y);
}
def test_new_touch_commands(self):
self.altDriver.load_scene('Scene 2 Draggable Panel')
draggable_area = self.altDriver.find_object(By.NAME, 'Drag Zone')
initial_position = draggable_area.get_screen_position()
finger_id = self.altDriver.begin_touch(draggable_area.get_screen_position())
self.altDriver.move_touch(finger_id, [int(draggable_area.x) + 10, int(draggable_area.y) + 10])
self.altDriver.end_touch(finger_id)
draggable_area = self.altDriver.find_object(By.NAME, 'Drag Zone')
self.assertNotEqual(initial_position, draggable_area)
EndTouch
Simulates ending of a touch on the screen. This command will destroy the touch making it no longer usable to other movements.
Parameters
Name | Type | Required | Description |
---|---|---|---|
fingerId | int | Yes | Identifier returned by BeginTouch command. |
Returns
Nothing
Examples
[Test]
public void TestNewTouchCommands()
{
var draggableArea = altDriver.FindObject(By.NAME, "Drag Zone");
var initialPosition = draggableArea.GetScreenPosition();
int fingerId = altDriver.BeginTouch(draggableArea.GetScreenPosition());
AltVector2 newPosition = new AltVector2(draggableArea.x + 20, draggableArea.y + 10);
altDriver.MoveTouch(fingerId, newPosition);
altDriver.EndTouch(fingerId);
draggableArea = altDriver.FindObject(By.NAME, "Drag Zone");
Assert.AreNotEqual(initialPosition, draggableArea.GetScreenPosition());
}
@Test
public void testNewTouchCommands() throws InterruptedException {
AltFindObjectsParams altFindObjectsParameters1 = new AltFindObjectsParams.Builder(
AltDriver.By.NAME, "Drag Zone").build();
AltObject draggableArea = altDriver.findObject(altFindObjectsParameters1);
Vector2 initialPosition = draggableArea.getScreenPosition();
int fingerId = altDriver.beginTouch(new AltBeginTouchParams.Builder(initialPosition).build());
Vector2 newPosition = new Vector2(draggableArea.x + 20, draggableArea.y + 10);
altDriver.moveTouch(new AltMoveTouchParams.Builder(fingerId, newPosition).build());
altDriver.endTouch(new AltEndTouchParams.Builder(fingerId).build());
draggableArea = altDriver.findObject(altFindObjectsParameters1);
assertNotEquals(initialPosition.x, draggableArea.getScreenPosition().x);
assertNotEquals(initialPosition.y, draggableArea.getScreenPosition().y);
}
def test_new_touch_commands(self):
self.altDriver.load_scene('Scene 2 Draggable Panel')
draggable_area = self.altDriver.find_object(By.NAME, 'Drag Zone')
initial_position = draggable_area.get_screen_position()
finger_id = self.altDriver.begin_touch(draggable_area.get_screen_position())
self.altDriver.move_touch(finger_id, [int(draggable_area.x) + 10, int(draggable_area.y) + 10])
self.altDriver.end_touch(finger_id)
draggable_area = self.altDriver.find_object(By.NAME, 'Drag Zone')
self.assertNotEqual(initial_position, draggable_area)
Click
Click at screen coordinates.
Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
coordinates | Vector2 | Yes | The screen coordinates. | |
count | int | No | 1 | Number of clicks. |
interval | float | No | 0.1 | Interval between clicks in seconds. |
wait | boolean | No | true | If set wait for command to finish. |
Returns
Nothing
Examples
[Test]
public void TestClickCoordinates()
{
const string name = "UIButton";
var altObject = altDriver.FindObject(By.NAME,name);
altDriver.Click(altObject.GetScreenPosition());
Assert.AreEqual(name, altObject.name);
altDriver.WaitForObject(By.PATH, "//CapsuleInfo[@text="UIButton clicked to jump capsule!"]");
}
@Test()
public void TestTapCoordinates() {
AltFindObjectsParams findCapsuleParams = new AltFindObjectsParams.Builder(By.NAME, "Capsule")
.build();
AltObject capsule = altDriver.findObject(findCapsuleParams);
AltTapClickCoordinatesParams clickParams = new AltTapClickCoordinatesParams.Builder(
capsule.getScreenPosition()).build();
altDriver.click(clickParams);
AltFindObjectsParams findCapsuleInfoParams = new AltFindObjectsParams.Builder(By.PATH,
"//CapsuleInfo[@text=Capsule was clicked to jump!]").build();
AltWaitForObjectsParams waitParams = new AltWaitForObjectsParams.Builder(findCapsuleInfoParams)
.build();
altDriver.waitForObject(waitParams);
}
def test_tap_coordinates(self):
capsule_element = self.altDriver.find_object(By.NAME, 'Capsule')
self.altDriver.click(capsule_element.get_screen_position())
Tap
Tap at screen coordinates.
Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
coordinates | Vector2 | Yes | The screen coordinates. | |
count | int | No | 1 | Number of taps. |
interval | float | No | 0.1 | Interval between taps in seconds. |
wait | boolean | No | true | If set wait for command to finish. |
Returns
Nothing
Examples
[Test]
public void TestTapCoordinates()
{
const string name = "UIButton";
var altObject = altDriver.FindObject(By.NAME,name);
altDriver.Tap(altObject.GetScreenPosition());
Assert.AreEqual(name, altObject.name);
altDriver.WaitForObject(By.PATH, "//CapsuleInfo[@text="UIButton clicked to jump capsule!"]");
}
@Test()
public void TestTapCoordinates() {
AltFindObjectsParams findCapsuleParams = new AltFindObjectsParams.Builder(By.NAME, "Capsule")
.build();
AltObject capsule = altDriver.findObject(findCapsuleParams);
AltTapClickCoordinatesParams tapParams = new AltTapClickCoordinatesParams.Builder(
capsule.getScreenPosition()).build();
altDriver.tap(tapParams);
AltFindObjectsParams findCapsuleInfoParams = new AltFindObjectsParams.Builder(By.PATH,
"//CapsuleInfo[@text=Capsule was clicked to jump!]").build();
AltWaitForObjectsParams waitParams = new AltWaitForObjectsParams.Builder(findCapsuleInfoParams)
.build();
altDriver.waitForObject(waitParams);
}
def test_tap_coordinates(self):
capsule_element = self.altDriver.find_object(By.NAME, 'Capsule')
self.altDriver.tap(capsule_element.get_screen_position())
Tilt
Simulates device rotation action in your app.
Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
acceleration | Vector3 | Yes | The linear acceleration of a device. | |
duration | float | No | 0.1 | How long the rotation will take in seconds. |
wait | boolean | No | true | If set wait for command to finish. |
Returns
Nothing
Examples
[Test]
public void TestAcceleration()
{
var capsule = altDriver.FindObject(By.NAME, "Capsule");
var initialWorldCoordinates = capsule.GetWorldPosition();
altDriver.Tilt(new AltVector3(1, 1, 1), 1);
Thread.Sleep(100);
capsule = altDriver.FindObject(By.NAME, "Capsule");
var afterTiltCoordinates = capsule.GetWorldPosition();
Assert.AreNotEqual(initialWorldCoordinates, afterTiltCoordinates);
}
@Test
public void TestAcceleration() throws InterruptedException {
AltFindObjectsParams altFindObjectsParameters1 = new AltFindObjectsParams.Builder(
AltDriver.By.NAME, "Capsule").build();
AltObject capsule = altDriver.findObject(altFindObjectsParameters1);
Vector3 initialWorldCoordinates = capsule.getWorldPosition();
altDriver.tilt(new AltTiltParams.Builder(new Vector3(1, 1, 1)).withDuration(1).build());
capsule = altDriver.findObject(altFindObjectsParameters1);
Vector3 afterTiltCoordinates = capsule.getWorldPosition();
assertNotEquals(initialWorldCoordinates, afterTiltCoordinates);
}
def test_acceleration(self):
self.altdriver.load_scene("Scene 1 AltDriverTestScene")
capsule = self.altdriver.find_object(By.NAME, "Capsule")
initial_position = [capsule.worldX, capsule.worldY, capsule.worldZ]
self.altdriver.tilt([1, 1, 1], 1)
capsule = self.altdriver.find_object(By.NAME, "Capsule")
final_position = [capsule.worldX, capsule.worldY, capsule.worldZ]
assert initial_position != final_position
ResetInput
Clears all active input actions simulated by AltTester.
Parameters
None
Returns
Nothing
Examples
[Test]
public void TestResetInput()
{
altDriver.KeyDown(AltKeyCode.P, 1);
Assert.True(altDriver.FindObject(By.NAME, "AltTesterPrefab").GetComponentProperty<bool>("Altom.AltTester.NewInputSystem", "Keyboard.pKey.isPressed", "Assembly-CSharp"));
altDriver.ResetInput();
Assert.False(altDriver.FindObject(By.NAME, "AltTesterPrefab").GetComponentProperty<bool>("Altom.AltTester.NewInputSystem", "Keyboard.pKey.isPressed", "Assembly-CSharp"));
int countKeyDown = altDriver.FindObject(By.NAME, "AltTesterPrefab").GetComponentProperty<int>("Input", "_keyCodesPressed.Count", "Assembly-CSharp");
Assert.AreEqual(0, countKeyDown);
}
@Test
public void testResetInput() throws InterruptedException {
AltFindObjectsParams prefab = new AltFindObjectsParams.Builder(
AltDriver.By.NAME, "AltTesterPrefab").build();
AltGetComponentPropertyParams pIsPressed = new AltGetComponentPropertyParams.Builder(
"Altom.AltTester.NewInputSystem",
"Keyboard.pKey.isPressed", "Assembly-CSharp").build();
AltGetComponentPropertyParams count = new AltGetComponentPropertyParams.Builder(
"Input",
"_keyCodesPressed.Count", "Assembly-CSharp").build();
altDriver.keyDown(new AltKeyDownParams.Builder(AltKeyCode.P).build());
assertTrue(altDriver.findObject(prefab).getComponentProperty(pIsPressed, Boolean.class));
altDriver.resetInput();
assertFalse(altDriver.findObject(prefab).getComponentProperty(pIsPressed, Boolean.class));
int countKeyDown = altDriver.findObject(prefab).getComponentProperty(count, Integer.class);
assertEquals(0, countKeyDown);
}
def test_reset_input(self):
self.altdriver.key_down(AltKeyCode.P, 1)
assert True == self.altdriver.find_object(By.NAME, "AltTesterPrefab").get_component_property(
"Altom.AltTester.NewInputSystem", "Keyboard.pKey.isPressed", "Assembly-CSharp")
self.altdriver.reset_input()
assert False == self.altdriver.find_object(By.NAME, "AltTesterPrefab").get_component_property(
"Altom.AltTester.NewInputSystem", "Keyboard.pKey.isPressed", "Assembly-CSharp")
countKeyDown = self.altdriver.find_object(By.NAME, "AltTesterPrefab").get_component_property(
"Input", "_keyCodesPressed.Count", "Assembly-CSharp")
assert 0 == countKeyDown
Screenshot
GetPNGScreenshot
Creates a screenshot of the current screen in png format.
Parameters
Name | Type | Required | Description |
---|---|---|---|
path | string | Yes | location where the image is created. |
Returns
Nothing
Examples
[Test]
public void TestGetScreenshot()
{
var path="testC.png";
altDriver.GetPNGScreenshot(path);
FileAssert.Exists(path);
}
@Test
public void testScreenshot()
{
String path="testJava2.png";
altDriver.getPNGScreenshot(path);
assertTrue(new File(path).isFile());
}
def test_screenshot(self):
png_path = "testPython.png"
self.altDriver.get_png_screenshot(png_path)
assert path.exists(png_path)
Unity Commands
PlayerPrefKeyType
This is an enum type used for the option parameter in the set_player_pref_key command listed below and has the following values:
Type | Assigned Value |
---|---|
Int | 1 |
String | 2 |
Float | 3 |
GettingPlayerPrefs
GetIntKeyPlayerPref
Returns the value for a given key from PlayerPrefs.
Parameters
Name
Type
Required
Description
keyname
string
Yes
Key to be retrieved
Returns
int
[Test] public void TestDeleteKey() { altDriver.DeletePlayerPref(); altDriver.SetKeyPlayerPref("test", 1); var val = altDriver.GetIntKeyPlayerPref("test"); Assert.AreEqual(1, val); altDriver.DeleteKeyPlayerPref("test"); try { altDriver.GetIntKeyPlayerPref("test"); Assert.Fail(); } catch (NotFoundException exception) { Assert.AreEqual("notFound", exception.Message); } }
GetFloatKeyPlayerPref
Returns the value for a given key from PlayerPrefs.
Parameters
Name
Type
Required
Description
keyname
string
Yes
Key to be retrieved
Returns
float
[Test] public void TestDeleteKey() { altDriver.DeletePlayerPref(); altDriver.SetKeyPlayerPref("test", 1.0f); var val = altDriver.GetFloatKeyPlayerPref("test"); Assert.AreEqual(1.0f, val); altDriver.DeleteKeyPlayerPref("test"); try { altDriver.GetFloatKeyPlayerPref("test"); Assert.Fail(); } catch (NotFoundException exception) { Assert.AreEqual("notFound", exception.Message); } }
GetStringKeyPlayerPref
Returns the value for a given key from PlayerPrefs.
Parameters
Name
Type
Required
Description
keyname
string
Yes
Key to be retrieved
Returns
string
[Test] public void TestDeleteKey() { altDriver.DeletePlayerPref(); altDriver.SetKeyPlayerPref("test", "1"); var val = altDriver.GetStringKeyPlayerPref("test"); Assert.AreEqual("1", val); altDriver.DeleteKeyPlayerPref("test"); try { altDriver.GetStringKeyPlayerPref("test"); Assert.Fail(); } catch (NotFoundException exception) { Assert.AreEqual("notFound", exception.Message); } }
getFloatKeyPlayerPref
Returns the value for a given key from PlayerPrefs.
Parameters
Name
Type
Required
Description
keyname
string
Yes
Key to be retrieved
Returns
float
@Test public void testDeleteKey() throws Exception { altDriver.deletePlayerPref(); altDriver.setKeyPlayerPref("test", 1.0f); float val = altDriver.getFloatKeyPlayerPref("test"); assertEquals(1.0f, val); altDriver.deleteKeyPlayerPref("test"); try { altDriver.getFloatKeyPlayerPref("test"); fail(); } catch(NotFoundException e) { assertEquals(e.getMessage(), "error:notFound"); } }
getIntKeyPlayerPref
Returns the value for a given key from PlayerPrefs.
Parameters
Name
Type
Required
Description
keyname
string
Yes
Key to be retrieved
Returns
int
@Test public void testDeleteKey() throws Exception { altDriver.deletePlayerPref(); altDriver.setKeyPlayerPref("test", 1); int val = altDriver.getIntKeyPlayerPref("test"); assertEquals(1, val); altDriver.deleteKeyPlayerPref("test"); try { altDriver.getIntKeyPlayerPref("test"); fail(); } catch(NotFoundException e) { assertEquals(e.getMessage(), "error:notFound"); } }
getStringKeyPlayerPref
Returns the value for a given key from PlayerPrefs.
Parameters
Name
Type
Required
Description
keyname
string
Yes
Key to be retrieved
Returns
string
@Test public void testDeleteKey() throws Exception { altDriver.deletePlayerPref(); altDriver.setKeyPlayerPref("test", "1"); String val = altDriver.getStringKeyPlayerPref("test"); assertEquals("1", val); altDriver.deleteKeyPlayerPref("test"); try { altDriver.getStringKeyPlayerPref("test"); fail(); } catch(NotFoundException e) { assertEquals(e.getMessage(), "error:notFound"); } }
get_player_pref_key
Returns the value for a given key from PlayerPrefs.
Parameters
Name
Type
Required
Description
keyname
string
Yes
Key to be retrieved
Returns
string/float/int
def test_delete_key_player_pref(self): self.altDriver.load_scene("Scene 1 AltDriverTestScene") self.altDriver.delete_player_prefs() player_pref_key_type = PlayerPrefKeyType.String self.altDriver.set_player_pref_key("test", "1", player_pref_key_type) val = self.altDriver.get_player_pref_key("test", player_pref_key_type) self.assertEqual("1", str(val)) self.altDriver.delete_player_pref_key("test") try: self.altDriver.get_player_pref_key("test", player_pref_key_type) self.fail() except NotFoundException as exception: self.assertEqual("notFound", str(exception))
SettingPlayerPrefs
SetKeyPlayerPref
Sets the value for a given key in PlayerPrefs.
Parameters
Name
Type
Required
Description
keyname
string
Yes
Key to be set
value
integer/float/string
Yes
Value to be set
Returns
Nothing
Examples
[Test] public void TestDeleteKey() { altDriver.DeletePlayerPref(); altDriver.SetKeyPlayerPref("test", "1"); var val = altDriver.GetStringKeyPlayerPref("test"); Assert.AreEqual("1", val); altDriver.DeleteKeyPlayerPref("test"); try { altDriver.GetStringKeyPlayerPref("test"); Assert.Fail(); } catch (NotFoundException exception) { Assert.AreEqual("notFound", exception.Message); } }
setKeyPlayerPref
Sets the value for a given key in PlayerPrefs.
Parameters
Name
Type
Required
Description
keyname
string
Yes
Key to be set
value
integer/float/string
Yes
Value to be set
Returns
Nothing
Examples
@Test public void testDeleteKey() throws Exception { altDriver.deletePlayerPref(); altDriver.setKeyPlayerPref("test", "1"); String val = altDriver.getStringKeyPlayerPref("test"); assertEquals("1", val); altDriver.deleteKeyPlayerPref("test"); try { altDriver.getStringKeyPlayerPref("test"); fail(); } catch(NotFoundException e) { assertEquals(e.getMessage(), "error:notFound"); } }
set_player_pref_key
Sets the value for a given key in PlayerPrefs.
Parameters
Name
Type
Required
Description
keyname
string
Yes
Key to be set
value
integer/float/string
Yes
Value to be set
option
PlayerPrefKeyType
Yes
Type of keyname
Returns
Nothing
Examples
def test_delete_key_player_pref(self): self.altDriver.load_scene("Scene 1 AltDriverTestScene") self.altDriver.delete_player_prefs() player_pref_key_type = PlayerPrefKeyType.String self.altDriver.set_player_pref_key("test", "1", player_pref_key_type) val = self.altDriver.get_player_pref_key("test", player_pref_key_type) self.assertEqual("1", str(val)) self.altDriver.delete_player_pref_key("test") try: self.altDriver.get_player_pref_key("test", player_pref_key_type) self.fail() except NotFoundException as exception: self.assertEqual("notFound", str(exception))
DeleteKeyPlayerPref
Removes key and its corresponding value from PlayerPrefs.
Parameters
Name | Type | Required | Description |
---|---|---|---|
keyname | sting | Yes | Key to be deleted. |
Returns
Nothing
Examples
[Test]
public void TestDeleteKey()
{
altDriver.DeletePlayerPref();
altDriver.SetKeyPlayerPref("test", 1);
var val = altDriver.GetIntKeyPlayerPref("test");
Assert.AreEqual(1, val);
altDriver.DeleteKeyPlayerPref("test");
try
{
altDriver.GetIntKeyPlayerPref("test");
Assert.Fail();
}
catch (NotFoundException exception)
{
Assert.AreEqual("notFound", exception.Message);
}
}
@Test
public void testDeleteKey() throws Exception
{
altDriver.deletePlayerPref();
altDriver.setKeyPlayerPref("test", 1);
int val = altDriver.getIntKeyPlayerPref("test");
assertEquals(1, val);
altDriver.deleteKeyPlayerPref("test");
try
{
altDriver.getIntKeyPlayerPref("test");
fail();
}
catch (NotFoundException e)
{
assertEquals(e.getMessage(), "notFound");
}
}
def test_delete_key_player_pref(self):
self.altDriver.load_scene("Scene 1 AltDriverTestScene")
self.altDriver.delete_player_prefs()
player_pref_key_type = PlayerPrefKeyType.String
self.altDriver.set_player_pref_key("test", "1", player_pref_key_type)
val = self.altDriver.get_player_pref_key("test", player_pref_key_type)
self.assertEqual("1", str(val))
self.altDriver.delete_player_pref_key("test")
try:
self.altDriver.get_player_pref_key("test", player_pref_key_type)
self.fail()
except NotFoundException as exception:
self.assertEqual("notFound", str(exception))
DeletePlayerPref
Removes all keys and values from PlayerPref.
Parameters
None
Returns
Nothing
Examples
[Test]
public void TestSetKeyInt()
{
altDriver.DeletePlayerPref();
altDriver.SetKeyPlayerPref("test", 1);
var val = altDriver.GetIntKeyPlayerPref("test");
Assert.AreEqual(1, val);
}
@Test
public void testSetKeyFloat() throws Exception
{
altDriver.deletePlayerPref();
altDriver.setKeyPlayerPref("test", 1f);
float val = altDriver.getFloatKeyPlayerPref("test");
assertEquals(1f, val, 0.01);
}
def test_delete_key_player_pref(self):
self.altDriver.load_scene("Scene 1 AltDriverTestScene")
self.altDriver.delete_player_prefs()
self.altDriver.set_player_pref_key("test", "1", PlayerPrefKeyType.String)
val = self.altDriver.get_player_pref_key("test", player_pref_key_type)
self.assertEqual("1", str(val))
GetCurrentScene
Returns the current active scene.
Parameters
None
Returns
String
Examples
[Test]
public void TestGetCurrentScene()
{
altDriver.LoadScene("Scene 1 AltDriverTestScene");
Assert.AreEqual("Scene 1 AltDriverTestScene", altDriver.GetCurrentScene());
}
@Test
public void testGetCurrentScene() throws Exception
{
altDriver.loadScene(new AltLoadSceneParams.Builder("Scene 1 AltDriverTestScene").build());
assertEquals("Scene 1 AltDriverTestScene", altDriver.getCurrentScene());
}
def test_get_current_scene(self):
self.altDriver.load_scene("Scene 1 AltDriverTestScene")
self.assertEqual("Scene 1 AltDriverTestScene",self.altDriver.get_current_scene())
LoadScene
Loads a scene.
Parameters
Name | Type | Required | Description |
---|---|---|---|
scene | string | Yes | The name of the scene to be loaded. |
loadSingle | bool | No | If set to false the scene will be loaded additive, together with the current loaded scenes. Default value is true. |
Returns
Nothing
Examples
[Test]
public void TestGetCurrentScene()
{
altDriver.LoadScene("Scene 1 AltDriverTestScene",true);
Assert.AreEqual("Scene 1 AltDriverTestScene", altDriver.GetCurrentScene());
}
@Test
public void testGetCurrentScene()
{
altDriver.loadScene(new AltLoadSceneParams.Builder("Scene 1 AltDriverTestScene").build());
assertEquals("Scene 1 AltDriverTestScene", altDriver.getCurrentScene());
}
def test_get_current_scene(self):
self.altDriver.load_scene("Scene 1 AltDriverTestScene",True)
self.assertEqual("Scene 1 AltDriverTestScene",self.altDriver.get_current_scene())
UnloadScene
Unloads a scene.
Parameters
Name | Type | Required | Description |
---|---|---|---|
scene | string | Yes | Name of the scene to be unloaded. |
Returns
Nothing
Examples
[Test]
public void TestUnloadScene()
{
altDriver.LoadScene("Scene 2 Draggable Panel", false);
Assert.AreEqual(2, altDriver.GetAllLoadedScenes().Count);
altDriver.UnloadScene("Scene 2 Draggable Panel");
Assert.AreEqual(1, altDriver.GetAllLoadedScenes().Count);
Assert.AreEqual("Scene 1 AltDriverTestScene", altDriver.GetAllLoadedScenes()[0]);
}
@Test
public void TestUnloadScene() {
AltLoadSceneParams altLoadSceneParams = new AltLoadSceneParams.Builder("Scene 2 Draggable Panel")
.loadSingle(false).build();
altDriver.loadScene(altLoadSceneParams);
assertEquals(2, altDriver.getAllLoadedScenes().length);
altDriver.unloadScene(new AltUnloadSceneParams.Builder("Scene 2 Draggable Panel").build());
assertEquals(1, altDriver.getAllLoadedScenes().length);
assertEquals("Scene 1 AltDriverTestScene", altDriver.getAllLoadedScenes()[0]);
}
def test_unload_scene(self):
self.altDriver.load_scene('Scene 1 AltDriverTestScene', True)
self.altDriver.load_scene('Scene 2 Draggable Panel', False)
self.assertEqual(2, len(self.altDriver.get_all_loaded_scenes()))
self.altDriver.unload_scene('Scene 2 Draggable Panel')
self.assertEqual(1, len(self.altDriver.get_all_loaded_scenes()))
self.assertEqual("Scene 1 AltDriverTestScene",
self.altDriver.get_all_loaded_scenes()[0])
GetAllLoadedScenes
Returns all the scenes that have been loaded.
Parameters
None
Returns
List of strings
Examples
[Test]
public void TestGetAllLoadedScenes()
{
altDriver.LoadScene("Scene 1 AltDriverTestScene");
System.Collections.Generic.List<string> loadedSceneNames = altDriver.GetAllLoadedScenes();
Assert.AreEqual(loadedSceneNames.Count, 1);
altDriver.LoadScene("Scene 2 Draggable Panel", false);
altDriver.LoadScene("Scene 3 Drag And Drop", false);
altDriver.LoadScene("Scene 4 No Cameras", false);
altDriver.LoadScene("Scene 5 Keyboard Input", false);
loadedSceneNames = altDriver.GetAllLoadedScenes();
Assert.AreEqual(loadedSceneNames.Count, 5);
}
@Test
public void TestGetAllLoadedScenes()
{
altDriver.loadScene(new AltLoadSceneParams.Builder("Scene 1 AltDriverTestScene").build());
List<String> loadedSceneNames = altDriver.getAllLoadedScenes();
assertEquals(loadedSceneNames.size(), 1);
altDriver.loadScene(new AltLoadSceneParams.Builder("Scene 2 Draggable Panel").loadSingle(false).build());
altDriver.loadScene(new AltLoadSceneParams.Builder("Scene 3 Drag And Drop").loadSingle(false).build());
altDriver.loadScene(new AltLoadSceneParams.Builder("Scene 4 No Cameras").loadSingle(false).build());
altDriver.loadScene(new AltLoadSceneParams.Builder("Scene 5 Keyboard Input").loadSingle(false).build());
loadedSceneNames = altDriver.getAllLoadedScenes();
assertEquals(loadedSceneNames.size(), 5);
}
def test_get_all_loaded_scenes(self):
self.altDriver.load_scene("Scene 1 AltDriverTestScene")
scenes_loaded = self.altDriver.get_all_loaded_scenes()
self.assertEqual(len(scenes_loaded), 1)
self.altDriver.load_scene("Scene 2 Draggable Panel", False)
self.altDriver.load_scene("Scene 3 Drag And Drop", False)
self.altDriver.load_scene("Scene 4 No Cameras", False)
self.altDriver.load_scene("Scene 5 Keyboard Input", False)
scenes_loaded = self.altDriver.get_all_loaded_scenes()
self.assertEqual(len(scenes_loaded), 5)
WaitForCurrentSceneToBe
Waits for the scene to be loaded for a specified amount of time.
Parameters
Name | Type | Required | Description |
---|---|---|---|
sceneName | string | Yes | The name of the scene to wait for. |
timeout | double | No | The time measured in seconds to wait for the specified scene. |
interval | double | No | How often to check that the scene was loaded in the given timeout. |
Returns
None
Examples
[Test]
public void TestWaitForCurrentSceneToBe()
{
const string name = "Scene 1 AltDriverTestScene";
var timeStart = DateTime.Now;
altDriver.WaitForCurrentSceneToBe(name);
var timeEnd = DateTime.Now;
var time = timeEnd - timeStart;
Assert.Less(time.TotalSeconds, 20);
var currentScene = altDriver.GetCurrentScene();
Assert.AreEqual("Scene 1 AltDriverTestScene", currentScene);
}
@Test
public void testWaitForCurrentSceneToBe() {
String name = "Scene 1 AltDriverTestScene";
long timeStart = System.currentTimeMillis();
AltWaitForCurrentSceneToBeParams params = new AltWaitForCurrentSceneToBeParams.Builder(name).build();
altDriver.waitForCurrentSceneToBe(params);
long timeEnd = System.currentTimeMillis();
long time = timeEnd - timeStart;
assertTrue(time / 1000 < 20);
String currentScene = altDriver.getCurrentScene();
assertEquals(name, currentScene);
}
def test_wait_for_current_scene_to_be_with_a_non_existing_scene(self):
scene_name = "Scene 0"
with pytest.raises(exceptions.WaitTimeOutException) as execinfo:
self.altdriver.wait_for_current_scene_to_be(scene_name, timeout=1, interval=0.5)
assert str(execinfo.value) == "Scene {} not loaded after 1 seconds".format(scene_name)
GetApplicationScreenSize
Returns the value of the application screen size.
Parameters
None
Returns
AltVector2
Examples
[Test]
public void TestGetApplicationScreenSize()
{
altDriver.CallStaticMethod<string>("UnityEngine.Screen", "SetResolution", "UnityEngine.CoreModule", new string[] { "1920", "1080", "true" }, new string[] { "System.Int32", "System.Int32", "System.Boolean" });
var screensize = altDriver.GetApplicationScreenSize();
Assert.AreEqual(1920, screensize.x);
Assert.AreEqual(1080, screensize.y);
}
@Test
public void TestGetApplicationScreenSize() {
AltCallStaticMethodParams altCallStaticMethodParams = new AltCallStaticMethodParams.Builder(
"UnityEngine.Screen", "SetResolution",
"UnityEngine.CoreModule", new Object[] { "1920", "1080", "True"})
.withTypeOfParameters(new String[] { "System.Int32", "System.Int32","System.Boolean" })
.build();
altDriver.callStaticMethod(altCallStaticMethodParams,Void.class);
int[] screensize = altDriver.getApplicationScreenSize();
assertEquals(1920, screensize[0]);
assertEquals(1080, screensize[1]);
}
def test_get_application_screen_size(self):
self.altdriver.call_static_method("UnityEngine.Screen", "SetResolution", "UnityEngine.CoreModule",
parameters=["1920", "1080", "True"],
type_of_parameters=["System.Int32", "System.Int32", "System.Boolean"],)
screensize = self.altdriver.get_application_screensize()
assert 1920 == screensize[0]
assert 1080 == screensize[1]
GetTimeScale
Returns the value of the time scale.
Parameters
None
Returns
float
Examples
[Test]
public void TestTimeScale()
{
altDriver.SetTimeScale(0.1f);
Thread.Sleep(1000);
var timeScaleFromApp = altDriver.GetTimeScale();
Assert.AreEqual(0.1f, timeScaleFromApp);
}
@Test
public void TestTimeScale() {
altDriver.setTimeScale(new AltSetTimeScaleParams.Builder(0.1f).build());
float timeScale = altDriver.getTimeScale();
assertEquals(0.1f, timeScale, 0);
}
def test_time_scale(self):
self.altDriver.set_time_scale(0.1)
time.sleep(1)
time_scale = self.altDriver.get_time_scale()
self.assertEqual(0.1, time_scale)
SetTimeScale
Sets the value of the time scale.
Parameters
Name | Type | Required | Description |
---|---|---|---|
timeScale | float | Yes | The value you want to set the time scale to. |
Returns
Nothing
Examples
[Test]
public void TestTimeScale()
{
altDriver.SetTimeScale(0.1f);
Thread.Sleep(1000);
var timeScaleFromApp = altDriver.GetTimeScale();
Assert.AreEqual(0.1f, timeScaleFromApp);
}
@Test
public void TestTimeScale() {
altDriver.setTimeScale(new AltSetTimeScaleParams.Builder(0.1f).build());
float timeScale = altDriver.getTimeScale();
assertEquals(0.1f, timeScale, 0);
}
def test_time_scale(self):
self.altDriver.set_time_scale(0.1)
time.sleep(1)
time_scale = self.altDriver.get_time_scale()
self.assertEqual(0.1, time_scale)
CallStaticMethod
Invokes static methods from your app.
Parameters
Name | Type | Required | Description |
---|---|---|---|
typeName | string | Yes | The name of the script. If the script has a namespace the format should look like this: "namespace.typeName". |
methodName | string | Yes | The name of the public method that we want to call. If the method is inside a static property/field to be able to call that method, methodName need to be the following format "propertyName.MethodName". |
assemblyName | string | Yes | The name of the assembly containing the script. |
parameters | array | Yes | An array containing the serialized parameters to be sent to the component method. |
typeOfParameters | array | No | An array containing the serialized type of parameters to be sent to the component method. |
Returns
This is a generic method. The return type depends on the type parameter.
Examples
[Test]
public void TestCallStaticMethod()
{
altDriver.CallStaticMethod<string>("UnityEngine.PlayerPrefs", "SetInt", "UnityEngine.CoreModule", new[] { "Test", "1" });
int a = altDriver.CallStaticMethod<int>("UnityEngine.PlayerPrefs", "GetInt", "UnityEngine.CoreModule", new[] { "Test", "2" });
Assert.AreEqual(1, a);
}
@Test
public void TestCallStaticMethod() throws Exception
{
AltCallStaticMethodParams altCallStaticMethodParams = new AltCallStaticMethodParams.Builder("UnityEngine.PlayerPrefs", "SetInt", "UnityEngine.CoreModule", new Object[] {"Test", 1}).withTypeOfParameters("").build();
altDriver.callStaticMethod(altCallStaticMethodParams, Void.class);
altCallStaticMethodParams = new AltCallStaticMethodParams.Builder("UnityEngine.PlayerPrefs", "GetInt", "UnityEngine.CoreModule", new Object[] {"Test", 2}).withTypeOfParameters("").build();
int a = altDriver.callStaticMethod(altCallStaticMethodParams, Integer.class);
assertEquals(1,a);
}
def test_call_static_method(self):
self.altdriver.call_static_method("UnityEngine.PlayerPrefs", "SetInt", "UnityEngine.CoreModule", ["Test", "1"])
a = int(self.altdriver.call_static_method("UnityEngine.PlayerPrefs", "GetInt", "UnityEngine.CoreModule", ["Test", "2"]))
self.assertEqual(1, a)
GetStaticProperty
Gets the value of the static field or property.
Parameters
Name | Type | Required | Description |
---|---|---|---|
componentName | string | Yes | The name of the component which has the static field or property to be retrieved. |
propertyName | string | Yes | The name of the static field or property to be retrieved. |
assemblyName | string | Yes | The name of the assembly containing the component. It is NULL by default. |
maxDepth | int | No | The maximum depth in the hierarchy to look for the static field or property. Its value is 2 by default. |
Returns
This is a generic method. The return type depends on the type of the static field or property to be retrieved.
Examples
[Test]
public void TestGetStaticProperty()
{
altDriver.CallStaticMethod<string>("UnityEngine.Screen", "SetResolution", "UnityEngine.CoreModule", new string[] {"1920", "1080", "true"}, new string[] {"System.Int32", "System.Int32", "System.Boolean"});
var width = altDriver.GetStaticProperty<int>("UnityEngine.Screen", "currentResolution.width", "UnityEngine.CoreModule");
Assert.AreEqual(1920, width);
}
@Test
public void testGetStaticProperty() {
AltCallStaticMethodParams altCallStaticMethodParams = new AltCallStaticMethodParams.Builder("UnityEngine.Screen", "SetResolution", "UnityEngine.CoreModule", new Object[] {"1920", "1080", "True"}).withTypeOfParameters(new String[] {"System.Int32", "System.Int32", "System.Boolean"}).build();
altDriver.callStaticMethod(altCallStaticMethodParams, Void.class);
AltGetComponentPropertyParams altGetComponentPropertyParams = new AltGetComponentPropertyParams.Builder("UnityEngine.Screen", "currentResolution.width", "UnityEngine.CoreModule").build();
int width = altDriver.GetStaticProperty(altGetComponentPropertyParams, Integer.class);
assertEquals(width, 1920);
}
def test_get_static_property(self):
self.altdriver.load_scene('Scene 1 AltDriverTestScene')
self.altdriver.call_static_method("UnityEngine.Screen", "SetResolution", "UnityEngine.CoreModule", ["1920", "1080", "True"], ["System.Int32", "System.Int32", "System.Boolean"])
width = self.altdriver.get_static_property(
"UnityEngine.Screen", "currentResolution.width", "UnityEngine.CoreModule")
self.assertEqual(int(width), 1920)
SetStaticProperty
Sets the value of the static field or property.
Parameters
Name | Type | Required | Description |
---|---|---|---|
componentName | string | Yes | The name of the component. If the component has a namespace the format should look like this: "namespace.componentName". |
propertyName | string | Yes | The name of the property whose value you want to set |
assemblyName | string | Yes | The name of the assembly containing the component. It is NULL by default. |
updatedProperty | object | Yes | The value to be set for the chosen component's static property |
Returns
Nothing
Examples
[Test]
public void TestSetStaticProperty()
{
var expectedValue = 5;
altDriver.SetStaticProperty("AltExampleScriptCapsule", "privateStaticVariable", "Assembly-CSharp", expectedValue);
var value = altDriver.GetStaticProperty<int>("AltExampleScriptCapsule", "privateStaticVariable", "Assembly-CSharp");
Assert.AreEqual(expectedValue, value);
}
@Test
public void testSetStaticProperty() {
final Integer expectedValue = 5;
AltSetComponentPropertyParams altSetComponentPropertyParams = new AltSetComponentPropertyParams.Builder(
"AltExampleScriptCapsule", "privateStaticVariable", "Assembly-CSharp", expectedValue.toString()).build();
altDriver.setStaticProperty(altSetComponentPropertyParams);
AltGetComponentPropertyParams altGetComponentPropertyParams = new AltGetComponentPropertyParams.Builder("AltExampleScriptCapsule", "privateStaticVariable", "Assembly-CSharp").build();
Integer value = altDriver.getStaticProperty(altGetComponentPropertyParams,Integer.class);
assertEquals(expectedValue, value);
}
def test_set_static_property(self):
expectedValue = 5
self.altdriver.set_static_property("AltExampleScriptCapsule", "privateStaticVariable", "Assembly-CSharp", expectedValue)
value = self.altdriver.get_static_property("AltExampleScriptCapsule", "privateStaticVariable", "Assembly-CSharp")
assert expectedValue == value
Other
SetServerLogging
Sets the level of logging on AltTester Unity SDK.
Parameters
Name | Type | Required | Description |
---|---|---|---|
logger | AltLogger | Yes | The type of logger. |
logLevel | AltLogLevel | Yes | The logging level. |
Returns
Nothing
Examples
altDriver.SetServerLogging(AltLogger.File, AltLogLevel.Off);
altDriver.SetServerLogging(AltLogger.Unity, AltLogLevel.Info);
altDriver.setServerLogging(AltLogger.File, AltLogLevel.Off);
altDriver.setServerLogging(AltLogger.Unity, AltLogLevel.Info);
altDriver.set_server_logging(AltLogger.File, AltLogLevel.Off);
altDriver.set_server_logging(AltLogger.Unity, AltLogLevel.Info);
AltObject
The AltObject class represents the objects present in the app and it allows you through the methods listed below to interact with them. It is the return type of the methods in the FindObjects category.
Fields
Name | Type | Description |
---|---|---|
name | string | The name of the object. |
id | int | The objects's id. |
x | int | The value for x axis coordinate on screen. |
y | int | The value for y axis coordinate on screen. |
mobileY | int | The value for y axis for appium. |
type | string | Object's type, for objects from the app is gameObject. |
enabled | bool | The local active state of the object. Note that an object may be inactive because a parent is not active, even if this returns true. |
worldX | float | The value for x axis coordinate in the app's world. |
worldY | float | The value for y axis coordinate in the app's world. |
worldZ | float | The value for z axis coordinate in the app's world. |
idCamera | int | The camera's id. |
transformId | int | The transform's component id. |
parentId | int | The transform parent's id. It's obsolete. Use transformParentId instead. |
transformParentId | int | The transform parent's id. |
The available methods are the following:
CallComponentMethod
Invokes a method from an existing component of the object.
Parameters
Name | Type | Required | Description |
---|---|---|---|
componentName | string | Yes | The name of the component. If the component has a namespace the format should look like this: "namespace.componentName". |
methodName | string | Yes | The name of the public method that will be called. If the method is inside a property/field to be able to call that method, methodName need to be the following format "propertyName.MethodName". |
assemblyName | string | Yes | The name of the assembly containing the component. |
parameters | array | Yes | An array containing the serialized parameters to be sent to the component method. |
typeOfParameters | array | No | An array containing the serialized type of parameters to be sent to the component method. |
Returns
This is a generic method. The return type depends on the type parameter.
Examples
[Test]
public void TestCallMethodWithAssembly()
{
AltObject capsule = altDriver.FindObject(By.NAME, "Capsule");
var initialRotation = capsule.GetComponentProperty("UnityEngine.Transform", "rotation");
capsule.CallComponentMethod<string>("UnityEngine.Transform", "Rotate", "UnityEngine.CoreModule", new[] { "10", "10", "10" }, new[] { "System.Single", "System.Single", "System.Single" });
AltObject capsuleAfterRotation = altDriver.FindObject(By.NAME, "Capsule");
var finalRotation = capsuleAfterRotation.GetComponentProperty("UnityEngine.Transform", "rotation");
Assert.AreNotEqual(initialRotation, finalRotation);
}
[Test]
public void TestCallMethodWithNoParameters()
{
const string componentName = "UnityEngine.UI.Text";
const string methodName = "get_text";
const string assemblyName = "UnityEngine.UI";
const string elementText = "Change Camera Mode";
var altElement = altDriver.FindObject(By.PATH, "/Canvas/Button/Text");
var data = altElement.CallComponentMethod<string>(componentName, methodName, assemblyName, new object[] { });
Assert.AreEqual(elementText, data);
}
[Test]
public void TestCallMethodWithParameters()
{
const string componentName = "UnityEngine.UI.Text";
const string methodName = "set_fontSize";
const string methodToVerifyName = "get_fontSize";
const string assemblyName = "UnityEngine.UI";
Int32 fontSizeExpected = 16;
string[] parameters = new[] {"16"};
var altElement = altDriver.FindObject(By.PATH, "/Canvas/UnityUIInputField/Text");
var data = altElement.CallComponentMethod<string>(componentName, methodName, assemblyName, parameters);
var fontSize = altElement.CallComponentMethod<Int32>(componentName, methodToVerifyName, assemblyName, new object[] { });
Assert.AreEqual(fontSizeExpected, fontSize);
}
@Test
public void TestCallMethodWithMultipleDefinitions() throws Exception
{
String capsuleName = "Capsule";
String capsuleInfo = "CapsuleInfo";
AltFindObjectsParams altFindObjectsParams = new AltFindObjectsParams.Builder(AltDriver.By.NAME, capsuleName).isEnabled(true).withCamera("Main Camera").build();
AltObject capsule=altDriver.findObject(altFindObjectsParams);
AltCallComponentMethodParams altCallComponentMethodParameters=new AltCallComponentMethodParams.Builder("Capsule", "Test", "Assembly-CSharp", "2").withTypeOfParameters("System.Int32").build();
capsule.callComponentMethod(altCallComponentMethodParams, Void.class);
altFindObjectsParams = new AltFindObjectsParams.Builder(AltDriver.By.NAME, capsuleInfo).isEnabled(true).withCamera("Main Camera").build();
AltObject capsuleInfo=altDriver.findObject(altFindObjectsParams);
assertEquals("6",capsuleInfo.getText());
}
@Test
public void testCallMethodWithNoParameters()
{
String componentName = "UnityEngine.UI.Text";
String methodName = "get_text";
String assembly = "UnityEngine.UI";
String expected_text = "Change Camera Mode";
AltFindObjectsParams altFindObjectsParams = new AltFindObjectsParams.Builder(AltDriver.By.PATH,
"/Canvas/Button/Text").build();
AltObject altElement = altDriver.findObject(altFindObjectsParams);
assertEquals(expected_text, altElement.callComponentMethod(
new AltCallComponentMethodParams.Builder(componentName, methodName, assembly, new Object[] {}).build(),
String.class));
}
@Test
public void testCallMethodWithParameters() throws Exception
{
String componentName = "UnityEngine.UI.Text";
String methodName = "set_fontSize";
String methodExpectedName = "get_fontSize";
String assembly = "UnityEngine.UI";
String[] parameters = new String[] { "16"};
AltFindObjectsParams altFindObjectsParams = new AltFindObjectsParams.Builder(AltDriver.By.PATH,
"/Canvas/UnityUIInputField/Text").build();
AltObject altElement = altDriver.findObject(altFindObjectsParams);
altElement.callComponentMethod(
new AltCallComponentMethodParams.Builder(componentName, methodName, assembly, parameters)
.build(),
Void.class);
Integer fontSize = altElement.callComponentMethod(
new AltCallComponentMethodParams.Builder(componentName, methodExpectedName, assembly, new Object[] {})
.build(),
Integer.class);
assert(16==fontSize);
}
def test_call_component_method(self):
result = self.altdriver.find_object(By.NAME, "Capsule").call_component_method(
"AltExampleScriptCapsule", "Jump", "Assembly-CSharp", ["setFromMethod"])
self.assertEqual(result, None)
self.altdriver.wait_for_object(By.PATH, '//CapsuleInfo[@text=setFromMethod]', timeout=1)
self.assertEqual('setFromMethod', self.altdriver.find_object(By.NAME, 'CapsuleInfo').get_text())
def test_call_component_method_with_no_parameters(self):
result = self.altdriver.find_object(By.PATH, "/Canvas/Button/Text")
text = result.call_component_method("UnityEngine.UI.Text", "get_text", "UnityEngine.UI")
assert text == "Change Camera Mode"
def test_call_component_method_with_parameters(self):
fontSizeExpected =16
altElement = self.altdriver.find_object(By.PATH, "/Canvas/UnityUIInputField/Text")
altElement.call_component_method("UnityEngine.UI.Text", "set_fontSize", "UnityEngine.UI", parameters=["16"])
fontSize = altElement.call_component_method("UnityEngine.UI.Text", "get_fontSize", "UnityEngine.UI", parameters=[])
assert fontSizeExpected == fontSize
WaitForComponentProperty
Wait until a property has a specific value and returns the value of the given component property.
Parameters
Name | Type | Required | Description |
---|---|---|---|
componentName | string | Yes | The name of the component. If the component has a namespace the format should look like this: "namespace.componentName" |
propertyName | string | Yes | Name of the property of which value you want. If the property is an array you can specify which element of the array to return by doing property[index], or if you want a property inside of another property you can get by doing property.property2 for example position.x. |
propertyValue | T | Yes | The value that property shoud have. |
assemblyName | string | Yes | The name of the assembly containing the component. |
Returns
Object
Examples
[Test]
public void TestWaitForComponentProperty()
{
const string componentName = "AltTester.AltRunner";
const string propertyName = "InstrumentationSettings.AltServerPort";
var altElement = altDriver.FindObject(By.NAME, "AltTesterPrefab");
Assert.NotNull(altElement);
string portStr = System.Environment.GetEnvironmentVariable("ALTSERVER_PORT");
int port = int.Parse(portStr);
var propertyValue = altElement.WaitForComponentProperty<int>(componentName, propertyName, port, "Assembly-CSharp");
Assert.AreEqual(port, propertyValue);
}
@Test
public void testWaitForComponentProperty() throws InterruptedException {
Thread.sleep(1000);
String componentName = "UnityEngine.CapsuleCollider";
String propertyName = "isTrigger";
AltFindObjectsParams altFindObjectsParams = new AltFindObjectsParams.Builder(AltDriver.By.NAME,
"Capsule").build();
AltObject altElement = altDriver.findObject(altFindObjectsParams);
assertNotNull(altElement);
AltGetComponentPropertyParams altGetComponentPropertyParams = new AltGetComponentPropertyParams.Builder(
componentName, propertyName, "").build();
AltWaitForComponentPropertyParams<Boolean> altWaitForComponentPropertyParams = new AltWaitForComponentPropertyParams. Builder<Boolean>(altGetComponentPropertyParams).build();
Boolean propertyValue = altElement.WaitForComponentProperty(
altWaitForComponentPropertyParams,
false,
Boolean.class);
assertEquals(Boolean.FALSE, propertyValue);
}
def test_wait_for_component_property(self):
alt_object = self.altdriver.find_object(By.NAME, "Capsule")
result = alt_object.wait_for_component_property(
"AltExampleScriptCapsule", "TestBool", True,
"Assembly-CSharp")
assert result is True
GetComponentProperty
Returns the value of the given component property.
Parameters
Name | Type | Required | Description |
---|---|---|---|
componentName | string | Yes | The name of the component. If the component has a namespace the format should look like this: "namespace.componentName" |
propertyName | string | Yes | Name of the property of which value you want. If the property is an array you can specify which element of the array to return by doing property[index], or if you want a property inside of another property you can get by doing property.property2 for example position.x. |
assemblyName | string | Yes | The name of the assembly containing the component. |
maxDepth | int | No | Set how deep the serialization of the property to do. For example for position property in transform the result are following: maxDepth=2 {"normalized":{"magnitude":1.0, "sqrMagnitude":1.0, "x":0.871575534, "y":0.490261227, "z":0.0}, "magnitude":1101.45361, "sqrMagnitude":1213200.0, "x":960.0,"y":540.0, "z":0.0} and for maxDepth=1 :{"normalized":{},"magnitude":1101.45361, "sqrMagnitude":1213200.0, "x":960.0,"y":540.0, "z":0.0} |
Returns
Object
Examples
[Test]
public void TestGetComponentProperty()
{
const string componentName = "AltTester.AltRunner";
const string propertyName = "InstrumentationSettings.AltTesterPort";
var altObject = altDriver.FindObject(By.NAME,"AltRunnerPrefab");
Assert.NotNull(altObject);
var propertyValue = altObject.GetComponentProperty<int>(componentName, propertyName, "Assembly-CSharp");
Assert.AreEqual(propertyValue, 13000);
}
@Test
public void testGetComponentProperty() throws Exception
{
String componentName = "AltTester.AltRunner";
String propertyName = "InstrumentationSettings.AltTesterPort";
AltFindObjectsParams altFindObjectsParams = new AltFindObjectsParams.Builder(AltDriver.By.NAME, "AltRunnerPrefab").isEnabled(true).withCamera("Main Camera").build();
AltObject altObject = altDriver.findObject(altFindObjectsParams);
assertNotNull(altObject);
AltGetComponentPropertyParams altGetComponentPropertyParameters=new AltGetComponentPropertyParams.Builder(componentName, propertyName, "Assembly-CSharp").build();
int propertyValue = altObject.getComponentProperty(altGetComponentPropertyParams,Integer.class);
assertEquals(propertyValue, 13000);
}
def test_get_component_property(self):
self.altDriver.load_scene('Scene 1 AltDriverTestScene')
result = self.altDriver.find_element("Capsule").get_component_property("Capsule", "arrayOfInts")
self.assertEqual(result, [1,2,3])
SetComponentProperty
Sets value of the given component property.
Parameters
Name | Type | Required | Description |
---|---|---|---|
componentName | string | Yes | The name of the component. If the component has a namespace the format should look like this: "namespace.componentName". |
propertyName | string | Yes | The name of the property of which value you want to set |
value | object | Yes | The value to be set for the chosen component's property |
assemblyName | string | Yes | The name of the assembly containing the component. It is NULL by default. |
Returns
Nothing
Examples
[Test]
public void TestSetComponentProperty()
{
const string componentName = "Capsule";
const string propertyName = "stringToSetFromTests";
var altObject = altDriver.FindObject(By.NAME, "Capsule");
Assert.NotNull(altObject);
altObject.SetComponentProperty(componentName, propertyName, "2", "Assembly-CSharp");
var propertyValue = altObject.GetComponentProperty<string>(componentName, propertyName);
Assert.AreEqual("2", propertyValue);
}
@Test
public void testSetComponentProperty()
{
String componentName = "Capsule";
String propertyName = "stringToSetFromTests";
AltFindObjectsParams altFindObjectsParams = new AltFindObjectsParams.Builder(AltDriver.By.NAME, "Capsule").isEnabled(true).withCamera("Main Camera").build();
AltObject altObject = altDriver.findObject(altFindObjectsParams);
assertNotNull(altObject);
altElement.setComponentProperty(new AltSetComponentPropertyParams.Builder(componentName, propertyName, "2", "Assembly-CSharp").build());
String propertyValue = altElement.getComponentProperty(new AltGetComponentPropertyParams.Builder(componentName,propertyName).build(), String.class);
assertEquals("2", propertyValue);
}
def test_set_component_property(self):
self.altDriver.load_scene("Scene 1 AltDriverTestScene")
componentName = "Capsule"
propertyName = "stringToSetFromTests"
altObject = self.altDriver.find_object(By.NAME, componentName)
self.assertNotEqual(altObject, None)
altObject.set_component_property(componentName, propertyName, "2", "Assembly-CSharp")
propertyValue = altObject.get_component_property(componentName, propertyName)
self.assertEqual("2", propertyValue)
GetText
Returns text value from a Button, Text, InputField. This also works with TextMeshPro elements.
Parameters
None
Returns
String
Examples
[Test]
public void TestWaitForObjectWithText()
{
const string name = "CapsuleInfo";
string text = altDriver.FindObject(By.NAME,name).GetText();
var timeStart = DateTime.Now;
var altObject = altDriver.WaitForObject(By.PATH, "//" + name + "[@text=" + text + "]");
var timeEnd = DateTime.Now;
var time = timeEnd - timeStart;
Assert.Less(time.TotalSeconds, 20);
Assert.NotNull(altObject);
Assert.AreEqual(altObject.GetText(), text);
}
@Test
public void testWaitForObjectWithText() throws Exception
{
String name = "CapsuleInfo";
AltFindObjectsParams altFindObjectsParams = new AltFindObjectsParams.Builder(AltDriver.By.NAME, name).isEnabled(true).withCamera("Main Camera").build();
String text = altDriver.findObject(altFindObjectsParams).getText();
long timeStart = System.currentTimeMillis();
AltWaitForObjectWithTextParams altWaitForElementWithTextParams = new AltWaitForObjectWithTextParams.Builder(altFindObjectsParams,text).withInterval(0).withTimeout(0).build();
AltObject altObject = altDriver.waitForObjectWithText(altWaitForElementWithTextParams);
long timeEnd = System.currentTimeMillis();
long time = timeEnd - timeStart;
assertTrue(time / 1000 < 20);
assertNotNull(altObject);
assertEquals(altObject.getText(), text);
}
def test_call_component_method(self):
self.altDriver.load_scene('Scene 1 AltDriverTestScene')
result = self.altDriver.find_element("Capsule").call_component_method("Capsule", "Jump", "setFromMethod")
self.assertEqual(result,"null")
self.altDriver.wait_for_element_with_text('CapsuleInfo', 'setFromMethod')
self.assertEqual('setFromMethod', self.altDriver.find_element('CapsuleInfo').get_text())
SetText
Sets text value for a Button, Text, InputField. This also works with TextMeshPro elements.
Parameters
Name | Type | Required | Description |
---|---|---|---|
text | string | Yes | The text to be set. |
submit | bool | No | If set will trigger a submit event. |
Returns
AltObject
Examples
[Test]
public void TestSetTextForElement()
{
const string name = "InputField";
const string text = "InputFieldTest";
var input = altDriver.FindObject(By.NAME, name).SetText(text, true);
Assert.NotNull(input);
Assert.AreEqual(input.GetText(), text);
}
@Test
public void testSetTextForElement()
{
String name = "InputField";
String text = "InputFieldTest";
AltFindObjectsParams altFindObjectsParams = new AltFindObjectsParams.Builder(AltDriver.By.NAME, name).isEnabled(true).withCamera("Main Camera").build();
AltObject altObject = altDriver.findObject(altFindObjectsParams);
AltSetTextParams setTextParams = new AltSetTextParams.Builder(text).withSubmit(true).build();
altObject.setText(setTextParams);
assertNotNull(altObject);
assertEquals(altObject.getText(), text);
}
def test_set_text_for_element(self):
self.altDriver.load_scene("Scene 1 AltDriverTestScene")
name = "InputField"
text = "InputFieldTest"
input = self.altDriver.find_object(By.NAME, name).set_text(text, submit=True)
self.assertNotEqual(input, None)
self.assertEqual(input.get_text(), text)
Tap
Tap current object.
Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
count | int | No | 1 | Number of taps. |
interval | float | No | 0.1 | Interval between taps in seconds. |
wait | boolean | No | true | Wait for command to finish. |
Returns
Nothing
Examples
[Test]
public void TestTap()
{
var counterButton = altDriver.FindObject(By.NAME, "ButtonCounter");
var counterButtonText = altDriver.FindObject(By.NAME, "ButtonCounter/Text");
counterButton.Tap();
altDriver.WaitForObject(By.PATH, "//ButtonCounter/Text[@text=1]");
}
@Test()
public void TestTapElement() {
AltFindObjectsParams findCapsuleParams = new AltFindObjectsParams.Builder(By.NAME, "Capsule")
.build();
AltObject capsule = altDriver.findObject(findCapsuleParams);
AltTapClickElementParams tapParams = new AltTapClickElementParams.Builder().build();
capsule.tap(tapParams);
AltFindObjectsParams findCapsuleInfoParams = new AltFindObjectsParams.Builder(By.PATH,
"//CapsuleInfo[@text=Capsule was clicked to jump!]").build();
AltWaitForObjectsParams waitParams = new AltWaitForObjectsParams.Builder(findCapsuleInfoParams)
.build();
altDriver.waitForObject(waitParams);
}
def test_tap_element(self):
self.altDriver.load_scene('Scene 1 AltDriverTestScene')
capsule_element = self.altDriver.find_object(By.NAME, 'Capsule')
capsule_element.tap()
Click
Click current object.
Parameters
Name | Type | Required | Default | Description |
---|---|---|---|---|
count | int | No | 1 | Number of clicks. |
interval | float | No | 0.1 | Interval between clicks in seconds. |
wait | boolean | No | true | Wait for command to finish. |
Returns
Nothing
Examples
[Test]
public void TestClickElement()
{
var counterButton = altDriver.FindObject(By.NAME, "ButtonCounter");
var counterButtonText = altDriver.FindObject(By.NAME, "ButtonCounter/Text");
counterButton.Click();
altDriver.WaitForObject(By.PATH, "//ButtonCounter/Text[@text=1]");
}
@Test()
public void TestClickElement() {
AltFindObjectsParams findCapsuleParams = new AltFindObjectsParams.Builder(By.NAME, "Capsule")
.build();
AltObject capsule = altDriver.findObject(findCapsuleParams);
AltTapClickElementParams clickParams = new AltTapClickElementParams.Builder().build();
capsule.Click(clickParams);
AltFindObjectsParams findCapsuleInfoParams = new AltFindObjectsParams.Builder(By.PATH,
"//CapsuleInfo[@text=Capsule was clicked to jump!]").build();
AltWaitForObjectsParams waitParams = new AltWaitForObjectsParams.Builder(findCapsuleInfoParams)
.build();
altDriver.waitForObject(waitParams);
}
def test_click_element(self):
self.altDriver.load_scene('Scene 1 AltDriverTestScene')
capsule_element = self.altDriver.find_object(By.NAME, 'Capsule')
capsule_element.click()
PointerDown
Simulates pointer down action on the object.
Parameters
None
Returns
AltObject
Examples
[Test]
public void TestPointerDownCommand()
{
var panel = altDriver.FindObject(By.NAME, "Panel");
var color1 = panel.GetComponentProperty("PanelScript", "normalColor", "Assembly-CSharp");
panel.PointerDownFromObject();
Thread.Sleep(1000);
var color2 = panel.GetComponentProperty("PanelScript", "highlightColor", "Assembly-CSharp");
Assert.AreNotEqual(color1, color2);
}
@Test
public void testPointerDownCommand() throws InterruptedException
{
AltObject panel = altDriver.findObject(AltDriver.By.NAME, "Panel");
String color1 = panel.getComponentProperty(new AltGetComponentPropertyParams.Builder("PanelScript", "normalColor", "Assembly-CSharp").build(), String.class);
panel.pointerDownFromObject();
Thread.sleep(1000);
String color2 = panel.getComponentProperty(new AltGetComponentPropertyParams.Builder( "PanelScript", "highlightColor", "Assembly-CSharp").build(), String.class);
assertTrue(color1 != color2);
}
def test_pointer_down_command():
self.altDriver.load_scene('Scene 2 Draggable Panel')
time.sleep(1)
p_panel = self.altDriver.find_object(By.NAME, 'Panel')
color1 = p_panel.get_component_property('PanelScript', 'normalColor', 'Assembly-CSharp')
p_panel.pointer_down_from_object()
time.sleep(1)
color2 = p_panel.get_component_property('PanelScript', 'highlightColor', 'Assembly-CSharp')
self.assertNotEquals(color1, color2)
PointerUp
Simulates pointer up action on the object.
Parameters
None
Returns
AltObject
Examples
[Test]
public void TestPointerUpCommand()
{
var panel = altDriver.FindObject(By.NAME, "Panel");
var color1 = panel.GetComponentProperty("PanelScript", "normalColor", "Assembly-CSharp");
panel.PointerDownFromObject();
Thread.Sleep(1000);
panel.PointerUpFromObject();
var color2 = panel.GetComponentProperty("PanelScript", "highlightColor", "Assembly-CSharp");
Assert.AreEqual(color1, color2);
}
@Test
public void testPointerUpCommand() throws InterruptedException
{
AltObject panel = altDriver.findObject(AltDriver.By.NAME, "Panel");
String color1 = panel.getComponentProperty(new AltGetComponentPropertyParams.Builder("PanelScript", "normalColor", "Assembly-CSharp").build(), String.class);
panel.pointerDownFromObject();
Thread.sleep(1000);
panel.pointerUpFromObject();
String color2 = panel.getComponentProperty(new AltGetComponentPropertyParams.Builder("PanelScript", "highlightColor", "Assembly-CSharp").build(), String.class);
assertEquals(color1, color2);
}
def test_pointer_up_command():
self.altDriver.load_scene('Scene 2 Draggable Panel')
time.sleep(1)
p_panel = self.altDriver.find_object(By.NAME, 'Panel')
color1 = p_panel.get_component_property('PanelScript', 'normalColor', 'Assembly-CSharp')
p_panel.pointer_down_from_object()
time.sleep(1)
p_panel.pointer_up_from_object()
color2 = p_panel.get_component_property('PanelScript', 'highlightColor', 'Assembly-CSharp')
self.assertEquals(color1, color2)
PointerEnter
Simulates pointer enter action on the object.
Parameters
None
Returns
AltObject
Examples
[Test]
public void TestPointerEnterAndExit()
{
var altObject = altDriver.FindObject(By.NAME,"Drop Image");
var color1 = altObject.GetComponentProperty("DropMe", "highlightColor", "Assembly-CSharp");
altDriver.FindObject(By.NAME,"Drop Image").PointerEnterObject();
var color2 = altObject.GetComponentProperty("DropMe", "highlightColor", "Assembly-CSharp");
Assert.AreNotEqual(color1,color2);
altDriver.FindObject(By.NAME,"Drop Image").PointerExitObject();
var color3 = altObject.GetComponentProperty("DropMe", "highlightColor", "Assembly-CSharp");
Assert.AreNotEqual(color3, color2);
Assert.AreEqual(color1,color3);
}
@Test
public void testPointerEnterAndExit()
{
AltFindObjectsParams altFindObjectsParams = new AltFindObjectsParams.Builder(AltDriver.By.NAME, "Drop Image").isEnabled(true).withCamera("Main Camera").build();
AltObject altObject = altDriver.findObject(altFindObjectsParams);
String color1 = panel.getComponentProperty(new AltGetComponentPropertyParams.Builder("DropMe", "highlightColor", "Assembly-CSharp").build(), String.class);
altDriver.findObject(altFindObjectsParams).pointerEnter();
String color2 = panel.getComponentProperty(new AltGetComponentPropertyParams.Builder("DropMe", "highlightColor", "Assembly-CSharp").build(), String.class);
assertNotEquals(color1,color2);
altDriver.findObject(altFindObjectsParams).pointerExit();
String color3 = panel.getComponentProperty(new AltGetComponentPropertyParams.Builder("DropMe", "highlightColor", "Assembly-CSharp").build(), String.class);
assertNotEquals(color3, color2);
assertEquals(color1,color3);
}
def test_pointer_enter_and_exit(self):
self.altDriver.load_scene("Scene 3 Drag And Drop")
alt_unity_object = self.altDriver.find_object(By.NAME,"Drop Image")
color1 = alt_unity_object.get_component_property("DropMe", "highlightColor", "Assembly-CSharp")
self.altDriver.find_object(By.NAME,"Drop Image").pointer_enter()
color2 = alt_unity_object.get_component_property("DropMe", "highlightColor", "Assembly-CSharp")
self.assertNotEqual(color1, color2)
self.altDriver.find_object(By.NAME,"Drop Image").pointer_exit()
color3 = alt_unity_object.get_component_property("DropMe", "highlightColor", "Assembly-CSharp")
self.assertNotEqual(color3, color2)
self.assertEqual(color1, color3)
PointerExit
Simulates pointer exit action on the object.
Parameters
None
Returns
AltObject
Examples
[Test]
public void TestPointerEnterAndExit()
{
var altObject = altDriver.FindObject(By.NAME,"Drop Image");
var color1 = altObject.GetComponentProperty("DropMe", "highlightColor", "Assembly-CSharp"));
altDriver.FindObject(By.NAME,"Drop Image").PointerEnterObject();
var color2 = altObject.GetComponentProperty("DropMe", "highlightColor", "Assembly-CSharp"));
Assert.AreNotEqual(color1,color2);
altDriver.FindObject(By.NAME,"Drop Image").PointerExitObject();
var color3 = altObject.GetComponentProperty("DropMe", "highlightColor", "Assembly-CSharp"));
Assert.AreNotEqual(color3, color2);
Assert.AreEqual(color1,color3);
}
@Test
public void testPointerEnterAndExit()
{
AltFindObjectsParams altFindObjectsParams = new AltFindObjectsParams.Builder(AltDriver.By.NAME, "Drop Image").isEnabled(true).withCamera("Main Camera").build();
AltObject altObject = altDriver.findObject(altFindObjectsParams);
String color1 = panel.getComponentProperty(new AltGetComponentPropertyParams.Builder("DropMe", "highlightColor", "Assembly-CSharp").build(), String.class);
altDriver.findObject(altFindObjectsParams).pointerEnter();
String color2 = panel.getComponentProperty(new AltGetComponentPropertyParams.Builder("DropMe", "highlightColor", "Assembly-CSharp").build(), String.class);
assertNotEquals(color1,color2);
altDriver.findObject(altFindObjectsParams).pointerExit();
String color3 = panel.getComponentProperty(new AltGetComponentPropertyParams.Builder("DropMe", "highlightColor", "Assembly-CSharp").build(), String.class);
assertNotEquals(color3, color2);
assertEquals(color1,color3);
}
def test_pointer_enter_and_exit(self):
self.altDriver.load_scene("Scene 3 Drag And Drop")
alt_unity_object = self.altDriver.find_object(By.NAME,"Drop Image")
color1 = alt_unity_object.get_component_property("DropMe", "highlightColor", "Assembly-CSharp")
self.altDriver.find_object(By.NAME,"Drop Image").pointer_enter()
color2 = alt_unity_object.get_component_property("DropMe", "highlightColor", "Assembly-CSharp")
self.assertNotEqual(color1, color2)
self.altDriver.find_object(By.NAME,"Drop Image").pointer_exit()
color3 = alt_unity_object.get_component_property("DropMe", "highlightColor", "Assembly-CSharp")
self.assertNotEqual(color3, color2)
self.assertEqual(color1, color3)
UpdateObject
Returns the object with new values.
Parameters
None
Returns
AltObject
Examples
[Test]
public void TestUpdateAltObject()
{
var cube = altDriver.FindObject(By.NAME, "Player1");
AltVector3 cubeInitialPostion = cube.GetWorldPosition();
altDriver.PressKey(AltKeyCode.W, 1, 2);
Assert.AreNotEqual(cubeInitialPostion, cube.UpdateObject().GetWorldPosition());
}
@Test
public void TestUpdateAltObject() throws InterruptedException {
AltFindObjectsParams altFindObjectsParameters = new AltFindObjectsParams.Builder(
AltDriver.By.NAME, "Player1").build();
AltObject cube = altDriver.findObject(altFindObjectsParameters);
float cubeInitWorldZ = cube.worldZ;
altDriver.pressKey(new AltPressKeyParams.Builder(AltKeyCode.W).withDuration(1).withPower(2)
.withWait(false).build());
Thread.sleep(2000);
assertNotEquals(cubeInitWorldZ, cube.UpdateObject().worldZ);
}
def test_update_altObject(self):
cube = self.altdriver.find_object(By.NAME, "Player1")
initial_position_z = cube.worldZ
self.altdriver.press_key(AltKeyCode.W, power=1, duration=0.1, wait=False)
time.sleep(5)
assert initial_position_z != cube.update_object().worldZ
GetParent
Returns the parent of the object on which it is called.
Parameters
None
Returns
AltObject
Examples
[Test]
public void TestGetParent()
{
var altObject = altDriver.FindObject(By.NAME, "Panel", By.NAME, "Main Camera");
var altObjectParent = altObject.GetParent();
Assert.AreEqual("Panel Drag Area", altObjectParent.name);
}
@Test
public void TestGetParent() {
AltFindObjectsParams altFindObjectsParams = new AltFindObjectsParams.Builder(By.NAME, "CapsuleInfo")
.build();
AltObject altObject = altDriver.findObject(altFindObjectsParams);
AltObject altObjectParent = altObject.getParent();
assertEquals("Canvas", altObjectParent.name);
}
def test_get_parent(self):
self.altDriver.load_scene('Scene 1 AltDriverTestScene', True)
element = self.altDriver.find_object(By.NAME, 'Canvas/CapsuleInfo')
elementParent = element.get_parent()
self.assertEqual('Canvas', elementParent.name)
GetScreenPosition
Returns the screen position of the AltTester object.
Parameters
None
Returns
AltVector2
Examples
[Test]
public void TestHoldButton()
{
const int duration = 1;
var button = altDriver.FindObject(By.NAME, "UIButton");
altDriver.HoldButton(button.GetScreenPosition(), duration);
var capsuleInfo = altDriver.FindObject(By.NAME, "CapsuleInfo");
var text = capsuleInfo.GetText();
Assert.AreEqual(text, "UIButton clicked to jump capsule!");
var time = float.Parse(altDriver.FindObject(By.NAME, "ChineseLetters").GetText());
Assert.Greater(time, duration);
}
@Test
public void testHoldButton() throws Exception {
AltObject button = altDriver
.findObject(new AltFindObjectsParams.Builder(AltDriver.By.NAME, "UIButton").build());
altDriver.holdButton(new AltHoldParams.Builder(button.getScreenPosition()).withDuration(1).build());
AltObject capsuleInfo = altDriver
.findObject(new AltFindObjectsParams.Builder(AltDriver.By.NAME, "CapsuleInfo").build());
String text = capsuleInfo.getText();
assertEquals(text, "UIButton clicked to jump capsule!");
}
def test_hold_button(self):
button = self.altdriver.find_object(By.NAME, "UIButton")
self.altdriver.hold_button(button.get_screen_position(), duration=1)
capsule_info = self.altdriver.find_object(By.NAME, "CapsuleInfo")
text = capsule_info.get_text()
assert text == "UIButton clicked to jump capsule!"
GetWorldPosition
Returns the world position of the AltTester object.
Parameters
None
Returns
AltVector3
Examples
[Test]
public void TestAcceleration()
{
var capsule = altDriver.FindObject(By.NAME, "Capsule");
var initialWorldCoordinates = capsule.GetWorldPosition();
altDriver.Tilt(new AltVector3(1, 1, 1), 1);
Thread.Sleep(100);
capsule = altDriver.FindObject(By.NAME, "Capsule");
var afterTiltCoordinates = capsule.GetWorldPosition();
Assert.AreNotEqual(initialWorldCoordinates, afterTiltCoordinates);
}
@Test
public void TestAcceleration() throws InterruptedException {
AltFindObjectsParams altFindObjectsParameters1 = new AltFindObjectsParams.Builder(
AltDriver.By.NAME, "Capsule").build();
AltObject capsule = altDriver.findObject(altFindObjectsParameters1);
Vector3 initialWorldCoordinates = capsule.getWorldPosition();
altDriver.tilt(new AltTiltParams.Builder(new Vector3(1, 1, 1)).withDuration(1).build());
capsule = altDriver.findObject(altFindObjectsParameters1);
Vector3 afterTiltCoordinates = capsule.getWorldPosition();
assertNotEquals(initialWorldCoordinates, afterTiltCoordinates);
}
def test_acceleration(self):
self.altdriver.load_scene("Scene 1 AltDriverTestScene")
capsule = self.altdriver.find_object(By.NAME, "Capsule")
initial_position = [capsule.worldX, capsule.worldY, capsule.worldZ]
self.altdriver.tilt([1, 1, 1], 1)
capsule = self.altdriver.find_object(By.NAME, "Capsule")
final_position = [capsule.worldX, capsule.worldY, capsule.worldZ]
assert initial_position != final_position
BY-Selector
It is used in find objects methods to set the criteria of which the objects are searched. Currently there are 7 types implemented:
By.TAG - search for objects that have a specific tag
By.LAYER - search for objects that are set on a specific layer
By.NAME - search for objects that are named in a certain way
By.COMPONENT - search for objects that have certain component
By.ID - search for objects that have assigned a certain id (every object has an unique id so this criteria always will return 1 or 0 objects). Id checks for InstanceId and AltId
By.TEXT - search for objects that have a certain text
By.PATH - search for objects that respect a certain path
Searching object by PATH
The following selecting nodes and attributes are implemented:
object - Selects all object with the name “object”
/ - Selects from the root node
// - Selects nodes in the document from the current node that match the selection no matter where they are
.. - Selects the parent of the current node
* - Matches any element node
contains - Selects objects that contain a certain string in the name
[n-th] - Selects n-th child of the current node. 0 - represents the first child, 1 - is the second child and so on. -1 -represents the last child
@tag
@layer
@name
@component
@id
@text
Examples
//NameOfParent/NameOfChild/*
//NameOfParent/NameOfChild//*
altDriver.FindObjects(By.PATH, "//Canvas/Panel/*")
Returns all direct children from Panel
altDriver.FindObjects(By.PATH, "//Canvas/Panel//*")
Returns all children from Panel
//CapsuleInfo/..
altDriver.FindObject(By.PATH, "//CapsuleInfo/..")
Returns the parent of the object CapsuleInfo
//NameOfParent/NameOfChild/*[@tag=tagName]
altDriver.FindObjects(By.PATH, "//Canvas/Panel/*[@tag=UI]")
Returns every object that is tagged as UI and is a direct child of Panel
//NameOfParent/NameOfChild/*[@layer=layerName]
altDriver.FindObjects(By.PATH, "//Canvas/Panel/*[@layer=UI]")
Returns every object that is in the UI layer and is a direct child of Panel
//NameOfParent/NameOfChild/*[@id=idMethod]
altDriver.FindObject(By.PATH, "//*[@id=8756]")
Returns the object which has the id equal to 8756
//NameOfParent/NameOfChild/*[@text=textName]
altDriver.FindObject(By.PATH, "//Canvas/Panel//*[@text=Start]")
Returns the first object that has the text “Start” and is a child of Panel
//NameOfParent/NameOfChild/*[contains(@name,name)]
//NameOfParent/NameOfChild/*[contains(@text,text)]
altDriver.FindObjects(By.PATH, "//*[contains(@name,Cub)]")
Returns every object that contains the string “Cub” in the name
//NameOfParent/NameOfChild/*[@selector1=selectorName1][@selector2=selectorName2][@selector3=selectorName3]
altDriver.FindObject(By.PATH, "//Canvas/Panel/*[@component=Button][@tag=Untagged][@layer=UI]"
Returns the first direct child of the Panel that is untagged, is in the UI layer and has a component named Button
//NameOfParent/NameObject
altDriver.FindObjects(By.PATH, "/Canvas//Button[@component=ButtonLogic]"
Returns every button which is in Canvas that is a root object and has a component named ButtonLogic
//NameOfParent/NameOfChild
//*[@id=idOfParent]/NameOfChild
altDriver.FindObjects(By.PATH, "//Canvas/Panel")
Returns all direct children from Canvas that have the name “Panel
altDriver.FindObjects(By.PATH, "//Canvas/*/text")
Returns all children on the second level from Canvas that are named “text”
altDriver.FindObject(By.PATH, "//Canvas/Panel/StartButton[1]")
Returns the second child of the first object that has the name “StartButton” and is a direct child of Panel
//NameOfParent[n]
//NameOfParent/NameOfChild[n]
altDriver.FindObject(By.PATH, "//Canvas[5]")
Returns the 6th direct child of the root Canvas
altDriver.FindObject(By.PATH, "//Canvas/Panel/*[@tag=Player][-1]")
Returns the last direct child of Panel that is tagged as Player
Escaping characters
There are several characters that you need to escape when you try to find an object. Some examples characters are the symbols for Request separator and Request ending, by default this are ;
and &
but can be changed in Server settings. If you don’t escape this characters the whole request is invalid and might shut down the server. Other characters are !
, [
, ]
, (
, )
, /
, \
, .
or ,
. This characters are used in searching algorithm and if not escaped might return the wrong object or not found at all. To escape all the characters mentioned before just add \\
before each character you want to escape.
Examples
//Q&A
- not escaped//Q\\&A
- escaped
AltId
Is a solution offered by AltTester Unity SDK in order to find object easier. This is an unique identifier stored in an component and added to every object. A limitation of this is that only the object already in the scene before building the app will have an AltId. Object instantiated during run time will not have an AltId
To add AltId to every object simply just click Add AltId to every object from AltTester menu.
AltReversePortForwarding
API to interact with adb
programmatically.
ReversePortForwardingAndroid
This method calls adb reverse [-s {deviceId}] tcp:{remotePort} tcp:{localPort}
.
Parameters
Name | Type | Required | Description |
---|---|---|---|
remotePort | int | No | The device port to do reverse port forwarding from. |
localPort | int | No | The local port to do reverse port forwarding to. |
deviceId | string | No | The id of the device. |
adbPath | string | No | The adb path. If no adb path is provided, it tries to use adb from ${ANDROID_SDK_ROOT}/platform-tools/adb . If ANDROID_SDK_ROOT env variable is not set, it tries to execute adb from PATH . |
Examples
[OneTimeSetUp]
public void SetUp()
{
AltReversePortForwarding.ReversePortForwardingAndroid();
altDriver = new AltDriver();
}
@BeforeClass
public static void setUp() throws IOException {
AltReversePortForwarding.reversePortForwardingAndroid();
altDriver = new AltDriver();
}
@classmethod
def setUpClass(cls):
AltReversePortForwarding.reverse_port_forwarding_android()
cls.altDriver = AltDriver()
RemoveReversePortForwardingAndroid
This method calls adb reverse --remove [-s {deviceId}] tcp:{devicePort}
or adb reverse --remove-all
if no port is provided.
Parameters
Name | Type | Required | Description |
---|---|---|---|
devicePort | int | No | The device port to be removed. |
deviceId | string | No | The id of the device to be removed. |
adbPath | string | No | The adb path. If no adb path is provided, it tries to use adb from ${ANDROID_SDK_ROOT}/platform-tools/adb . If ANDROID_SDK_ROOT env variable is not set, it tries to execute adb from PATH . |
Returns
Nothing
Examples
[OneTimeTearDown]
public void TearDown()
{
altDriver.Stop();
AltReversePortForwarding.RemoveReversePortForwardingAndroid();
}
@AfterClass
public static void tearDown() throws Exception {
altDriver.stop();
AltReversePortForwarding.removeReversePortForwardingAndroid();
}
@classmethod
def tearDownClass(cls):
cls.altDriver.stop()
AltReversePortForwarding.remove_reverse_port_forwarding_android()
RemoveAllReversePortForwardingsAndroid
This method calls adb reverse --remove-all
.
Parameters
Name | Type | Required | Description |
---|---|---|---|
adbPath | string | No | The adb path. If no adb path is provided, it tries to use adb from ${ANDROID_SDK_ROOT}/platform-tools/adb . If ANDROID_SDK_ROOT env variable is not set, it tries to execute adb from PATH . |
Returns
Nothing
Examples
[OneTimeTearDown]
public void TearDown()
{
altDriver.Stop();
AltReversePortForwarding.RemoveAllReversePortForwardingsAndroid();
}
@AfterClass
public static void tearDown() throws Exception {
altDriver.stop();
AltReversePortForwarding.removeAllReversePortForwardingsAndroid();
}
@classmethod
def tearDownClass(cls):
cls.altDriver.stop()
AltReversePortForwarding.remove_all__reverse_port_forwardings_android()