public void AbleToCreateNewEmployeeWth_ValidData() { ExcelLib.PopulateInCollection(Test.Base.ExcelPath, "Employees"); NavigateToEmployeesPage(); Driver.wait(2); Name.SendKeys(ExcelLib.ReadData(10, "Name")); Username.SendKeys(ExcelLib.ReadData(10, "UserName")); Edit_Contact.Click(); Driver.driver.SwitchTo().Frame(Driver.driver.FindElement(By.TagName("iframe"))); SaveEditContactwithValidData(); Driver.wait(2); Driver.driver.SwitchTo().ParentFrame(); Password.SendKeys(ExcelLib.ReadData(10, "Password")); RetypePassword.SendKeys(ExcelLib.ReadData(10, "Confirm Password")); Driver.wait(2); if (!IsAdmin.Selected) { Thread.Sleep(3000); IsAdmin.Click(); } Save_btn.Click(); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Info, "Save button clicked after entering valid data"); IWebElement title = Driver.driver.FindElement(By.XPath("html/body/div[4]/h2")); string page_title = title.Text; try { string URL = Driver.driver.Url; Console.WriteLine(URL); Assert.AreSame("http://52.65.131.15/User", URL); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "User Navigated back to Administration>Employees Page"); } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Still on Create New Employee Page, Should navigate back to Administration>Employees Page"); Back_to_list.Click(); } try { Search_For_Record("Valid"); } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Employees details are not found in the list. Test Failed"); } }
public void Verify_Max_Lngth() { ExcelLib.PopulateInCollection(Test.Base.ExcelPath, "Employees"); int Name_length = 0; int Uname_length = 0; NavigateToEmployeesPage(); try { string name = ExcelLib.ReadData(5, "Name"); Name.SendKeys(name); string uname = ExcelLib.ReadData(5, "UserName"); Username.SendKeys(uname); Name_length = name.Length; Uname_length = uname.Length; Driver.wait(2); Save_btn.Click(); try { if (Name_length > 30) { IWebElement Name_Err_Element = Driver.driver.FindElement(By.XPath("html/body/div[4]/form/div/div[1]/div/span/span")); bool IsErrorDisplayed = Name_Err_Element.Displayed; string Actual_err_msge = Name_Err_Element.Text; string Expctd_err_msge = ExcelLib.ReadData(2, "Verify_Lgth_err"); if (IsErrorDisplayed == true) { if (Actual_err_msge == Expctd_err_msge) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Test Failed, Name should be in between 1-30 alphabetical characters"); Console.WriteLine("Name should be in between 1-30 alphabetical characters"); } else { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Test Failed, Incorrect Error message. It should be \"Name should be in between 1-30 alphabetical characters\""); Console.WriteLine("Name should be in between 1-30 alphabetical characters"); } } } else { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "Name textfield accepts only 1-30 alphabetical characters"); Console.WriteLine("Test Pass"); } } catch (Exception e) { string length = "No. of characters used is " + Convert.ToString(Name_length) + "."; Console.WriteLine("Name characters Length is: {0}, No error message displayed", Name_length); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Test Fail : Name is longer than Maximum length, No error message displayed", length); } try { if (Uname_length > 30) { IWebElement Uname_Err_Element = Driver.driver.FindElement(By.XPath("html/body/div[4]/form/div/div[2]/div/span/span")); bool IsErrorDisplayed = Uname_Err_Element.Displayed; string Actual_err_msge = Uname_Err_Element.Text; string Expctd_err_msge = ExcelLib.ReadData(3, "Verify_Lgth_err"); if (IsErrorDisplayed == true) { if (Actual_err_msge == Expctd_err_msge) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Test Failed, UserName should be in between 1-30 alphabetical characters"); Console.WriteLine("UserName should be in between 1-30 alphabetical characters"); } else { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Test Failed, Incorrect Error message. It should be \"UserName should be in between 1-30 alphabetical characters\""); Console.WriteLine("UserName should be in between 1-30 alphabetical characters"); } } } else { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "UserName textfield accepts only 1-30 alphabetical characters"); Console.WriteLine("Test Pass"); } } catch (Exception e) { string length = "No. of characters used is " + Convert.ToString(Uname_length) + "."; Console.WriteLine("UserName characters Length is: {0}, No error message displayed", Uname_length); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Test Fail : UserName is longer than Maximum length, No error message displayed", length); } } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, " Test failed due to unknown reasons. Please check defined variables and Webelements"); } }
public void Create_Employee_Wth_NullData() { ExcelLib.PopulateInCollection(Test.Base.ExcelPath, "Employees"); NavigateToEmployeesPage(); Driver.wait(2); Save_btn.Click(); // To check is user is still on the same page. try { IWebElement title = Driver.driver.FindElement(By.XPath("html/body/div[4]/h2")); string page_title = title.Text; Console.WriteLine(page_title); Assert.AreEqual("Employee Details", page_title); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "Still on Create new Employee Page, Details not added"); } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Navigated to a different page"); } // To check if user is getting any error message on entering Invalid data try { IWebElement element = Driver.driver.FindElement(By.XPath("html/body/div[4]/form/div/div[1]/div/span/span")); bool visible = element.Displayed; string actual_err = element.Text; string expected_err = ExcelLib.ReadData(2, "Null_data_error"); try { if (visible == true) { Assert.AreEqual(expected_err, actual_err); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "Name Field: Correct error message displayed"); } } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Name Field: Incorrect error message displayed"); } } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Name Field: Error message missing"); } // Validate error message for UserName Textfield try { IWebElement element = Driver.driver.FindElement(By.XPath("html/body/div[4]/form/div/div[2]/div/span/span")); bool visible = element.Displayed; string actual_err = element.Text; string expected_err = ExcelLib.ReadData(3, "Null_data_error"); try { if (visible == true) { Assert.AreEqual(expected_err, actual_err); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "UserName Field: Correct error message displayed"); } } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "UserName Field: Incorrect error message displayed"); } } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "UserName Field: Error message missing"); } // Validate error message for Password Textfield try { IWebElement element = Driver.driver.FindElement(By.XPath("html/body/div[4]/form/div/div[4]/div/span/span")); bool visible = element.Displayed; string actual_err = element.Text; string expected_err = ExcelLib.ReadData(4, "Null_data_error"); try { if (visible == true) { Assert.AreEqual(expected_err, actual_err); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "Password Field: Correct error message displayed"); } } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Password Field: Incorrect error message displayed"); } } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Password Field: Error message missing"); } }
public void CreateEmployee_Wth_InvalidData() { ExcelLib.PopulateInCollection(Test.Base.ExcelPath, "Employees"); NavigateToEmployeesPage(); Driver.wait(2); Name.SendKeys(ExcelLib.ReadData(2, "Name")); Username.SendKeys(ExcelLib.ReadData(2, "UserName")); Password.SendKeys(ExcelLib.ReadData(2, "Password")); RetypePassword.SendKeys(ExcelLib.ReadData(2, "Confirm Password")); Driver.wait(2); if (!IsAdmin.Selected) { Thread.Sleep(3000); IsAdmin.Click(); } Save_btn.Click(); // To check is user is still on the same page. try { IWebElement title = Driver.driver.FindElement(By.XPath("html/body/div[4]/h2")); string page_title = title.Text; Console.WriteLine(page_title); Assert.AreEqual("Employee Details", page_title); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "Still on Create new Employee Page, Details not added"); } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Navigated to a different page"); } // To check if user is getting any error message on entering Invalid data try { IWebElement element = Driver.driver.FindElement(By.XPath("html/body/div[4]/form/div/div[1]/div/span/span")); bool visible = element.Displayed; string actual_err = element.Text; string expected_err = ExcelLib.ReadData(2, "Error_messages"); try { if (visible == true) { Assert.AreEqual(expected_err, actual_err); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "Name Field: Correct error message displayed"); } } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Name Field: Incorrect error message displayed"); } } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Name Field: Error message missing"); } // Validate error message for UserName Textfield try { IWebElement element = Driver.driver.FindElement(By.XPath("html/body/div[4]/form/div/div[2]/div/span/span")); bool visible = element.Displayed; string actual_err = element.Text; string expected_err = ExcelLib.ReadData(3, "Error_messages"); try { if (visible == true) { Assert.AreEqual(expected_err, actual_err); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "UserName Field: Correct error message displayed"); } } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "UserName Field: Incorrect error message displayed"); } } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "UserName Field: Error message missing"); } // Validate error message for Password Textfield try { IWebElement element = Driver.driver.FindElement(By.XPath("html/body/div[4]/form/div/div[4]/div/span/span")); bool visible = element.Displayed; string actual_err = element.Text; string expected_err = ExcelLib.ReadData(4, "Error_messages"); try { if (visible == true) { Assert.AreEqual(expected_err, actual_err); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "Password Field: Correct error message displayed"); } } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Password Field: Incorrect error message displayed"); } } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Password Field: Error message missing"); } // Calling Search method to verify if invalid record is created try { Search_For_Record("Invalid"); } catch { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "Invalid data Record Not Created"); } }