Ejemplo n.º 1
0
 void AddMenuItem(GenericMenu menu, string menuPath, UserActionInfo action, int index)
 {
     menu.AddItem(new GUIContent(menuPath), false, () =>
     {
         action.SelectedIndex = index;
     });
 }
 public void ApplyAction(UserActionInfo action)
 {
     if (userFlowModel != null)
     {
         userFlowModel.ApplyAction(action);
     }
 }
Ejemplo n.º 3
0
        private UserActionInfo AddUserActionAndSetSelectedAssertation(UserActionInfo newAction)
        {
            if (newAction.CodeGenerators.Count > 0)
            {
                var selectedIndex = newAction.AvailableAssertations.FindIndex(assertation => assertation.IsDefault);
                if (selectedIndex < 0)
                {
                    selectedIndex = newAction.CodeGenerators.FindIndex(generator =>
                    {
                        var allGenerators = generator.CalculateGeneratorSequence();
                        return(allGenerators.Any(gen => gen.GetType() == typeof(ParameterPathToGameObject)));
                    });
                }

                if (selectedIndex < 0)
                {
                    selectedIndex = newAction.AvailableAssertations.FindIndex(assertation =>
                    {
                        return(assertation.Helper is Interact.ButtonWaitDelayAndClick);
                    });
                }

                newAction.SelectedIndex = selectedIndex >= 0 ? selectedIndex : 0;
                UserActions.Add(newAction);
                return(newAction);
            }

            return(null);
        }
Ejemplo n.º 4
0
 private void SetGeneratorsToUserAction(
     Dictionary <Assertation, GameObject> gameObjectToAssertation,
     UserActionInfo userActionInfo)
 {
     userActionInfo.CodeGenerators        = new List <AbstractGenerator>();
     userActionInfo.AvailableAssertations = new List <Assertation>();
     foreach (var gameObjectToAssert in gameObjectToAssertation)
     {
         var generator = gameObjectToAssert.Key.Helper.CreateGenerator(gameObjectToAssert.Value);
         userActionInfo.CodeGenerators.Add(generator);
         userActionInfo.AvailableAssertations.Add(gameObjectToAssert.Key);
     }
 }
Ejemplo n.º 5
0
        public void HandleClick(Vector2 pixelPos)
        {
            var gameObjectToAssertation = FindGameObjectToAssertationByClick(pixelPos);

            var percentPos = new Vector2(pixelPos.x / Screen.width, pixelPos.y / Screen.height);
            var newAction  = new UserActionInfo
            {
                DeviceDPI        = Screen.dpi,
                DeviceResolution = new Vector2(Screen.width, Screen.height),
                PixelPos         = pixelPos,
                PercentPos       = percentPos
            };

            SetGeneratorsToUserAction(gameObjectToAssertation, newAction);
            AddUserActionAndSetSelectedAssertation(newAction);
        }
Ejemplo n.º 6
0
        public UserActionInfo HandleGameObject(GameObject go)
        {
            var newAction = new UserActionInfo();
            var gameObjectToAssertation = new Dictionary <Assertation, GameObject>();

            foreach (var assertation in assertations)
            {
                var adjustedGo = FindAvailableInParents(go, assertation.Helper);
                if (adjustedGo)
                {
                    gameObjectToAssertation[assertation] = adjustedGo;
                }
            }

            SetGeneratorsToUserAction(gameObjectToAssertation, newAction);
            return(AddUserActionAndSetSelectedAssertation(newAction));
        }
        private void GenerateText(UserActionInfo userAction)
        {
            generatedLabels.Clear();
            generatedCodes.Clear();

            generatedLabels.Add("GameObject Path: ");
            generatedCodes.Add(UITestUtils.GetGameObjectFullPath(selectedGameObject));

            maxWidthForAssertationName = 0;

            WaitVariablesContainer.SilentMode = true;
            for (int i = 0; i < userAction.AvailableAssertations.Count; i++)
            {
                userAction.SelectedIndex = i;
                try
                {
                    var result = userAction.GenerateCode();
                    if (!string.IsNullOrEmpty(result))
                    {
                        generatedCodes.Add(result);
                    }
                    else
                    {
                        continue;
                    }
                }
                catch (Exception ex)
                {
                    continue;
                }

                var label = userAction.SelectedAssertation.AssertationMethodDescription + ": ";
                label = label.Replace("/", " ");
                generatedLabels.Add(label);
                var currentWidth = GetContentLenght(label);
                if (maxWidthForAssertationName < currentWidth)
                {
                    maxWidthForAssertationName = currentWidth;
                }
            }
            WaitVariablesContainer.SilentMode = false;
        }
