コード例 #1
0
    public void WaitForElementToNotBePresent(string name, string cameraName = "", double timeout = 20, double interval = 0.5)
    {
        double         time       = 0;
        bool           found      = false;
        AltUnityObject altElement = null;

        while (time <= timeout)
        {
            found = false;
            try
            {
                altElement = FindElement(name, cameraName);
                found      = true;
                System.Threading.Thread.Sleep(System.Convert.ToInt32(interval * 1000));
                time += interval;
                UnityEngine.Debug.Log("Waiting for element " + name + " to not be present");
            }
            catch (System.Exception)
            {
                break;
            }
        }

        if (found)
        {
            throw new Assets.AltUnityTester.AltUnityDriver.WaitTimeOutException("Element " + name + " still found after " + timeout + " seconds");
        }
    }
コード例 #2
0
    public AltUnityObject WaitForElementWithText(string name, string text, string cameraName = "", double timeout = 20, double interval = 0.5)
    {
        double         time       = 0;
        AltUnityObject altElement = null;

        while (time < timeout)
        {
            try
            {
                altElement = FindElement(name, cameraName);
                if (altElement.GetText().Equals(text))
                {
                    break;
                }
                throw new System.Exception("Not the wanted text");
            }
            catch (System.Exception)
            {
                System.Threading.Thread.Sleep(System.Convert.ToInt32(interval * 1000));
                time += interval;
                UnityEngine.Debug.Log("Waiting for element " + name + " to have text " + text);
            }
        }
        if (altElement != null && altElement.GetText().Equals(text))
        {
            return(altElement);
        }
        throw new Assets.AltUnityTester.AltUnityDriver.WaitTimeOutException("Element with text: " + text + " not loaded after " + timeout + " seconds");
    }
コード例 #3
0
    public AltUnityObject WaitForElementWhereNameContains(string name, string cameraName = "", double timeout = 20, double interval = 0.5)
    {
        double         time       = 0;
        AltUnityObject altElement = null;

        while (time < timeout)
        {
            try
            {
                altElement = FindElementWhereNameContains(name, cameraName);
                break;
            }
            catch (System.Exception)
            {
                UnityEngine.Debug.Log("Waiting for element where name contains " + name + "....");
                System.Threading.Thread.Sleep(System.Convert.ToInt32(interval * 1000));
                time += interval;
            }
        }
        if (altElement != null)
        {
            return(altElement);
        }
        throw new Assets.AltUnityTester.AltUnityDriver.WaitTimeOutException("Element " + name + " still not found after " + timeout + " seconds");
    }
コード例 #4
0
    public AltUnityObject Execute()
    {
        double         time       = 0;
        AltUnityObject altElement = null;

        while (time < timeout)
        {
            try
            {
                altElement = new FindElement(SocketSettings, name, cameraName, enabled).Execute();
                if (altElement.GetText().Equals(text))
                {
                    break;
                }
                throw new System.Exception("Not the wanted text");
            }
            catch (System.Exception)
            {
                System.Threading.Thread.Sleep(System.Convert.ToInt32(interval * 1000));
                time += interval;
                System.Diagnostics.Debug.WriteLine("Waiting for element " + name + " to have text " + text);
            }
        }
        if (altElement != null && altElement.GetText().Equals(text))
        {
            return(altElement);
        }
        throw new Assets.AltUnityTester.AltUnityDriver.WaitTimeOutException("Element with text: " + text + " not loaded after " + timeout + " seconds");
    }
コード例 #5
0
    public AltUnityObject Execute()
    {
        double         time       = 0;
        AltUnityObject altElement = null;

        while (time < timeout)
        {
            try
            {
                altElement = new FindObjectWhichContains(SocketSettings, by, value, cameraName, enabled).Execute();
                break;
            }
            catch (System.Exception)
            {
                System.Diagnostics.Debug.WriteLine("Waiting for element where name contains " + value + "....");
                System.Threading.Thread.Sleep(System.Convert.ToInt32(interval * 1000));
                time += interval;
            }
        }
        if (altElement != null)
        {
            return(altElement);
        }
        throw new Assets.AltUnityTester.AltUnityDriver.WaitTimeOutException("Element " + value + " not loaded after " + timeout + " seconds");
    }
コード例 #6
0
 public GetComponentProperty(SocketSettings socketSettings, string componentName, string propertyName, string assemblyName, AltUnityObject altUnityObject) : base(socketSettings)
 {
     this.componentName  = componentName;
     this.propertyName   = propertyName;
     this.assemblyName   = assemblyName;
     this.altUnityObject = altUnityObject;
 }
