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 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); } }
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)); }
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 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> /// 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); }
/// <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 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 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()); } }
public static void ClickMenuItem(string text) { GraphBrowser.Wait(By.XPath(text)); var element = GraphBrowser.FindElement(By.XPath(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"); }