public void StartTwoInstances()
        {
            var propertyExpression = new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_MAIN_WINDOW);
            foreach (var i in Enumerable.Range(0,2))
            {
                var metl = new UITestHelper(UITestHelper.RootElement, MeTL.StartProcess());
                metl.SearchProperties.Add(propertyExpression);

                var success = metl.WaitForControlEnabled();
                Assert.IsTrue(success, ErrorMessages.EXPECTED_MAIN_WINDOW);
            }

            var desktopBounds = AutomationElement.RootElement.Current.BoundingRectangle;
            var windows = MeTL.GetAllMainWindows(2, true);
            Assert.AreEqual(2, windows.Count);

            // move each window into position
            var windowCount = 0;
            foreach (AutomationElement window in windows)
            {
                var windowPattern = window.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern;
                windowPattern.SetWindowVisualState(WindowVisualState.Normal);

                var transformPattern = window.GetCurrentPattern(TransformPattern.Pattern) as TransformPattern;
                transformPattern.Resize(desktopBounds.Width, desktopBounds.Height / 2);
                transformPattern.Move(0, (desktopBounds.Height / 2) * windowCount++);
            }
        }
        public UITestHelper(UITestHelper parent)
        {
            if (parent == null)
                parent = new UITestHelper(AutomationElement.RootElement);

            parentElement = parent.AutomationElement;
        }
        public void Setup()
        {
            metlWindow = MeTL.GetMainWindow();

            homeTab = new HomeTabScreen(metlWindow.AutomationElement).OpenTab();
            canvas = new CollapsedCanvasStack(metlWindow.AutomationElement);
        }
        public void CheckVersionAgainstHardcoded()
        {
            var version = new UITestHelper(metlWindow);
            version.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_VERSION_LABEL));

            version.Find();
            Assert.AreEqual(version.AutomationElement.Current.Name, expectedVersionString, ErrorMessages.VERSION_MISMATCH);
        }
        public void WaitUntilConversationJoined(AutomationElement parent)
        {
            // wait until we've finished joining the conversation before returning
            var canvasStack = new UITestHelper(parent);
            canvasStack.SearchProperties.Add(new PropertyExpression(AutomationElement.ClassNameProperty, typeof(SandRibbon.Components.CollapsedCanvasStack).Name));
            var success = canvasStack.WaitForControlEnabled();

            Assert.IsTrue(success, ErrorMessages.WAIT_FOR_CONTROL_FAILED);
        }
        public void StartOneInstance()
        {
            Assert.AreEqual(0, MeTL.GetAllMainWindows().Count);

            var metl = new UITestHelper(UITestHelper.RootElement, MeTL.StartProcess());
            metl.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_MAIN_WINDOW));

            var success = metl.WaitForControlEnabled();
            Assert.IsTrue(success, ErrorMessages.EXPECTED_MAIN_WINDOW);
        }
        public void ChangePrivacyToOnlyOwner()
        {
            var results = new UITestHelper(metlWindow);
            results.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_CONVERSATION_SEARCH_RESULTS));

            results.WaitForControlCondition((uiControl) => { return Rect.Empty.Equals(uiControl.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty)); });

            var editConversation = new ConversationEditScreen(results.AutomationElement);

            editConversation.ChangeGroup(TestConstants.OWNER_USERNAME).Save().ReturnToCurrent();
        }
        public void LoginFromSavedCredentials()
        {
            var loggingIn = new UITestHelper(metlWindow);
            loggingIn.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_LOGGING_IN_LABEL));

            var success = loggingIn.WaitForControlExist();
            Assert.IsTrue(success, ErrorMessages.WAIT_FOR_CONTROL_FAILED);

            var login = new Login(metlWindow.AutomationElement);
            login.WaitForSearchScreen();
        }
 public void WaitForControlTest()
 {
     UITestHelper target = new UITestHelper(); // TODO: Initialize to an appropriate value
     string controlAutomationId = string.Empty; // TODO: Initialize to an appropriate value
     UITestHelper.WaitCondition loopCondition = null; // TODO: Initialize to an appropriate value
     UITestHelper.WaitCondition returnCondition = null; // TODO: Initialize to an appropriate value
     bool expected = false; // TODO: Initialize to an appropriate value
     bool actual;
     actual = target.WaitForControl(loopCondition, returnCondition);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
        public void SearchForConversationAndJoin(UITestHelper window, string conversationTitle)
        {
            var search = new ConversationSearcher(window.AutomationElement);

            search.searchField(conversationTitle);
            search.Search();

            if (!search.ResultsContainQueried(conversationTitle))
            {
                CreateAndRenameConversation(window, conversationTitle);
            }

            search.JoinQueried(conversationTitle);
        }
        public void CreateAndRenameConversation(UITestHelper window, string conversationTitle)
        {
            // create a new conversation with the name of the computer appended
            new ApplicationPopup(window.AutomationElement).CreateConversation();

            UITestHelper.Wait(TimeSpan.FromSeconds(2));

            SwitchToSearchCurrentConversation(window);

            UITestHelper.Wait(TimeSpan.FromSeconds(2));

            var edit = new ConversationEditScreen(window.AutomationElement);

            edit.Rename(conversationTitle).Save();
        }
        public void PrivacyIsSetToUnrestricted()
        {
            var results = new UITestHelper(metlWindow);
            results.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_CONVERSATION_SEARCH_RESULTS));
            results.OverrideTimeout = 5000;

            results.WaitForControlCondition((uiControl) => { return Rect.Empty.Equals(uiControl.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty)); });

            var editConversation = new ConversationEditScreen(results.AutomationElement);

            bool selected = false;
                
            editConversation.IsGroupSelected(TestConstants.AUTH_GROUP_UNRESTRICTED, out selected).Save().ReturnToCurrent();
            Assert.IsTrue(selected, ErrorMessages.EXPECTED_SET_PRIVACY);
        }
        public void SearchForDeletedConversation()
        {
            var search = new ConversationSearcher(metlWindow.AutomationElement);

            search.searchField(TestConstants.DELETED_CONVERSATION_TITLE);
            search.Search();

            var results = new UITestHelper(metlWindow);
            results.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_CONVERSATION_SEARCH_RESULTS));

            results.WaitForControlCondition((uiControl) => { return Rect.Empty.Equals(uiControl.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty)); });

            var success = search.IsEmptyResult();
            Assert.IsTrue(success, ErrorMessages.EXPECTED_NO_RESULTS);
        }
        public void CloseInstance()
        {
            if (metlWindows == null)
                metlWindows = MeTL.GetAllMainWindows();
            Assert.IsTrue(metlWindows.Count == 1, ErrorMessages.EXPECTED_ONE_INSTANCE);

            var metlWindow = new UITestHelper(UITestHelper.RootElement, metlWindows[0]);
            metlWindow.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_MAIN_WINDOW));
            metlWindow.Find();

            new ApplicationPopup(metlWindow.AutomationElement).Quit();

            UITestHelper.Wait(TimeSpan.FromSeconds(2));

            Assert.AreEqual(0, MeTL.GetAllMainWindows().Count);
        }
        public void CloseAllInstances()
        {
            if (metlWindows == null)
                metlWindows = MeTL.GetAllMainWindows();

            foreach (AutomationElement window in metlWindows)
            {
                var metlWindow = new UITestHelper(UITestHelper.RootElement, window);
                metlWindow.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_MAIN_WINDOW));
                metlWindow.Find();

                new ApplicationPopup(metlWindow.AutomationElement).Quit();

                UITestHelper.Wait(TimeSpan.FromSeconds(2));
            }

            Assert.AreEqual(0, MeTL.GetAllMainWindows().Count);
        }
        public void SwitchToSearchCurrentConversation(UITestHelper window)
        {
            var manualEvent = new ManualResetEvent(false);
            var completedSearch = false;

            var searchBox = new UITestHelper(window.AutomationElement);
            searchBox.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_CONVERSATION_SEARCH_BOX));
            searchBox.Find();

            Automation.AddAutomationEventHandler(AutomationElement.AsyncContentLoadedEvent, searchBox.AutomationElement, TreeScope.Element, (sender, args) => { completedSearch = true; manualEvent.Set(); });

            new ApplicationPopup(window.AutomationElement).SearchMyConversation();

            UITestHelper.Wait(TimeSpan.FromSeconds(5));
            
            manualEvent.WaitOne(5000, false);
            Assert.IsTrue(completedSearch);

            var currentConversation = new UITestHelper(window);
            currentConversation.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_SEARCH_CURRENT_CONVERSATION_BUTTON));

            currentConversation.Find();

            currentConversation.AutomationElement.Select();

            UITestHelper.Wait(TimeSpan.FromSeconds(5));

            /*var resultsText = new UITestHelper(metlWindow, metlWindow.AutomationElement.Descendant(Constants.ID_METL_SEARCH_RESULTS_TEXT));
            resultsText.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_SEARCH_RESULTS_TEXT));

            var correct = resultsText.WaitForControlCondition((uiControl) =>
            {
                if (uiControl.Current.Name == "Found 1 result.")
                {
                    return false;
                }

                return true;
            });

            Assert.IsTrue(correct);
             */
        }
        public void LogoutAndCloseInstance()
        {
            if (metlWindows == null)
                metlWindows = MeTL.GetAllMainWindows();
            Assert.IsTrue(metlWindows.Count == 1, ErrorMessages.EXPECTED_ONE_INSTANCE);

            var metlWindow = new UITestHelper(UITestHelper.RootElement, metlWindows[0]);
            metlWindow.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_MAIN_WINDOW));
            metlWindow.Find();

            var logoutAndExit = new UITestHelper(metlWindow);
            logoutAndExit.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_LOGOUT_AND_EXIT_BACKNAV_BUTTON));

            logoutAndExit.WaitForControlExist();
            logoutAndExit.AutomationElement.Invoke(); 

            UITestHelper.Wait(TimeSpan.FromSeconds(2));

            Assert.AreEqual(0, MeTL.GetAllMainWindows().Count);
        }
        public void AttachToProcess()
        {
            var win1 = MeTL.StartProcess();
            var win2 = MeTL.StartProcess();

            var metlWindow1 = new UITestHelper();
            var metlWindow2 = new UITestHelper();

            var propertyExpression = new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_MAIN_WINDOW);
            metlWindow1.SearchProperties.Add(propertyExpression);
            metlWindow2.SearchProperties.Add(propertyExpression);
            metlWindow1.WaitForControlExist();
            metlWindow2.WaitForControlExist();

            Thread.Sleep(3000);

            if (windows == null)
                windows = MeTL.GetAllMainWindows();

            Assert.IsTrue(windows.Count == 2, "Expected two instances to be running.");
            Assert.IsNotNull(windows, "Could not find a process named MeTL.  Have you started an instance (it can be clickonce)");
        }
 public void Setup()
 {
     metlWindow = MeTL.GetMainWindow();
     metlWindow.AutomationElement.SetFocus();
 }
 public void UITestHelperConstructorTest()
 {
     UITestHelper target = new UITestHelper();
     Assert.Inconclusive("TODO: Implement code to verify target");
 }
        public void SwitchToSearchMyConversations()
        {
            new ApplicationPopup(metlWindow.AutomationElement).SearchMyConversation();

            var filter = new UITestHelper(metlWindow);
            filter.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_SEARCH_ALL_CONVERSATIONS_BUTTON));

            var success = filter.WaitForControlVisible();
            Assert.IsTrue(success, ErrorMessages.WAIT_FOR_CONTROL_FAILED);

            var filterButton = filter.AutomationElement;
            Assert.AreEqual("Filter my Conversations", filterButton.Current.Name, ErrorMessages.EXPECTED_CONTENT);

            var results = new UITestHelper(metlWindow);
            results.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_CONVERSATION_SEARCH_RESULTS));

            results.WaitForControlCondition((uiControl) => { return Rect.Empty.Equals(uiControl.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty)); });
        }
        public void AddPageToConversation()
        {
            var slideDisplay = new UITestHelper(metlWindow, metlWindow.AutomationElement.Descendant(typeof(SlideDisplay)));
            var rangeValue = slideDisplay.AutomationElement.GetCurrentPattern(RangeValuePattern.Pattern) as RangeValuePattern;
            var currentCount = rangeValue.Current.Maximum;

            var navi = new SlideNavigation(metlWindow.AutomationElement);

            navi.Add();

            slideDisplay.WaitForControlCondition((uiControl) =>
            {
                var range = uiControl.GetCurrentPattern(RangeValuePattern.Pattern) as RangeValuePattern;
                return range.Current.Maximum == currentCount;
            });
    
            Assert.AreEqual(currentCount + 1, rangeValue.Current.Maximum);
        }
 public void Setup()
 {
     metlWindow = MeTL.GetMainWindow();
 }
        public void DeleteCurrentConversation()
        {
            var results = new UITestHelper(metlWindow);
            results.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_CONVERSATION_SEARCH_RESULTS));

            results.WaitForControlCondition((uiControl) => { return Rect.Empty.Equals(uiControl.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty)); });
            
            var editConversation = new ConversationEditScreen(results.AutomationElement);

            editConversation.Delete();
        }
        public void Setup()
        {
            MeTL.StartProcess();

            metlWindow = MeTL.GetMainWindow();
        }
 public UITestHelper(UITestHelper parent, AutomationElement child) : this(parent)
 {
     matchingElement = child;
 }
        private void DeleteTextbox()
        {
            var deleteButton = new UITestHelper(metlWindow);
            deleteButton.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, "deleteButton"));

            var success = deleteButton.WaitForControlExist();
            Assert.IsTrue(success, ErrorMessages.WAIT_FOR_CONTROL_FAILED);

            deleteButton.AutomationElement.Invoke(); 
        }
        public void SearchForHavePermissionAndJoin()
        {
            var search = new ConversationSearcher(metlWindow.AutomationElement);

            search.searchField(TestConstants.NONOWNER_CONVERSATION_TITLE);
            search.Search();

            var results = new UITestHelper(metlWindow);
            results.SearchProperties.Add(new PropertyExpression(AutomationElement.AutomationIdProperty, Constants.ID_METL_CONVERSATION_SEARCH_RESULTS));

            results.WaitForControlCondition((uiControl) => { return Rect.Empty.Equals(uiControl.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty)); });

            search.JoinQueried(TestConstants.NONOWNER_CONVERSATION_TITLE);
        }