public static void SourceImage(GameObject go, string sourceName) { var image = UITestUtils.FindGameObjectWithComponentInParents <Image>(go); var sr = UITestUtils.FindGameObjectWithComponentInParents <SpriteRenderer>(go); if (image != null) { Assert.IsNotNull(image.sprite, "SourceImage: Image " + UITestUtils.GetGameObjectFullPath(go) + " has no sprite."); Assert.AreEqual(image.sprite.name, sourceName, "SourceImage: Image " + UITestUtils.GetGameObjectFullPath(go) + " has sprite: " + image.sprite.name + " - but expected: " + sourceName); return; } if (sr != null) { Assert.IsNotNull(sr.sprite, "SourceImage: SpriteRenderer " + UITestUtils.GetGameObjectFullPath(go) + " has no sprite."); Assert.AreEqual(sr.sprite.name, sourceName, "SourceImage: SpriteRenderer " + UITestUtils.GetGameObjectFullPath(go) + " has sprite: " + sr.sprite.name + " - but expected: " + sourceName); return; } Assert.Fail("SourceImage: Game object " + UITestUtils.GetGameObjectFullPath(go) + " has no Image and SpriteRenderer component."); }
/// <summary> /// Awaits for 'GameObject' to become enabled and interactible if it is a button /// </summary> /// <param name="go">'GameObject' of button</param> /// <param name="timeout">Timeout (optional, default = 2)</param> /// <param name="dontFail">Whether the test should fail upon exceeding timeout (optional, default = false)</param> /// <param name="ignoreTimeScale">Should time scale be ignored or not (optional, default = false)</param> public static IEnumerator ButtonInteractible(GameObject go, float timeout = 2f, bool dontFail = false, bool ignoreTimeScale = false) { string path = UITestUtils.GetGameObjectFullPath(go); yield return(WaitFor(() => { if (go.activeInHierarchy) { string overlay = IsOverlayed(go); if (overlay != null) { return new WaitFailed("gameobject object " + path + " isOverlayed by " + overlay); } if (IsClickable(go)) { return new WaitSuccess(); } return new WaitFailed("gameobject " + path + " button is not interactable"); } return new WaitFailed("gameobject " + path + " is not " + (go == null ? "present on scene" : "active in hierarchy")); }, timeout, dontFail, ignoreTimeScale: ignoreTimeScale)); }
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); }
public static IEnumerator AnimatorStateStarted(string path, string stateName, float timeout, bool ignoreTimeScale = false) { var stateNames = stateName.Split(';'); var obj = UITestUtils.FindEnabledGameObjectByPath(path); if (obj == null || !obj.activeInHierarchy) { yield return(Wait.ObjectEnabled(path, timeout)); } var animator = UITestUtils.FindEnabledGameObjectByPath(path).GetComponent <Animator>(); if (GetCurrentStateName == null) { GetCurrentStateName = BuildFastOpenMemberDelegate <Animator, int, string>("GetCurrentStateName"); } yield return(Wait.WaitFor(() => { if (animator.enabled) { for (int i = 0; i < animator.layerCount; i++) { var name = GetCurrentStateName(animator, i); if (stateNames.Any(x => name.EndsWith(x))) { return new WaitSuccess(); } } } return new WaitFailed("AnimatorStateStarted failed for path: " + path + " and state name: " + stateName); }, timeout, ignoreTimeScale: ignoreTimeScale)); }
public static IEnumerator ScrollToPosition(string path, float horizontalPosition, float verticalPosition, float animationDuration = 1f, float timeout = 2f, bool ignoreTimeScale = false) { var go = UITestUtils.FindEnabledGameObjectByPath(path); ScrollRect scrollRect = null; yield return(Wait.WaitFor(() => { scrollRect = go.GetComponentInParent <ScrollRect>(); if (scrollRect != null) { return new WaitSuccess(); } return new WaitFailed("can't find scroll rect durin timeout for object: " + path); }, timeout, ignoreTimeScale: ignoreTimeScale)); var currentTime = 0f; var currentPos = scrollRect.normalizedPosition; var newPos = new Vector2(horizontalPosition, verticalPosition); while (currentTime < animationDuration) { var targetPos = Vector2.Lerp(currentPos, newPos, currentTime / animationDuration); scrollRect.normalizedPosition = targetPos; currentTime += Time.deltaTime; yield return(null); } scrollRect.normalizedPosition = newPos; }
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; } } } }
public ParameterPathToGameObject(GameObject go) { if (go) { ParameterValue = UITestUtils.GetGameObjectFullPath(go); } }
protected override bool Check() { var go = UITestUtils.FindEnabledGameObjectByPath(path); if (go) { var animation = go.GetComponent <Animation>(); if (animation) { if (animation.IsPlaying(animationName)) { return(true); } else { debug = 3; } } else { debug = 2; } } else { debug = 1; } return(false); }
private void DrawPlayingSounds() { if (GUILayout.Button("Find playing sounds", GUILayout.ExpandWidth(true))) { audioClipNameToGameObject = FindObjectsOfType <AudioSource>() .Where(source => source.isPlaying && source.clip) .Select(source => { var kvp = new KeyValuePair <GameObject, string>( source.gameObject, source.clip.name); return(kvp); }).ToList(); } if (audioClipNameToGameObject != null) { GUILayout.Space(5); var indent = GetContentLenght(" GameObject path:"); foreach (var kvp in audioClipNameToGameObject) { var firstRect = EditorGUILayout.BeginHorizontal(); GUI.Box(new Rect(firstRect.x, firstRect.y - 3, firstRect.width, firstRect.height * 2 + 9), ""); EditorGUILayout.LabelField(" Audio name:"); firstRect.x = indent + 5; firstRect.width = firstRect.width - 80 - indent; EditorGUI.TextField(firstRect, kvp.Value); if (GUILayout.Button("Copy", GUILayout.Width(60))) { EditorGUIUtility.systemCopyBuffer = kvp.Value; } GUILayout.Space(5); EditorGUILayout.EndHorizontal(); var secondRect = EditorGUILayout.BeginHorizontal(); secondRect.x = indent + 5; secondRect.width = secondRect.width - 80 - indent; if (kvp.Key != null) { EditorGUILayout.LabelField(" GameObject path:"); EditorGUI.TextField(secondRect, UITestUtils.GetGameObjectFullPath(kvp.Key)); } GUILayout.FlexibleSpace(); if (GUILayout.Button("Select", GUILayout.Width(60))) { Selection.activeGameObject = kvp.Key; } GUILayout.Space(5); EditorGUILayout.EndHorizontal(); GUILayout.Space(5); } } }
public static IEnumerator AnimationCompleted(string path, string animationName, float timeout = 10, bool ignoreTimeScale = false) { float currentTime = Time.time; yield return(AsyncWait.StartWaitingForUnityAnimation(path, animationName, timeout)); float restTime = timeout - (Time.time - currentTime); yield return(WaitFor(() => { var go = UITestUtils.FindEnabledGameObjectByPath(path); if (go == null) { return new WaitFailed("WaitingForUnityAnimationCompleted: Object not found"); } var animation = go.GetComponent <Animation>(); if (animation != null) { if (animation.IsPlaying(animationName)) { return new WaitFailed("WaitingForUnityAnimationCompleted: Animation is played"); } else { return new WaitSuccess(); } } else { return new WaitFailed("WaitingForUnityAnimationCompleted: Animator not found"); } }, restTime, ignoreTimeScale: ignoreTimeScale)); }
/// <summary> /// Checks that `GameObject` is active in hierarchy /// </summary> /// <param name="go">`GameObject`</param> public static void IsEnabled(GameObject go) { if (!go.activeInHierarchy) { Assert.Fail("IsEnabled by object instance: with path " + UITestUtils.GetGameObjectFullPath(go) + " Game Object disabled"); } }
/// <summary> /// Checks that `GameObject` is not active in hierarchy /// </summary> /// <param name="go">`GameObject`</param> public static void IsDisabled(GameObject go) { if (go.activeInHierarchy) { Assert.Fail("IsDisabled by object instance: Game Object " + UITestUtils.GetGameObjectFullPath(go) + " enabled"); } }
public static void DoesNotExist(string path) { var go = UITestUtils.FindAnyGameObject(path); if (go != null) { Assert.Fail("DoesNotExist: Object with path " + path + " exists."); } }
/// <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."); } }
public override AbstractGenerator CreateGenerator(GameObject go) { var pos = UITestUtils.CenterPointOfObject(go.GetComponent <RectTransform>()); var anyCamera = GameObject.FindObjectOfType <Camera>(); pos.x = pos.x / anyCamera.pixelWidth; pos.y = pos.y / anyCamera.pixelHeight; return(VoidMethod.Path(go).Float(pos.x).Float(pos.y).Float(pos.x).Float(pos.y).Float(1)); }
/// <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."); } }
private static void Click(string path) { GameObject go = UITestUtils.FindEnabledGameObjectByPath(path); if (go == null) { Assert.Fail("Trying to click to " + path + " but it doesn't exist"); } Click(go); }
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); }
/// <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)); }
/// <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"); } }
public static void ClickPixels(int x, int y) { GameObject go = UITestUtils.FindObjectByPixels(x, y); if (go == null) { Assert.Fail("Cannot click to pixels [" + x + ";" + y + "], couse there are no objects."); } Interact.Click(go); }
public override bool IsAvailable(GameObject go) { if (!go) { return(false); } var toggleGo = UITestUtils.FindGameObjectWithComponentInParents <Toggle>(go); return(toggleGo && toggleGo.gameObject.activeInHierarchy); }
public LogWaiter(string message, bool isRegExp, bool expectedErrorMessageCouldBeSubstring, LogType logType, float timeout) { this.logType = logType; Application.logMessageReceived += ApplicationOnLogMessageReceived; OnCompleteCallback += OnComplete; stringComparator = UITestUtils.GetStringComparator(message, isRegExp, expectedErrorMessageCouldBeSubstring); this.message = message; StartWait(timeout); }
/// <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); }
/// <summary> /// Uses `UnityEngine.EventSystems.EventSystem` class to raycast by given coordinates to find `GameObject` and perform drag on it /// </summary> /// <param name="from">Start position in pixels</param> /// <param name="to">Finish position in pixels</param> /// <param name="time">Drag Time (optional, default = 1)</param> public static IEnumerator DragPixels(Vector2 from, Vector2 to, float time = 1) { var go = UITestUtils.FindObjectByPixels(from.x, from.y); if (go == null) { Assert.Fail("Cannot grag object from pixels [" + from.x + ";" + from.y + "], couse there are no objects."); } yield return(DragPixels(go, from, to, time)); }
public override bool IsAvailable(GameObject go) { if (!go) { return(false); } var image = UITestUtils.FindGameObjectWithComponentInParents <Image>(go); var sr = UITestUtils.FindGameObjectWithComponentInParents <SpriteRenderer>(go); return(image || sr); }
public static void ClickPercents(float x, float y) { GameObject go = UITestUtils.FindObjectByPercents(x, y); if (go == null) { Assert.Fail("Cannot click to percents [" + x + ";" + y + "], couse there are no objects."); } Click(go); }
public override bool IsAvailable(GameObject go) { if (go == null) { return(false); } var fromPos = new Vector2(); var scrollElement = UITestUtils.GetScrollElement(go, ref fromPos); return(scrollElement != null); }
/// <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)); }
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)); }