Skip to content

Commit 47235e0

Browse files
Documentation improvements on the waitforobject method (#1725)
* improvements on waitForObject * initialize driver * capital case * unreal docs
1 parent 7bf2491 commit 47235e0

File tree

2 files changed

+110
-91
lines changed

2 files changed

+110
-91
lines changed

Docs/source/pages/commands.md

Lines changed: 55 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,42 @@ An AltDriver instance will connect to the running instrumented Unity application
2222
| deviceInstanceId| string | No | The device instance id of the Unity application. The default value is`unknown`. |
2323
| appId | string | No | The unique id of the Unity application. The default value is `unknown`. |
2424

25+
**_Examples_**
26+
27+
```eval_rst
28+
.. tabs::
29+
30+
.. code-tab:: c#
31+
32+
[Test]
33+
public void MyTest()
34+
{
35+
AltDriver altDriver = new AltDriver(host: "127.0.0.1", port: 13000);
36+
}
37+
38+
.. code-tab:: java
39+
40+
@Test
41+
public void MyTest()
42+
{
43+
AltDriver altDriver = new AltDriver(host: "127.0.0.1", port: 13000);
44+
}
45+
46+
.. code-tab:: py
47+
48+
def my_test(self):
49+
alt_driver = AltDriver(
50+
host="127.0.0.1",
51+
port=13000
52+
)
53+
54+
.. code-tab:: robot
55+
56+
My Test
57+
Initialize AltDriver host="127.0.0.1" port=13000
58+
59+
```
60+
2561
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:
2662

2763
### Find Objects
@@ -451,7 +487,7 @@ Returns information about every objects loaded in the currently loaded scenes. T
451487

452488
#### WaitForObject
453489

454-
Waits until it finds an object that respects the given criteria or until timeout limit is reached. Check [By](#by-selector) for more information about criteria.
490+
Waits until it finds an object that respects the given criteria or until the timeout limit is reached. Check [By](#by-selector) for more information about criteria.
455491

456492
```eval_rst
457493
@@ -469,8 +505,8 @@ Waits until it finds an object that respects the given criteria or until timeout
469505
| cameraBy | [By](#by-selector) | No | Set what criteria to use in order to find the camera. |
470506
| 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. |
471507
| enabled | boolean | No | If `true` will match only objects that are active in hierarchy. If `false` will match all objects. |
472-
| timeout | double | No | The number of seconds that it will wait for object. |
473-
| interval | double | No | The number of seconds after which it will try to find the object again. The interval should be smaller than timeout. |
508+
| timeout | double | No | The number of seconds that it will wait for the object. By default it is set to 20 seconds. |
509+
| interval | double | No | The number of seconds after which it will try to find the object again. The interval should be smaller than the timeout. |
474510
475511
**_Returns_**
476512
@@ -484,48 +520,33 @@ Waits until it finds an object that respects the given criteria or until timeout
484520
.. code-tab:: c#
485521
486522
[Test]
487-
public void TestWaitForExistingElement()
523+
public void TestWaitForObject()
488524
{
489525
const string name = "Capsule";
490-
var timeStart = DateTime.Now;
491-
var altElement = altDriver.WaitForObject(By.NAME, name);
492-
var timeEnd = DateTime.Now;
493-
var time = timeEnd - timeStart;
494-
Assert.Less(time.TotalSeconds, 20);
495-
Assert.NotNull(altElement);
496-
Assert.AreEqual(altElement.name, name);
526+
var altObject = altDriver.WaitForObject(By.NAME, name);
497527
}
498528
499529
.. code-tab:: java
500530
501531
@Test
502-
public void testWaitForExistingElement() {
532+
public void testWaitForObject() {
503533
String name = "Capsule";
504-
long timeStart = System.currentTimeMillis();
505534
AltFindObjectsParams altFindObjectsParams = new AltFindObjectsParams.Builder(AltDriver.By.NAME,
506535
name).build();
507536
AltWaitForObjectsParams altWaitForObjectsParams = new AltWaitForObjectsParams.Builder(
508537
altFindObjectsParams).build();
509-
AltObject altElement = altDriver.waitForObject(altWaitForObjectsParams);
510-
long timeEnd = System.currentTimeMillis();
511-
long time = timeEnd - timeStart;
512-
assertTrue(time / 1000 < 20);
513-
assertNotNull(altElement);
514-
assertEquals(altElement.name, name);
538+
AltObject altObject = altDriver.waitForObject(altWaitForObjectsParams);
515539
}
516540
517541
.. code-tab:: py
518542
519543
def test_wait_for_object(self):
520544
alt_object = self.alt_driver.wait_for_object(By.NAME, "Capsule")
521-
assert alt_object.name == "Capsule"
522545
523546
.. code-tab:: robot
524547
525548
Test Wait For Object By Name
526549
${capsule}= Wait For Object NAME Capsule
527-
${capsule_name}= Get Object Name ${capsule}
528-
Should Be Equal ${capsule_name} Capsule
529550
530551
```
531552

@@ -549,7 +570,7 @@ Waits until it finds an object that respects the given criteria or time runs out
549570
| cameraBy | [By](#by-selector) | No | Set what criteria to use in order to find the camera. |
550571
| 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. |
551572
| enabled | boolean | No | If `true` will match only objects that are active in hierarchy. If `false` will match all objects. |
552-
| timeout | double | No | The number of seconds that it will wait for object |
573+
| timeout | double | No | The number of seconds that it will wait for the object. By default it is set to 20 seconds. |
553574
| interval | double | No | The number of seconds after which it will try to find the object again. interval should be smaller than timeout |
554575
555576
**_Returns_**
@@ -567,44 +588,33 @@ Waits until it finds an object that respects the given criteria or time runs out
567588
public void TestWaitForObjectWhichContains()
568589
{
569590
var altObject = altDriver.WaitForObjectWhichContains(By.NAME, "Canva");
570-
Assert.AreEqual("Canvas", altObject.name);
571591
}
572592
573593
.. code-tab:: java
574594
575595
@Test
576-
public void TestWaitForObjectWhichContainsWithCameraId() {
577-
AltFindObjectsParams altFindObjectsParametersCamera = new AltFindObjectsParams.Builder(By.PATH,
578-
"//Main Camera").build();
579-
AltObject camera = altDriver.findObject(altFindObjectsParametersCamera);
580-
581-
AltFindObjectsParams altFindObjectsParametersObject = new AltFindObjectsParams.Builder(By.NAME, "Canva")
582-
.withCamera(By.ID, String.valueOf(camera.id)).build();
596+
public void TestWaitForObjectWhichContains() {
597+
AltFindObjectsParams altFindObjectsParametersObject = new AltFindObjectsParams.Builder(By.NAME, "Canva").build();
583598
AltWaitForObjectsParams altWaitForObjectsParams = new AltWaitForObjectsParams.Builder(
584599
altFindObjectsParametersObject).build();
585600
AltObject altObject = altDriver.waitForObjectWhichContains(altWaitForObjectsParams);
586-
assertEquals("Canvas", altObject.name);
587-
588601
}
589602
590603
.. code-tab:: py
591604
592605
def test_wait_for_object_which_contains(self):
593-
alt_object = self.alt_driver.wait_for_object_which_contains(By.NAME, "Main")
594-
assert alt_object.name == "Main Camera"
606+
alt_object = self.alt_driver.wait_for_object_which_contains(By.NAME, "Canva")
595607
596608
.. code-tab:: robot
597609
598610
Test Wait For Object Which Contains
599-
${alt_object}= Wait For Object Which Contains NAME Main
600-
${alt_object_name}= Get Object Name ${alt_object}
601-
Should Be Equal As Strings ${alt_object_name} Main Camera
611+
${alt_object}= Wait For Object Which Contains NAME Canva
602612
603613
```
604614

605615
#### WaitForObjectNotBePresent
606616

607-
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](#by-selector) for more information about criteria.
617+
Waits until the object in the scene that respects the given criteria is no longer in the scene or until the timeout limit is reached. Check [By](#by-selector) for more information about criteria.
608618

609619
```eval_rst
610620
@@ -622,7 +632,7 @@ Waits until the object in the scene that respects the given criteria is no longe
622632
| cameraBy | [By](#by-selector) | No | Set what criteria to use in order to find the camera. |
623633
| 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. |
624634
| enabled | boolean | No | If `true` will match only objects that are active in hierarchy. If `false` will match all objects. |
625-
| timeout | double | No | The number of seconds that it will wait for object. |
635+
| timeout | double | No | The number of seconds that it will wait for the object. By default it is set to 20 seconds. |
626636
| interval | double | No | The number of seconds after which it will try to find the object again. interval should be smaller than timeout. |
627637
628638
**_Returns_**
@@ -637,9 +647,9 @@ Waits until the object in the scene that respects the given criteria is no longe
637647
.. code-tab:: c#
638648
639649
[Test]
640-
public void TestWaitForObjectToNotExist()
650+
public void TestWaitForObjectNotBePresent()
641651
{
642-
altDriver.WaitForObjectNotBePresent(By.NAME, "Capsulee", timeout: 1, interval: 0.5f);
652+
altDriver.WaitForObjectNotBePresent(By.NAME, "Capsulee");
643653
}
644654
645655
.. code-tab:: java
@@ -654,15 +664,12 @@ Waits until the object in the scene that respects the given criteria is no longe
654664
.. code-tab:: py
655665
656666
def test_wait_for_object_to_not_be_present(self):
657-
self.alt_driver.wait_for_object_to_not_be_present(By.NAME, "Capsuule")
667+
self.alt_driver.wait_for_object_to_not_be_present(By.NAME, "Capsulee")
658668
659669
.. code-tab:: robot
660670
661-
Test Wait For Object Not Be Present By Camera
662-
Wait For Object To Not Be Present NAME ObjectDestroyedIn5Secs camera_by=NAME camera_value=Main Camera
663-
${elements}= Get All Elements
664-
${list}= Convert To String ${elements}
665-
Should Not Contain ${list} 'name': 'ObjectDestroyedIn5Secs'
671+
Test Wait For Object To Not Be Present
672+
Wait For Object To Not Be Present NAME Capsulee
666673
667674
```
668675

0 commit comments

Comments
 (0)