public void AddressBook()
        {
            // Get account name
            var desktop   = AutomationElement.RootElement;
            var nameSpace = outlookApp.GetNamespace("MAPI");

            Outlook.MAPIFolder folder   = nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
            string             userName = folder.Parent.Name;

            // Get outlook window
            var condition_Outlook = new PropertyCondition(AutomationElement.NameProperty, "Inbox - " + userName + " - Outlook");
            var window_outlook    = Utilities.WaitForElement(desktop, condition_Outlook, TreeScope.Children, 10);

            // Select Home tab
            Condition            cd_RibbonTabs      = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TabItem), new PropertyCondition(AutomationElement.NameProperty, "Home"));
            AutomationElement    item_RibbonTabs    = Utilities.WaitForElement(window_outlook, cd_RibbonTabs, TreeScope.Descendants, 300);
            SelectionItemPattern pattern_RibbonTabs = (SelectionItemPattern)item_RibbonTabs.GetCurrentPattern(SelectionItemPattern.Pattern);

            if (pattern_RibbonTabs.Current.IsSelected == false)
            {
                pattern_RibbonTabs.Select();
            }

            // Select Address Book tab
            Condition         cd_AddressButton      = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Address Book..."));
            AutomationElement item_AddressButton    = Utilities.WaitForElement(window_outlook, cd_AddressButton, TreeScope.Descendants, 300);
            InvokePattern     pattern_AddressButton = (InvokePattern)item_AddressButton.GetCurrentPattern(InvokePattern.Pattern);

            pattern_AddressButton.Invoke();

            // Get the pop up Address Book window
            var condition_AddressWin = new PropertyCondition(AutomationElement.NameProperty, "Address Book: Global Address List");
            var window_AddressWin    = Utilities.WaitForElement(desktop, condition_AddressWin, TreeScope.Children, 30000);

            // Find NameOnly checkBox and select it
            PropertyCondition    cd_nameOnly      = new PropertyCondition(AutomationElement.NameProperty, "Name only");
            AutomationElement    item_nameOnly    = Utilities.WaitForElement(window_AddressWin, cd_nameOnly, TreeScope.Descendants, 10);
            SelectionItemPattern pattern_nameOnly = (SelectionItemPattern)item_nameOnly.GetCurrentPattern(SelectionItemPattern.Pattern);

            if (pattern_nameOnly.Current.IsSelected == false)
            {
                pattern_nameOnly.Select();
            }

            // Focus on search text and input a search value
            Condition         cd_textSearch       = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit), new PropertyCondition(AutomationElement.NameProperty, "Search:"));
            AutomationElement item_textSearch     = Utilities.WaitForElement(window_AddressWin, cd_textSearch, TreeScope.Descendants, 10);
            ValuePattern      pattern_textGoValue = (ValuePattern)item_textSearch.GetCurrentPattern(ValuePattern.Pattern);

            item_textSearch.SetFocus();
            pattern_textGoValue.SetValue("hi");
            Thread.Sleep(10000);

            Condition         cd_close      = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Close"));
            AutomationElement item_close    = Utilities.WaitForElement(window_AddressWin, cd_close, TreeScope.Descendants, 10);
            InvokePattern     pattern_close = (InvokePattern)item_close.GetCurrentPattern(InvokePattern.Pattern);

            pattern_close.Invoke();

            // Parse the saved trace using MAPI Inspector
            List <string> allRopLists = new List <string>();
            bool          result      = MessageParser.ParseMessage(out allRopLists);

            // Update the XML file for the covered message
            Utilities.UpdateXMLFile(allRopLists);

            // Assert failed if the parsed result has error
            Assert.IsTrue(result, "Case failed, check the details information in error.txt file.");
        }
        public void NewRecurringMeetingAndUpdateOneStartTime()
        {
            // Get account name
            var desktop   = AutomationElement.RootElement;
            var nameSpace = outlookApp.GetNamespace("MAPI");

            Outlook.MAPIFolder folder   = nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
            string             userName = folder.Parent.Name;

            // Get outlook window
            var condition_Outlook = new PropertyCondition(AutomationElement.NameProperty, "Inbox - " + userName + " - Outlook");
            var window_outlook    = Utilities.WaitForElement(desktop, condition_Outlook, TreeScope.Children, 10);

            // Get New Items and click it to new create meeting
            Condition             condition_NewItems = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.MenuItem), new PropertyCondition(AutomationElement.NameProperty, "New Items"));
            var                   item_NewItems      = Utilities.WaitForElement(window_outlook, condition_NewItems, TreeScope.Descendants, 10);
            ExpandCollapsePattern pattern_NewItems   = (ExpandCollapsePattern)item_NewItems.GetCurrentPattern(ExpandCollapsePatternIdentifiers.Pattern);

            pattern_NewItems.Expand();
            AutomationElement listItem = item_NewItems.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Meeting"));
            InvokePattern     clickPattern_listItem = (InvokePattern)listItem.GetCurrentPattern(InvokePattern.Pattern);

            clickPattern_listItem.Invoke();

            // Get Untitled - Meeting Window
            var condition_MeetingWindow = new PropertyCondition(AutomationElement.NameProperty, "Untitled - Meeting  ");
            var window_Meeting          = Utilities.WaitForElement(desktop, condition_MeetingWindow, TreeScope.Children, 10);

            // Add recipient in "To" text
            Condition         cd_to      = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit), new PropertyCondition(AutomationElement.NameProperty, "To"));
            AutomationElement item_to    = Utilities.WaitForElement(window_Meeting, cd_to, TreeScope.Descendants, 10);
            ValuePattern      pattern_to = (ValuePattern)item_to.GetCurrentPattern(ValuePattern.Pattern);

            item_to.SetFocus();
            string safeRecipent = ConfigurationManager.AppSettings["safeRecipients"].ToString();

            Thread.Sleep(100);
            SendKeys.SendWait(safeRecipent);

            // Add subject in subject text
            Condition         cd_Subject      = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document), new PropertyCondition(AutomationElement.NameProperty, "Subject"));
            AutomationElement item_Subject    = Utilities.WaitForElement(window_Meeting, cd_Subject, TreeScope.Descendants, 10);
            ValuePattern      pattern_Subject = (ValuePattern)item_Subject.GetCurrentPattern(ValuePattern.Pattern);

            item_Subject.SetFocus();
            pattern_Subject.SetValue("Meeting test");

            // Add value for location
            Condition         cd_Location      = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ComboBox), new PropertyCondition(AutomationElement.NameProperty, "Location"));
            AutomationElement item_Location    = Utilities.WaitForElement(window_Meeting, cd_Location, TreeScope.Descendants, 10);
            ValuePattern      pattern_Location = (ValuePattern)item_Location.GetCurrentPattern(ValuePattern.Pattern);

            item_Location.SetFocus();
            pattern_Location.SetValue("1");

            // click recurrence button to make this meeting recurrence
            Condition         cd_Recurrence         = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Recurrence..."));
            AutomationElement item_Recurrence       = Utilities.WaitForElement(window_Meeting, cd_Recurrence, TreeScope.Descendants, 10);
            TogglePattern     pattern_TogRecurrence = (TogglePattern)item_Recurrence.GetCurrentPattern(TogglePattern.Pattern);

            pattern_TogRecurrence.Toggle();
            PropertyCondition cd_RecurrenceWindow   = new PropertyCondition(AutomationElement.NameProperty, "Appointment Recurrence");
            AutomationElement item_RecurrenceWindow = Utilities.WaitForElement(window_Meeting, cd_RecurrenceWindow, TreeScope.Descendants, 10);
            Condition         cd_EndByEdit          = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit), new PropertyCondition(AutomationElement.NameProperty, "End by:"));
            AutomationElement item_EndByEdit        = Utilities.WaitForElement(item_RecurrenceWindow, cd_EndByEdit, TreeScope.Descendants, 10);
            ValuePattern      pattern_EndByEdit     = (ValuePattern)item_EndByEdit.GetCurrentPattern(ValuePattern.Pattern);

            item_EndByEdit.SetFocus();
            pattern_EndByEdit.SetValue(DateTime.Today.AddDays(1).ToShortDateString());
            Condition         cd_OKButton   = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "OK"));
            AutomationElement item_OKButton = Utilities.WaitForElement(item_RecurrenceWindow, cd_OKButton, TreeScope.Descendants, 10);
            InvokePattern     pattern_OK    = (InvokePattern)item_OKButton.GetCurrentPattern(InvokePattern.Pattern);

            pattern_OK.Invoke();

            // Get Untitled - Meeting Window
            var condition_MeetingSeriesWindow = new PropertyCondition(AutomationElement.NameProperty, "Meeting test - Meeting Series  ");
            var window_MeetingSeriesWindow    = Utilities.WaitForElement(desktop, condition_MeetingSeriesWindow, TreeScope.Children, 10);

            // Check the receiver name
            Condition         cd_CheckName      = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Check Names"));
            AutomationElement item_CheckName    = Utilities.WaitForElement(window_MeetingSeriesWindow, cd_CheckName, TreeScope.Descendants, 10);
            InvokePattern     pattern_CheckName = (InvokePattern)item_CheckName.GetCurrentPattern(InvokePattern.Pattern);

            pattern_CheckName.Invoke();

            // Send meeting
            Condition         cd_send      = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Send"));
            AutomationElement item_send    = Utilities.WaitForElement(window_MeetingSeriesWindow, cd_send, TreeScope.Descendants, 10);
            InvokePattern     pattern_send = (InvokePattern)item_send.GetCurrentPattern(InvokePattern.Pattern);

            pattern_send.Invoke();

            // Get the newest meeting and update it
            Outlook.AppointmentItem appointmentSended = Utilities.GetAppointment();

            // Create the recall function for when "meeting" window opening
            AutomationEventHandler eventHandler = new AutomationEventHandler(Utilities.OnWindowOpen);

            // Registers the listener event
            Automation.AddAutomationEventHandler(WindowPattern.WindowOpenedEvent, desktop, TreeScope.Children, eventHandler);
            appointmentSended.Display(true);

            Outlook.Folder calFolder = outlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar) as Outlook.Folder;
            Utilities.DeleteAllItemInMAPIFolder(calFolder);

            // Parse the saved trace using MAPI Inspector
            List <string> allRopLists = new List <string>();
            bool          result      = MessageParser.ParseMessage(out allRopLists);

            // Update the XML file for the covered message
            Utilities.UpdateXMLFile(allRopLists);

            // Assert failed if the parsed result has error
            Assert.IsTrue(result, "Case failed, check the details information in error.txt file.");
        }
        public void ModifyMailViewArrage()
        {
            // Create and send a simple mail
            Outlook.MailItem omail = Utilities.CreateSimpleEmail();
            Utilities.SendEmail(omail);

            // Get the latest send mail from send mail folder
            Outlook.MailItem omailSend = Utilities.GetNewestItemInMAPIFolder(sentMailFolder, "Email subject");

            // Get account name
            var desktop   = AutomationElement.RootElement;
            var nameSpace = outlookApp.GetNamespace("MAPI");

            Outlook.MAPIFolder folder   = nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
            string             userName = folder.Parent.Name;

            // Get outlook window
            var condition_Outlook = new PropertyCondition(AutomationElement.NameProperty, "Inbox - " + userName + " - Outlook");
            var window_outlook    = Utilities.WaitForElement(desktop, condition_Outlook, TreeScope.Children, 10);

            // Get View tab and select it
            Condition            cd_RibbonTabs      = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TabItem), new PropertyCondition(AutomationElement.NameProperty, "View"));
            AutomationElement    item_RibbonTabs    = Utilities.WaitForElement(window_outlook, cd_RibbonTabs, TreeScope.Descendants, 300);
            SelectionItemPattern pattern_RibbonTabs = (SelectionItemPattern)item_RibbonTabs.GetCurrentPattern(SelectionItemPattern.Pattern);

            pattern_RibbonTabs.Select();

            // Get the window visual states, and make sure the window is in maximized size
            WindowPattern     pattern_window    = (WindowPattern)window_outlook.GetCurrentPattern(WindowPatternIdentifiers.Pattern);
            WindowVisualState windowVisualState = pattern_window.Current.WindowVisualState;

            if (windowVisualState != WindowVisualState.Maximized)
            {
                Condition         cd_Max       = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Maximize"));
                AutomationElement item_Max     = Utilities.WaitForElement(window_outlook, cd_Max, TreeScope.Descendants, 300);
                InvokePattern     pattern_Max1 = (InvokePattern)item_Max.GetCurrentPattern(InvokePattern.Pattern);
                pattern_Max1.Invoke();
            }

            // Select Categories item in view tab window
            AutomationElement item_categories    = window_outlook.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Categories"));
            InvokePattern     pattern_categories = (InvokePattern)item_categories.GetCurrentPattern(InvokePattern.Pattern);

            pattern_categories.Invoke();

            // Get the latest received mail in Inbox folder
            Outlook.MailItem omailReceived = Utilities.GetNewestItemInMAPIFolder(inboxFolders, "Email subject");

            // Collapse the mail grouped by Categories
            int       inboxItemCount   = inboxFolders.Items.Count;
            int       inboxUnreadCount = inboxFolders.UnReadItemCount;
            Condition cd_cateExpandGroup;

            cd_cateExpandGroup = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Group), new PropertyCondition(AutomationElement.NameProperty, string.Format("Group By: Expanded: Categories: (none): {0} item(s)", inboxItemCount)));
            AutomationElement item_cateExpandGroup = Utilities.WaitForElement(window_outlook, cd_cateExpandGroup, TreeScope.Descendants, 300);

            if (item_cateExpandGroup == null)
            {
                cd_cateExpandGroup   = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Group), new PropertyCondition(AutomationElement.NameProperty, string.Format("Group By: Expanded: Categories: (none): {0} item(s), {1} unread", inboxItemCount, inboxUnreadCount)));
                item_cateExpandGroup = Utilities.WaitForElement(window_outlook, cd_cateExpandGroup, TreeScope.Descendants, 300);
            }

            ExpandCollapsePattern pattern_cateExpandGroup = (ExpandCollapsePattern)item_cateExpandGroup.GetCurrentPattern(ExpandCollapsePatternIdentifiers.Pattern);

            pattern_cateExpandGroup.Collapse();

            // Select Date item in view tab window
            AutomationElement item_date    = window_outlook.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Date"));
            InvokePattern     pattern_date = (InvokePattern)item_date.GetCurrentPattern(InvokePattern.Pattern);

            pattern_date.Invoke();
            Thread.Sleep(TestBase.waittimeItem);

            // Select Categories item in view tab window
            AutomationElement item_categoriesagain    = window_outlook.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Categories"));
            InvokePattern     pattern_categoriesagain = (InvokePattern)item_categoriesagain.GetCurrentPattern(InvokePattern.Pattern);

            pattern_categoriesagain.Invoke();
            Thread.Sleep(TestBase.waittimeItem);

            // Parse the saved trace using MAPI Inspector
            List <string> allRopLists = new List <string>();
            bool          result      = MessageParser.ParseMessage(out allRopLists);

            // Update the XML file for the covered message
            Utilities.UpdateXMLFile(allRopLists);

            // Assert failed if the parsed result has error
            Assert.IsTrue(result, "Case failed, check the details information in error.txt file.");
        }
        public void ModifyFolderPermissions()
        {
            // Get account name
            var desktop   = AutomationElement.RootElement;
            var nameSpace = outlookApp.GetNamespace("MAPI");

            Outlook.MAPIFolder folder   = nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
            string             userName = folder.Parent.Name;

            // Get outlook window
            var condition_Outlook = new PropertyCondition(AutomationElement.NameProperty, "Inbox - " + userName + " - Outlook");
            var window_outlook    = Utilities.WaitForElement(desktop, condition_Outlook, TreeScope.Children, 10);

            // Get Folder Tab and select it
            Condition            cd_RibbonTabs      = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TabItem), new PropertyCondition(AutomationElement.NameProperty, "Folder"));
            AutomationElement    item_RibbonTabs    = Utilities.WaitForElement(window_outlook, cd_RibbonTabs, TreeScope.Descendants, 300);
            SelectionItemPattern pattern_RibbonTabs = (SelectionItemPattern)item_RibbonTabs.GetCurrentPattern(SelectionItemPattern.Pattern);

            pattern_RibbonTabs.Select();

            // Get "Folder Permissions" and select it
            Condition         cd_FolderPermissions           = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Folder Permissions"));
            AutomationElement item_FolderPermissions         = Utilities.WaitForElement(window_outlook, cd_FolderPermissions, TreeScope.Descendants, 10);
            InvokePattern     clickPattern_FolderPermissions = (InvokePattern)item_FolderPermissions.GetCurrentPattern(InvokePattern.Pattern);

            clickPattern_FolderPermissions.Invoke();

            // Get "Inbox Properties" window
            var condition_permission = new PropertyCondition(AutomationElement.NameProperty, "Inbox Properties");
            var window_FolderProp    = Utilities.WaitForElement(window_outlook, condition_permission, TreeScope.Children, 10);

            // Get and select "Create items"
            Condition         cd_write      = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.CheckBox), new PropertyCondition(AutomationElement.NameProperty, "Edit all"));
            AutomationElement item_write    = Utilities.WaitForElement(window_FolderProp, cd_write, TreeScope.Descendants, 10);
            TogglePattern     pattern_write = (TogglePattern)item_write.GetCurrentPattern(TogglePattern.Pattern);

            if (pattern_write.Current.ToggleState == ToggleState.Off)
            {
                pattern_write.Toggle();

                // Click OK in Microsoft Outlook dialog box
                var           condition_Dailog      = new PropertyCondition(AutomationElement.NameProperty, "Microsoft Outlook");
                var           window_Dailog         = Utilities.WaitForElement(window_FolderProp, condition_Dailog, TreeScope.Children, 10);
                var           condition_DailogOK    = new PropertyCondition(AutomationElement.AutomationIdProperty, "6");
                var           item_DailogOK         = Utilities.WaitForElement(window_Dailog, condition_DailogOK, TreeScope.Children, 10);
                InvokePattern clickPattern_DailogOK = (InvokePattern)item_DailogOK.GetCurrentPattern(InvokePattern.Pattern);
                clickPattern_DailogOK.Invoke();
            }

            // Click OK in "Inbox Properties" window
            var           condition_FolderPropOK        = new PropertyCondition(AutomationElement.AutomationIdProperty, "1");
            var           item_FolderPropertyOK         = Utilities.WaitForElement(window_FolderProp, condition_FolderPropOK, TreeScope.Children, 10);
            InvokePattern clickPattern_FolderPropertyOK = (InvokePattern)item_FolderPropertyOK.GetCurrentPattern(InvokePattern.Pattern);

            clickPattern_FolderPropertyOK.Invoke();

            // Parse the saved trace using MAPI Inspector
            List <string> allRopLists = new List <string>();
            bool          result      = MessageParser.ParseMessage(out allRopLists);

            // Update the XML file for the covered message
            Utilities.UpdateXMLFile(allRopLists);

            // Assert failed if the parsed result has error
            Assert.IsTrue(result, "Case failed, check the details information in error.txt file.");
        }