Ejemplo n.º 8
0
        public UserActionInfo(UserActionInfo copy)
        {
            Description      = copy.Description;
            DeviceResolution = new Vector2(copy.DeviceResolution.x, copy.DeviceResolution.y);
            DeviceDPI        = copy.DeviceDPI;
            PixelPos         = copy.PixelPos;
            PercentPos       = copy.PercentPos;
            InchPos          = copy.InchPos;
            SelectedIndex    = copy.SelectedIndex;
            if (copy.CodeGenerators != null)
            {
                CodeGenerators = new List <AbstractGenerator>();
                foreach (var generator in copy.CodeGenerators)
                {
                    var copyGenerator = generator.Clone();
                    CodeGenerators.Add(copyGenerator);
                }
            }

            AvailableAssertations = copy.AvailableAssertations;
        }
Ejemplo n.º 9
0
        public void ApplyAction(UserActionInfo userAction)
        {
            var assertationToApply = userAction.SelectedAssertation;

            if (assertationToApply.methodInfo == null)
            {
                Debug.LogError("can't apply action: methodInfo is null");
                return;
            }

            var generators = userAction.SelectedCodeGenerator.CalculateGeneratorSequence();
            var parameters = generators
                             .Where(gen => gen is AbstractParameter)
                             .Select(gen => (gen as AbstractParameter).ParameterValueToObject()).ToArray();

            var isCorrect = IsAssertationParamsCorrect(parameters, assertationToApply.methodInfo);

            if (!isCorrect)
            {
                Debug.LogError("can't apply action: parameters mismatch");
                return;
            }

            if (assertationToApply.methodInfo.ReturnType == typeof(IEnumerator))
            {
                var result = (IEnumerator)assertationToApply.methodInfo.Invoke(null, parameters);
                if (!mb)
                {
                    var go = new GameObject();
                    go.name = "UI_TEST_TOOLS_COROUTINE_HELPER";
                    mb      = go.AddComponent <EmptyMono>();
                }

                mb.StartCoroutine(result);
            }
            else
            {
                assertationToApply.methodInfo.Invoke(null, parameters);
            }
        }
Ejemplo n.º 10
0
        public void CreateNoGameobjectAction()
        {
            var gameObjectToAssertation = new Dictionary <Assertation, GameObject>();

            foreach (var assertation in assertations)
            {
                if (assertation.Helper.IsAvailable(null))
                {
                    gameObjectToAssertation[assertation] = null;
                }
            }

            if (gameObjectToAssertation.Count > 0)
            {
                var newAction = new UserActionInfo
                {
                    DeviceDPI        = Screen.dpi,
                    DeviceResolution = new Vector2(Screen.width, Screen.height)
                };
                SetGeneratorsToUserAction(gameObjectToAssertation, newAction);
                UserActions.Add(newAction);
            }
        }
