/// <summary>
        /// Execute the menu display toggle
        /// </summary>
        public static void ToggleMenu()
        {
            var element = GraphBrowser.FindElement(By.Id("toggleLeftPanel"));

            GraphBrowser.Click(element);
            GraphBrowser.Wait(TimeSpan.FromSeconds(2));
        }
        public static void ClickLogin()
        {
            GraphBrowser.Wait(By.XPath("/html/body/div[1]/div/div[2]/div/div/div/div/article[2]/div/div/div/div[1]/button"));
            var element = GraphBrowser.FindElement(By.XPath("/html/body/div[1]/div/div[2]/div/div/div/div/article[2]/div/div/div/div[1]/button"));

            GraphBrowser.Click(element);
        }
        public static void ClickLogout()
        {
            GraphBrowser.Wait(By.XPath("//a[@ng-click='logout()']"));
            var element = GraphBrowser.FindElement(By.XPath("//a[@ng-click='logout()']"));

            GraphBrowser.Click(element);
        }
        public static void InputExplorerHeaders(string properties)
        {
            GraphBrowser.Wait(By.XPath("/html/body/div[1]/div/div[2]/div/div/div/div/article[2]/div/div/div/div/md-tabs[1]/md-tabs-content-wrapper/md-tab-content[1]/div/div/textarea"));
            var element = GraphBrowser.FindElement(By.XPath("/html/body/div[1]/div/div[2]/div/div/div/div/article[2]/div/div/div/div/md-tabs[1]/md-tabs-content-wrapper/md-tab-content[1]/div/div/textarea"));

            element.SendKeys(properties);
        }
        /// <summary>
        /// Get the banner image url of MS Graph site
        /// </summary>
        /// <returns>The url of the banner image</returns>
        public static string GetGraphBannerImageUrl()
        {
            var element = GraphBrowser.FindElement(By.Id("banner-image"));

            if (element == null)
            {
                element = GraphBrowser.FindElement(By.CssSelector("div#layout-featured>div>article>div>div>div>div"));
            }
            string styleString = element.GetAttribute("style");

            string[] styles = styleString.Split(';');

            string url = string.Empty;

            foreach (string style in styles)
            {
                if (style.Contains("background-image"))
                {
                    int startIndex = style.IndexOf("http");
                    //2 is the length of ") or ')
                    url = style.Substring(startIndex, style.Substring(startIndex).Length - 2);
                    break;
                }
            }
            return(url);
        }
        public static List <SearchedResult> SearchText(string keyWord)
        {
            List <SearchedResult> searchedResults = new List <SearchedResult>();

            var element = GraphBrowser.FindElement(By.CssSelector("input#q"));

            element.Clear();
            element.SendKeys(keyWord);
            var searchButton = GraphBrowser.FindElement(By.XPath("//button[text()='Search']"));

            GraphBrowser.Click(searchButton);

            GraphBrowser.Wait(By.CssSelector("ul#local-docs-ul>li"));
            int resultCount = GraphBrowser.webDriver.FindElements(By.CssSelector("ul#local-docs-ul>li")).Count;

            for (int i = 0; i < resultCount; i++)
            {
                SearchedResult result = new SearchedResult();
                result.Name        = GraphBrowser.webDriver.FindElement(By.CssSelector("ul#local-docs-ul>li:nth-child(" + (int)(i + 2) + ")>div > div.event-info > div > div.col-xs-8.name.cp1")).Text;
                result.Description = GraphBrowser.webDriver.FindElement(By.CssSelector("ul#local-docs-ul>li:nth-child(" + (int)(i + 2) + ")> div > div> div.desc")).Text;
                result.DetailLink  = GraphBrowser.webDriver.FindElement(By.CssSelector("ul#local-docs-ul>li:nth-child(" + (int)(i + 2) + ") > div > div.event-info > div > div.col-xs-8.event-links > a")).GetAttribute("href");
                searchedResults.Add(result);
            }
            return(searchedResults);
        }
        /// <summary>
        /// Login on a sign-in page
        /// </summary>
        /// <param name="userName">The userName to input</param>
        /// <param name="password">The password to input</param>
        public static void Login(string userName, string password)
        {
            var userIdElement = GraphBrowser.FindElement(By.Id("cred-userid-inputtext"));

            if (userIdElement.Displayed)
            {
                userIdElement.SendKeys(userName);
            }
            else
            {
                var existentUser = GraphBrowser.webDriver.FindElement(By.CssSelector("li#login_user_chooser>a#" + userName.Replace("@", "_").Replace(".", "_") + "_link"));
                GraphBrowser.Click(existentUser);
            }
            var passwordElement = GraphBrowser.FindElement(By.XPath("/html/body/div/div[2]/div[3]/div/div[2]/div/div[5]/form/div[4]/div/input"));

            passwordElement.SendKeys(password);
            GraphBrowser.Wait(By.XPath("/html/body/div/div[2]/div[3]/div/div[2]/div/div[5]/form/div[6]/input[1]"));
            var signInElement = GraphBrowser.FindElement(By.XPath("/html/body/div/div[2]/div[3]/div/div[2]/div/div[5]/form/div[6]/input[1]"));
            int waitTime      = Int32.Parse(GraphUtility.GetConfigurationValue("WaitTime"));
            int retryCount    = Int32.Parse(GraphUtility.GetConfigurationValue("RetryCount"));
            int i             = 0;

            do
            {
                GraphBrowser.Wait(TimeSpan.FromSeconds(waitTime));
                //Reload the element to avoid it timeout
                signInElement = GraphBrowser.FindElement(By.XPath("/html/body/div/div[2]/div[3]/div/div[2]/div/div[5]/form/div[6]/input[1]"));
                i++;
            } while (i < retryCount && !signInElement.Enabled);
            GraphBrowser.Click(signInElement);
        }
