/// <summary> /// Perform selected operation on a row of a table For Order Module /// </summary> /// <param name="table">IWebElement table</param> /// <param name="driver">IWebDriver</param> /// <param name="rowNo">Index of row to perform operation.</param> /// <param name="operation">Operation to perform</param> public static void SelectOperationsForRowsBasedOnValueForOrderModule(this IWebElement table, IWebDriver driver, int rowNo, string operation) { WaitHelpers.ExplicitWait(200); Assert.IsTrue(table.FindElement(By.TagName("tbody")).FindElements(By.TagName("tr")).Count > 0, "Any row with the desired Cell text/date is not found"); var flag = true; table.WaitForPresent(driver); WaitHelpers.ExplicitWait(200); var row = table.FindElement(By.TagName("tbody")).FindElements(By.TagName("tr"))[rowNo]; switch (operation) { default: var cell = row.FindElement(By.XPath(".//div[contains(@id,'ActionsMenu')]/button/i")); cell.DrawHighlight(driver); WaitHelpers.WaitForClickable(cell).Click(); WaitHelpers.ExplicitWait(250); if (cell.FindElements(By.XPath(".//parent::*//parent::*//ul//li//a//span")).Any(e => e.Text.ToLower().Equals(operation.ToLower()))) { WaitHelpers.WaitForClickable(cell.FindElements(By.XPath(".//parent::*//parent::*//ul//li//a//span")).Where(e => e.Text.ToLower().Equals(operation.ToLower())).ToArray()[0]).Click(); flag = false; } break; } Assert.IsFalse(flag, "The desried operation is not found for the particular row: " + rowNo + "Expected Operation: " + operation); }
/// <summary> /// Accepts or Cancels a Java Alert Pop up. /// </summary> /// <param name="dismiss">dismiss or accept alert.</param> /// <returns>The alerts text.</returns> public static string HandleJavaAlert(bool dismiss = false) { WaitHelpers.ExplicitWait(); try { var javaAlert = WebDriverFactory.LastDriver.SwitchTo().Alert(); var alertText = javaAlert.Text; WaitHelpers.ExplicitWait(); if (dismiss) { javaAlert.Dismiss(); } else { javaAlert.Accept(); } //Driver.SwitchTo().Window(""); WaitHelpers.ExplicitWait(); return(alertText); } catch (Exception) { return(null); } }
/// <summary> /// Selects the item in the multi-select by text. /// </summary> /// <param name="ele">Kendo multi-select element.</param> /// <param name="text">Text of item to select.</param> public static void SetTextMultiSelect(this IWebElement ele, string text) { //generate the locator of the list element. var listLocator = By.XPath( $"//ul[contains(@id, '{ele.FindElement(By.XPath(".//parent::*")).FindElement(By.TagName("input")).GetAttribute("aria-owns").Split(' ')[1]}')]"); //check to see if text is available in list. if (!string.IsNullOrEmpty(text) || WebDriverFactory.LastDriver.FindElement(listLocator).FindElements(By.TagName("li")) .Any(p => p.GetAttribute("innerHTML").ToLower().Equals(text.ToLower()))) { //click to display listbox ele.FindElement(By.XPath(".//parent::*")).Click(); //wait for list to be visible var wait = new WebDriverWait(WebDriverFactory.LastDriver, WaitHelpers.DefaultWait); wait.PollingInterval = TimeSpan.FromMilliseconds(100); wait.Until(ExpectedConditions.ElementIsVisible(listLocator)); WaitHelpers.ExplicitWait(); //select text WebDriverFactory.LastDriver.FindElement(listLocator).FindElements(By.TagName("li")) .Where(p => p.GetAttribute("innerHTML").ToLower().Equals(text.ToLower())).ToArray()[0].Click(); //wait until listbox is invisible wait.Until(ExpectedConditions.InvisibilityOfElementLocated(listLocator)); } else { ele.FindElement(By.XPath(".//parent::*")).FindElement(By.TagName("input")).ForceTextToListInput(text); } }
/// <summary> /// Change to tab/subtab specified /// </summary> /// <param name="tab">name of top level tab</param> /// <param name="dropDownItem">name of submenu item</param> public static void ChangeTab(string tab, string dropDownItem = null) { //locate the tab link and click it WaitHelpers.WaitForElementVisible(By.CssSelector(".nav.top-tab-bar")); WaitHelpers.WaitForClickable(By.CssSelector(".nav.top-tab-bar")); IWebElement tabStrip = WebDriverFactory.LastDriver.FindElement(By.CssSelector(".nav.top-tab-bar")); var xpathLocator = $"//a[descendant::div[contains(@id,\"DetailView_{tab}\")]] | //a[descendant::div[contains(@id,'DetailView_') and contains(.,\"{tab}\")]]"; WaitHelpers.WaitForElementVisible(By.XPath(xpathLocator)); IWebElement tabToClick = WaitHelpers.WaitForClickable(tabStrip.FindElement(By.XPath(xpathLocator))); WaitHelpers.ExplicitWait(); tabToClick.Click(); //if drop-down, click the drop-down item if (!string.IsNullOrEmpty(dropDownItem)) { //IWebElement element = WebDriverFactory.LastDriver.ExecuteJavaScript<IWebElement>("return $" + "(\"a:has(div:contains(\'Demographics\'))\").filter(\":visible\")" + ".get(0)"); //element.DrawHighlight(); //var els = tabToClick.FindElements(By.XPath($"//a[descendant::div[contains(.,\"{dropDownItem}\")]]")); //foreach (var e in els) //{ // if (e.Displayed) { e.Click(); } //} //IWebElement dropDownToClick = WaitHelpers.WaitForClickable(tabToClick.FindElement(By.XPath($"//a[descendant::div[contains(.,\"{dropDownItem}\")]]"))); //dropDownToClick.Click(); WebDriverFactory.LastDriver.FindElement(CustomBy.jQuery($"(\"a:has(div:contains(\'{dropDownItem}\'))\").filter(\":visible\")")).Click(); } WaitHelpers.WaitForAjaxLoad(); }
/// <summary> /// Removes item from the multi-select. /// </summary> /// <param name="ele">Kendo multi-select.</param> /// <param name="text">text of the item to remove.</param> public static void RemoveTextMultiSelect(this IWebElement ele, string text) { //generate the locator of the list element. var listLocator = By.XPath( $"//ul[contains(@id, '{ele.FindElement(By.XPath(".//parent::*")).FindElement(By.TagName("input")).GetAttribute("aria-owns").Split(' ')[1]}')]"); //check to see if text is available in list. if (!string.IsNullOrEmpty(text) || ele.FindElement(listLocator).FindElements(By.TagName("li")) .Any(p => p.GetAttribute("innerHTML").ToLower().Equals(text.ToLower()))) { //remove text ele.FindElements(By.TagName("li")) .Where(p => p.FindElement(By.TagName("span")).GetAttribute("innerHTML").ToLower().Equals(text.ToLower())).ToArray()[0].FindElement(By.CssSelector(".k-icon.k-delete")).Click(); WaitHelpers.ExplicitWait(100); } else { var listItems = ele.FindElements(By.TagName("li")); foreach (var item in listItems) { item.FindElement(By.CssSelector(".k-icon.k-delete")).Click(); WaitHelpers.ExplicitWait(100); } } }
/// <summary> /// Retrieves all values from a Kendo ComboDropDown /// </summary> /// <param name="ele">IWebElement Kendo ComboDropDown</param> /// <returns>Dictionary with values from the Kendo ComboDropDown element.</returns> public static Dictionary<string,string> GetAllValueFromComboDropdown(this IWebElement ele) { WaitHelpers.ExplicitWait(200); ele.DrawHighlight(); WaitHelpers.ExplicitWait(200); return WebDriverFactory.LastDriver.FindElements( By.XPath($"//ul[contains(@id,'{ele.GetAttribute("aria-owns")}')]/li")).Select(p => p.GetAttribute("innerHTML").ToUpper().Trim()).Distinct().ToDictionary(p => p); }
/// <summary> /// Force text into Kendo DropDownCombo input. /// </summary> /// <param name="ele">IWebElement input</param> /// <param name="text">text to input</param> private static void ForceTextToListInput(this IWebElement ele, string text)//ToDo: remove sleeps once Netlag is fixed - dg 03/14/17 { WaitHelpers.ExplicitWait(200); WaitHelpers.WaitForAjaxLoad(); WaitHelpers.ExplicitWait(100); ele.Click(); WaitHelpers.ExplicitWait(100); ele.Clear(); WaitHelpers.ExplicitWait(100); ele.SendKeys(text); WaitHelpers.ExplicitWait(100); ele.SendKeys(Keys.Tab); WaitHelpers.ExplicitWait(100); }
public static DataSet GetData(string query, string connectionString = "") { if (String.IsNullOrEmpty(connectionString)) { connectionString = ConnectionString; } var retData = new DataSet(); var connection = new SqlConnection(connectionString); using (connection) { WaitHelpers.ExplicitWait(); var adapter = new SqlDataAdapter(query, connection); adapter.Fill(retData); } return(retData); }
public static void Upload(string filePath, string browserType) { throw new NotImplementedException("File upload being re-architected");//todo: address after control is re-architectec -dg 06/02/2017 if (browserType == "Grid" || browserType == "Mobile") { RemoteWebDriverUpload(filePath); } //get and attach to browser process var browser = Application.Attach(Process.GetProcessById(WebDriverFactory.CurrentBrowserPID)); //get file upload window var fileUploadWindow = browser.GetWindows().Where(w => w.Name == "File Upload" || w.Name == "Open").ToArray(); var x = browser.GetWindows(); //enter filepath var searchCriteria = SearchCriteria .ByControlType(ControlType.Edit) .AndAutomationId("1148"); var fileNameCombo = (TextBox)fileUploadWindow[0].Get(searchCriteria); fileNameCombo.Text = filePath; WaitHelpers.ExplicitWait(250); //click open button var openSearch = SearchCriteria .ByControlType(ControlType.Button) .AndAutomationId("1"); var openButton = (Button)fileUploadWindow[0].Get(openSearch); openButton.Click(); WaitHelpers.ExplicitWait(1000); var wait = new WebDriverWait(WebDriverFactory.LastDriver, TimeSpan.FromSeconds(5)); wait.PollingInterval = TimeSpan.FromSeconds(1); wait.Until( ExpectedConditions.TextToBePresentInElement(WebDriverFactory.LastDriver.FindElement(By.CssSelector(".k-upload-status")), "Done")); }
/// <summary> /// Perform selected operation on a row of a table. /// </summary> /// <param name="table">IWebElement table</param> /// <param name="driver">IWebDriver</param> /// <param name="rowNo">Index of row to perform operation.</param> /// <param name="operation">Operation to perform</param> public static void SelectOperationsForRowsBasedOnValue(this IWebElement table, IWebDriver driver, int rowNo, string operation) { WaitHelpers.ExplicitWait(200); Assert.IsTrue(table.FindElement(By.TagName("tbody")).FindElements(By.TagName("tr")).Count > 0, "Any row with the desired Cell text/date is not found"); var flag = true; table.WaitForPresent(driver); WaitHelpers.ExplicitWait(200); var row = table.FindElement(By.TagName("tbody")).FindElements(By.TagName("tr"))[rowNo]; switch (operation) { case "Edit": row.FindElement(By.XPath("(//i[text()='mode_edit'])[" + (rowNo + 1) + "]")).DrawHighlight(driver); WaitHelpers.WaitForClickable(row.FindElement(By.XPath("(//i[text()='mode_edit'])[" + (rowNo + 1) + "]"))).Click(); flag = false; break; case "Go To Details": row.FindElement(By.XPath("(//i[text()='keyboard_arrow_right'])[" + (rowNo + 2) + "]")).DrawHighlight(driver); WaitHelpers.WaitForClickable(row.FindElement(By.XPath("(//i[text()='keyboard_arrow_right'])[" + (rowNo + 2) + "]"))).Click(); flag = false; break; case "Expand_More": //WaitHelpers.WaitForClickable(table.FindElement(By.XPath("(//i[text()='expand_more'])[" + (rowNo + 3) + "]"))).DrawHighlight(driver); WaitHelpers.WaitForClickable(table.FindElement(By.XPath($"(//i[text()='expand_more' and contains(@class, 'actionButton')])[{rowNo + 1}]"))).DrawHighlight(driver); table.FindElement(By.XPath($"(//i[text()='expand_more' and contains(@class, 'actionButton')])[{rowNo + 1}]")).Click(); flag = false; break; case "Expand_Less": //table.FindElement(By.XPath("(//i[text()='expand_more'])[" + (rowNo + 1) + "]")).DrawHighlight(driver); WaitHelpers.WaitForClickable(table.FindElement(By.XPath($"(//i[contains(text(), 'expand_less') and contains(@class, 'actionButton')])[{rowNo + 1}]"))).DrawHighlight(driver); table.FindElement(By.XPath($"(//i[contains(text(),'expand_less') and contains(@class, 'actionButton')])[{rowNo + 1}]")).Click(); flag = false; break; case "Transfer Credit": var cell = row.FindElement(By.CssSelector(".material-icons.dropdown-toggle")); cell.DrawHighlight(driver); WaitHelpers.WaitForClickable(cell).Click(); WaitHelpers.ExplicitWait(250); WaitHelpers.WaitForClickable(table.FindElement(By.XPath($"(//a[text()='Transfer Credit'])[{rowNo + 1}]"))).DrawHighlight(driver); table.FindElement(By.XPath($"(//a[text()='Transfer Credit'])[{rowNo + 1}]")).Click(); flag = false; break; case "Add New Order": cell = row.FindElement(By.CssSelector(".material-icons.dropdown-toggle")); cell.DrawHighlight(driver); WaitHelpers.WaitForClickable(cell).Click(); WaitHelpers.ExplicitWait(250); if (cell.FindElements(By.XPath(".//parent::*//ul//li//a")).Any(e => e.Text.ToLower().Contains("Add New Order".ToLower()))) { WaitHelpers.WaitForClickable(cell.FindElements(By.XPath(".//parent::*//ul//li//a")).Where(e => e.Text.ToLower().Contains("Add New Order".ToLower())).ToArray()[0]).Click(); flag = false; } break; default: cell = row.FindElement(By.CssSelector(".material-icons.dropdown-toggle")); cell.DrawHighlight(driver); WaitHelpers.WaitForClickable(cell).Click(); WaitHelpers.ExplicitWait(250); if (cell.FindElements(By.XPath(".//parent::*//ul//li//a")).Any(e => e.Text.ToLower().Equals(operation.ToLower()))) { WaitHelpers.WaitForClickable(cell.FindElements(By.XPath(".//parent::*//ul//li//a")).Where(e => e.Text.ToLower().Equals(operation.ToLower())).ToArray()[0]).Click(); flag = false; } break; } Assert.IsFalse(flag, "The desried operation is not found for the particular row: " + rowNo + "Expected Operation: " + operation); }
/// <summary> /// Scrolls IWebElement into view. /// </summary> /// <param name="ele">IWebElement to scroll into view.</param> public static void ScrollIntoView(this IWebElement ele) { Executor.ExecuteJavascript("arguments[0].scrollIntoView()", ele); WaitHelpers.ExplicitWait(250); }