Example #5
0
        public void JunkAddRemoveRecipert()
        {
            // Get account name
            var desktop   = AutomationElement.RootElement;
            var nameSpace = outlookApp.GetNamespace("MAPI");

            Outlook.MAPIFolder folder       = nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
            string             userName     = folder.Parent.Name;
            string             safeRecipent = ConfigurationManager.AppSettings["safeRecipients"].ToString();

            // Get outlook window
            var condition_Outlook = new PropertyCondition(AutomationElement.NameProperty, "Inbox - " + userName + " - Outlook");
            var window_outlook    = Utilities.WaitForElement(desktop, condition_Outlook, TreeScope.Children, 10);

            // Get Junk item and expand it
            PropertyCondition     cd_Junk               = new PropertyCondition(AutomationElement.NameProperty, "Junk");
            AutomationElement     item_Junk             = Utilities.WaitForElement(window_outlook, cd_Junk, TreeScope.Descendants, 300);
            ExpandCollapsePattern expandCollapsePattern = (ExpandCollapsePattern)item_Junk.GetCurrentPattern(ExpandCollapsePatternIdentifiers.Pattern);

            expandCollapsePattern.Expand();

            // Select "Junk E-mail Options..."
            AutomationElement item_JunkOptions         = item_Junk.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.NameProperty, "Junk E-mail Options..."));
            InvokePattern     clickPattern_JunkOptions = (InvokePattern)item_JunkOptions.GetCurrentPattern(InvokePattern.Pattern);

            clickPattern_JunkOptions.Invoke();

            // Get Junk E-mail Options window
            PropertyCondition condition_JunkWindow;

            condition_JunkWindow = new PropertyCondition(AutomationElement.NameProperty, "Junk Email Options - " + userName);
            AutomationElement window_JunkWindow = Utilities.WaitForElement(window_outlook, condition_JunkWindow, TreeScope.Children, 10);

            if (window_JunkWindow == null)
            {
                condition_JunkWindow = new PropertyCondition(AutomationElement.NameProperty, "Junk E-mail Options - " + userName);
                window_JunkWindow    = Utilities.WaitForElement(window_outlook, condition_JunkWindow, TreeScope.Children, 10);
            }

            // Get and click "safe Recipients" button
            Condition            cd_SafeRecipent      = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TabItem), new PropertyCondition(AutomationElement.NameProperty, "Safe Recipients"));
            AutomationElement    item_SafeRecipent    = Utilities.WaitForElement(window_JunkWindow, cd_SafeRecipent, TreeScope.Descendants, 10);
            SelectionItemPattern pattern_SafeRecipent = (SelectionItemPattern)item_SafeRecipent.GetCurrentPattern(SelectionItemPattern.Pattern);

            pattern_SafeRecipent.Select();

            // Get recipient list item
            Condition cd_recipentList = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ListItem), new PropertyCondition(AutomationElement.NameProperty, safeRecipent));
            var       setRecipent     = window_JunkWindow.FindFirst(TreeScope.Descendants, cd_recipentList);

            if (setRecipent == null)
            {
                // Click Add button
                Condition     cd_recipentAdd      = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Add..."));
                var           item_recipentAdd    = Utilities.WaitForElement(window_JunkWindow, cd_recipentAdd, TreeScope.Descendants, 10);
                InvokePattern pattern_recipentAdd = (InvokePattern)item_recipentAdd.GetCurrentPattern(InvokePattern.Pattern);
                pattern_recipentAdd.Invoke();

                // Get "Add address or domain" window
                var condition_AddWindow = new PropertyCondition(AutomationElement.NameProperty, "Add address or domain");
                var window_AddWindow    = Utilities.WaitForElement(window_JunkWindow, condition_AddWindow, TreeScope.Children, 10);

                // Input the address need to added
                var          condition_edit = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit);
                var          item_edit      = Utilities.WaitForElement(window_AddWindow, condition_edit, TreeScope.Children, 10);
                ValuePattern pattern_edit   = (ValuePattern)item_edit.GetCurrentPattern(ValuePattern.Pattern);
                item_edit.SetFocus();
                pattern_edit.SetValue(safeRecipent);

                // Click OK in "Add address or domain" window
                var           condition_AddOK    = new PropertyCondition(AutomationElement.NameProperty, "OK");
                var           item_AddOK         = Utilities.WaitForElement(window_AddWindow, condition_AddOK, TreeScope.Children, 10);
                InvokePattern clickPattern_AddOK = (InvokePattern)item_AddOK.GetCurrentPattern(InvokePattern.Pattern);
                clickPattern_AddOK.Invoke();

                // Click OK in "Junk E-mail Options" window
                var           condition_JunkOK    = new PropertyCondition(AutomationElement.NameProperty, "OK");
                var           item_JunkOK         = Utilities.WaitForElement(window_JunkWindow, condition_JunkOK, TreeScope.Children, 10);
                InvokePattern clickPattern_JunkOK = (InvokePattern)item_JunkOK.GetCurrentPattern(InvokePattern.Pattern);
                clickPattern_JunkOK.Invoke();
                Thread.Sleep(20000);
            }
            else
            {
                SelectionItemPattern pattern_S = (SelectionItemPattern)setRecipent.GetCurrentPattern(SelectionItemPattern.Pattern);
                pattern_S.Select();

                // Click Add button
                Condition     cd_recipentAdd      = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Add..."));
                var           item_recipentAdd    = Utilities.WaitForElement(window_JunkWindow, cd_recipentAdd, TreeScope.Descendants, 10);
                InvokePattern pattern_recipentAdd = (InvokePattern)item_recipentAdd.GetCurrentPattern(InvokePattern.Pattern);
                pattern_recipentAdd.Invoke();

                // Get "Add address or domain" window
                var condition_AddWindow = new PropertyCondition(AutomationElement.NameProperty, "Add address or domain");
                var window_AddWindow    = Utilities.WaitForElement(window_JunkWindow, condition_AddWindow, TreeScope.Children, 10);

                // Close the "Add address or domain" window:  this step is used to enable the edit button in window_JunkWindow
                var           condition_cancel = new PropertyCondition(AutomationElement.NameProperty, "Cancel");
                var           item_cancel      = Utilities.WaitForElement(window_AddWindow, condition_cancel, TreeScope.Children, 10);
                InvokePattern pattern_cancel   = (InvokePattern)item_cancel.GetCurrentPattern(InvokePattern.Pattern);
                pattern_cancel.Invoke();

                // Click remove button in "Junk E-mail Options" window
                Condition     cd_recipentEdit      = new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button), new PropertyCondition(AutomationElement.NameProperty, "Remove"));
                var           item_recipentEdit    = Utilities.WaitForElement(window_JunkWindow, cd_recipentEdit, TreeScope.Descendants, 10);
                InvokePattern pattern_recipentEdit = (InvokePattern)item_recipentEdit.GetCurrentPattern(InvokePattern.Pattern);
                pattern_recipentEdit.Invoke();

                // Click OK in "Junk E-mail Options" window
                var           condition_JunkOK    = new PropertyCondition(AutomationElement.NameProperty, "OK");
                var           item_JunkOK         = Utilities.WaitForElement(window_JunkWindow, condition_JunkOK, TreeScope.Children, 10);
                InvokePattern clickPattern_JunkOK = (InvokePattern)item_JunkOK.GetCurrentPattern(InvokePattern.Pattern);
                clickPattern_JunkOK.Invoke();
                Thread.Sleep(20000);
            }

            // Parse the saved trace using MAPI Inspector
            List <string> allRopLists = new List <string>();
            bool          result      = MessageParser.ParseMessage(out allRopLists);

            // Update the XML file for the covered message
            Utilities.UpdateXMLFile(allRopLists);

            // Assert failed if the parsed result has error
            Assert.IsTrue(result, "Case failed, check the details information in error.txt file.");
        }
