Example #1
0
        internal void AddService()
        {
            //Populate the Excel Sheet
            GlobalDefinitions.ExcelLib.PopulateInCollection(Base.ExcelPath, "ShareSkill");
            GlobalDefinitions.wait(10);

            //Check if user is able to click on ShareSkill button
            ShareSkillbtn.Click();
            GlobalDefinitions.wait(10);
            Boolean isPresent = GlobalDefinitions.driver.FindElements(By.XPath("//input[@name='title']")).Count > 0;

            if (isPresent == true)
            {
                Base.test.Log(LogStatus.Pass, "Share Skill button is clicked Successfully");
            }
            else
            {
                Base.test.Log(LogStatus.Fail, "Share Skill button Click is UnSuccessful");
            }

            //Check if user is able to enter valid data as Title
            Title.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "Title"));
            //checking for invalid data
            Boolean isError = GlobalDefinitions.driver.FindElements(By.XPath("//div[@class='ui basic red prompt label transition visible']")).Count > 0;

            if (isError == true)
            {
                if (Invalid.Text == GlobalDefinitions.ExcelLib.ReadData(2, "Title Error Message"))
                {
                    Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "Error displayed as expected: First character must be an alphabet character or a number");
                }
            }
            else
            {
                //Check if user is able to Enter Title
                Boolean isTitleFetched = GlobalDefinitions.driver.FindElements(By.XPath("//input[@value='Software Tester']")).Count > 0;
                if (isTitleFetched == true)
                {
                    Base.test.Log(LogStatus.Pass, "Title is Fetched from The Excel Successfully");
                }
                else
                {
                    Base.test.Log(LogStatus.Fail, "Title is not fetched correctly");
                }
            }


            //Check if user is able to enter valid data as description
            Description.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "Description"));
            //checking for invalid data
            if (isError == true)
            {
                if (Invalid.Text == GlobalDefinitions.ExcelLib.ReadData(2, "Title Error Message"))
                {
                    Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "Error displayed as expected: Special characters are not allowed");
                }
            }
            //code for valid data
            else
            {
                if (Description.Text == GlobalDefinitions.ExcelLib.ReadData(2, "Description"))
                {
                    Base.test.Log(LogStatus.Pass, "Description is Fetched from The Excel Successfully");
                }
                else
                {
                    Base.test.Log(LogStatus.Fail, "Description is not fetched correctly");
                }
            }

            //Check if user is able to select Category
            CategoryId.Click();
            IList <IWebElement> Category = CategoryId.FindElements(By.TagName("option"));
            int categorycount            = Category.Count;

            for (int i = 0; i < categorycount; i++)
            {
                if (Category[i].Text == GlobalDefinitions.ExcelLib.ReadData(2, "CategoryId"))
                {
                    Category[i].Click();
                    Base.test.Log(LogStatus.Pass, "Selected Category");
                    break;
                }
                else
                {
                    Base.test.Log(LogStatus.Info, "Cant find Category");
                }
            }

            //Check if user is able to choose Subcategory
            SubcategoryId.Click();
            IList <IWebElement> SubCategory = SubcategoryId.FindElements(By.TagName("option"));
            int subcategorycount            = SubCategory.Count;

            for (int j = 0; j < subcategorycount; j++)
            {
                if (SubCategory[j].Text == GlobalDefinitions.ExcelLib.ReadData(2, "SubcategoryId"))
                {
                    SubCategory[j].Click();
                    Base.test.Log(LogStatus.Pass, "Selected Subcategory");
                    break;
                }
                else
                {
                    Base.test.Log(LogStatus.Info, "Cant find Subcategory");
                }
            }


            //Check if user is able to Enter valid tags
            Boolean isTagPresent = GlobalDefinitions.driver.FindElements(By.XPath("//span[contains(.,'test')]")).Count > 0;

            if (isTagPresent == true)
            {
                Base.test.Log(LogStatus.Info, "Tag already exists");
            }
            else
            {
                Tags.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "Tags"));
                Tags.SendKeys(Keys.Enter);
                Tags.SendKeys(Keys.Tab);
                Base.test.Log(LogStatus.Pass, "Tag added successfully");
            }

            //Check if user is able to select Service Type
            switch (GlobalDefinitions.ExcelLib.ReadData(2, "Service Type"))
            {
            case "Hourlybasis":
                HourlybasisServiceButton.Click();
                Base.test.Log(LogStatus.Pass, "Hourly basis service is selected");
                break;

            case "One-off":
                OneoffServiceButton.Click();
                Base.test.Log(LogStatus.Pass, "One-off service is selected");
                break;
            }

            //Check if user is able to select Location Type
            switch (GlobalDefinitions.ExcelLib.ReadData(2, "Location Type"))
            {
            case "On-site":
                OnsiteButton.Click();
                Base.test.Log(LogStatus.Pass, "Onsite location type is selected");
                break;

            case "Online":
                OnlineButton.Click();
                Base.test.Log(LogStatus.Pass, "Online location type is selected");
                break;
            }

            //Check if user is able to enter valid Date
            StartDate.Click();
            GlobalDefinitions.wait(10);
            StartDate.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "StartDate"));
            //checking for invalid start date
            if (isError == true)
            {
                if (Invalid.Text == GlobalDefinitions.ExcelLib.ReadData(2, "Title Error Message"))
                {
                    Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "Error displayed as expected: Start Date cannot be set to a day in the past");
                }
            }
            EndDate.Click();
            GlobalDefinitions.wait(10);
            EndDate.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "EndDate"));
            Day.Click();
            GlobalDefinitions.wait(10);

            //Check if user is able to select Time
            StartTime.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "StartTime"));
            EndTime.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "EndTime"));
            Base.test.Log(LogStatus.Pass, "Availability is selected");

            //Check if user is able to slect Skill-Trade
            switch (GlobalDefinitions.ExcelLib.ReadData(2, "Skill Trade"))
            {
            case "Skill-exchange":
                SkillExchangebutton.Click();
                Boolean isSkillTagPresent = GlobalDefinitions.driver.FindElements(By.XPath("//span[contains(.,'cooking')]")).Count > 0;
                if (isTagPresent == true)
                {
                    Base.test.Log(LogStatus.Info, "Tag already exists");
                }
                else
                {
                    SkillTag.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "Skills"));
                    SkillTag.SendKeys(Keys.Enter);
                    SkillTag.SendKeys(Keys.Tab);
                    Base.test.Log(LogStatus.Pass, "SkillTag is fetched successfully");
                }
                break;

            case "Credit":
                Creditbutton.Click();
                Base.test.Log(LogStatus.Info, "Credit is selected");
                Credit.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "Credit"));
                Boolean isCreditFetched = GlobalDefinitions.driver.FindElements(By.XPath("//input[@value='10']")).Count > 0;
                if (isCreditFetched == true)
                {
                    Base.test.Log(LogStatus.Pass, "Credit is Fetched from The Excel Successfully");
                }
                else
                {
                    Base.test.Log(LogStatus.Fail, "Credit is not fetched correctly");
                }
                break;
            }

            //Check if user is able to Upload worksample using AutoIt tool
            WorkSample.Click();
            Thread.Sleep(1000);
            AutoItX.WinActivate("Open");
            AutoItX.Send(GlobalDefinitions.ExcelLib.ReadData(2, "Upload File Path"));
            Thread.Sleep(1000);
            AutoItX.Send("{Enter}");
            Boolean isWorksampleUploaded = GlobalDefinitions.driver.FindElements(By.XPath("//a[text()='dd.txt']")).Count > 0;

            if (isWorksampleUploaded == true)
            {
                Base.test.Log(LogStatus.Pass, "Uploaded file successfully");
            }
            else
            {
                Base.test.Log(LogStatus.Fail, "File Updation Unsuccessful");
            }

            //Check if user is able to choose state
            switch (GlobalDefinitions.ExcelLib.ReadData(2, "State"))
            {
            case "Active":
                GlobalDefinitions.wait(60);
                Activebutton.Click();
                Base.test.Log(LogStatus.Pass, "Active state is selected");
                break;

            case "Hidden":
                Hiddenbutton.Click();
                Base.test.Log(LogStatus.Pass, "Hidden state is selected");
                break;
            }

            //Check if user is able to click Save button
            Savebtn.Click();
            Base.test.Log(LogStatus.Pass, "Save button is clicked");
        }