public async Task Until_LateElementCreation_ElementFound()
        {
            // Arrange
            var          timeout = TimeSpan.FromSeconds(TIMEOUT_SECONDS + 1);
            const string DELAY_COUNTER_TEXT_NAME = "Delayed_Counter_Text";
            var          textQuery = _driver.FindElement(By.Name(DELAY_COUNTER_TEXT_NAME));

            var currentText    = textQuery.Text;
            var text           = currentText.Split(new [] { ' ' }).Last();
            var currentCounter = int.Parse(text);

            // Act
            const string DELAY_COUNTER_BUTTON_NAME = "Delayed_Counter_Button";
            var          buttonQuery = _driver.FindElement(By.Name(DELAY_COUNTER_BUTTON_NAME));

            buttonQuery.LeftClick();

            const string EXPECTED_EFFECT_TEXT_NAME = "DelayedEffect_Text_{0}";
            var          nameString       = string.Format(EXPECTED_EFFECT_TEXT_NAME, currentCounter + 1);
            var          wait             = new UnityDriverWait(_driver, timeout);
            var          expectedTextName = await wait.Until(d => d.FindElement(By.Type <Text>(nameString)));

            // Assert
            Assert.IsTrue(expectedTextName.IsActive, nameString + " not found.");
        }
        public void FindElementByName_ElementExists_FindsElement()
        {
            // Arrange
            _testGos.Add(new GameObject(TEST_GO_NAME));

            // Act
            var uiElement = _driver.FindElement(By.Name(TEST_GO_NAME));

            // Assert
            Assert.IsNotNull(uiElement);
        }
Exemple #3
0
    public void Setup()
    {
        var rootGO = new GameObject("rootGo");

        _rootTransform = rootGO.transform;
        var canvasGO = new GameObject("Canvas", typeof(Canvas));

        canvasGO.transform.SetParent(rootGO.transform);
        var eventSystemGO = new GameObject("EventSystem", typeof(EventSystem));

        eventSystemGO.transform.SetParent(rootGO.transform);
        var testDropdownGO = new GameObject("TestDropdown", typeof(RectTransform), typeof(Dropdown));

        testDropdownGO.transform.SetParent(canvasGO.transform);
        _dropdown         = rootGO.GetComponentInChildren <Dropdown>();
        _dropdown.options = new System.Collections.Generic.List <Dropdown.OptionData>()
        {
            new Dropdown.OptionData("None"),
            new Dropdown.OptionData("Option 1"),
            new Dropdown.OptionData("Option 2"),
        };

        var agent = new NativeUnityDriverAgent();

        _driver          = new UnityDriver(agent);
        _dropdownElement = _driver.FindElement(By.Name("TestDropdown"));
    }
    private void ClickCorrespondingButton(string buttonName)
    {
        var altButtonName    = buttonName + ButtonGridClickHandler.ALT_AFFIX;
        var altButtonElement = _driver.FindElement(By.Type <Button>(altButtonName));

        altButtonElement.LeftClick();
    }
Exemple #5
0
    public void Text_OnTextElement_ReturnsText()
    {
        // Arrange
        var go = new GameObject(TEST_TEXT_GO_NAME, typeof(Text));

        go.transform.SetParent(_testRootGo);
        var          testText      = go.GetComponent <Text>();
        const string EXPECTED_TEXT = "Text_OnTextElement_ReturnsText";

        testText.text = EXPECTED_TEXT;
        var textQuerty = _driver.FindElement(By.Type <Text>(TEST_TEXT_GO_NAME));

        // Act
        var actualText = textQuerty.Text;

        // Assert
        Assert.AreEqual(EXPECTED_TEXT, actualText);
    }
    public void FindElementByPath_ElementPartialNameExists_FindsElement()
    {
        // Arrange
        const string CHILD_GO_NAME          = "baby";
        const string CHILD_GO_PARTIAL_QUERY = "*[contains(ab)]";
        var          parent = new GameObject(TEST_GO_NAME);
        var          child  = new GameObject(CHILD_GO_NAME);

        child.transform.parent = parent.transform;
        _testGos.Add(parent);
        _testGos.Add(child);

        // Act
        var uiElement = _driver.FindElement(By.Path(TEST_GO_NAME + "/" + CHILD_GO_PARTIAL_QUERY));

        // Assert
        Assert.IsNotNull(uiElement);
    }
Exemple #7
0
    public void EulerRotation_OnRotatedObject_ReturnsEulerRotation()
    {
        // Arrange
        const string EXPECTED_OBJECT_NAME = nameof(EulerRotation_OnRotatedObject_ReturnsEulerRotation);
        const float  EXPECTED_ROTATION    = 25f;
        var          go = GameObject.CreatePrimitive(PrimitiveType.Cube);

        go.name = EXPECTED_OBJECT_NAME;
        var expectedRotation = Quaternion.Euler(EXPECTED_ROTATION, EXPECTED_ROTATION, EXPECTED_ROTATION);

        go.transform.localRotation = expectedRotation;
        var goQuery = _driver.FindElement(By.Type <GameObject>(EXPECTED_OBJECT_NAME));

        // Act
        var actualPos = goQuery.EulerRotation;

        // Assert
        Assert.That(expectedRotation.eulerAngles.x, Is.EqualTo(actualPos.X).Within(float.Epsilon));
        Assert.That(expectedRotation.eulerAngles.y, Is.EqualTo(actualPos.Y).Within(float.Epsilon));
        Assert.That(expectedRotation.eulerAngles.z, Is.EqualTo(actualPos.Z).Within(float.Epsilon));
    }
Exemple #8
0
    public void Setup()
    {
        var rootGO = new GameObject("rootGo");
        _rootTransform = rootGO.transform;
        var canvasGO = new GameObject("Canvas", typeof(Canvas));
        canvasGO.transform.SetParent(rootGO.transform);
        var eventSystemGO = new GameObject("EventSystem", typeof(EventSystem));
        eventSystemGO.transform.SetParent(rootGO.transform);
        var testButtonGO = new GameObject("TestButton", typeof(RectTransform), typeof(Button));
        testButtonGO.transform.SetParent(canvasGO.transform);
        _button = rootGO.GetComponentInChildren<Button>();

        var agent = new NativeUnityDriverAgent();
        var driver = new UnityDriver(agent);
        _buttonElement = driver.FindElement(By.Type<Button>());
    }
Exemple #9
0
    public IEnumerator OnValueChanged_OnSelect_ElementIsSelected()
    {
        // Arrange
        int selected = -1;
        var expected = 1;

        _dropdown.onValueChanged.AddListener((x) => selected = x);

        // Act
        _dropdownElement.LeftClick();
        yield return(new WaitForEndOfFrame());

        var _dropdownOptionElement = _driver.FindElement(By.Path("*[contains(Option 1)]"));

        _dropdownOptionElement.LeftClick();
        yield return(new WaitForEndOfFrame());

        // Assert
        Assert.AreEqual(expected, selected);
    }