Example #6
0
        public void Initialize()
        {
            this.GetTestCatgoryInformation();
            EndStartedOutLook();
            Thread.Sleep(10000);
            MessageParser.ClearSessions();
            string outLookPath = ConfigurationManager.AppSettings["OutLookPath"].ToString();

            waittimeWindow = int.Parse(ConfigurationManager.AppSettings["WaitTimeWindow"].ToString());
            waittimeItem   = int.Parse(ConfigurationManager.AppSettings["WaitTimeItem"].ToString());
            Process p = Process.Start(outLookPath);

            AutomationElement outlookWindow = null;
            var    desktop           = AutomationElement.RootElement;
            string userName          = ConfigurationManager.AppSettings["Office365Account"].ToString();
            var    condition_Outlook = new PropertyCondition(AutomationElement.NameProperty, "Inbox - " + userName + " - Outlook");

            int count = 0;

            while (outlookWindow == null)
            {
                outlookWindow = desktop.FindFirst(TreeScope.Children, condition_Outlook);
                Thread.Sleep(waittimeItem / 10);
                count += waittimeItem / 10;
                if (count >= waittimeWindow)
                {
                    break;
                }
            }

            Process[] pp = Process.GetProcesses();
            if (pp.Count() > 0)
            {
                foreach (Process pp1 in pp)
                {
                    if (pp1.ProcessName != "OUTLOOK" && pp1.ProcessName != "explorer" && pp1.MainWindowHandle != IntPtr.Zero)
                    {
                        AutomationElement element = AutomationElement.FromHandle(pp1.MainWindowHandle);
                        if (element != null)
                        {
                            try
                            {
                                element.SetFocus();
                            }
                            catch
                            {
                                continue;
                            }
                        }

                        break;
                    }
                }
            }

            Thread.Sleep(waittimeItem);
            try
            {
                outlookApp = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;
            }
            catch
            {
                throw new Exception("Get active outlook application failed, please check if outlook is running");
            }

            inboxFolders        = outlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
            sentMailFolder      = outlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
            deletedItemsFolders = outlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDeletedItems);
            draftsFolders       = outlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDrafts);
        }
Example #7
0
 public static void AssemblyCleanup()
 {
     MessageParser.CloseFiddler();
     GenerateReport.GenerateCoverageReport();
 }
Example #8
0
 public static void AssemblyInit(TestContext context)
 {
     MessageParser.StartFiddler();
 }