//SPECIFICS TO TEST - DB QUERIES AND COMMON STEPS //DB Queries protected static DataRowCollection ExecuteQueryOnDB(string query, Dictionary <string, string> parameters) { DataTable results = new DataTable(); using (SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings.Get("DBConnectionString"))) { //Prepare command to execute SqlCommand command = new SqlCommand(query, connection); //Add given parameters if (parameters != null) { foreach (KeyValuePair <string, string> param in parameters) { command.Parameters.AddWithValue("@" + param.Key, param.Value); } } //Connect to DB and execute connection.Open(); SqlDataAdapter dataAdapter = new SqlDataAdapter(command); dataAdapter.Fill(results); TestsLogger.Log("RowsAffected: " + results.Rows.Count); } return(results.Rows); }
//waits for the requested element to (be visible and) loose the attribute until it appears or times out protected IWebElement WaitForElementToLooseAttribute(By by, string attribute, int seconds) { string logMsg = "WaitForElementToLooseAttribute " + by.ToString() + ". Attribute = " + attribute + " for " + seconds + " seconds top."; TestsLogger.Log(logMsg); try { WebDriverWait webDriverWait = new WebDriverWait(this.driver, GetTimeSpanInMilliseconds(seconds)); webDriverWait.IgnoreExceptionTypes(typeof(NoSuchElementException)); //to avoid instant failure breaks return(webDriverWait.Until <IWebElement>((d) => { IWebElement element = d.FindElement(by); if (element.Displayed && element.Enabled && element.GetAttribute(attribute) == null) { return element; } throw new WebDriverTimeoutException(); })); } catch (WebDriverException exception) { throw new MissingElementException("Exception when performing: " + logMsg, exception); } }
public PageObject(IWebDriver driver, string pageExpectedTitle) { //set the driver this.driver = driver; this.Pause(1); //set focus to opened window this.driver.SwitchTo().Window(this.driver.CurrentWindowHandle); //wait for the page to be loaded and contain the correct title if (pageExpectedTitle != null) { int timeToWaitForPage = defaultTimeoutGroupElement; timeToWaitForPage = timeToWaitForPage * 2; //Click on Login page to load - for IE only if ((driver.GetType() == typeof(InternetExplorerDriver)) && (pageExpectedTitle.Contains("Login"))) { timeToWaitForPage = timeToWaitForPage * 5; driver.FindElement(By.XPath("//body")).Click(); TestsLogger.Log("[IEDriver] Click on <body> tag was made"); } string titleLocator = string.Format(universalPageTitle, pageExpectedTitle); this.WaitForElementToBePresent(By.XPath(titleLocator), timeToWaitForPage); } }
public void clickMoreTransactionsButton(string action) { WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20)); Thread.Sleep(1500); WaitForBlockOverlayToDissapear(); if (action != "No") { IWebElement scrollToMe = wait.Until(ExpectedConditions.ElementExists(By.XPath("//span[@id='summarySectionTitle']"))); scrollToElement(scrollToMe); IWebElement label = createVisibleWebElementByXpath("//menu-link//div[@id='More-menu-link-button']/ul/li/a"); Assert.True(label.Text.Contains("More")); IWebElement iconFirstState = createVisibleWebElementByXpath("//menu-link//div[@id='More-menu-link-button']/ul/li/span/i"); assertAttributeContainsText(iconFirstState, "class", "fa-chevron-down"); IWebElement button = wait.Until(ExpectedConditions.ElementIsVisible(By.Id("More-menu-link-button"))); WaitForBlockOverlayToDissapear(); button.Click(); WaitForBlockOverlayToDissapear(); IWebElement listTitle1 = createVisibleWebElementByXpath("//div[@class='menuLinkListContainer'][1]/span"); IWebElement listTitle2 = createVisibleWebElementByXpath("//div[@class='menuLinkListContainer'][2]/span"); assertElementContainsSingleText(listTitle1, "Receipt Transactions", "Receipt Transactions link is incorrect on More Transactions section"); assertElementContainsSingleText(listTitle2, "Disbursement Transactions", "Disbursement Transactions link is incorrect on More Transactions section"); IWebElement iconSecondState = createVisibleWebElementByXpath("//menu-link//div[@id='More-menu-link-button']/ul/li/span/i"); assertAttributeContainsText(iconSecondState, "class", "fa-chevron-up"); } else { TestsLogger.Log("No need to click the More button"); } WaitForBlockOverlayToDissapear(); }
public static void Teardown() { TestsLogger.Log("Closing out browser (close, quit and dispose)... "); //driver.Close(); driver.Quit(); //driver.Dispose(); }
//waits for the requested element to (be visible and) have the attribute value until it appears or times out protected IWebElement WaitForElementToHaveAttributeValue(By by, string attribute, string value, int seconds) { string logMsg = "WaitForElementToHaveAttributeValue " + by.ToString() + ". Attribute = " + attribute + ", Value = " + value + ". Waiting for " + seconds + " seconds top."; TestsLogger.Log(logMsg); try { WebDriverWait webDriverWait = new WebDriverWait(this.driver, GetTimeSpanInMilliseconds(seconds)); webDriverWait.IgnoreExceptionTypes(typeof(NoSuchElementException)); //to avoid instant failure breaks //TODO INVESTIGATE if this can be done with ExpectedConditions.ElementToHaveTextValue return(webDriverWait.Until <IWebElement>((d) => { IWebElement element = d.FindElement(by); if (element.Displayed && element.Enabled && element.GetAttribute(attribute) == value) { return element; } throw new WebDriverTimeoutException(); })); } catch (WebDriverException exception) { throw new MissingElementException("Exception when performing: " + logMsg, exception); } }
private IWebElement WaitForElementToBeVisibleAndHaveSomeText(By by, int seconds) { string logMsg = "WaitForElementToBeVisibleAndHaveSomeText " + by.ToString() + " for " + seconds + " seconds top."; TestsLogger.Log(logMsg); try { WebDriverWait webDriverWait = new WebDriverWait(this.driver, GetTimeSpanInMilliseconds(seconds)); webDriverWait.IgnoreExceptionTypes(typeof(NoSuchElementException)); //to avoid instant failure breaks return(webDriverWait.Until <IWebElement>((d) => { IWebElement element = d.FindElement(by); if (element.Displayed && element.Enabled && element.Text.Length > 0) { return element; } throw new WebDriverTimeoutException(); })); } catch (WebDriverException exception) { throw new MissingElementException("Exception when performing: " + logMsg, exception); } }
public void ForceToLoadURL(string url) { TestsLogger.Log("Forcing URL load to " + url); driver.Navigate().GoToUrl(url); Thread.Sleep(1000); this.WaitForBlockOverlayToDissapear(); }
public static void BeforeScenario() { //Log test start to easily locate scenarios on the LOG TestsLogger.Log("[TEST START] " + ScenarioContext.Current.ScenarioInfo.Title); //Instantiate the WebDriver according to the browser on the App.config switch (browserName) { case browserFireFox: driver = new FirefoxDriver(); break; case browserChrome: ///////////// Here I open Chrome in Incognito Mode //////////// var optionsChrome = new ChromeOptions(); //Removing incognito, it does not clear cache //bad side-effectes: causes failure with Chrome 57 and avoids window resizing-> click errors. //¡¡¡DO NOT ACTIVATE THIS AGAIN!!! optionsChrome.AddArgument("incognito"); //These could be useful for any extension errors that prevent browser from launching //optionsChrome.AddArgument("--aggressive-cache-discard"); optionsChrome.AddArgument("--disable-infobars"); optionsChrome.AddArgument("--disable-extensions"); //For disabling popup blocking optionsChrome.AddArgument("--disable-popup-blocking"); optionsChrome.AddArgument("--IGNORE"); driver = new ChromeDriver(optionsChrome); //driver = new ChromeDriver(); break; case browserIE: ////Ignore browser security warning //var options = new InternetExplorerOptions(); //options.IntroduceInstabilityByIgnoringProtectedModeSettings = true; //driver = new InternetExplorerDriver(options); driver = GetNewInternetExplorerDriver(driverPath, driverPort); break; default: driver = new FirefoxDriver(); break; } //Configure driver basic settings driver.Manage().Cookies.DeleteAllCookies(); //driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(0)); driver.Manage().Window.Maximize(); //IMPORTANT: Keep this size to avoid CLICK issues //Size size = new Size(1920, 1080); // driver.Manage().Window.Size = size; //Navigate to the portal portalURL driver.Navigate().GoToUrl(portalURL); TestsLogger.Log("Running Tests on " + browserName + " for " + portalURL); }
public SuperAdminPage ClickOnCaseResultByCaseNumberOnSupreadmin(string caseNbr) { this.WaitForElementToBeVisible(By.XPath(String.Format(searchResultByText, caseNbr))).Click(); TestsLogger.Log("Waiting for block overlay to dissappear after selecting case on Search"); this.Pause(2); this.WaitForElementToDissapear(blockOverlay, blockOverlayWaitTimeout + 10); TestsLogger.Log("Block overlay dissappeared after selecting case on Search. Next wait will be on CaseDetailPage constructor."); return(new SuperAdminPage(driver)); }
public static void BeforeScenario() { //Clear previous ScenarioContext data ScenarioContext.Current.Clear(); driver.Navigate().Refresh(); //Log test start to easily locate scenarios on the LOG TestsLogger.Log("[TEST START] " + ScenarioContext.Current.ScenarioInfo.Title); }
public static void Teardown() { TestsLogger.Log("Ending the run of a feature file... "); /* driver.Close(); * //driver.Close(); * driver.Quit(); * //driver.Dispose();*/ }
public void DeleteAllTestClaimsOnCase1092() { Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("CaseId", "1092"); DataRowCollection results = ExecuteQueryOnDB(Properties.Resources.DeleteAutomationCreatedTestClaimsFromCaseByCaseId, parameters); TestsLogger.Log("Deleted all claims generated on Case 1092!"); }
private static IWebDriver GetNewChromeDriver(string driverPath, int driverPort) { //setup driver's folder and port var chromeDriverService = ChromeDriverService.CreateDefaultService(driverPath); chromeDriverService.Port = driverPort; TestsLogger.Debug("Attempting to start Chrome browser on port " + driverPort); return(new ChromeDriver(chromeDriverService)); }
//DRIVERS SPECIAL CONSTRUCTORS FOR SPECIFIC PORTS ON HOST MACHINE //(NOT USING RIGHT NOW) private static IWebDriver GetNewFirefoxDriver(int driverPort) { //setup driver's port FirefoxProfile profile = new FirefoxProfile(); profile.Port = driverPort; TestsLogger.Debug("Attempting to start Firefox browser on port " + profile.Port); return(new FirefoxDriver(profile)); }
protected static void scrollListDownToSpecificElement(IWebElement element, string textToMatch, IWebElement elementToSendKeys, string elementXpath) { while (element.Text.Contains(textToMatch).Equals(false)) { elementToSendKeys.SendKeys(Keys.ArrowDown); element = createVisibleWebElementByXpath(elementXpath); string actualText = element.Text; TestsLogger.Log(actualText + " VS " + textToMatch); } }
protected void WaitForBlockOverlayToDissapear() { //Message 'Please wait' is appearing multiple times, //expecting it as many times as the max we could define per the current pages Ajax calls //Thread.Sleep(2000); TestsLogger.Log("WaitForBlockOverlayToDissapear with locator " + By.CssSelector("div.blockUI.blockOverlay") + " for " + 65 + " secs (" + 30 + " times)"); for (int i = 0; i < 30; i++) { this.WaitForElementToDissapear(By.CssSelector("div.blockUI.blockOverlay"), 65); } }
protected void WaitForBlockOverlayToDissapear() { //Message 'Please wait' is appearing multiple times, //expecting it as many times as the max we could define per the current pages Ajax calls this.Pause(2); TestsLogger.Log("WaitForBlockOverlayToDissapear with locator " + blockOverlays + " for " + blockOverlayWaitTimeout + " secs (" + maxTimesOverlays + " times)"); for (int i = 0; i < maxTimesOverlays; i++) { this.WaitForElementToDissapear(blockOverlays, blockOverlayWaitTimeout); } }
private void DeleteCreatedTransactionsByCaseId() { //remove all transactions created with text "Test Automation" from the current Case string casenbr = ScenarioContext.Current.Get <string>("Case Number"); Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("CaseId", Convert.ToString(CaseDetailSteps.GetCaseIdFromCaseNumber(casenbr))); DataRowCollection rows = ExecuteQueryOnDB(Properties.Resources.DeleteAutomationCreatedTransactionsByCaseId, parameters); TestsLogger.Log("Removed all transactions created with text 'Test Automation' from Case with Caseid=" + casenbr); }
public void DeleteCreatedAssetsDocketsAndDocumentsFromDB() { //Delete assets, dockets and documents that could have been created by superadmin tests //This is necessaary when delete does not work on the UI to remove all created data after the test fails string itemNames = "for Super Admin Test Automation"; Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("OfficeCode", ConfigurationManager.AppSettings.Get("Office")); parameters.Add("ItemsNameLike", itemNames); ExecuteQueryOnDB(Properties.Resources.Delete_AssetsDocketsAndDocumentsByName, parameters); TestsLogger.Log("DELETED created itemss for Test Automation of superadmin"); }
private void CreateANoteWithText(string text) { //Wait 1 second to make sure this note goes after the previous one that could have just been created caseDetailPage.Pause(3); //Create the note with the given text TestsLogger.Log("Creating note with text '" + text + "'"); caseDetailPage.Notes.CreateNote(text); //Save created note's text ScenarioContext.Current.Add("Note Text Create", text); }
public void GivenIAddItemsInTheCaseOnDatabase(int count, string itemType) { string caseNumber = ScenarioContext.Current.Get <string>("Case Number"); List <string> createdItems = new List <string>(); Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("OfficeCode", ConfigurationManager.AppSettings.Get("Office")); parameters.Add("CoreCaseNumber", caseNumber); for (int i = 1; i <= count; i++) { //define a name for the item string itemName = itemType + " for Super Admin Test Automation " + i; if (itemType == "Document") { itemName += ".pdf"; } if (parameters.ContainsKey("ItemName")) { parameters.Remove("ItemName"); } parameters.Add("ItemName", itemName); //Create item on DB switch (itemType) { case "Asset": ExecuteQueryOnDB(Properties.Resources.Create_Asset, parameters); break; case "Docket": ExecuteQueryOnDB(Properties.Resources.Create_Docket, parameters); break; case "Document": ExecuteQueryOnDB(Properties.Resources.Create_Document, parameters); break; default: throw new NotImplementedException(); } TestsLogger.Log("Created item '" + itemName + "' on Case " + caseNumber); createdItems.Add(itemName); } //save names added items AddDataToScenarioContextOverridingExistentKey("Created Items Type", itemType); AddDataToScenarioContextOverridingExistentKey("Created Items", createdItems); }
public void DeleteCreatedParticipant() { string expectedParticipantName = ScenarioContext.Current.Get <string>("Participant Description"); string casenbr = ScenarioContext.Current.Get <string>("Case Number"); //Get all participants created for automated tests and remove them Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("ParticipantNameLike", expectedParticipantName); DataRowCollection results = ExecuteQueryOnDB(Properties.Resources.DeleteAutomationCreatedTestParticipantsByName, parameters); TestsLogger.Log("Deleted all Created Participants generated on Case " + casenbr + " with Name like '" + expectedParticipantName + "'"); }
public static void CheckForExceptions() { //Checks for exceptions and, if there are any, //asserts a failure with the corresponding log and Stack Trace var exception = ScenarioContext.Current.TestError; if (exception is Exception) { TestsLogger.Log(exception.StackTrace); Assert.Fail(exception.Message); ((IDisposable)ScenarioContext.Current).Dispose(); } }
private void CreateANoteWithRandomText() { //Generate note text string text = GetRandomTextForNote(); //Wait 1 second to make sure this note goes after the previous one that could have just been created caseDetailPage.Pause(1); //Create the note TestsLogger.Log("Creating note with text '" + text + "'"); caseDetailPage.Notes.CreateNote(text); ScenarioContext.Current.Add("Note Text Create", text); }
protected static void enterTextIntoField(string valueToType, IWebElement element) { if (valueToType != "") { Thread.Sleep(100); element.Click(); element.Clear(); typeStringByChar(valueToType, element); } else { TestsLogger.Log("No Need to enter value into field"); } }
public void saveDepositForDepNumber(string transactionType, string depositNumber) { WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20)); pleaseWaitSignDissapear(); Thread.Sleep(2500); IWebElement idToSave = null; string newDepositNumber = ""; if (depositNumber != "") { if (transactionType == "Deposit") { idToSave = createVisibleWebElementByXpath("//p[@id[contains(.,'transactionSerialNumber-')]][contains(text(),'Deposit #" + depositNumber + "')]"); } else if (transactionType == "Check") { idToSave = createVisibleWebElementByXpath("//p[@id[contains(.,'transactionSerialNumber-')]][contains(text(),'Check #" + depositNumber + "')]"); } else if (transactionType == "Transfer Funds") { idToSave = createVisibleWebElementByXpath("//p[@id[contains(.,'transactionSerialNumber-')]][contains(text(),'Transfer Funds #" + depositNumber + "')]"); } } else { if (transactionType == "Deposit") { newDepositNumber = ScenarioContext.Current.Get <string>("depositNumber"); idToSave = createVisibleWebElementByXpath("//p[@id[contains(.,'transactionSerialNumber-')]][contains(text(),'Deposit #" + newDepositNumber + "')]"); } else if (transactionType == "Check") { newDepositNumber = ScenarioContext.Current.Get <string>("depositNumber"); idToSave = createVisibleWebElementByXpath("//p[@id[contains(.,'transactionSerialNumber-')]][contains(text(),'Check #" + newDepositNumber + "')]"); } else if (transactionType == "Transfer Funds") { newDepositNumber = ScenarioContext.Current.Get <string>("depositNumber"); idToSave = createVisibleWebElementByXpath("//p[@id[contains(.,'transactionSerialNumber-')]][contains(text(),'Transfer Funds #" + newDepositNumber + "')]"); } } string transactionIDString = idToSave.GetAttribute("id").ToString().Replace("transactionSerialNumber-", ""); int transactionIdInt = Convert.ToInt32(transactionIDString); AddDataToScenarioContextOverridingExistentKey("transactionId", transactionIdInt); TestsLogger.Log(transactionIDString); pleaseWaitSignDissapear(); }
//Waits for an element to be visible and enabled on the UI for the given time, then and returns its IWebElement protected IWebElement WaitForElementToBeClickeable(By by, int seconds) { string logMsg = "WaitForElementToBeClickeable " + by.ToString() + " for " + seconds + " seconds top."; TestsLogger.Log(logMsg); try { WebDriverWait webDriverWait = new WebDriverWait(this.driver, GetTimeSpanInMilliseconds(seconds)); webDriverWait.IgnoreExceptionTypes(typeof(NoSuchElementException)); //to avoid instant failure breaks return(webDriverWait.Until(ExpectedConditions.ElementToBeClickable(by))); } catch (WebDriverException exception) { throw new MissingElementException("Exception when performing: " + logMsg, exception); } }
protected static void scrollListDown(ReadOnlyCollection <IWebElement> collection, int collectionExpectedCount, IWebElement elementToSendKeys, string collectionXpath) { DateTime dt = DateTime.Now.AddMinutes(5); while (collection.Count != collectionExpectedCount && dt >= DateTime.Now) { elementToSendKeys.Click(); for (int i = 0; i < 200; i++) { elementToSendKeys.SendKeys(Keys.ArrowDown); } collection = createVisibleElementsCollectionByXpath(collectionXpath); string actualCount = collection.Count.ToString(); TestsLogger.Log(actualCount + " VS " + collectionExpectedCount); } }
//waits for an element to be visible and have the exact given text for the given amount of time protected IWebElement WaitForElementToHaveText(By by, string text, int seconds) { string logMsg = "WaitForElementToHaveText " + by.ToString() + " : '" + text + "' for " + seconds + " seconds top."; TestsLogger.Log(logMsg); try { IWebElement we = WaitForElementToBeVisible(by, seconds); WebDriverWait webDriverWait = new WebDriverWait(this.driver, GetTimeSpanInMilliseconds(seconds)); webDriverWait.IgnoreExceptionTypes(typeof(NoSuchElementException)); //to avoid instant failure breaks webDriverWait.Until(ExpectedConditions.TextToBePresentInElementLocated(by, text)); return(we); } catch (WebDriverException exception) { throw new MissingElementException("Exception when performing: " + logMsg, exception); } }
// const string ADMIN_NAME = "mngr"; // const string ADMIN_PSWD = "mngrPswd"; public ThreadTest(TestsLogger testsLogger, BridgeForumGenerator bridge) { this.bridge = bridge; this.testsLogger = testsLogger; this.bridge.reset(); }
public AdminAccTests(TestsLogger testsLogger, BridgeForumGenerator bridge) { this.bridge = bridge; this.testsLogger = testsLogger; }
public SuperUserAccTests(TestsLogger testsLogger, BridgeForumGenerator bridge) { this.bridge = bridge; this.testsLogger = testsLogger; }
public ScalabiltyTest(TestsLogger testsLogger, BridgeForumGenerator bridge) { this.bridge = bridge; this.testsLogger = testsLogger; }
public GuestAccTests(TestsLogger testsLogger, BridgeForumGenerator bridge) { this.bridge = bridge; this.testsLogger = testsLogger; this.bridge.reset(); }
public AdvancedTest(TestsLogger testsLogger, BridgeForumGenerator bridge) { this.bridge = bridge; this.testsLogger = testsLogger; }