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 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 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> /// 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> /// 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 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); }
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); } }
public static bool CheckTwoCardsDisplayed() { GraphBrowser.Wait(By.Id("setup")); var elements = GraphBrowser.Driver.FindElements(By.ClassName("card")); if (elements.Count > 0) { foreach (IWebElement item in elements) { string itemId = item.GetAttribute("id"); if ((itemId == "intro" || itemId == "setup") && !item.Displayed) { return(false); } if (itemId != "intro" && itemId != "setup" && item.Displayed) { return(false); } } return(true); } else { return(false); } }
/// <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 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); } }
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> /// Verify whether the current graph page has the specific title /// </summary> /// <param name="graphTitle">The expected page title</param> /// <returns>True if yes, else no.</returns> public bool IsAtGraphPage(string graphTitle) { var graphPage = new GraphPage(); string title = graphPage.GraphTitle.Replace(" ", ""); GraphBrowser.GoBack(); return(title.Contains(graphTitle.Replace(" ", ""))); }
/// <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]); }
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; } } }
/// <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(""); }
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> /// 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> /// Input a query string on Graph explorer page /// </summary> /// <param name="version">The target service version</param> /// <param name="request">The resource to access/manipulate in the Microsoft Graph API request</param> public static void InputExplorerQueryString(string version, string resource) { string lcn = GetLCN(); string request; if (lcn.Equals("zh-cn")) { request = "https://microsoftgraph.chinacloudapi.cn/" + version + "/" + resource; } else { request = "https://graph.microsoft.com/" + version + "/" + resource; } GraphBrowser.Wait(By.XPath("/html/body/div[1]/div/div[2]/div/div/div/div/article[2]/div/div/div/div[3]/form/div/md-autocomplete/md-autocomplete-wrap/input")); var inputElement = GraphBrowser.Driver.FindElement(By.XPath("/html/body/div[1]/div/div[2]/div/div/div/div/article[2]/div/div/div/div[3]/form/div/md-autocomplete/md-autocomplete-wrap/input")); inputElement.Clear(); inputElement.SendKeys(request); }
/// <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> /// Get the response on Graph explorer page /// </summary> /// <returns>The composed response string</returns> public static string GetExplorerResponse() { GraphBrowser.Wait(By.XPath("//div[@id='jsonViewer']/div/div[contains(@class,'ace_content')]/div[contains(@class,'ace_text-layer')]")); StringBuilder responseBuilder = new StringBuilder(); IReadOnlyList <IWebElement> responseElements = GraphBrowser.webDriver.FindElements(By.CssSelector("div#jsonViewer>div.ace_scroller>div>div.ace_layer.ace_text-layer>div.ace_line> span")); for (int i = 0; i < responseElements.Count; i++) { responseBuilder.Append(responseElements[i].Text); } //Remove the braces if (responseBuilder.ToString().StartsWith("{")) { int length = responseBuilder.Length; return(responseBuilder.ToString().Substring(1, length - 2)); } else { return(responseBuilder.ToString()); } }
/// <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> /// The constructor method /// </summary> /// <param name="atGraphSite">Indicates whether it is during the testing of ms graph or dev.office.com</param> public GraphPage() { GraphBrowser.Wait(By.CssSelector("head>title")); graphTitle = (OpenQA.Selenium.Remote.RemoteWebElement)GraphBrowser.Driver.FindElement(By.CssSelector("head>title")); }
/// <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> /// 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); }
/// <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); }
/// <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); }