コード例 #7
0
    public void Execute()
    {
        double         time       = 0;
        bool           found      = false;
        AltUnityObject altElement = null;

        while (time <= timeout)
        {
            found = false;
            try
            {
                altElement = new FindElement(SocketSettings, name, cameraName, enabled).Execute();
                found      = true;
                System.Threading.Thread.Sleep(System.Convert.ToInt32(interval * 1000));
                time += interval;
                System.Diagnostics.Debug.WriteLine("Waiting for element " + name + " to not be present");
            }
            catch (System.Exception)
            {
                break;
            }
        }
        if (found)
        {
            throw new Assets.AltUnityTester.AltUnityDriver.WaitTimeOutException("Element " + name + " still found after " + timeout + " seconds");
        }
    }
コード例 #8
0
    public void TestCallMethodWithMultipleDefinitions()
    {
        AltUnityObject capsule = altUnityDriver.FindElement("Capsule");

        capsule.CallComponentMethod("Capsule", "Test", "2", "System.Int32");
        AltUnityObject capsuleInfo = altUnityDriver.FindElement("CapsuleInfo");

        Assert.AreEqual("6", capsuleInfo.GetText());
    }
コード例 #9
0
 public CallComponentMethod(SocketSettings socketSettings, string componentName, string methodName, string parameters, string typeOfParameters, string assembly, AltUnityObject altUnityObject) : base(socketSettings)
 {
     this.componentName    = componentName;
     this.methodName       = methodName;
     this.parameters       = parameters;
     this.typeOfParameters = typeOfParameters;
     this.assemblyName     = assembly;
     this.altUnityObject   = altUnityObject;
 }
コード例 #10
0
 public static UnityEngine.GameObject GetGameObject(AltUnityObject altUnityObject)
 {
     foreach (UnityEngine.GameObject gameObject in UnityEngine.Resources.FindObjectsOfTypeAll <UnityEngine.GameObject>())
     {
         if (gameObject.GetInstanceID() == altUnityObject.id)
         {
             return(gameObject);
         }
     }
     throw new Assets.AltUnityTester.AltUnityDriver.NotFoundException("Object not found");
 }
コード例 #11
0
    protected AltUnityObject ReceiveAltUnityObject()
    {
        string data = Recvall();

        if (!data.Contains("error:"))
        {
            AltUnityObject altElement = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityObject>(data);
            altElement.socketSettings = SocketSettings;
            return(altElement);
        }
        HandleErrors(data);
        return(null);
    }
コード例 #12
0
    public AltUnityObject GameObjectToAltUnityObject(UnityEngine.GameObject altGameObject, UnityEngine.Camera camera = null)
    {
        int cameraId = -1;

        //if no camera is given it will iterate through all cameras until  found one that sees the object if no camera sees the object it will return the position from the last camera
        //if there is no camera in the scene it will return as scren position x:-1 y=-1, z=-1 and cameraId=-1
        if (camera == null)
        {
            _position = new UnityEngine.Vector3(-1, -1, -1);
            foreach (var camera1 in UnityEngine.Camera.allCameras)
            {
                _position = getObjectScreePosition(altGameObject, camera1);
                cameraId  = camera1.GetInstanceID();
                if (_position.x > 0 && _position.y > 0 && _position.x < UnityEngine.Screen.width && _position.y < UnityEngine.Screen.height && _position.z >= 0)//Check if camera sees the object
                {
                    break;
                }
            }
        }
        else
        {
            _position = getObjectScreePosition(altGameObject, camera);
            cameraId  = camera.GetInstanceID();
        }
        int parentId = 0;

        if (altGameObject.transform.parent != null)
        {
            parentId = altGameObject.transform.parent.GetInstanceID();
        }


        AltUnityObject altObject = new AltUnityObject(name: altGameObject.name,
                                                      id: altGameObject.GetInstanceID(),
                                                      x: System.Convert.ToInt32(UnityEngine.Mathf.Round(_position.x)),
                                                      y: System.Convert.ToInt32(UnityEngine.Mathf.Round(_position.y)),
                                                      z: System.Convert.ToInt32(UnityEngine.Mathf.Round(_position.z)),//if z is negative object is behind the camera
                                                      mobileY: System.Convert.ToInt32(UnityEngine.Mathf.Round(UnityEngine.Screen.height - _position.y)),
                                                      type: "",
                                                      enabled: altGameObject.activeSelf,
                                                      worldX: altGameObject.transform.position.x,
                                                      worldY: altGameObject.transform.position.y,
                                                      worldZ: altGameObject.transform.position.z,
                                                      idCamera: cameraId,
                                                      transformId: altGameObject.transform.GetInstanceID(),
                                                      parentId: parentId);

        return(altObject);
    }
