Пример #1
0
        public static void TextNotEquals(string path, string expectedText)
        {
            var go = UITestUtils.FindAnyGameObject(path);

            Assert.IsNotNull(go, "InputEquals: Object " + path + " is not exist");
            TextNotEquals(go, expectedText);
        }
        protected override void EditorDrawInner(ParameterPathToGameObject parameter, Rect rect, MethodInfo methodInfo)
        {
            var index      = parameter.CurrentParameterIndex();
            var parameters = methodInfo.GetParameters();

            if (parameters.Length <= index)
            {
                Debug.LogWarning("missmatch parameters amount for: " + methodInfo.Name);
                return;
            }
            var paramName = parameters[index].Name;

            if (parameter.ParameterValue != null)
            {
                Rect parameterRect = new Rect(rect.min, rect.size + new Vector2(-(SELECT_BUTTON_WIDTH + SPACE), 0f));
                Rect buttonRect    = new Rect(new Vector2(parameterRect.max.x + SPACE, rect.min.y), new Vector2(SELECT_BUTTON_WIDTH, rect.size.y));

                parameter.ParameterValue =
                    EditorGUI.TextField(parameterRect, new GUIContent(paramName.FirstCharToUpper() + ":", paramName.FirstCharToUpper()), parameter.ParameterValue);

                if (GUI.Button(buttonRect, "Select"))
                {
                    GameObject target = UITestUtils.FindAnyGameObject(parameter.ParameterValue);

                    if (target != null)
                    {
                        Selection.activeGameObject = target;
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Checks that no `GameObject` with component `T` is present on scene
        /// </summary>
        /// <typeparam name="T">`Type` of object</typeparam>
        public static void DoesNotExist <T>() where T : Component
        {
            var go = UITestUtils.FindAnyGameObject <T>();

            if (go != null)
            {
                Assert.Fail("DoesNotExist<" + typeof(T) + ">: Object exists.");
            }
        }
Пример #4
0
        public static void DoesNotExist(string path)
        {
            var go = UITestUtils.FindAnyGameObject(path);

            if (go != null)
            {
                Assert.Fail("DoesNotExist: Object with path " + path + " exists.");
            }
        }
Пример #5
0
        /// <summary>
        /// Checks that `GameObject` by given path with component `T` is not present on scene
        /// </summary>
        /// <param name="path">Path to `GameObject` in hierarchy</param>
        /// <typeparam name="T">`Type` of object</typeparam>
        public static void DoesNotExist <T>(string path) where T : Component
        {
            var go = UITestUtils.FindAnyGameObject <T>(path);

            if (go != null)
            {
                Assert.Fail("DoesNotExist<" + typeof(T) + ">: Object with path " + path + " exists.");
            }
        }
Пример #6
0
        public static GameObject IsExists(string path)
        {
            var go = UITestUtils.FindAnyGameObject(path);

            if (go == null)
            {
                Assert.Fail("IsExist: Object with path " + path + " does not exist.");
            }
            return(go);
        }
Пример #7
0
        /// <summary>
        /// Checks that `GameObject` by given path is present on scene, contains component `T` and is not active in hierarchy
        /// </summary>
        /// <param name="path">Path to `GameObject` in hierarchy</param>
        /// <typeparam name="T">`Type` of object</typeparam>
        public static void IsDisabled <T>(string path) where T : Component
        {
            IsExists <T>(path);
            var go = UITestUtils.FindAnyGameObject <T>(path);

            if (go.gameObject.activeInHierarchy)
            {
                Assert.Fail("IsDisabled<" + typeof(T) + ">: with path " + path + " Game Object enabled");
            }
        }
Пример #8
0
        /// <summary>
        /// Perform drag on `GameObject` by path
        /// </summary>
        /// <param name="path">Path to GameObject in hierarchy</param>
        /// <param name="to">Finish position in pixels</param>
        /// <param name="time">Drag Time (optional, default = 1)</param>
        public static IEnumerator DragPixels(string path, Vector2 to, float time = 1)
        {
            GameObject go = UITestUtils.FindAnyGameObject(path);

            if (go == null)
            {
                Assert.Fail("Cannot grag object " + path + ", couse there are not exist.");
            }
            yield return(DragPixels(go, to, time));
        }
Пример #9
0
        /// <summary>
        /// Searches for `GameObject` with component `T` on scene
        /// </summary>
        /// <typeparam name="T">`Type` of object</typeparam>
        /// <returns>`GameObject`</returns>
        public static GameObject IsExists <T>() where T : Component
        {
            var go = UITestUtils.FindAnyGameObject <T>();

            if (go == null)
            {
                Assert.Fail("IsExists<" + typeof(T) + ">: Object does not exist.");
            }

            return(go.gameObject);
        }
Пример #10
0
 public static IEnumerator ObjectDisabled(string path, float timeout = 5, bool ignoreTimeScale = false)
 {
     yield return(WaitFor(() =>
     {
         var obj = UITestUtils.FindAnyGameObject(path);
         if (obj != null && !obj.gameObject.activeInHierarchy)
         {
             return new WaitSuccess();
         }
         return new WaitFailed("WaitObjectDisabled path: " + path);
     }, timeout, ignoreTimeScale: ignoreTimeScale));
 }
Пример #11
0
 /// <summary>
 /// Waits until 'GameObject' with component 'T' becomes present on scene and disabled in hierarchy or fails after specified timeout
 /// </summary>
 /// <param name="timeout">Timeout (optional, default = 2)</param>
 /// <param name="ignoreTimeScale">Should time scale be ignored or not (optional, default = false)</param>
 /// <typeparam name="T">Type of component</typeparam>
 public static IEnumerator ObjectDisabled <T>(float timeout = 2f, bool ignoreTimeScale = false) where T : Component
 {
     yield return(WaitFor(() =>
     {
         var obj = UITestUtils.FindAnyGameObject <T>();
         if (obj != null && !obj.gameObject.activeInHierarchy)
         {
             return new WaitSuccess();
         }
         return new WaitFailed("WaitObjectDisabled<" + typeof(T) + ">");
     }, timeout, ignoreTimeScale: ignoreTimeScale));
 }
Пример #12
0
 public static IEnumerator ObjectDestroyed(string path, float timeout = 2f, bool ignoreTimeScale = false)
 {
     yield return(WaitFor(() =>
     {
         var gameObj = UITestUtils.FindAnyGameObject(path);
         if (gameObj == null)
         {
             return new WaitSuccess();
         }
         return new WaitFailed("WaitForDestroy path: " + path);
     }, timeout, ignoreTimeScale: ignoreTimeScale));
 }
Пример #13
0
 /// <summary>
 /// Waits until 'GameObject' with component 'T' disappears from scene or fails after specified timeout
 /// </summary>
 /// <param name="timeout">Timeout (optional, default = 2)</param>
 /// <param name="ignoreTimeScale">Should time scale be ignored or not (optional, default = false)</param>
 /// <typeparam name="T">Type of component</typeparam>
 public static IEnumerator ObjectDestroyed <T>(float timeout = 2f, bool ignoreTimeScale = false) where T : Component
 {
     yield return(WaitFor(() =>
     {
         var obj = UITestUtils.FindAnyGameObject <T>();
         if (obj == null)
         {
             return new WaitSuccess();
         }
         return new WaitFailed("WaitForDestroy<" + typeof(T) + ">");
     }, timeout, ignoreTimeScale: ignoreTimeScale));
 }
Пример #14
0
 public static IEnumerator ObjectInstantiated(string path, float timeout = 5, bool ignoreTimeScale = false)
 {
     yield return(WaitFor(() =>
     {
         var go = UITestUtils.FindAnyGameObject(path);
         if (go)
         {
             return new WaitSuccess();
         }
         return new WaitFailed("WaitForObject path: " + path);
     }, timeout, ignoreTimeScale: ignoreTimeScale));
 }
Пример #15
0
        public static IEnumerator DoesNotExistOrDisabled(string path, float timeout = 2, bool ignoreTimeScale = false)
        {
            var go = UITestUtils.FindAnyGameObject(path);

            yield return(Wait.WaitFor(() =>
            {
                if (go == null || !go.activeInHierarchy)
                {
                    return new WaitSuccess();
                }
                return new WaitFailed("DoesNotExistOrDisabled: object with path: " + path + " exists or enabled after " + timeout + " second(s)");
            }, timeout, ignoreTimeScale: ignoreTimeScale));
        }
Пример #16
0
        public static IEnumerator MakeScreenshotAndCompare(string screenShotName, string referenceName,
                                                           float percentOfCorrectPixels = 0.9f, bool dontFail = false)
        {
#if UNITY_EDITOR
            if (PlayModeTestRunner.ForceMakeReferenceScreenshot)
            {
                yield return(MakeScreenShotReference(referenceName));

                yield break;
            }
#endif
            var screenshotPathToCapture = TestScreenshotTools.ScreenshotDirectoryToCaptureByUnity;
            if (!Directory.Exists(screenshotPathToCapture))
            {
                Directory.CreateDirectory(screenshotPathToCapture);
            }
            var screenShotNameWithTime = TestScreenshotTools.GenerateScreenshotNameWithTime(screenShotName);
            yield return(CaptureScreenshot(screenshotPathToCapture + '/' + screenShotNameWithTime));

            var screenshotPathToLoad = TestScreenshotTools.ScreenshotDirectoryToLoadByFileSystem + '/' +
                                       screenShotNameWithTime;

            var referenceFullPath = TestScreenshotTools.ReferenceScreenshotDirectoryToLoadFromResources + '/' +
                                    referenceName;

            var screenshotCompareError = "screenshot: " + screenShotName +
                                         " doesn't match reference: " + referenceFullPath;

            var screenshotBytes   = File.ReadAllBytes(screenshotPathToLoad);
            var camera            = UITestUtils.FindAnyGameObject <Camera>();
            var screenshotTexture = new Texture2D(camera.pixelWidth, camera.pixelHeight,
                                                  TextureFormat.RGB24, false);
            screenshotTexture.LoadImage(screenshotBytes);
            screenshotTexture.Apply();

            var referenceTex             = Resources.Load <Texture2D>(referenceFullPath);
            var referenceNotFoundMessage = "can't find reference screen shot with path: "
                                           + referenceFullPath +
                                           " to compare it with screen shot: " + screenShotName;
            if (!referenceTex)
            {
                if (dontFail)
                {
                    MakeScreenshotAndCompareClass.AddScreenshotErrorLog(referenceNotFoundMessage);
                    yield break;
                }

                Assert.Fail(referenceNotFoundMessage);
            }

            var pixelsRef  = referenceTex.GetPixels32();
            var screenShot = screenshotTexture.GetPixels32();

            if (dontFail)
            {
                if (pixelsRef.Length != screenShot.Length)
                {
                    screenshotCompareError += " reason: resolution missmatch";
                    MakeScreenshotAndCompareClass.AddScreenshotErrorLog(screenshotCompareError);
                    yield break;
                }
            }

            Assert.AreEqual(pixelsRef.Length, screenShot.Length, screenshotCompareError);
            var matchedPixels = 0f;
            var epsilon       = 20f;
            for (int i = 0; i < pixelsRef.Length; i++)
            {
                if (Mathf.Abs(pixelsRef[i].r - screenShot[i].r) < epsilon &&
                    Mathf.Abs(pixelsRef[i].g - screenShot[i].g) < epsilon &&
                    Mathf.Abs(pixelsRef[i].b - screenShot[i].b) < epsilon)
                {
                    matchedPixels++;
                }
            }

            var actualPercentOfCorrectPixels = matchedPixels / pixelsRef.Length;

            if (dontFail)
            {
                if (actualPercentOfCorrectPixels < percentOfCorrectPixels)
                {
                    var errorMessage = screenshotCompareError + " actual treshold: " + actualPercentOfCorrectPixels +
                                       "  need treshold: " + percentOfCorrectPixels;
                    MakeScreenshotAndCompareClass.AddScreenshotErrorLog(errorMessage);
                    yield break;
                }
            }

            Assert.GreaterOrEqual(actualPercentOfCorrectPixels, percentOfCorrectPixels, screenshotCompareError);
            GameObject.DestroyImmediate(screenshotTexture, true);
            //GameObject.DestroyImmediate(referenceTex, true); //todo find out how to unload texture carefully

            File.Delete(screenshotPathToLoad);
#if UNITY_EDITOR
            TestScreenshotTools.ClearScreenshotsEmptyFolders();
#endif
        }
Пример #17
0
        public static void SetText(string path, string text)
        {
            GameObject go = UITestUtils.FindAnyGameObject(path);

            SetText(go, text);
        }