コード例 #1
0
        internal bool ShareSkill()
        {
            try
            {
                //Populate From Excel
                GlobalDefinitions.ExcelLib.PopulateInCollection(Base.ExcelPath, "ShareSkill");
                Thread.Sleep(2000);

                //Enter Title
                Title.SendKeys(ExcelLib.ReadData(2, "Title"));

                //Enter Description
                Description.SendKeys(ExcelLib.ReadData(2, "Description"));

                Thread.Sleep(2000);
                //Select Category
                SelectElement Categories = new SelectElement(Category);
                Categories.SelectByText(ExcelLib.ReadData(2, "Category"));

                //select Sub category
                SelectElement SubCategories = new SelectElement(Subcategory);
                SubCategories.SelectByText(ExcelLib.ReadData(2, "Subcategory"));

                Thread.Sleep(2000);
                //Enter Tags
                TagInner.SendKeys(ExcelLib.ReadData(2, "Tags"));
                TagInner.SendKeys(Keys.Enter);

                //Service type
                string ServiceToSelect = ExcelLib.ReadData(2, "ServiceType");
                if (ServiceToSelect == "One-off service")
                {
                    ServiceOne.Click();
                }
                else if (ServiceToSelect == "Hourly basis service")
                {
                    ServiceHourly.Click();
                }

                //select Location type
                string Locationtype = ExcelLib.ReadData(2, "LocationType");
                if (Locationtype == "On-site")
                {
                    LocationOnsite.Click();
                }
                else if (Locationtype == "Online")
                {
                    LocationOnline.Click();
                }
                Thread.Sleep(2000);
                string   SDate     = ExcelLib.ReadData(2, "StartDate");
                string[] SDateForm = SDate.Split(' ');

                StartDate.SendKeys(SDateForm[0]);

                string   EDate     = ExcelLib.ReadData(2, "EndDate");
                string[] EDateForm = EDate.Split(' ');

                EndDate.SendKeys(EDateForm[0]);

                Thread.Sleep(2000);
                string days           = ExcelLib.ReadData(2, "AvailableDays");
                string DaysToLwercase = days.ToLower();

                string[] Dayslist = DaysToLwercase.Split(',');
                int      count    = Dayslist.Count();

                string   StartTimevalue = ExcelLib.ReadData(2, "StartTime");
                string[] Starttimelist  = StartTimevalue.Split(',');


                string   EndTimeValue = ExcelLib.ReadData(2, "EndTime");
                string[] EndTimelist  = EndTimeValue.Split(',');


                for (int i = 0; i <= count - 1; i++)
                {
                    if (Dayslist[i].ToLower() == "sunday")
                    {
                        GlobalDefinitions.driver.FindElement(By.XPath("//div[@class='form-wrapper']//div[2]//div[1]//div[1]//input[1]")).Click();
                        IWebElement StartTime = GlobalDefinitions.driver.FindElement(By.XPath("//div[@class='form-wrapper']//div[2]//div[2]//input[1]"));
                        IWebElement EndTime   = GlobalDefinitions.driver.FindElement(By.XPath("//div[@class='form-wrapper']//div[2]//div[3]//input[1]"));
                        StartTime.SendKeys(Starttimelist[i]);
                        EndTime.SendKeys(EndTimelist[i]);
                    }
                    else if (Dayslist[i].ToLower() == "monday")
                    {
                        GlobalDefinitions.driver.FindElement(By.XPath("//div[@class='form-wrapper']//div[3]//div[1]//div[1]//input[1]")).Click();
                        IWebElement StartTime = GlobalDefinitions.driver.FindElement(By.XPath("//div[@class='form-wrapper']//div[3]//div[2]//input[1]"));
                        IWebElement EndTime   = GlobalDefinitions.driver.FindElement(By.XPath("//div[@class='form-wrapper']//div[3]//div[3]//input[1]"));
                        StartTime.SendKeys(Starttimelist[i]);
                        EndTime.SendKeys(EndTimelist[i]);
                    }
                    else if (Dayslist[i].ToLower() == "tuesday")
                    {
                        GlobalDefinitions.driver.FindElement(By.XPath("//div[@class='form-wrapper']//div[4]//div[1]//div[1]//input[1]")).Click();
                        IWebElement StartTime = GlobalDefinitions.driver.FindElement(By.XPath("//div[@class='form-wrapper']//div[4]//div[2]//input[1]"));
                        IWebElement EndTime   = GlobalDefinitions.driver.FindElement(By.XPath("//div[@class='form-wrapper']//div[4]//div[3]//input[1]"));
                        StartTime.SendKeys(Starttimelist[i]);
                        EndTime.SendKeys(EndTimelist[i]);
                    }

                    else if (Dayslist[i].ToLower() == "wednesday")
                    {
                        GlobalDefinitions.driver.FindElement(By.XPath("//div[@class='form-wrapper']//div[5]//div[1]//div[1]//input[1]")).Click();
                        IWebElement StartTime = GlobalDefinitions.driver.FindElement(By.XPath("//div[@class='form-wrapper']//div[5]//div[2]//input[1]"));
                        IWebElement EndTime   = GlobalDefinitions.driver.FindElement(By.XPath("//div[@class='form-wrapper']//div[5]//div[3]//input[1]"));
                        StartTime.SendKeys(Starttimelist[i]);
                        EndTime.SendKeys(EndTimelist[i]);
                    }

                    else if (Dayslist[i].ToLower() == "thursday")
                    {
                        GlobalDefinitions.driver.FindElement(By.XPath("//div[@class='form-wrapper']//div[6]//div[1]//div[1]//input[1]")).Click();
                        IWebElement StartTime = GlobalDefinitions.driver.FindElement(By.XPath("//div[@class='form-wrapper']//div[6]//div[2]//input[1]"));
                        IWebElement EndTime   = GlobalDefinitions.driver.FindElement(By.XPath("//div[@class='form-wrapper']//div[6]//div[3]//input[1]"));
                        StartTime.SendKeys(Starttimelist[i]);
                        EndTime.SendKeys(EndTimelist[i]);
                    }
                    else if (Dayslist[i].ToLower() == "friday")
                    {
                        GlobalDefinitions.driver.FindElement(By.XPath("//div[@class='form-wrapper']//div[7]//div[1]//div[1]//input[1]")).Click();
                        IWebElement StartTime = GlobalDefinitions.driver.FindElement(By.XPath("//div[@class='form-wrapper']//div[7]//div[2]//input[1]"));
                        IWebElement EndTime   = GlobalDefinitions.driver.FindElement(By.XPath("//div[@class='form-wrapper']//div[7]//div[3]//input[1]"));
                        StartTime.SendKeys(Starttimelist[i]);
                        EndTime.SendKeys(EndTimelist[i]);
                    }

                    else if (Dayslist[i].ToLower() == "saturday")
                    {
                        GlobalDefinitions.driver.FindElement(By.XPath("//div[@class='form-wrapper']//div[8]//div[1]//div[1]//input[1]")).Click();
                        IWebElement StartTime = GlobalDefinitions.driver.FindElement(By.XPath("//div[@class='form-wrapper']//div[8]//div[2]//input[1]"));
                        IWebElement EndTime   = GlobalDefinitions.driver.FindElement(By.XPath("//div[@class='form-wrapper']//div[8]//div[3]//input[1]"));
                        StartTime.SendKeys(Starttimelist[i]);
                        EndTime.SendKeys(EndTimelist[i]);
                    }
                }


                //select Skill trade
                string SkillTrade = ExcelLib.ReadData(2, "SkillTrade");
                if (SkillTrade == "Credit")
                {
                    Skillcredit.Click();
                    //Add credit
                    Credit.SendKeys(ExcelLib.ReadData(2, "Credit"));
                }
                else if (SkillTrade == "Skill-exchange")
                {
                    SkillExcha.Click();

                    //Add Skill Exchange
                    SkillExchange.SendKeys(ExcelLib.ReadData(2, "SkillExchange"));
                    SkillExchange.SendKeys(Keys.Enter);
                }

                Samples.Click();
                Thread.Sleep(2000);
                AutoItX3 file = new AutoItX3();
                file.WinActivate("Open");
                file.Send(ExcelLib.ReadData(2, "WorkSamples"));
                Thread.Sleep(1000);
                file.Send("{ENTER}");

                Thread.Sleep(2000);

                Save.Click();

                Thread.Sleep(2000);
                return(true);
            }

            catch (Exception e)
            {
                Base.test.Log(LogStatus.Fail, "Error in adding service" + e.Message);
                return(false);
            }
        }