コード例 #13
0
    public AltUnityObject FindElementWhereNameContains(string name, string cameraName = "", bool enabled = true)
    {
        Socket.Client.Send(toBytes(CreateCommand("findObjectWhereNameContains", name, cameraName, enabled.ToString())));
        string data = Recvall();

        if (!data.Contains("error:"))
        {
            AltUnityObject altElement = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityObject>(data);
            if (altElement.name.Contains(name))
            {
                return(altElement);
            }
        }
        HandleErrors(data);
        return(null);
    }
コード例 #14
0
    public AltUnityObject Tap()
    {
        string altObject = Newtonsoft.Json.JsonConvert.SerializeObject(this);

        altUnityDriver.Socket.Client.Send(System.Text.Encoding.ASCII.GetBytes(altUnityDriver.CreateCommand("tapObject", altObject)));
        string data = altUnityDriver.Recvall();

        if (!data.Contains("error:"))
        {
            AltUnityObject altElement = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityObject>(data);
            if (altElement.name.Contains(name))
            {
                return(altElement);
            }
        }

        AltUnityDriver.HandleErrors(data);
        return(null);
    }
コード例 #15
0
    public AltUnityObject DropObject(UnityEngine.Vector2 position)
    {
        string altObject      = Newtonsoft.Json.JsonConvert.SerializeObject(this);
        string positionString = Newtonsoft.Json.JsonConvert.SerializeObject(position, Newtonsoft.Json.Formatting.Indented, new Newtonsoft.Json.JsonSerializerSettings
        {
            ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
        });

        altUnityDriver.Socket.Client.Send(System.Text.Encoding.ASCII.GetBytes(altUnityDriver.CreateCommand("dropObject", positionString, altObject)));
        string data = altUnityDriver.Recvall();

        if (!data.Contains("error:"))
        {
            AltUnityObject altElement = Newtonsoft.Json.JsonConvert.DeserializeObject <AltUnityObject>(data);
            if (altElement.name.Contains(name))
            {
                return(altElement);
            }
        }

        AltUnityDriver.HandleErrors(data);
        return(null);
    }
コード例 #16
0
 public ClickEvent(SocketSettings socketSettings, AltUnityObject altUnityObject) : base(socketSettings)
 {
     this.altUnityObject = altUnityObject;
 }
コード例 #17
0
 public PointerUpFromObject(SocketSettings socketSettings, AltUnityObject altUnityObject) : base(socketSettings)
 {
     this.altUnityObject = altUnityObject;
 }
コード例 #18
0
 public GetAllMethods(SocketSettings socketSettings, AltUnityComponent altUnityComponent, AltUnityObject altUnityObject) : base(socketSettings)
 {
     this.altUnityComponent = altUnityComponent;
     this.altUnityObject    = altUnityObject;
 }
コード例 #19
0
 public GetAllComponents(SocketSettings socketSettings, AltUnityObject altUnityObject) : base(socketSettings)
 {
     AltUnityObject = altUnityObject;
 }
コード例 #20
0
    public void TestInactiveObject()
    {
        AltUnityObject cube = altUnityDriver.FindElement("Cube", enabled: false);

        Assert.AreEqual(false, cube.enabled);
    }
コード例 #21
0
 public DragObject(SocketSettings socketSettings, Vector2 position, AltUnityObject altUnityObject) : base(socketSettings)
 {
     this.position       = position;
     this.altUnityObject = altUnityObject;
 }
コード例 #22
0
 public GetText(SocketSettings socketSettings, AltUnityObject altUnityObject) : base(socketSettings)
 {
     this.altUnityObject = altUnityObject;
 }
コード例 #23
0
    public void TestTapScreenWhereThereIsNoObjects()
    {
        AltUnityObject altObject = altUnityDriver.TapScreen(1, 1);

        Assert.AreEqual(null, altObject);
    }
コード例 #24
0
 public SetText(SocketSettings socketSettings, AltUnityObject altUnityObject, string text) : base(socketSettings)
 {
     this.altUnityObject = altUnityObject;
     this.newText        = text;
 }