static GraphBrowser() { switch (GraphUtility.GetConfigurationValue("Browser").ToLower()) { case ("chrome"): webDriver = new ChromeDriver(System.IO.Directory.GetCurrentDirectory() + @"/Drivers/"); break; case ("ie32"): webDriver = new InternetExplorerDriver(System.IO.Directory.GetCurrentDirectory() + @"/Drivers/IE32/"); break; case ("ie64"): webDriver = new InternetExplorerDriver(System.IO.Directory.GetCurrentDirectory() + @"/Drivers/IE64/", new InternetExplorerOptions() { RequireWindowFocus = true }); break; case ("firefox"): default: webDriver = new FirefoxDriver(); break; } defaultHandle = webDriver.CurrentWindowHandle; }
/// <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 void SaveScreenShot(string fileName) { ITakesScreenshot screenshot = (ITakesScreenshot)webDriver; fileName = string.Format("{0}\\{1}.png", GraphUtility.GetConfigurationValue("ScreenShotSavePath"), fileName); Screenshot s = screenshot.GetScreenshot(); s.SaveAsFile(fileName, System.Drawing.Imaging.ImageFormat.Png); }
/// <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)); }