Ejemplo n.º 11
0
        private void DrawListOfUserAction()
        {
            if (Event.current.type != EventType.Repaint)
            {
                if (indexToCopy != -1)
                {
                    var newUserAction = new UserActionInfo(controller.UserActions[indexToCopy]);

                    controller.UserActions.Insert(indexToCopy + 1, newUserAction);

                    indexToCopy = -1;
                }
                if (toRemove != null)
                {
                    controller.UserActions.Remove(toRemove);
                    toRemove = null;
                }
            }

            GUILayout.Space(2);
            CalculateListItemsHeight();

            if (reorderableList == null || reorderableList.count != controller.UserActions.Count)
            {
                reorderableList = new ReorderableList(controller.UserActions, null, true, false, true, false);

                reorderableList.drawElementCallback           = DrawUserClickInfo;
                reorderableList.elementHeightCallback         = index => heights[index];
                reorderableList.drawElementBackgroundCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
                {
                    if (Event.current.type == EventType.Layout || index == -1)
                    {
                        return;
                    }

                    Color c = GUI.backgroundColor;

                    var userAction = (UserActionInfo)reorderableList.list[index];

                    if (userAction.SelectedAssertation == null || userAction.SelectedAssertation.methodInfo == null)
                    {
                        Debug.LogError(String.Format("UITestFlowRecorderWindow: SELECTED ASSERTATION OR ITS METHOD INFO IS NULL FOR ELEMENT #{0}", index));

                        toRemove = userAction;

                        return;
                    }

                    var declaringType = userAction.SelectedAssertation.methodInfo.DeclaringType.Name;

                    switch (declaringType)
                    {
                    case "Wait":
                    case "AsyncWait":
                        GUI.backgroundColor = new Color(0.827f, 0.859f, 0.827f);
                        break;

                    case "Check":
                    case "AsyncCheck":
                        GUI.backgroundColor = new Color(0.859f, 0.851f, 0.827f);
                        break;

                    case "Interact":
                        GUI.backgroundColor = new Color(0.827f, 0.831f, 0.85f);
                        break;
                    }

                    if (isActive)
                    {
                        GUI.backgroundColor *= new Color(0.8f, 0.8f, 0.8f, 1);
                    }

                    rect.y     += 1;
                    rect.height = GetHeight(index, isActive) - 2;
                    rect.x      = 3;
                    rect.width -= 6;
                    GUI.Box(rect, "");
                    GUI.backgroundColor = c;
                };

                reorderableList.onReorderCallback = (ReorderableList list) =>
                {
                    CalculateListItemsHeight();
                };

                reorderableList.onAddCallback = (ReorderableList list) =>
                {
                    controller.CreateNoGameobjectAction();
                };
            }

            m_NonDragTargetIndices = (List <int>) typeof(UnityEditorInternal.ReorderableList).GetField("m_NonDragTargetIndices", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(reorderableList);

            reorderableList.DoLayoutList();

            Repaint();
        }
Ejemplo n.º 12
0
        private void DrawUserClickInfo(Rect rect, int index, bool isActive, bool isFocused)
        {
            float topLineHeight  = EditorGUIUtility.singleLineHeight;
            var   rectToDrawWith = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);

            var userAction = (UserActionInfo)reorderableList.list[index];

            if (userAction.SelectedAssertation == null || userAction.SelectedAssertation.methodInfo == null)
            {
                Debug.LogError(String.Format("UITestFlowRecorderWindow: SELECTED ASSERTATION OR ITS METHOD INFO IS NULL FOR ELEMENT #{0}", index));

                toRemove = userAction;

                return;
            }

            AbstractParameter[] parameters = new AbstractParameter[0];
            if (userAction.SelectedCodeGenerator != null)
            {
                var generators = userAction.SelectedCodeGenerator.CalculateGeneratorSequence();
                parameters = generators.OfType <AbstractParameter>().ToArray();
            }

            var shiftY = (heights[index] - EditorGUIUtility.singleLineHeight) / (parameters.Length + 2);

            rectToDrawWith.y += EditorGUIUtility.singleLineHeight * 0.5f;

            rectToDrawWith.width -= 64;

            rectToDrawWith.width -= 62;
            rectToDrawWith.x     += 30;

            var style = new GUIStyle(GUI.skin.label)
            {
                fontSize = INDEX_SIZE, normal = new GUIStyleState()
                {
                    textColor = indexColor
                }, stretchWidth = true, fixedHeight = INDEX_SIZE + 10
            };

            EditorGUI.LabelField(new Rect(rectToDrawWith.x - 30, rectToDrawWith.y, 30, rectToDrawWith.height), (index + 1).ToString(), style);

            if (userAction.SelectedAssertation == null)
            {
                return;
            }

            var labelForButton = userAction.SelectedAssertation.AssertationMethodDescription;

            labelForButton = labelForButton.Replace("/", " / ");
            if (GUI.Button(rectToDrawWith, labelForButton))
            {
                GenericMenu menu = new GenericMenu();
                for (int i = 0; i < userAction.AvailableAssertations.Count; i++)
                {
                    AddMenuItem(menu, userAction.AvailableAssertations[i].AssertationMethodDescription, userAction, i);
                }

                menu.ShowAsContext();
            }

            rectToDrawWith.width += 62;
            rectToDrawWith.x     -= 30;


            Rect buttonRect = new Rect();

            buttonRect.x      = rectToDrawWith.width + rectToDrawWith.x - 30;
            buttonRect.y      = rectToDrawWith.y;
            buttonRect.height = 16;
            buttonRect.width  = 30;


            EditorGUI.BeginDisabledGroup(!EditorApplication.isPlaying);
            if (GUI.Button(buttonRect, "►"))
            {
                controller.ApplyAction(userAction);
            }

            buttonRect.x    += 32;
            buttonRect.width = 37;
            EditorGUI.EndDisabledGroup();

            if (CopyShortcutPressed && isFocused)
            {
                indexToCopy = index;

                Repaint();
            }

            if (GUI.Button(buttonRect, "copy"))
            {
                indexToCopy = index;
            }
            buttonRect.x      = rectToDrawWith.width + rectToDrawWith.x + 41;
            buttonRect.y      = rectToDrawWith.y;
            buttonRect.height = 16;
            buttonRect.width  = 22;

            if (GUI.Button(buttonRect, "x"))
            {
                toRemove = (UserActionInfo)reorderableList.list[index];
            }
            rectToDrawWith.width += 64 - 28;

            rectToDrawWith.y           += shiftY + 4;
            rectToDrawWith.x           += 28;
            EditorGUIUtility.labelWidth = 100;

            userAction.Description = EditorGUI.TextField(rectToDrawWith, "Description: ", userAction.Description);

            foreach (var parameter in parameters)
            {
                rectToDrawWith.y += shiftY;
                var drawer = drawersFactory.GetDrawer(parameter);
                if (drawer != null)
                {
                    drawer.EditorDraw(parameter, rectToDrawWith,
                                      userAction.SelectedAssertation.methodInfo);
                }
            }
        }