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> /// 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); }
static GraphBrowser() { switch (GraphUtility.GetConfigurationValue("Browser").ToLower()) { case ("chrome"): webDriver = new ChromeDriver(System.IO.Directory.GetCurrentDirectory() + @"/Drivers/"); break; case ("ie32"): InternetExplorerOptions ieOptions = new InternetExplorerOptions(); ieOptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true; webDriver = new InternetExplorerDriver(System.IO.Directory.GetCurrentDirectory() + @"/Drivers/IE32/", ieOptions); 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; }
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)); }