internal void EnterShareSkill1() { Global.GlobalDefinitions.wait(60000); ShareSkillButton.Click(); //Populate the Excel Sheet GlobalDefinitions.ExcelLib.PopulateInCollection(Base.ExcelPath, "ShareSkill"); //********************************** //Enter the Title Title.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "Title")); Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Info, "Title has been successfully entered"); //******************************************** //Enter the Description Description.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "Description")); Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Info, "Description has been successfully entered"); //****************************************** //Select the Category option Actions action = new Actions(GlobalDefinitions.driver); action.MoveToElement(CategoryDropDown).Build().Perform(); System.Collections.Generic.IList <IWebElement> ServiceCategory = CategoryDropDown.FindElements(By.TagName("option")); int count = ServiceCategory.Count; Console.WriteLine("Number of Category : " + count); for (int i = 0; i < count; i++) { if (ServiceCategory[i].Text == GlobalDefinitions.ExcelLib.ReadData(2, "Category")) { ServiceCategory[i].Click(); Base.test.Log(LogStatus.Info, "Category has been successfully selected"); break; } } //**************************************** //Select the subcategory action.MoveToElement(SubCategoryDropDown).Build().Perform(); IList <IWebElement> SubCategory = SubCategoryDropDown.FindElements(By.TagName("option")); int subcategorycount = SubCategory.Count; Console.WriteLine("Number of Sub Category : " + subcategorycount); for (int i = 0; i < subcategorycount; i++) { if (SubCategory[i].Text == GlobalDefinitions.ExcelLib.ReadData(2, "SubCategory")) { SubCategory[i].Click(); Base.test.Log(LogStatus.Info, "Sub Category has been successfully selected"); break; } } //************************************** //Enter Tag name Tags.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "Tags")); Tags.SendKeys(Keys.Enter); Base.test.Log(LogStatus.Pass, "Tag name has been succesfully enetered"); //************************************ //Service Type Option action.MoveToElement(ServiceTypeOptions).Build().Perform(); Thread.Sleep(3000); // Storing all the elements under category of 'Service Type' in the list of WebLements IList <IWebElement> ServiceType = ServiceTypeOptions.FindElements(By.XPath("//div/input[@name='serviceType']")); //Indicating the number of buttons present int servicetypecount = ServiceType.Count; Console.WriteLine("Number of Service type : " + servicetypecount); for (int i = 0; i < servicetypecount; i++) { //Storing the radio button to the string variable "Value", using the "value" attribute string Value = ServiceType.ElementAt(i).GetAttribute("value"); int j = i + 1; var Name = GlobalDefinitions.driver.FindElement(By.XPath("//*[@id='service-listing-section']/div[2]/div/form/div[5]/div[2]/div[1]/div[" + j + "]/div/label")).Text; //Checking if Name equals the "name" attribute - "ServiceType" if (Name.Equals(ExcelLib.ReadData(2, "ServiceType")) && Value.Equals("" + i)) { ServiceType.ElementAt(i).Click(); Base.test.Log(LogStatus.Pass, "Service Type has been succesfully selected"); break; } } //***************************************** //Location Type Option action.MoveToElement(LocationTypeOption).Build().Perform(); Thread.Sleep(3000); // Storing all the elements under category of 'Location Type' in the list of WebLements IList <IWebElement> LocationType = LocationTypeOption.FindElements(By.XPath("//div/input[@name='locationType']")); //Indicating the number of buttons present int locationtypecount = LocationType.Count; Console.WriteLine("Number of Location type : " + locationtypecount); for (int i = 0; i < locationtypecount; i++) { //Storing the radio button to the string variable "Value", using the "value" attribute string Value = LocationType.ElementAt(i).GetAttribute("value"); int j = i + 1; var Name = GlobalDefinitions.driver.FindElement(By.XPath("//*[@id='service-listing-section']/div[2]/div/form/div[6]/div[2]/div[1]/div[" + j + "]/div/label")).Text; //Checking if Name equals the "name" attribute - "LocationType" if (Name.Equals(ExcelLib.ReadData(2, "LocationType")) && Value.Equals("" + i)) { LocationType.ElementAt(i).Click(); Base.test.Log(LogStatus.Pass, "Location Type has been succesfully selected"); break; } } //****************************************** //Entering start date StartDateDropDown.SendKeys(Keys.Delete); Console.WriteLine("Start date read from excel is : " + GlobalDefinitions.ExcelLib.ReadData(2, "Startdate")); //1st Method using DateTime Class //==================================== var dateTime = GlobalDefinitions.ExcelLib.ReadData(2, "Startdate"); Console.WriteLine("Date is : " + dateTime); /*DateTime parsedDate = DateTime.Parse(dateTime); * Console.WriteLine("Parsed Date is : " + parsedDate); * //var dateTimeNow = DateTime.Now; /C:\Users\Vidhya\source\repos\MarsFramework\MarsFramework\packages\WebDriver.ChromeDriver.win32.2.41.0\content\chromedriver.exe/ Return 00/00/0000 00:00:00 * //Console.WriteLine("Date Time Now : " + dateTimeNow); * //var dateOnlyString = dateTimeNow.ToShortDateString(); //Return 00/00/0000 * //Console.WriteLine("Date only string is : " + dateOnlyString); * var dateOnlyString = parsedDate.ToShortDateString(); //To convert string to DateTime format Return 00/00/0000 00:00:00 * Console.WriteLine("Date only string is : " + dateOnlyString); * StartDateDropDown.SendKeys(dateOnlyString);*/ //2nd Method using string split //============================== string[] splitDate = dateTime.Split(' '); int countSplitDate = splitDate.Count(); Console.WriteLine("The count of date string is : " + countSplitDate); Console.WriteLine($"String 1 is : {splitDate[0]} "); Console.WriteLine($"String 2 is : {splitDate[1]} "); Console.WriteLine($"String 3 is : {splitDate[2]} "); StartDateDropDown.SendKeys(splitDate[0]); StartDateDropDown.SendKeys(Keys.Tab); Base.test.Log(LogStatus.Pass, "Start Date has succesfully been edited"); //****************************************** //Entering End date //Console.Out.Write("End Date read from excel is : " + GlobalDefinitions.ExcelLib.ReadData(2, "Enddate")); Console.WriteLine("End Date read from excel is : " + GlobalDefinitions.ExcelLib.ReadData(2, "Enddate")); //var endDate = GlobalDefinitions.ExcelLib.ReadData(2, "Enddate"); //DateTime parsedEndDate = DateTime.Parse(endDate); //var endDateonly = parsedEndDate.ToShortDateString(); //EndDateDropDown.SendKeys(endDateonly); EndDateDropDown.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "Enddate")); EndDateDropDown.SendKeys(Keys.Tab); Base.test.Log(LogStatus.Pass, "End Date has succesfully been edited"); //*************************************** //Selecting the day action.MoveToElement(Days).Build().Perform(); IList <IWebElement> allDays = Days.FindElements(By.XPath("//div/div/div/input[@name = 'Available']")); int allDaysCount = allDays.Count; Console.WriteLine("Number of Days : " + allDaysCount); for (int i = 0; i < allDaysCount; i++) { int j = i + 2; var day = GlobalDefinitions.driver.FindElement(By.XPath("//div[" + j + "]/div[1]/div[1]/label")).Text; if (day.Equals(ExcelLib.ReadData(2, "Selectday"))) { allDays.ElementAt(i).Click(); Base.test.Log(LogStatus.Pass, "Day has been succesfully selected"); break; } } //***************************************** //Entering the starttime Console.WriteLine("Start time read from excel is : " + GlobalDefinitions.ExcelLib.ReadData(2, "Starttime")); var startTime = GlobalDefinitions.ExcelLib.ReadData(2, "Starttime"); DateTime parsedStartTime = DateTime.Parse(startTime); var startTimeString = parsedStartTime.ToString("hh:mmtt"); //var startTimeString = parsedStartTime.ToShortTimeString(); Console.WriteLine("Start Time String is : " + startTimeString); StartTimeDropDown.SendKeys(startTimeString); StartTimeDropDown.SendKeys(Keys.Tab); //***************************************** //Entering the endtime GlobalDefinitions.wait(5); Console.WriteLine("End time read from excel is : " + GlobalDefinitions.ExcelLib.ReadData(2, "Endtime")); var endTime = GlobalDefinitions.ExcelLib.ReadData(2, "Endtime"); DateTime parsedEndTime = DateTime.Parse(endTime); var endTimeString = parsedEndTime.ToString("hh:mmtt"); Console.WriteLine("End Time String is : " + endTimeString); EndTimeDropDown.SendKeys(endTimeString); //****************************************** //Skill Trade Option action.MoveToElement(SkillTradeOption).Build().Perform(); // Storing all the elements under category of 'Skill Trade' in the list of WebLements IList <IWebElement> SkillTrade = SkillTradeOption.FindElements(By.XPath("//div/input[@name='skillTrades']")); //Indicating the number of buttons present int skilltradecount = SkillTrade.Count; Console.WriteLine("Number of Skill Trade : " + skilltradecount); for (int i = 0; i < skilltradecount; i++) { //Storing the radio button to the string variable "Value", using the "value" attribute string Value = SkillTrade.ElementAt(i).GetAttribute("value"); int j = i + 1; var Name = GlobalDefinitions.driver.FindElement(By.XPath("//*[@id='service-listing-section']/div[2]/div/form/div[8]/div[2]/div[1]/div[" + j + "]/div/label")).Text; //Checking if Name equals the "name" attribute - "LocationType" if (Name.Equals(ExcelLib.ReadData(2, "SkillTrade")) && Value.Equals("" + i)) { SkillTrade.ElementAt(i).Click(); Base.test.Log(LogStatus.Pass, "Skill Trade has been succesfully selected"); break; } } //**************************************** //Enter Skill-Exchange Tag name SkillExchange.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "Skill-Exchange")); SkillExchange.SendKeys(Keys.Enter); Base.test.Log(LogStatus.Pass, "Skill-Exchange Tag name has been succesfully enetered"); //************************************** //Active Option action.MoveToElement(ActiveOption).Build().Perform(); Thread.Sleep(3000); // Storing all the elements under category of 'Active' in the list of WebLements IList <IWebElement> Active = ActiveOption.FindElements(By.XPath("//div/input[@name='isActive']")); //Indicating the number of buttons present int activecount = Active.Count; Console.WriteLine("Number of Active : " + activecount); for (int i = 0; i < activecount; i++) { //Storing the radio button to the string variable "Value", using the "value" attribute string Value = Active.ElementAt(i).GetAttribute("value"); int j = i + 1; var Name = GlobalDefinitions.driver.FindElement(By.XPath("//*[@id='service-listing-section']/div[2]/div/form/div[10]/div[2]/div[1]/div[" + j + "]/div/label")).Text; //Checking if Name equals the "name" attribute - "Active Option" if (Name.Equals(ExcelLib.ReadData(2, "Active")))// && Value.Equals("" + i)) { Active.ElementAt(i).Click(); Base.test.Log(LogStatus.Pass, "Services option has been succesfully selected"); break; } } //************************************ //Save the page Save.Click(); }
internal void EditShareSkill() { //Populate the Excel sheet Global.GlobalDefinitions.ExcelLib.PopulateInCollection(Global.Base.ExcelPath, "ShareSkill"); int excelRowToRead = 3; Title.Clear(); Title.SendKeys(Global.GlobalDefinitions.ExcelLib.ReadData(excelRowToRead, "Title")); //Click on Description Description.Clear(); Description.SendKeys(Global.GlobalDefinitions.ExcelLib.ReadData(excelRowToRead, "Description")); //Select A Category CategoryDropDown.Click(); String categoryValue = Global.GlobalDefinitions.ExcelLib.ReadData(excelRowToRead, "Category"); IList <IWebElement> CategoriesDropDownList = CategoryDropDown.FindElements(By.XPath("//option")); int DpListCount = CategoriesDropDownList.Count; for (int i = 0; i < DpListCount; i++) { if (CategoriesDropDownList[i].Text == categoryValue) { CategoriesDropDownList[i].Click(); } } //Select Sub Category Thread.Sleep(1000); IWebElement SubCategorySelection = Global.GlobalDefinitions.driver.FindElement(By.Name("subcategoryId")); SubCategorySelection.Click(); String SubCategoryValue = Global.GlobalDefinitions.ExcelLib.ReadData(excelRowToRead, "SubCategory"); IList <IWebElement> SubCategoriesDropDownList = SubCategorySelection.FindElements(By.XPath("//option")); int SbDpListCount = SubCategoriesDropDownList.Count; for (int i = 0; i < SbDpListCount; i++) { if (SubCategoriesDropDownList[i].Text == SubCategoryValue) { SubCategoriesDropDownList[i].Click(); } } //Clear and Add Tags IWebElement tagsInputBox = Global.GlobalDefinitions.driver.FindElement(By.XPath("//*[@id='service-listing-section']/div[2]/div/form/div[4]/div[2]/div")); IList <IWebElement> RemoveButtons = tagsInputBox.FindElements(By.ClassName("ReactTags__remove")); foreach (IWebElement element in RemoveButtons) { element.Click(); } Tags.SendKeys(Global.GlobalDefinitions.ExcelLib.ReadData(excelRowToRead, "Tag")); Tags.SendKeys(Keys.Enter); //Select Service Type String ServiceType = Global.GlobalDefinitions.ExcelLib.ReadData(excelRowToRead, "Service Type"); if (ServiceType.Equals("Hourly basis Service")) { HourlyServiceType.Click(); } else if (ServiceType.Equals("One-off Service")) { OneOffServiceType.Click(); } //Select Location Type String LocatioType = Global.GlobalDefinitions.ExcelLib.ReadData(excelRowToRead, "Location Type"); if (LocatioType.Equals("On-site")) { OnSiteLocationType.Click(); } else if (OnSiteLocationType.Equals("Online")) { OnlineLocationType.Click(); } //Select Available Start Date IWebElement AvailableStartDateInput = AvailabilityForm.FindElement(By.Name("startDate")); AvailableStartDateInput.SendKeys(Global.GlobalDefinitions.ExcelLib.ReadData(excelRowToRead, "AvailableStartDate")); //Select Available End Date IWebElement AvailableEndDateInput = AvailabilityForm.FindElement(By.Name("endDate")); AvailableEndDateInput.SendKeys(Global.GlobalDefinitions.ExcelLib.ReadData(excelRowToRead, "AvailableEndDate")); String[] WeekDays = new String[] { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; //Cleared Selected Checkboxes IList <IWebElement> AvailableCheckBoxes = AvailabilityForm.FindElements(By.Name("Available")); foreach (IWebElement element in AvailableCheckBoxes) { if (element.Selected) { element.Click(); } } //Select Check boxes based on data String AvailableDaysValue = Global.GlobalDefinitions.ExcelLib.ReadData(excelRowToRead, "AvailableDays"); IList <String> AvailableDays = AvailableDaysValue.Split(','); for (int i = 0; i < WeekDays.Count(); i++) { if (AvailableDays.Contains(WeekDays[i])) { AvailableCheckBoxes[i].Click(); } } //Set Start times IList <IWebElement> AvailableStartTimeInputs = AvailabilityForm.FindElements(By.Name("StartTime")); String AvailableStartTimesValue = Global.GlobalDefinitions.ExcelLib.ReadData(excelRowToRead, "AvailableStartTimes"); IList <String> AvailableStartTimes = AvailableStartTimesValue.Split(','); for (int i = 0; i < AvailableStartTimes.Count(); i++) { IList <String> startTimeInfo = AvailableStartTimes[i].Split(':'); String startTimeDay = startTimeInfo[0]; String startTimeValue = startTimeInfo[1]; int indexOfDay = Array.IndexOf(WeekDays, startTimeDay); AvailableStartTimeInputs[indexOfDay].SendKeys(startTimeValue); } //Set End times IList <IWebElement> AvailableEndTimeInputs = AvailabilityForm.FindElements(By.Name("EndTime")); String AvailableEndTimesValue = Global.GlobalDefinitions.ExcelLib.ReadData(excelRowToRead, "AvailableEndTimes"); IList <String> AvailableEndTimes = AvailableEndTimesValue.Split(','); for (int i = 0; i < AvailableEndTimes.Count(); i++) { IList <String> endTimeInfo = AvailableEndTimes[i].Split(':'); String endTimeDay = endTimeInfo[0]; String endTimeValue = endTimeInfo[1]; int indexOfDay = Array.IndexOf(WeekDays, endTimeDay); AvailableEndTimeInputs[indexOfDay].SendKeys(endTimeValue); } //Select Skill Exchange Type String SkillTradeType = Global.GlobalDefinitions.ExcelLib.ReadData(excelRowToRead, "SkillTradeType"); if (SkillTradeType.Equals("Skill-exchange")) { SkillExchangeType.Click(); //Clear and Add Tags IWebElement SkillTagsInputBox = Global.GlobalDefinitions.driver.FindElement(By.XPath("//*[@id='service-listing-section']/div[2]/div/form/div[8]/div[4]/div/div")); IList <IWebElement> CrossButtons = SkillTagsInputBox.FindElements(By.ClassName("ReactTags__remove")); foreach (IWebElement element in CrossButtons) { element.Click(); } SkillExchangeTag.SendKeys(Global.GlobalDefinitions.ExcelLib.ReadData(excelRowToRead, "SkillExchangeTab")); SkillExchangeTag.SendKeys(Keys.Enter); } else if (SkillTradeType.Equals("Credit")) { CreditsType.Click(); CreditAmount.Clear(); CreditAmount.SendKeys(Global.GlobalDefinitions.ExcelLib.ReadData(excelRowToRead, "CreditsAmount")); } //Select Active Status Button String ActiveType = Global.GlobalDefinitions.ExcelLib.ReadData(excelRowToRead, "ActiveType"); if (SkillTradeType.Equals("Active")) { ActiveButton.Click(); } else if (SkillTradeType.Equals("Hidden")) { HiddenButton.Click(); } //Click on Save Button SaveButton.Click(); Thread.Sleep(3000); //Verify IWebElement listingTable = Global.GlobalDefinitions.driver.FindElement(By.XPath("//*[@id='listing-management-section']/div[2]/div[1]/table")); IList <IWebElement> tableRows = listingTable.FindElements(By.TagName("tr")); Boolean isListingEdited = false; for (int i = 0; i <= tableRows.Count; i++) { IWebElement row = tableRows[i]; if (row.Text.Contains(Global.GlobalDefinitions.ExcelLib.ReadData(excelRowToRead, "Title")) && row.Text.Contains(Global.GlobalDefinitions.ExcelLib.ReadData(excelRowToRead, "Description"))) { isListingEdited = true; break; } } if (isListingEdited == true) { Global.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "Edit Skill test Successful"); } else { Global.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Edit Skill test Failed"); } }