/// <summary> /// This code is to perform selenium function, switch the handle to the alert /// </summary> /// <author>Nishanth; Chintamani(CHNG235)</author> public void SwithchToAlert() { try { Driver.SwitchTo().Alert(); Selenium.Log.Log(LogStatus.Pass, "Switched to: " + (Driver.SwitchTo().Alert()).GetType()); } catch (Exception e) { string screenShotPath = AutomationReport.Capture(Selenium.ObjDriver); Selenium.Log.Log(LogStatus.Fail, "Snapshot below: " + Selenium.Log.AddScreenCapture(screenShotPath)); Selenium.Log.Log(LogStatus.Fail, "Not able to move to switch to alert " + " || " + " Build Error Message: " + e); throw (e); } }
/// <summary> /// This code is to perform selenium function, switch to a particular window /// </summary> /// <author>Nishanth; Chintamani(CHNG235)</author> public void SwitchWindow(string windowname) { try { Driver.SwitchTo().Window(windowname); Selenium.Log.Log(LogStatus.Pass, "Switched to window: " + windowname); } catch (Exception e) { string screenShotPath = AutomationReport.Capture(Selenium.ObjDriver); Selenium.Log.Log(LogStatus.Fail, "Snapshot below: " + Selenium.Log.AddScreenCapture(screenShotPath)); Selenium.Log.Log(LogStatus.Fail, "Not able to switch to window " + " || " + " Build Error Message: " + e); throw (e); } }
/// <summary> /// This code is to perform selenium function, switch to the default window /// </summary> /// <author>Nishanth; Chintamani(CHNG235)</author> public void SwitchDefaultContent() { try { Driver.SwitchTo().DefaultContent(); Selenium.Log.Log(LogStatus.Pass, "Switched to window: " + (Driver.SwitchTo().DefaultContent()).Title); } catch (Exception e) { string screenShotPath = AutomationReport.Capture(Selenium.ObjDriver); Selenium.Log.Log(LogStatus.Fail, "Snapshot below: " + Selenium.Log.AddScreenCapture(screenShotPath)); Selenium.Log.Log(LogStatus.Fail, "Not able to switch to default content " + " || " + " Build Error Message: " + e); throw (e); } }
/// <summary> /// This code is to perform selenium function, dismiss alerts/ pop-ups /// </summary> /// <author>Nishanth; Chintamani(CHNG235)</author> public void AlertDismiss() { try { var Alert = Driver.SwitchTo().Alert(); Alert.Dismiss(); Selenium.Log.Log(LogStatus.Pass, "Alert Accepted: " + Alert); } catch (Exception e) { string screenShotPath = AutomationReport.Capture(Selenium.ObjDriver); Selenium.Log.Log(LogStatus.Fail, "Snapshot below: " + Selenium.Log.AddScreenCapture(screenShotPath)); Selenium.Log.Log(LogStatus.Fail, "Not able to move to dismiss alert " + " || " + " Build Error Message: " + e); throw (e); } }
/// <summary> /// This code is to perform selenium function, Gets text using javaScriptExecutor /// </summary> /// <author>Nishanth; Chintamani(CHNG235)</author> public void ScrollToElement(IWebElement element, string selement) { try { IJavaScriptExecutor JSExecutor = (IJavaScriptExecutor)Driver; JSExecutor.ExecuteScript("arguments[0].scrollIntoView();", element); Selenium.Log.Log(LogStatus.Info, "Scrolled down to " + element); } catch (Exception e) { string screenShotPath = AutomationReport.Capture(Selenium.ObjDriver); Selenium.Log.Log(LogStatus.Warning, "Snapshot below: " + Selenium.Log.AddScreenCapture(screenShotPath)); Selenium.Log.Log(LogStatus.Warning, "Unable to scroll to -> " + element + " || " + " Build Error Message: " + e); throw (e); } }
/// <summary> /// This code is to perform selenium function, send keys eg: input text /// </summary> /// <param name="element"></param> /// <param name="text"></param> /// <author>Nishanth; Chintamani(CHNG235)</author> public void SendKeys(IWebElement element, string text, string selement) { try { WaitFluent(element); element.SendKeys(text); Selenium.Log.Log(LogStatus.Pass, "Entered Text in: " + selement); } catch (Exception e) { string screenShotPath = AutomationReport.Capture(Selenium.ObjDriver); Selenium.Log.Log(LogStatus.Fail, "Snapshot below: " + Selenium.Log.AddScreenCapture(screenShotPath)); Selenium.Log.Log(LogStatus.Fail, "Not able to enter into Element -> " + selement + " || " + " Build Error Message: " + e); throw (e); } }
/// <summary> ///This code is to perform selenium function, move to a pirticular element using action class /// </summary> /// <param name="element"></param> /// <author>Nishanth; Chintamani(CHNG235)</author> public void Clear(IWebElement element, string selement) { try { WaitFluent(element); element.Clear(); Selenium.Log.Log(LogStatus.Pass, "Cleared " + selement); } catch (Exception e) { string screenShotPath = AutomationReport.Capture(Selenium.ObjDriver); Selenium.Log.Log(LogStatus.Fail, "Snapshot below: " + Selenium.Log.AddScreenCapture(screenShotPath)); Selenium.Log.Log(LogStatus.Fail, "Not able to move to the element -> " + selement + " || " + " Build Error Message: " + e); throw (e); } }
/// <summary> /// This code is to perform selenium function, Context click (Right Click) functionality using action class /// </summary> /// <param name="element"></param> /// <author>Nishanth; Chintamani(CHNG235)</author> public void ActionContexClick(IWebElement element, string selement) { try { Actions Act = new Actions(Driver); Act.MoveToElement(element).ContextClick().Build().Perform(); Selenium.Log.Log(LogStatus.Pass, "Right Clicked/Context Clicked on: " + selement); } catch (Exception e) { string screenShotPath = AutomationReport.Capture(Selenium.ObjDriver); Selenium.Log.Log(LogStatus.Fail, "Snapshot below: " + Selenium.Log.AddScreenCapture(screenShotPath)); Selenium.Log.Log(LogStatus.Fail, "Not able to click the element -> " + selement + " || " + " Build Error Message: " + e); throw (e); } }
/// <summary> /// This code is to perform selenium function, click /// </summary>Click /// <param name="element"></param> /// <author>Nishanth; Chintamani(CHNG235)</author> public void Click(IWebElement element, string selement) { try { WaitFluent(element); element.Click(); Selenium.Log.Log(LogStatus.Pass, "Clicked Element: " + selement); } catch (Exception e) { string screenShotPath = AutomationReport.Capture(Selenium.ObjDriver, selement + DateTime.Today.ToString("MM-dd-yyyy_hh_mm_ss")); Selenium.Log.Log(LogStatus.Fail, "Snapshot below: " + Selenium.Log.AddScreenCapture(screenShotPath)); Selenium.Log.Log(LogStatus.Fail, "Not able to click the Element -> " + selement + " || " + " Build Error Message: " + e); throw(e); } }
/// <summary> /// This code is to perform selenium function, send keys/text using javaScriptExecutor /// </summary> /// <author>Nishanth; Chintamani(CHNG235)</author> public void SendKeysJS(IWebElement element, string text, string selement) { try { WaitFluent(element); IJavaScriptExecutor JSExecutor = (IJavaScriptExecutor)Driver; JSExecutor.ExecuteScript("arguments[0].setAttribute('value', '" + text + "')", element); Selenium.Log.Log(LogStatus.Pass, "Entered text into: " + selement); } catch (Exception e) { string screenShotPath = AutomationReport.Capture(Selenium.ObjDriver); Selenium.Log.Log(LogStatus.Fail, "Snapshot below: " + Selenium.Log.AddScreenCapture(screenShotPath)); Selenium.Log.Log(LogStatus.Fail, "Not able to enter into element -> " + selement + " || " + " Build Error Message: " + e); throw (e); } }
/// <summary> /// This code is to perform selenium function, gets the text of the element /// </summary> /// <param name="element"></param> /// <author>Nishanth; Chintamani(CHNG235)</author> public string GetText(IWebElement element, string selement) { try { WaitFluent(element); return(element.Text); Selenium.Log.Log(LogStatus.Pass, "Retrived Text of: " + selement); } catch (Exception e) { string screenShotPath = AutomationReport.Capture(Selenium.ObjDriver); Selenium.Log.Log(LogStatus.Fail, "Snapshot below: " + Selenium.Log.AddScreenCapture(screenShotPath)); Selenium.Log.Log(LogStatus.Fail, "Not able get the text -> " + selement + " || " + " Build Error Message: " + e); throw (e); } }
/// <summary> /// This code is to perform selenium function, checks the visibility of an element /// </summary> /// <param name="element"></param> /// <author>Nishanth; Chintamani(CHNG235)</author> public bool IsVisible(IWebElement element, string selement) { try { WaitFluent(element); bool value = element.Enabled; Selenium.Log.Log(LogStatus.Pass, "Visibility checked for: " + selement); return(value); } catch (Exception e) { string screenShotPath = AutomationReport.Capture(Selenium.ObjDriver); Selenium.Log.Log(LogStatus.Fail, "Snapshot below: " + Selenium.Log.AddScreenCapture(screenShotPath)); Selenium.Log.Log(LogStatus.Fail, "element not found -> " + selement + " || " + " Build Error Message: " + e); throw (e); } }
/// <summary> /// This code is to perform selenium function, select an element from the dropdown with 'Index' as reference /// </summary> /// <param name="element"></param> /// <param name="index"></param> /// <author>Nishanth; Chintamani(CHNG235)</author> public void SelectDropDownByIndex(IWebElement element, int index, string selement) { try { WaitFluent(element); SelectElement DrpDown = new SelectElement(element); DrpDown.SelectByIndex(index); Selenium.Log.Log(LogStatus.Pass, "Selected dropdown option: " + selement); } catch (Exception e) { string screenShotPath = AutomationReport.Capture(Selenium.ObjDriver); Selenium.Log.Log(LogStatus.Fail, "Snapshot below: " + Selenium.Log.AddScreenCapture(screenShotPath)); Selenium.Log.Log(LogStatus.Fail, "Not able to select drop down index -> " + selement + " || " + " Build Error Message: " + e); throw (e); } }
/// <summary> ///This code is to perform selenium function, gets the present webpage title /// </summary> /// <author>Nishanth; Chintamani(CHNG235)</author> public string GetTitle() { string Title; try { Title = Driver.Title; Selenium.Log.Log(LogStatus.Pass, "Retrived Title for : " + Driver); return(Title); } catch (Exception e) { string screenShotPath = AutomationReport.Capture(Selenium.ObjDriver); Selenium.Log.Log(LogStatus.Fail, "Snapshot below: " + Selenium.Log.AddScreenCapture(screenShotPath)); Selenium.Log.Log(LogStatus.Fail, "Not able to get the title of the page -> " + Driver + " || " + " Build Error Message: " + e); throw (e); } }
/// <summary> /// This code is to perform selenium function, Gets text using javaScriptExecutor /// </summary> /// <author>Nishanth; Chintamani(CHNG235)</author> public string GetTextJS(IWebElement element, string selement) { try { WaitFluent(element); IJavaScriptExecutor JSExecutor = (IJavaScriptExecutor)Driver; string text = (string)JSExecutor.ExecuteScript("return arguments[0].value;", element); Selenium.Log.Log(LogStatus.Pass, "Retrived text from: " + selement); return(text); } catch (Exception e) { string screenShotPath = AutomationReport.Capture(Selenium.ObjDriver); Selenium.Log.Log(LogStatus.Fail, "Snapshot below: " + Selenium.Log.AddScreenCapture(screenShotPath)); Selenium.Log.Log(LogStatus.Fail, "Not able to enter into element -> " + selement + " || " + " Build Error Message: " + e); throw (e); } }
/// <summary> ///returns the selected drop down value text /// </summary> /// <author>Nishanth; Chintamani(CHNG235)</author> public string GetSelectedTxt(IWebElement DrpDwn, string selement) { try { WaitFluent(DrpDwn); SelectElement select = new SelectElement(DrpDwn); IWebElement option = select.SelectedOption; string Item = option.Text; return(Item); } catch (Exception e) { string screenShotPath = AutomationReport.Capture(Selenium.ObjDriver); Selenium.Log.Log(LogStatus.Fail, "Snapshot below: " + Selenium.Log.AddScreenCapture(screenShotPath)); Selenium.Log.Log(LogStatus.Fail, "Not able to get the title of the page -> " + Driver + " || " + " Build Error Message: " + e); throw (e); } }
/// <summary> /// This code is to perform selenium function, send keys/text using javaScriptExecutor /// </summary> /// <author>Nishanth; Chintamani(CHNG235)</author> public bool IsDisplayed(IWebElement element, string selement) { bool val; try { WaitFluent(element); val = element.Displayed; Selenium.Log.Log(LogStatus.Pass, "Checked if displayed for: " + selement); return(val); } catch (Exception e) { string screenShotPath = AutomationReport.Capture(Selenium.ObjDriver); Selenium.Log.Log(LogStatus.Fail, "Snapshot below: " + Selenium.Log.AddScreenCapture(screenShotPath)); Selenium.Log.Log(LogStatus.Fail, "Not able to find the element -> " + selement + " || " + " Build Error Message: " + e); throw (e); } }
/// <summary> /// This code is to perform selenium function, returns the CSSValue of a webelement /// </summary> /// <param name="cssvalue"></param> /// <param name="element"></param> /// <author>Nishanth; Chintamani(CHNG235)</author> public string GetCSSValue(IWebElement element, string valueType, string selement) { string value; try { WaitFluent(element); value = element.GetCssValue(valueType); Selenium.Log.Log(LogStatus.Pass, "Retrived CSS Value for : " + selement); return(value); } catch (Exception e) { string screenShotPath = AutomationReport.Capture(Selenium.ObjDriver); Selenium.Log.Log(LogStatus.Fail, "Snapshot below: " + Selenium.Log.AddScreenCapture(screenShotPath)); Selenium.Log.Log(LogStatus.Fail, "Not able to get the CSS value -> " + selement + " || " + " Build Error Message: " + e); throw (e); } }
/// <summary> /// Method to select the browser environment for the test case to be executed based on the selection made from TestBase /// </summary> /// <param name="browser"></param> /// <author>Nishanth; Chintamani(CHNG235)</author> public static void InitiateDriver(string url, string browser, string cnn) { string Drivers = @"..\..\Resources\Drivers"; if (browser.Equals("IE")) { InternetExplorerOptions Options = new InternetExplorerOptions(); Options.IgnoreZoomLevel = true; Options.IntroduceInstabilityByIgnoringProtectedModeSettings = true; Options.AcceptInsecureCertificates = false; Options.RequireWindowFocus = true; Driver = new InternetExplorerDriver(Drivers, Options, TimeSpan.FromSeconds(30)); } else if (browser.Equals("Chrome")) { ChromeOptions Options = new ChromeOptions(); Driver = new ChromeDriver(Drivers, Options); } else if (browser.Equals("Firefox")) { FirefoxOptions Options = new FirefoxOptions(); Driver = new FirefoxDriver(Drivers, Options); } Driver.Url = url; Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(50); Driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(50); Driver.Manage().Window.Maximize(); var cookies = Driver.Manage().Cookies.AllCookies; Selenium.Set(Driver); Selenium.Driver = new DriverFunctions(Driver); Selenium.Extent = AutomationReport.StartReport(); }