public void ATC3348_CRMEntityClientNameCreateNew() { //3348: Entity: Client Name - Create New #region Start Up Excel MyBook = MyApp.Workbooks.Open(DatasourceDir + @"\Clients.xlsx", 0, false, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); MySheet = (Excel.Worksheet)MyBook.Sheets[Properties.Settings.Default.ENVIRONMENT.ToString()]; MyRange = MySheet.UsedRange; //Get specific row for the data int testDataRows = MyRange.Rows.Count; System.Diagnostics.Debug.WriteLine("testDataRows Present: " + testDataRows.ToString()); int MyRow = 0; for (int i = 2; i <= testDataRows; i++) { if (MyRange.Cells[i, 1].Value.ToString() == "ClientTestData") { MyRow = i; break; } } #endregion string clientName = (MyRange.Cells[MyRow, ClientsSchema.GetColumnIndex("CLIENT_NAME")].Value.ToString()); String Title = (MyRange.Cells[MyRow, ClientsSchema.GetColumnIndex("TITLE")].Value.ToString()); String GivenName = (MyRange.Cells[MyRow, ClientsSchema.GetColumnIndex("GIVEN_NAME")].Value.ToString()); //String MiddleName = "Jackie"; String MiddleName = (MyRange.Cells[MyRow, ClientsSchema.GetColumnIndex("MIDDLE_NAME")].Value.ToString()); String FamilyName = (MyRange.Cells[MyRow, ClientsSchema.GetColumnIndex("FAMILY_NAME")].Value.ToString()); //String Suffix = "AM"; String Suffix = (MyRange.Cells[MyRow, ClientsSchema.GetColumnIndex("SUFFIX")].Value.ToString()); //Login in as role User user = this.environment.GetUser(SecurityRole.InvestigationsManager); new LoginDialog().Login(user.Id, user.Password); HomePage homePage = new HomePage(driver); homePage.HoverCRMRibbonTab(); homePage.ClickClientServicesRibbonButton(); homePage.HoverClientServicesRibbonTab(); homePage.ClickClientsRibbonButton(); ClientsSearchPage clientsSearchPage = new ClientsSearchPage(driver); clientsSearchPage.SetClientSearchText("BLAIR TEST"); Table table = new Table(clientsSearchPage.GetSearchResultTable()); StringAssert.Equals(table.GetCellValue("Full Name", "BLAIR TEST", "Full Name"), "BLAIR TEST"); table.ClickCellValue("Full Name", "BLAIR TEST", "Full Name"); //Navigate to Cient Name homePage.HoverClientXRibbonTab("BLAIR TEST"); homePage.ClickClientXClientNamesRibbonButton(); //Add new Cient Name ClientPage clientPage = new ClientPage(driver); string BaseWindow = driver.CurrentWindowHandle; System.Diagnostics.Debug.WriteLine("BaseWindow handle :" + BaseWindow.ToString()); clientPage.ClickAddNewClientName(); //*****************This needs to be moved out of here******************************************** string NewWindow = ""; //prepares for the new window handle ReadOnlyCollection<string> handles = null; //Check for Alert Present System.Diagnostics.Debug.WriteLine("Check for Alert Present"); try { if (driver.SwitchTo().Alert() != null) { System.Diagnostics.Debug.WriteLine("Alert Present: " + driver.SwitchTo().Alert().Text); System.Diagnostics.Debug.WriteLine("alert type: " + driver.SwitchTo().Alert().GetType().ToString()); driver.SwitchTo().Alert().Accept(); // prepares Selenium to handle alert } } catch (NoAlertPresentException) { // no alert message System.Diagnostics.Debug.WriteLine("No Alert Present"); } //switch to new window //for some reason UICommon.SwitchToNewBrowser does not detect there is a new window, so I'll reinstate the old code below // generally the old code detects the new window in under 10 sec. However, UICommon.SwitchToNewBrowser runs for 30sec and fails to find the new window, although it should find it. //driver = UICommon.SwitchToNewBrowser(driver, BaseWindow); //Check for New Window Present for (int i = 1; i < 10; i++) { if (driver.WindowHandles.Count == 1) { Thread.Sleep(1000); } else { break; } } handles = driver.WindowHandles; System.Diagnostics.Debug.WriteLine("window handle count :" + handles.Count); foreach (string handle in handles) { System.Diagnostics.Debug.WriteLine("window handle :" + handle.ToString()); var Handles = handle; if (BaseWindow != handle) { NewWindow = handle; driver = driver.SwitchTo().Window(NewWindow); System.Diagnostics.Debug.WriteLine("SwitchTo() New Window: " + NewWindow.ToString()); break; } } //Populate Client Name Page ClientNamePage clientNamePage = new ClientNamePage(driver); //select Client Title //clientNamePage.ClickTitleList(); clientNamePage.SetTitleListValue(Title); //clientNamePage.ClickGivenName(); clientNamePage.SetGivenNameValue(GivenName); //clientNamePage.ClickMiddleName(); clientNamePage.SetMiddleNameValue(MiddleName); //clientNamePage.ClickFamilyName(); clientNamePage.SetFamilyNameValue(FamilyName); //clientNamePage.ClickSuffixList(); clientNamePage.SetSuffixListValue(Suffix); clientNamePage.ClickSaveButton(); //switch back to Client Name Page window. This may not be necessary as we are already there. //switch to new window //driver = UICommon.SwitchToNewBrowser(driver, BaseWindow); string FormTitle_Expected = Title + " " + GivenName + " " + MiddleName + " " + FamilyName + " " + Suffix; //string FormTitle_Expected = Title + " " + GivenName + " " + FamilyName; //Get the saved FormTitle Text which gets displayed on the screen after the record is saved. //string FormTitle = clientNamePage.GetFormTitle("MISS Jan Jackie Rivers AM"); string FormTitle_Actual = clientNamePage.GetFormTitle(); System.Diagnostics.Debug.WriteLine("FormTitle_Actual: " + FormTitle_Actual); System.Diagnostics.Debug.WriteLine("FormTitle_Expected: " + FormTitle_Expected); //Assert clientName has saved. Assert.IsTrue(FormTitle_Actual.Equals(FormTitle_Expected.ToUpper()), "Actual Form Title does not match the expected (saved) value: " + FormTitle_Expected.ToUpper()); //Save and close the Client Name Page clientNamePage.ClickSaveCloseButton(); }