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);
        }
        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);
        }
        /// <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));
        }
        /// <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);
        }
        public static List <string> TraverseTocAndGetFailedDocs()
        {
            List <string> failedDocs = new List <string>();
            string        xPath      = "//nav[@id='home-nav-blade']/ul/li";
            IWebElement   currElement;
            IReadOnlyList <IWebElement> nextLevelElements;
            Stack elementsToTraverse = new Stack();

            //Initialize stack with each top level element in TOC
            IReadOnlyList <IWebElement> topLevelElements = GraphBrowser.webDriver.FindElements(By.XPath(xPath + "/a"));

            foreach (IWebElement elem in topLevelElements)
            {
                elementsToTraverse.Push(elem);
            }

            while (elementsToTraverse.Count != 0)
            {
                currElement = (IWebElement)elementsToTraverse.Pop();
                //click currElement
                if (currElement.Displayed)
                {
                    GraphBrowser.Click(currElement);
                }
                else
                {
                    return(new List <string> {
                        "The element was not displayed and clickable!", currElement.GetAttribute("href")
                    });
                }

                //Validate that document title exists and isn't "Document not found."
                //Note: even if the current container does not have an associated doc, the user should not see "document not found"
                string validationResult = ValidateDocumentByTitle();
                if (validationResult != "")
                {
                    failedDocs.Add(validationResult + currElement.GetAttribute("href"));
                }

                //Make an HttpWebRequest to ensure that the file exists and does not have "Document not found." title
                validationResult = ValidateDocumentByHttpRequest(currElement.GetAttribute("href"));
                if (validationResult != "")
                {
                    failedDocs.Add(validationResult + currElement.GetAttribute("href"));
                }

                //Find all elements one level down in TOC and add to stack
                nextLevelElements = currElement.FindElements(By.XPath("../ul/li/a"));
                foreach (IWebElement elem in nextLevelElements)
                {
                    elementsToTraverse.Push(elem);
                }
            }

            return(failedDocs);
        }
        /// <summary>
        /// Find a button according to the specific text and click it
        /// </summary>
        /// <param name="text">The text of the element</param>
        public static void ClickButton(string text)
        {
            IReadOnlyList <IWebElement> elements = GraphBrowser.webDriver.FindElements(By.TagName("button"));

            foreach (IWebElement elementToClick in elements)
            {
                if (elementToClick.GetAttribute("innerHTML").Trim().Contains(text) && elementToClick.Displayed)
                {
                    GraphBrowser.Click(elementToClick);
                    break;
                }
            }
        }
Beispiel #8
0
        public string Select(string menuName)
        {
            string menuItemText = string.Empty;

            switch (menuName)
            {
            case ("Home"):
                menuItemText = homeLinkElement.Text;
                GraphBrowser.Click(homeLinkElement);
                break;

            case ("Get started"):
                menuItemText = getstartedLinkElement.Text;
                GraphBrowser.Click(getstartedLinkElement);
                break;

            case ("Documentation"):
                menuItemText = documentationLinkElement.Text;
                GraphBrowser.Click(documentationLinkElement);
                break;

            case ("Graph explorer"):
                menuItemText = exploreLinkElement.Text;
                GraphBrowser.Click(exploreLinkElement);
                break;

            case ("App registration"):
                menuItemText = appregistrationLinkElement.Text;
                GraphBrowser.Click(appregistrationLinkElement);
                break;

            case ("Samples & SDKs"):
                menuItemText = samplesandsdksLinkElement.Text;
                GraphBrowser.Click(samplesandsdksLinkElement);
                break;

            case ("Changelog"):
                menuItemText = changelogLinkElement.Text;
                GraphBrowser.Click(changelogLinkElement);
                break;

            default:
                break;
            }
            return(menuItemText);
        }
        /// <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>
        /// 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);
        }
        public static void SelectNewAppRegisstrationPortal()
        {
            var element = GraphBrowser.FindElement(By.XPath("//a[contains(@href,'apps.dev.microsoft.com')]"));

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

            GraphBrowser.Click(element);
        }
Beispiel #14
0
        public string Select(string menuName, bool prodSite = false)
        {
            IWebElement menuItem;
            string      menuItemText = string.Empty;

            switch (menuName)
            {
            case ("Home"):
                //if (prodSite)
                //{
                //    menuItem = GraphBrowser.FindElement(By.XPath("//a[@class='c-logo c-top-nav-link' and contains(@href,'/graph')"));
                //}
                //else
                //{
                //    menuItem = GraphBrowser.FindElement(By.XPath("//a[@class='c-logo' and contains(@href,'/graph')"));
                //}
                //menuItemText = menuItem.Text;
                //GraphBrowser.Click(menuItem);
                //break;

                menuItemText = homeLinkElement.Text;
                GraphBrowser.Click(homeLinkElement);
                break;

            case ("Quick start"):
                //if (prodSite)
                //{
                //    menuItem = GraphBrowser.FindElement(By.XPath("//ul[@class='c-menu-container shell-category-top-level shell-category-nav-wrapper']/li/a[contains(@href,'/graph/quick-start')"));
                //}
                //else
                //{
                //    menuItem = GraphBrowser.FindElement(By.XPath("//nav[@id='uhf-c-nav']/a[contains(@href,'/graph/quick-start')"));
                //}
                //menuItemText = menuItem.Text;
                //GraphBrowser.Click(menuItem);
                //break;

                menuItemText = getstartedLinkElement.Text;
                GraphBrowser.Click(getstartedLinkElement);
                break;

            case ("Documentation"):
                menuItemText = documentationLinkElement.Text;
                GraphBrowser.Click(documentationLinkElement);
                break;

            case ("Graph explorer"):
                menuItemText = exploreLinkElement.Text;
                GraphBrowser.Click(exploreLinkElement);
                break;

            case ("Samples & SDKs"):
                menuItemText = samplesandsdksLinkElement.Text;
                GraphBrowser.Click(samplesandsdksLinkElement);
                break;

            case ("Changelog"):
                menuItemText = changelogLinkElement.Text;
                GraphBrowser.Click(changelogLinkElement);
                break;

            case ("Examples"):
                menuItemText = examplesLinkElement.Text;
                GraphBrowser.Click(examplesLinkElement);
                break;

            default:
                break;
            }
            return(menuItemText);
        }