internal void LoginSteps() { // extent reports Base.test = Base.extent.StartTest("Login steps test"); //Populate excel data GlobalDefinitions.ExcelLib.PopulateInCollection(Base.ExcelPath, "SignIn"); // Wait Element GlobalDefinitions.WaitForElementClickable(GlobalDefinitions.driver, "XPath", "//a[contains(text(),'Sign')]", 10); // Click signin tab to signin page SignIntab.Click(); // Input username Email.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "Username")); // Input password Password.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "Password")); // Click Login button LoginBtn.Click(); // Verify the login status GlobalDefinitions.WaitForElementClickable(GlobalDefinitions.driver, "XPath", "//*[@id='account-profile-section']" + "//div[1]/div[2]/div/span", 10); var greeting = GlobalDefinitions.driver.FindElement(By.XPath("//*[@id='account-profile-section']//div[1]/div[2]/div/span")).Text; //Assert.That(loginName, Contains.Substring("Kimi")); if (greeting.Contains("Hi")) { Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "Login Successful"); } else { Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Login failed"); } }
internal void Notifications() { //Click on Notification tab GlobalDefinitions.WaitForElementVisibility(GlobalDefinitions.driver, "XPath", "//*[@id='account-profile-section']/div/div[1]/div[2]/div/div", 10000); ClickNotification.Click(); //Click on See all GlobalDefinitions.WaitForElementVisibility(GlobalDefinitions.driver, "LinkText", "See All...", 10000); ClickSeeAll.Click(); //Click on select all // Wait GlobalDefinitions.WaitForElementClickable(GlobalDefinitions.driver, "XPath", "//*[@id='notification-section']//" + "div[last()-1]/div/div/div[3]/input", 1000); // GlobalDefinitions.WaitForElementVisibility(GlobalDefinitions.driver, "XPath", "//div[@data-tooltip='Select all']", 10000); SelectAll.Click(); Thread.Sleep(1000); Base.test.Log(LogStatus.Info, "Successfully selected all notifications"); //UnSelect All GlobalDefinitions.WaitForElementVisibility(GlobalDefinitions.driver, "XPath", "//*[@id='notification-section']/div[2]/div/div/div[3]/div[1]/div[2]", 10000); UnSelectAll.Click(); Base.test.Log(LogStatus.Info, "Successfully Unselected all notifications"); //Select one GlobalDefinitions.WaitForElementVisibility(GlobalDefinitions.driver, "XPath", "//*[@id='notification-section']/div[2]/div/div/div[3]/div[2]/span/span/div/div[1]/div/div/div[3]/input", 10000); SelectOne.Click(); //Mark Selction as read GlobalDefinitions.WaitForElementVisibility(GlobalDefinitions.driver, "XPath", "//*[@id='notification-section']/div[2]/div/div/div[3]/div[1]/div[4]", 10000); MarkSelection.Click(); //Delete Notification GlobalDefinitions.WaitForElementVisibility(GlobalDefinitions.driver, "XPath", "//*[@id='notification-section']/div[2]/div/div/div[3]/div[1]/div[3]/i", 10000); Delete.Click(); Thread.Sleep(2000); Base.test.Log(LogStatus.Info, "Delete notification successfull"); }
internal void SearchSkillsByFilters(IWebDriver driver) { // Wait and click on Search icon GlobalDefinitions.WaitForElementClickable(driver, "XPath", "//i[@class='search link icon']", 10); SearchIcon.Click(); // Wait and check total results GlobalDefinitions.WaitForElementClickable(driver, "XPath", "//*[@id='service-search-section']//div[2]/div/button[2]", 10); totalResults = int.Parse(driver.FindElement(By.XPath("//*[@id='service-search-section']//" + "div[1]/div[1]/div/a[1]/span")).Text); // Check online results FilterOnline.Click(); GlobalDefinitions.WaitForElementClickable(driver, "XPath", "//*[@id='service-search-section']//div[2]/div/button[2]", 10); onlineResults = int.Parse(driver.FindElement(By.XPath("//*[@id='service-search-section']//" + "div[1]/div[1]/div/a[1]/span")).Text); // Check onsite results FilterOnsite.Click(); GlobalDefinitions.WaitForElementClickable(driver, "XPath", "//*[@id='service-search-section']//div[2]/div/button[2]", 10); onsiteResults = int.Parse(driver.FindElement(By.XPath("//*[@id='service-search-section']//" + "div[1]/div[1]/div/a[1]/span")).Text); // Check show all results FilterShowAll.Click(); GlobalDefinitions.WaitForElementClickable(driver, "XPath", "//*[@id='service-search-section']//div[2]/div/button[2]", 10); showAllResults = int.Parse(driver.FindElement(By.XPath("//*[@id='service-search-section']//" + "div[1]/div[1]/div/a[1]/span")).Text); // Extent report Base.test.Log(LogStatus.Pass, "Search skills by filter successfully!"); }
// Send Request internal void SendRequest(IWebDriver driver) { // Populate the excel data into system GlobalDefinitions.ExcelLib.PopulateInCollection(Base.ExcelPath, "SignIn"); // Wait and click on Search icon GlobalDefinitions.WaitForElementClickable(driver, "XPath", "//i[@class='search link icon']", 10); SearchIcon.Click(); // Wait and Enter name in Search user part GlobalDefinitions.WaitForElement(driver, "XPath", "//input[@placeholder='Search user']", 10); SearchUserInput.SendKeys(GlobalDefinitions.ExcelLib.ReadData(3, "Name")); // Wait and Choosse the first one option Thread.Sleep(1000); DropdownFirstOpt.Click(); // Wait and Choose the first one result GlobalDefinitions.WaitForElement(driver, "XPath", "//*[@id='service-search-section']//div[2]/div/div/div[1]/a/img", 10); ResultFirstOpt.Click(); // Wait, Record Skill Name and Click on Request GlobalDefinitions.WaitForElementClickable(driver, "XPath", "//div[@class='ui teal button']", 10); skillTitle = driver.FindElement(By.ClassName("skill-title")).Text; RequestButton.Click(); // Wait and click on YES GlobalDefinitions.WaitForElement(driver, "XPath", "//button[@role='button']", 10); ConfirmButtonYes.Click(); }
internal void SelectNotification(IWebDriver driver) { // Scroll up the page GlobalDefinitions.ScrollToTop(); Thread.Sleep(500); try { // Wait GlobalDefinitions.WaitForElementClickable(driver, "XPath", "//*[@id='notification-section']//" + "div[last()-1]/div/div/div[3]/input", 10); // Click on select all button and judge if all notifications' status SelectAllBtn.Click(); Thread.Sleep(1000); } catch (NoSuchElementException e) { Base.test.Log(LogStatus.Fail, "Make sure at least 1 notification inside to operate!"); Assert.Fail("Please make sure at least 1 notification inside to operate!", e.Message); } Base.test.Log(LogStatus.Pass, "Select all notifications successfully!"); }
internal void ViewChatHistory(IWebDriver driver) { // Wait and click on Chat icon. GlobalDefinitions.WaitForElementClickable(driver, "XPath", "//a[@href='/Home/Message']", 10); ChatIcon.Click(); }
//TAGS internal void EnterTag(string tag) { GlobalDefinitions.WaitForElementClickable(GlobalDefinitions.driver, Tags, 5).SendKeys(tag); }
internal void ClickShareSkillButton() { GlobalDefinitions.WaitForElementClickable(GlobalDefinitions.driver, ShareSkillButton, 10).Click(); }
internal void SelectEndTime(string endTime) { GlobalDefinitions.WaitForElementClickable(GlobalDefinitions.driver, EndTimeOnMon, 5).SendKeys(endTime); StartDateDropDown.SendKeys(Keys.Enter); }
internal void AddTag() { GlobalDefinitions.WaitForElementClickable(GlobalDefinitions.driver, Tags, 5).SendKeys(Keys.Enter); }
internal void ViewSkillItem(int index) { GlobalDefinitions.WaitForElementClickable(GlobalDefinitions.driver, LocatorView(index), 5).Click(); }
internal void VerifyEnterShareSkill(IWebDriver driver) { // Wait element turn up & Verify part info on default manage listing page GlobalDefinitions.WaitForElementClickable(driver, "XPath", "//*[@id='listing-management-section']" + "//tr[1]/td[8]/div/button[1]/i", 10); // Verify Title var titleExpected = driver.FindElement(By.XPath("//*[@id='listing-management-section']" + "//tbody/tr[1]/td[3]")).Text; Assert.That(titleExpected, Is.EqualTo(GlobalDefinitions.ExcelLib.ReadData(2, "Title"))); // Verify Category var categoryExpected = driver.FindElement(By.XPath("//*[@id='listing-management-section']" + "//tbody/tr[1]/td[2]")).Text; Assert.That(categoryExpected, Is.EqualTo(GlobalDefinitions.ExcelLib.ReadData(2, "Category"))); // Verify Tags // Not available now on this page // Verify Service Type var serviceTypeExpected = driver.FindElement(By.XPath("//*[@id='listing-management-section']" + "//tbody/tr[1]/td[5]")).Text; if (serviceTypeExpected == "Hourly") { serviceTypeExpected = "0"; Assert.That(serviceTypeExpected, Is.EqualTo(GlobalDefinitions.ExcelLib.ReadData(2, "ServiceType"))); } if (serviceTypeExpected == "One-off") { serviceTypeExpected = "1"; Assert.That(serviceTypeExpected, Is.EqualTo(GlobalDefinitions.ExcelLib.ReadData(2, "ServiceType"))); } // Verify Skill Trade / Two conditions string skillTradeExpected = driver.FindElement(By.XPath("//*[@id='listing-management-section']" + "//tbody/tr[1]/td[6]")).GetAttribute("class").ToString(); if (skillTradeExpected == "grey remove circle large icon") { skillTradeExpected = "false"; Assert.That(skillTradeExpected, Is.EqualTo(GlobalDefinitions.ExcelLib.ReadData(2, "SkillTrade"))); } else if (skillTradeExpected == "blue check circle outline large icon") { skillTradeExpected = "true"; Assert.That(skillTradeExpected, Is.EqualTo(GlobalDefinitions.ExcelLib.ReadData(2, "SkillTrade"))); } // Verify Active // Not available // Verify remaining parts on detail page // Click eye icon and wait element turn up driver.FindElement(By.XPath("//*[@id='listing-management-section']" + "//tr[1]/td[8]/div/button[1]/i")).Click(); IWebElement titleOnDetailsPage = driver.FindElement(By.XPath("//span[@class='skill-title']")); GlobalDefinitions.WaitForTextPresentInElement(driver, titleOnDetailsPage, GlobalDefinitions.ExcelLib.ReadData(2, "Title"), 10); // Verify Description var descriptionExpected = driver.FindElement(By.XPath("//*[@id='service-detail-section']" + "/div[2]/div/div[2]/div[1]/div[1]/div[2]/div[2]/div/div/div[1]//div[2]")).Text; Assert.That(descriptionExpected, Is.EqualTo(GlobalDefinitions.ExcelLib.ReadData(2, "Description"))); // Verify Location Tyoe var locationTypeExpected = driver.FindElement(By.XPath("//*[@id='service-detail-section']" + "//div[1]//div[2]//div[3]//div[3]//div[2]")).Text; if (locationTypeExpected == "On-Site") { locationTypeExpected = "0"; Assert.That(locationTypeExpected, Is.EqualTo(GlobalDefinitions.ExcelLib.ReadData(2, "LocationType"))); } if (locationTypeExpected == "Online") { locationTypeExpected = "1"; Assert.That(locationTypeExpected, Is.EqualTo(GlobalDefinitions.ExcelLib.ReadData(2, "LocationType"))); } // Verify Subcategory var subCategoryExpected = driver.FindElement(By.XPath("//*[@id='service-detail-section']" + "//div[2]/div[2]/div//div[2]//div[2]/div/div[2]")).Text; Assert.That(subCategoryExpected, Is.EqualTo(GlobalDefinitions.ExcelLib.ReadData(2, "SubCategory"))); // Verify Available days and time var startDateExpected = driver.FindElement(By.XPath("//*[@id='service-detail-section']" + "//div[3]/div/div[1]/div/div[2]")).Text; var startDateExcel = GlobalDefinitions.ExcelLib.ReadData(2, "StartDate"); DateTime startDt = DateTime.Parse(startDateExcel); var startDateFormat = startDt.ToString("yyyy-MM-dd"); Assert.That(startDateExpected, Is.EqualTo(startDateFormat)); var endDateExpected = driver.FindElement(By.XPath("//*[@id='service-detail-section']" + "//div[2]//div[3]//div[2]//div[2]")).Text; var endDateExcel = GlobalDefinitions.ExcelLib.ReadData(2, "EndDate"); DateTime endDt = DateTime.Parse(endDateExcel); var endDateFormat = endDt.ToString("yyyy-MM-dd"); Assert.That(endDateExpected, Is.EqualTo(endDateFormat)); }
internal string GetTitle() { return(GlobalDefinitions.WaitForElementClickable(GlobalDefinitions.driver, Title, 5).GetAttribute("value")); }
internal void DeleteNotification(IWebDriver driver) { // Wait and Click on Notification GlobalDefinitions.WaitForElementClickable(driver, "XPath", "//*[@id='account-profile-section']/div/div[1]/div[2]/div/div", 10); NotificationBtn.Click(); // Wait and Click on See All button GlobalDefinitions.WaitForElementClickable(driver, "XPath", "//a[contains(text(), 'See All')]", 10); SeeAllLink.Click(); // Wait and Click on Load More Thread.Sleep(2000); GlobalDefinitions.ScrollToBottom(); Thread.Sleep(500); GlobalDefinitions.WaitForElementClickable(driver, "XPath", "//a[contains(text(),'Load More')]", 15); ShowLessAndLoadMoreBtn.Click(); // Judge if all notifications are fully loaded Thread.Sleep(1500); bool present; do { try { driver.FindElement(By.XPath("//a[contains(text(),'Load More')]")); present = true; } catch (NoSuchElementException) { present = false; break; } GlobalDefinitions.ScrollToBottom(); Thread.Sleep(500); driver.FindElement(By.XPath("//a[contains(text(),'Load More')]")).Click(); Thread.Sleep(1500); }while (present); // Record the elements qty Thread.Sleep(500); var notification = driver.FindElements(By.XPath("//h4[contains(text(),'Service Request')]")); NotificationQty = notification.Count(); Debug.WriteLine("The qty of notification is:" + NotificationQty); // Scroll down to end of page and Select the notification GlobalDefinitions.ScrollToBottom(); Thread.Sleep(1000); LastNotificationCheckbox.Click(); Thread.Sleep(300); // Scroll to top of page GlobalDefinitions.ScrollToTop(); Thread.Sleep(500); // Click on delete button GlobalDefinitions.WaitForElementClickable(driver, "XPath", "//div[@data-tooltip='Delete selection']", 10); DeleteBtn.Click(); // Extent report Base.test.Log(LogStatus.Pass, "Delete notification successfully!"); }
//Work Sample category internal void ClickWorkSampleButton() { GlobalDefinitions.WaitForElementClickable(GlobalDefinitions.driver, WorkSamplesAdd, 5).Click(); }
internal void ClickSave() { GlobalDefinitions.WaitForElementClickable(GlobalDefinitions.driver, Save, 5).Click(); }
internal void EnterCreditAmount(string creditAmount) { GlobalDefinitions.WaitForElementClickable(GlobalDefinitions.driver, CreditAmount, 5).SendKeys(creditAmount); }
internal void AddTagNameSkillExchange() { GlobalDefinitions.WaitForElementClickable(GlobalDefinitions.driver, SkillExchange, 5).SendKeys(Keys.Enter); }
internal void EnterTagNameSkillExchange(string tag) { GlobalDefinitions.WaitForElementClickable(GlobalDefinitions.driver, SkillExchange, 5).SendKeys(tag); }
internal void DeleteSkillItem(int index) { GlobalDefinitions.WaitForElementClickable(GlobalDefinitions.driver, LocatorDelete(index), 5).Click(); GlobalDefinitions.WaitForElementClickable(GlobalDefinitions.driver, yesButton, 5).Click(); }
internal string GetEndTimeOnMondayText() { return(GlobalDefinitions.WaitForElementClickable(GlobalDefinitions.driver, EndTimeOnMon, 5).GetAttribute("value"));//Just for Monday }
internal void ClickManageListingButton() { GlobalDefinitions.WaitForElementClickable(GlobalDefinitions.driver, manageListingsLink, 8).Click(); }
internal string GetSkillExchangeTagFieldText() { return(GlobalDefinitions.WaitForElementClickable(GlobalDefinitions.driver, SkillExchange, 5).GetAttribute("value")); }
internal void EnterShareSkill(IWebDriver driver) { // Populate data saved in excel to collection GlobalDefinitions.ExcelLib.PopulateInCollection(Base.ShareSkillPath, "ShareSkill"); // Click ShareSkill Button GlobalDefinitions.WaitForElementClickable(driver, "LinkText", "Share Skill", 5); ShareSkillBtn.Click(); // Wait Elements on new page GlobalDefinitions.WaitForTextPresentInElement(driver, Title, "", 10); // Enter Title from excel Title.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "Title")); // Enter Description from excel Description.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "Description")); // Select Category from Excel GlobalDefinitions.WaitForElement(driver, "Name", "categoryId", 10); new SelectElement(CategoryDropdown).SelectByText(GlobalDefinitions.ExcelLib.ReadData(2, "Category")); new SelectElement(SubCategoryDropdown).SelectByText(GlobalDefinitions.ExcelLib.ReadData(2, "SubCategory")); // Enter tags from excel Tags.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "Tags")); Tags.SendKeys(Keys.Enter); // Choose Service Type radio button from excel IWebElement ServiceTypeRadioBtn = driver.FindElement(By.XPath("//input[@name='serviceType' " + "and @value='" + GlobalDefinitions.ExcelLib.ReadData(2, "ServiceType") + "'] ")); ServiceTypeRadioBtn.Click(); // Choose Location Type radio button from excel IWebElement LocationTypeRadioBtn = driver.FindElement(By.XPath("//input[@name='locationType' " + "and @value='" + GlobalDefinitions.ExcelLib.ReadData(2, "LocationType") + "']")); LocationTypeRadioBtn.Click(); // Enter Available days from excel // *** Enter start date and end date *** StartDateInputArea.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "StartDate")); EndDateInputArea.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "EndDate")); // *** Set loop for days checkbox *** for (int rows = 2; rows < 9; rows++) { var sr = GlobalDefinitions.ExcelLib.ReadData(rows, "SelectDay").ToString(); if (sr != null && sr != "") { // Select checkbox IWebElement DaysCheckbox = driver.FindElement(By.XPath("//input[@name='Available' " + "and @index='" + GlobalDefinitions.ExcelLib.ReadData(rows, "SelectDay") + "']")); DaysCheckbox.Click(); // Enter start time IWebElement StartTimeInputArea = driver.FindElement(By.XPath("//input[@name='StartTime' " + "and @index='" + GlobalDefinitions.ExcelLib.ReadData(rows, "SelectDay") + "']")); StartTimeInputArea.SendKeys(GlobalDefinitions.ExcelLib.ReadData(rows, "StartTime")); // Enter end time IWebElement EndTimeInputArea = driver.FindElement(By.XPath("//input[@name='EndTime' " + "and @index='" + GlobalDefinitions.ExcelLib.ReadData(rows, "SelectDay") + "']")); EndTimeInputArea.SendKeys(GlobalDefinitions.ExcelLib.ReadData(rows, "EndTime")); } else { break; } } // Choose Skill Trade radio button try { string SkillTradeTypeExcel = GlobalDefinitions.ExcelLib.ReadData(2, "SkillTrade").ToString(); IWebElement SkillTradeRadioBtn = driver.FindElement(By.XPath("//input[@name='skillTrades' " + "and @value='" + SkillTradeTypeExcel + "']")); SkillTradeRadioBtn.Click(); // Condition1: Enter Skill-Exchange from excel-------Condition2: Enter Credit if (SkillTradeTypeExcel == "true") { SkillExchange.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "Skill-Exchange Tag")); SkillExchange.SendKeys(Keys.Enter); } if (SkillTradeTypeExcel == "false") { try { var CreditExcel = Convert.ToDecimal(GlobalDefinitions.ExcelLib.ReadData(2, "Credit")); if (0 <= CreditExcel && CreditExcel <= 10) { CreditAmount.SendKeys(CreditExcel.ToString()); } else { Assert.Fail("Please enter a number between 0-10."); } } catch (Exception e) { Assert.Fail("Credit input is illegal, please check format!", e.Message); } } } catch (Exception ex) { Assert.Fail("Test failed at choosing skill trade type", ex.Message); } //Upload document from the path saved in excel, if it's input type, then can send path directly // Option 1: SendKeys //try //{ // IWebElement upload = driver.FindElement(By.XPath("//input[@id='selectFile']")); // // Uploading File path // var SampleWorkPath = MarsResource.SampleWorkPath; // string fullPath = System.IO.Path.GetFullPath(SampleWorkPath); // upload.SendKeys(fullPath); //} //catch (Exception e) //{ // Assert.Fail("Failed to upload work sample", e.Message); //} // Option 2: AutoIt //driver.FindElement(By.ClassName("huge plus circle icon padding-25")).Click(); //Class Name Shouldn't have space inside, or use xpath or css. driver.FindElement(By.CssSelector("i[class='huge plus circle icon padding-25']")).Click(); AutoItX3 AutoIt = new AutoItX3(); AutoIt.WinActivate("Open"); // Must wait input text ready to input or will lose part of the url AutoIt.WinWaitActive("Open", "Edit", 3); var SampleWorkPath = MarsResource.SampleWorkPath; AutoIt.Send(Path.GetFullPath(SampleWorkPath)); Thread.Sleep(1500); AutoIt.Send("{ENTER}"); // Choose Active radio button GlobalDefinitions.WaitForElement(driver, "XPath", "//i[@class='remove sign icon floatRight']", 10); IWebElement IsActiveRadioBtn = driver.FindElement(By.XPath("//input[@name='isActive' and" + " @value='" + GlobalDefinitions.ExcelLib.ReadData(2, "Active") + "']")); IsActiveRadioBtn.Click(); // Click Save Button to save all data Save.Click(); }
internal static string GetTextOfElement(IWebElement iwebElement) { return(GlobalDefinitions.WaitForElementClickable(GlobalDefinitions.driver, iwebElement, 5).Text); }
internal string GetStartDateText() { return(GlobalDefinitions.WaitForElementClickable(GlobalDefinitions.driver, StartDateDropDown, 5).GetAttribute("value")); }
//Available days internal void SelectStartDate(string startDate) { GlobalDefinitions.WaitForElementClickable(GlobalDefinitions.driver, StartDateDropDown, 5).SendKeys(startDate); StartDateDropDown.SendKeys(Keys.Enter); }