Beispiel #8
0
        public bool CanLoadImages(GraphPageImages image)
        {
            switch (image)
            {
            case (GraphPageImages.MainBanner):
                var element = GraphBrowser.FindElement(By.Id("banner-image"));
                //The div in Home page does not have id attribute
                if (element == null)
                {
                    element = GraphBrowser.FindElement(By.CssSelector("div#layout-featured>div>article>div>div>div>div"));
                }
                string Url = ((string)(GraphBrowser.webDriver as IJavaScriptExecutor).ExecuteScript(@"return getComputedStyle(arguments[0])['background-image'];", element)).Replace(@"url(""", "").Replace(@""")", "");
                return(GraphUtility.ImageExist(Url));

            case (GraphPageImages.Others):
                var elements = GraphBrowser.Driver.FindElements(By.CssSelector("img"));
                foreach (IWebElement item in elements)
                {
                    Url = item.GetAttribute("src");
                    if (!GraphUtility.ImageExist(Url))
                    {
                        return(false);
                    }
                }

                return(true);

            default:
                return(false);
            }
        }
Beispiel #9
0
        public bool CanLoadImages(GraphPageImages image)
        {
            string prefix = GraphUtility.RemoveRedundantPartsfromExtractBaseAddress();

            switch (image)
            {
            case (GraphPageImages.MainBanner):
                var    element = GraphBrowser.FindElement(By.TagName("picture")).FindElement(By.TagName("img"));
                string Url     = element.GetAttribute("src");
                //The div in Home page does not have id attribute
                //if (element == null)
                //{
                //    element = GraphBrowser.FindElement(By.CssSelector("div#layout-featured>div>article>div>div>div>div"));
                //}
                //string Url = ((string)(GraphBrowser.webDriver as IJavaScriptExecutor).ExecuteScript(@"return getComputedStyle(arguments[0])['background-image'];", element)).Replace(@"url(""", "").Replace(@""")", "");
                return(GraphUtility.FileExist(Url));

            case (GraphPageImages.Others):
                var elements = GraphBrowser.Driver.FindElements(By.CssSelector("img"));
                foreach (IWebElement item in elements)
                {
                    Url = item.GetAttribute("src");
                    if (!GraphUtility.FileExist(Url))
                    {
                        return(false);
                    }
                }

                return(true);

            default:
                return(false);
            }
        }
Beispiel #10
0
        public bool CanLoadImages(GraphPageImages image)
        {
            switch (image)
            {
            case (GraphPageImages.MainBanner):
                var    element = GraphBrowser.FindElement(By.ClassName("dxp-banner-default"));
                string Url     = ((string)(GraphBrowser.webDriver as IJavaScriptExecutor).ExecuteScript(@"return getComputedStyle(arguments[0])['background-image'];", element)).Replace(@"url(""", "").Replace(@""")", "");
                return(GraphUtility.FileExist(Url));

            case (GraphPageImages.Others):
                var elements = GraphBrowser.Driver.FindElements(By.CssSelector("img"));
                foreach (IWebElement item in elements)
                {
                    Url = item.GetAttribute("src");
                    if (!GraphUtility.FileExist(Url))
                    {
                        return(false);
                    }
                }

                return(true);

            default:
                return(false);
            }
        }
        /// <summary>
        /// Get the document title in the current doc page
        /// </summary>
        /// <returns>The title of document</returns>
        public static string GetDocTitle()
        {
            string docTitle = GraphBrowser.FindElement(By.CssSelector("h1")).Text;

            //If docTitle includes a line break followed by "Edit in GitHub," only return the first part
            string[] titleParts = docTitle.Split('\r');
            return(titleParts[0]);
        }
Beispiel #12
0
        /// <summary>
        /// Wait for the returned response
        /// </summary>
        public static void WaitForExploreResponse()
        {
            GraphBrowser.Wait(By.CssSelector("#jsonViewer > div.ace_scroller > div > div.ace_layer.ace_text-layer > div.ace_line"));
            var element    = GraphBrowser.FindElement(By.CssSelector("#jsonViewer > div.ace_scroller > div > div.ace_layer.ace_text-layer > div.ace_line"));
            int waitTime   = Int32.Parse(GraphUtility.GetConfigurationValue("WaitTime"));
            int retryCount = Int32.Parse(GraphUtility.GetConfigurationValue("RetryCount"));
            int i          = 0;

            do
            {
                GraphBrowser.Wait(TimeSpan.FromSeconds(waitTime));
                element = GraphBrowser.FindElement(By.CssSelector("#jsonViewer > div.ace_scroller > div > div.ace_layer.ace_text-layer > div.ace_line"));
                i++;
            } while (i < retryCount && element.Text.Equals(string.Empty));
        }
 //Wait for doc title to appear, check whether it is "Document not found."
 //If document not found, return "'Document not found' displays to user: "******"Could not find doc title: "
 //If document title exists and is valid, return ""
 public static string ValidateDocumentByTitle()
 {
     try
     {
         GraphBrowser.Wait(By.CssSelector("h1"));
         if (GraphBrowser.FindElement(By.CssSelector("h1")).Text == "Document not found.")
         {
             return("'Document not found' displays to user: "******"Could not find doc title: ");
     }
     return("");
 }
        /// <summary>
        /// Verify whether a TOC item's related sub layer is shown
        /// </summary>
        /// <param name="item">The TOC item</param>
        /// <returns>True if yes, else no.</returns>
        public static bool SubLayerDisplayed(string item)
        {
            string xpath     = @"//nav[@id='home-nav-blade']";
            var    element   = GraphBrowser.FindElement(By.XPath(xpath));
            var    menuItem  = element.FindElement(By.LinkText(item));
            string subMenuId = menuItem.GetAttribute("data-target");

            if (subMenuId != null && subMenuId != string.Empty)
            {
                var subMenu = element.FindElement(By.XPath("//ul[@id='" + subMenuId.Replace("#", string.Empty) + "']"));
                return(subMenu.Displayed);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// Verify whether the logged in user is correct
        /// </summary>
        /// <param name="expectedUserName">The expected logged in user</param>
        /// <returns>True if yes, else no.</returns>
        public static bool IsLoggedIn(string expectedUserName = "")
        {
            GraphBrowser.Wait(By.XPath("//div[@ng-show='userInfo.isAuthenticated']/span"));
            var element = GraphBrowser.FindElement(By.XPath("//div[@ng-show='userInfo.isAuthenticated']/span"));

            if (element.Displayed && expectedUserName != "" && element.Text.Equals(expectedUserName))
            {
                return(true);
            }
            else if (expectedUserName == "" && element.Displayed)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// Format a property to JSON format  and put it in Explorer request field
        /// </summary>
        /// <param name="properties">The properties to format</param>
        public static void InputExplorerJSONBody(Dictionary <string, string> properties)
        {
            GraphBrowser.Wait(By.XPath("/html/body/div[1]/div/div[2]/div/div/div/div/article[2]/div/div/div/div/md-tabs[1]/md-tabs-content-wrapper/md-tab-content[2]/div/div/textarea"));
            var element = GraphBrowser.FindElement(By.CssSelector("div#jsonEditor>textarea"));

            element.SendKeys("{");
            int index = 0;

            foreach (KeyValuePair <string, string> property in properties)
            {
                index++;
                element.SendKeys("\"" + property.Key + "\":\"" + property.Value + "\"");
                if (index != properties.Count)
                {
                    element.SendKeys(",");
                }
            }
            element.SendKeys("}");
        }
        /// <summary>
        /// Get The layer count of TOC
        /// </summary>
        /// <returns>The layer count</returns>
        public static int GetTOCLayer()
        {
            string xpath       = "//nav[@id='home-nav-blade']";
            var    menuElement = GraphBrowser.FindElement(By.XPath(xpath));
            int    layer       = 0;

            try
            {
                do
                {
                    layer++;
                    xpath += "/ul/li";
                    var element = menuElement.FindElement(By.XPath(xpath + "/a"));
                } while (true);
            }
            catch (NoSuchElementException)
            {
            }
            return(layer - 1);
        }
        /// <summary>
        /// Find an link or a button role span according to the specific text and click it
        /// </summary>
        /// <param name="text">The text of the element</param>
        public static void Click(string text)
        {
            var element = GraphBrowser.FindElement(By.LinkText(text));

            //a link
            if (element != null && element.Displayed)
            {
                GraphBrowser.Click(element);
            }
            else
            {
                IReadOnlyList <IWebElement> elements = GraphBrowser.webDriver.FindElements(By.XPath("//*[@role='button']"));
                foreach (IWebElement elementToClick in elements)
                {
                    if (elementToClick.GetAttribute("innerHTML").Equals(text) && (elementToClick.Displayed))
                    {
                        GraphBrowser.Click(elementToClick);
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// Select "Try the API" on Home page
        /// </summary>
        public static void SelectToTryAPI()
        {
            var element = GraphBrowser.FindElement(By.XPath("//div/a[contains(@href,'graph-explorer')]"));

            GraphBrowser.Click(element);
        }
 /// <summary>
 /// Verify if the toggle arrow is found on the page
 /// </summary>
 /// <returns>Trye if yes, else no.</returns>
 public static bool IsToggleArrowDisplayed()
 {
     return(GraphBrowser.FindElement(By.Id("toggleLeftPanelContainer")).Displayed);
 }
 /// <summary>
 /// Check whether in this article control is displayed
 /// </summary>
 /// <returns>True if yes, else no.</returns>
 public static bool IsInThisArticleDisplayed()
 {
     //Wait for in this article to render. Will time out after 45 seconds if failed
     GraphBrowser.Wait(By.CssSelector("#inThisArticle"));
     return(GraphBrowser.FindElement(By.CssSelector("#sidebarcontrol")).GetCssValue("display") != "none");
 }
 /// <summary>
 /// Verify if the menu-content is found on the page
 /// </summary>
 /// <returns>Trye if yes, else no.</returns>
 public static bool IsMenuContentDisplayed()
 {
     return(GraphBrowser.FindElement(By.CssSelector("#docMenu")).Displayed);
 }
        /// <summary>
        /// Try to find a cooperation note on Chinese Explorer page.
        /// </summary>
        /// <returns>True if found, else no.</returns>
        public static bool FindCHNExplorerNote()
        {
            var noteElement = GraphBrowser.FindElement(By.XPath("//div[contains(text(),'注意')]"));

            return(noteElement != null);
        }
        public static void SelectO365AppRegisstration()
        {
            var element = GraphBrowser.FindElement(By.XPath("//a[contains(@href,'dev.office.com/app-registration')]"));

            GraphBrowser.Click(element);
        }
        public static void SelectNewAppRegisstrationPortal()
        {
            var element = GraphBrowser.FindElement(By.XPath("//a[contains(@href,'apps.dev.microsoft.com')]"));

            GraphBrowser.Click(element);
        }
        /// <summary>
        /// Select "See OverView" on Home page
        /// </summary>
        public static void SelectToSeeOverView()
        {
            var element = GraphBrowser.FindElement(By.XPath("//div/a[contains(@href,'/docs')]"));

            GraphBrowser.Click(element);
        }