コード例 #1
0
        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");
            }
        }
コード例 #2
0
        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");
            }
        }