diff --git a/drivers/chromedriver.exe b/drivers/chromedriver.exe new file mode 100644 index 0000000..28a4067 Binary files /dev/null and b/drivers/chromedriver.exe differ diff --git a/src/main/java/com/orasi/bluesource/Admin.java b/src/main/java/com/orasi/bluesource/Admin.java new file mode 100644 index 0000000..1c9cc47 --- /dev/null +++ b/src/main/java/com/orasi/bluesource/Admin.java @@ -0,0 +1,84 @@ +package com.orasi.bluesource; + +import org.openqa.selenium.By; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.support.FindBy; + +import com.orasi.web.OrasiDriver; +import com.orasi.web.webelements.Button; +import com.orasi.web.webelements.Label; +import com.orasi.web.webelements.Listbox; + +import com.orasi.web.webelements.impl.internal.ElementFactory; + +public class Admin { + private OrasiDriver driver = null; + + /**Page Elements**/ + @FindBy(id= "date_month") private Listbox lbMonth; + @FindBy(xpath = "//*[@value='Create Lock']") private Button btnCreateLock; + @FindBy(xpath = "//*[@id='notification-area']/div") private Label lblSuccessMessage; + + /**Constructor**/ + public Admin(OrasiDriver driver){ + this.driver = driver; + ElementFactory.initElements(driver, this); + } + + /**Page Interactions**/ + + /** + * Selects the month of the year on the Timesheet Locks screen + * @param month - The month of the year to be selected + * @author Andrew McGrail + */ + public void selectMonth(String month) { + lbMonth.syncVisible(2,true); + lbMonth.select(month); + } + + public void clickCreateLock() { + btnCreateLock.syncVisible(2,true); + btnCreateLock.click(); + driver.switchTo().alert().accept(); + } + + /** + * Matchs the passed String with the success message at the top of the + * timelock screen. + * @param message - Message to be matched + * @return True the message matchs + * @author Andrew McGrail + */ + public boolean verifySuccessMessage(String message) { + return lblSuccessMessage.getText().substring(2, 2+message.length()).equalsIgnoreCase(message); // Stops before the # of timesheets altered + } + + /** + * This method verifies the Create Lock button exists on the page + * @return - True if Create Lock exists + * @author Andrew McGrail + */ + public boolean verifyCreateLock() { + return btnCreateLock.syncVisible(1); + } + + /** + * This method closes the timesheet lock for the month passed to it + * @param month - The month of the lock + * @author Andrew McGrail + */ + public void clickCloseTimesheet(String month) { + for(int i=1;i<5;i++) { + try { + if(driver.findLabel(By.xpath("//tr["+i+"]/td[1]")).getText().equalsIgnoreCase(month)) { + driver.findButton(By.xpath("//tr["+i+"]/td[3]/a/div")).click(); + driver.switchTo().alert().accept(); + } + } + catch(NoSuchElementException e) { + break; + } + } + } +} \ No newline at end of file diff --git a/src/main/java/com/orasi/bluesource/EmployeePage.java b/src/main/java/com/orasi/bluesource/EmployeePage.java index 2cf3f9b..4153851 100644 --- a/src/main/java/com/orasi/bluesource/EmployeePage.java +++ b/src/main/java/com/orasi/bluesource/EmployeePage.java @@ -1,13 +1,15 @@ package com.orasi.bluesource; +import org.openqa.selenium.By; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.StaleElementReferenceException; import org.openqa.selenium.support.FindBy; import com.orasi.web.OrasiDriver; +import com.orasi.web.PageLoaded; import com.orasi.web.webelements.Button; -import com.orasi.web.webelements.Checkbox; -import com.orasi.web.webelements.Element; import com.orasi.web.webelements.Label; -import com.orasi.web.webelements.Textbox; +import com.orasi.web.webelements.Listbox; import com.orasi.web.webelements.Webtable; import com.orasi.web.webelements.impl.internal.ElementFactory; @@ -17,9 +19,14 @@ public class EmployeePage { /**Page Elements**/ @FindBy(xpath = "//tr[1]//a[@class='glyphicon glyphicon-pencil']") Button btnEditFirstProject; @FindBy(xpath = "//div[@id='panel_body_1']//table") Webtable tblProjectInfo; - @FindBy(xpath = "//button[@data-target='#modal_1']") Button btnEditGeneral; - @FindBy(xpath = "//div//a[contains(text(),'Deactivate Employee')]") Button btnDeactivateEmployee; - @FindBy(xpath = "//div[@class='panel-heading']//a[contains(text(),'Deactivate')]") Button btnDeactivate; + @FindBy(xpath = "//*[@id=\'accordion\']/div/div[7]/button") Button btnEditGeneral; + @FindBy(partialLinkText = "Deactivate Employee") Button btnDeactivateEmployee; + @FindBy(partialLinkText = "Deactivate") Button btnDeactivate; + @FindBy(xpath = "//*[@id='content']/h1") Label lblEmployeeName; + @FindBy(xpath = "//*[@id='accordion']/div/div[3]/h4/a") Button btnManageProjectInfo; + @FindBy(xpath = "//*[@id='date_month']") private Listbox lbTimesheetMonth; + @FindBy(id = "select_date_range") private Button btnTimesheetGo; + @FindBy(xpath = "//*[@id='content']/h3") private Label lblTimesheetTitle; /**Constructor**/ public EmployeePage(OrasiDriver driver){ @@ -28,6 +35,7 @@ public EmployeePage(OrasiDriver driver){ } /**Page Interactions**/ + public void clickFirstEditProjectButton(){ btnEditFirstProject.click(); } @@ -59,16 +67,95 @@ public boolean verifyStartDate(String strStartDate, String strProject) { } public void editGeneralInfo() { + btnEditGeneral.syncVisible(3, true); btnEditGeneral.click(); } public void clickDeactivateEmployee() { + btnDeactivateEmployee.syncVisible(2, true); btnDeactivateEmployee.click(); } public void clickDeactivate(){ + btnDeactivateEmployee.syncVisible(2, true); btnDeactivate.click(); } + public boolean verifyEmployeeName(String name) { + return lblEmployeeName.getText().equalsIgnoreCase(name); + } + + public void clickManageProject() { + btnManageProjectInfo.syncVisible(2,true); + btnManageProjectInfo.click(); + } + + /** + * This method checks if the driver is on the Timesheet Lock page + * @return - True if Timesheet Page is loaded + * @author Andrew McGrail + */ + public boolean verifyTimesheetPage(){ + return PageLoaded.isElementLoaded(this.getClass(), driver, lbTimesheetMonth); + } + + /** + * This method selects the month passed into it for the employee time sheet display month + * @param month - String month to be set to + * @author Andrew McGrail + */ + public void setMonth(String month) { + lbTimesheetMonth.syncVisible(2,true); + lbTimesheetMonth.select(month); + } + + public void clickTimesheetGo() { + btnTimesheetGo.syncVisible(2,true); + btnTimesheetGo.click(); + } + + /** + * This method verifies the employee's timesheet page report to be the same + * as the month passed in. + * @param month - String month to be checked + * @return - True if matchs + * @author Andrew McGrail + */ + public boolean verifyTimesheetTitle(String month) { + try { + lblTimesheetTitle.syncVisible(2,true); + int subStringPoint = lblTimesheetTitle.getText().indexOf('-'); + return lblTimesheetTitle.getText().substring(subStringPoint+2, subStringPoint+2+month.length()).equalsIgnoreCase(month); + } + catch(StaleElementReferenceException e) { + lblTimesheetTitle.syncVisible(2,true); + int subStringPoint = lblTimesheetTitle.getText().indexOf('-'); + return lblTimesheetTitle.getText().substring(subStringPoint+2, subStringPoint+2+month.length()).equalsIgnoreCase(month); + } + } + + /** + * This method checks an employee's timesheet for the approval status passed in, + * returning true if ALL weeks match the passed String + * @param status - Status of the employee's timesheet weeks + * @return - True if all weeks match the passed string + * @author Andrew McGrail + */ + public boolean verifyTimesheetLocked(String status) { + boolean verify = false; + for(int i=1;i<5;i++) { + try{ + String checkThis = driver.findLabel(By.xpath("(//div[@class='approval-status'])["+i+"]")).getText(); + if(checkThis.equals(status)) + verify=true; + else + verify=false; + } + catch(NoSuchElementException e) { + break; + } + } + return verify; + } } \ No newline at end of file diff --git a/src/main/java/com/orasi/bluesource/Employees.java b/src/main/java/com/orasi/bluesource/Employees.java index 4f7c74d..43f3039 100644 --- a/src/main/java/com/orasi/bluesource/Employees.java +++ b/src/main/java/com/orasi/bluesource/Employees.java @@ -3,7 +3,6 @@ import java.util.ResourceBundle; import org.openqa.selenium.By; -import org.openqa.selenium.Keys; import org.openqa.selenium.support.FindBy; import com.orasi.utils.Constants; @@ -14,7 +13,6 @@ import com.orasi.web.PageLoaded; import com.orasi.web.exceptions.OptionNotInListboxException; import com.orasi.web.webelements.Button; -import com.orasi.web.webelements.Element; import com.orasi.web.webelements.Label; import com.orasi.web.webelements.Link; import com.orasi.web.webelements.Listbox; @@ -38,6 +36,7 @@ public class Employees { @FindBy(xpath = "//*[@id='accordion']/div/div[3]/h4/a") private Button btnManage; @FindBy(xpath = "//div//input[@id='search-bar']") private Textbox txtEmployeeSearch; @FindBy(xpath = "//*[@id=\"employee_account_permission\"]") private Listbox lstAccountPermission; + @FindBy(xpath = "//tr[2]/td[1]/a") private Link lnkFirstEmployeeName; /**Constructor**/ public Employees(OrasiDriver driver){ @@ -46,6 +45,11 @@ public Employees(OrasiDriver driver){ } /**Page Interactions**/ + + public boolean verifyPageIsLoaded(){ + return PageLoaded.isElementLoaded(this.getClass(), driver, txtEmployeeSearch); + } + public void employeeSearch(String strSearch){ txtEmployeeSearch.set(strSearch); } @@ -55,8 +59,10 @@ public void employeeSearch(String strSearch){ * @author Paul */ public void clickAddEmployee() { - btnAdd.syncEnabled(5,true); - btnAdd.click(); + btnAdd.syncVisible(2,true); + btnAdd.syncEnabled(2,true); + btnAdd.syncInFrame(2,true); + btnAdd.click(); } /** @@ -309,7 +315,20 @@ public boolean checkAccountPermissionOption(String strOption) { catch (OptionNotInListboxException e){ return false; } - } - + + /** + * This method checks if the passed string is in the search bar + * @param name - Name to be verified in the search bar + * @return - True if the search bar matchs the passed name + * @author Andrew McGrail + */ + public boolean verifySearchBar(String name) { + return txtEmployeeSearch.getText().equalsIgnoreCase(name); + } + + public void clickFirstEmployeeName() { + lnkFirstEmployeeName.syncVisible(2,true); + lnkFirstEmployeeName.click(); + } } \ No newline at end of file diff --git a/src/main/java/com/orasi/bluesource/Header.java b/src/main/java/com/orasi/bluesource/Header.java index 1c09b5a..b8c0048 100644 --- a/src/main/java/com/orasi/bluesource/Header.java +++ b/src/main/java/com/orasi/bluesource/Header.java @@ -1,11 +1,10 @@ package com.orasi.bluesource; -import javax.wsdl.Message; - import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.support.FindBy; import com.orasi.web.OrasiDriver; +import com.orasi.web.webelements.Button; import com.orasi.web.webelements.Link; import com.orasi.web.webelements.impl.internal.ElementFactory; @@ -18,6 +17,8 @@ public class Header { @FindBy(xpath = "//li[contains(.,'Employees')]/a") private Link lnkEmployees; @FindBy(xpath = "//a[contains(text(),'Project')]") private Link lnkProjemployees; @FindBy(xpath = "//a[contains(text(),'Project')]//..//..//..//following-sibling::a") private Link lnkEmployeeSelector; + @FindBy(xpath = "/html/body/header/div/nav/ul/li[2]/a") private Button btnAdminMenu; + @FindBy(xpath = "//a[@href='/admin/lock-timesheets/2018']") private Link lnkTimesheetLocks; @FindBy(linkText = "Admin") private Link lnkAdmin; @FindBy(linkText = "Timesheet Locks") private Link lnkTimesheetLocks; @@ -64,9 +65,12 @@ else if (accountBool == false) * @author Paul */ public void navigateEmployees() { - MessageCenter messageCenter = new MessageCenter(driver); - messageCenter.closeMessageCenter(); - lnkEmployees.click(); + lnkEmployees.syncVisible(2,true); + // MessageCenter messageCenter = new MessageCenter(driver); + // messageCenter.closeMessageCenter(); + lnkEmployees.syncVisible(2,true); + lnkEmployees.syncInFrame(2,true); + lnkEmployees.click(); } public void navigateProjectEmployees() { @@ -82,6 +86,16 @@ public void navigateLogout() { messageCenter.closeMessageCenter(); lnkLogout.click(); } + + /** + * This method navigates to Admin/Timesheet lock page + * @author Andrew McGrail + */ + public void navigateTimesheetLocks() { + btnAdminMenu.click(); + lnkTimesheetLocks.syncVisible(2,true); + lnkTimesheetLocks.click(); + } public void navigateTimesheetLocks() { MessageCenter messageCenter = new MessageCenter(driver); diff --git a/src/test/java/com/bluesource/PendingTimeShouldBeConverted.java b/src/test/java/com/bluesource/PendingTimeShouldBeConverted.java new file mode 100644 index 0000000..bd1356b --- /dev/null +++ b/src/test/java/com/bluesource/PendingTimeShouldBeConverted.java @@ -0,0 +1,121 @@ +/** + * Tests Issue #926 Pending time should be converted to approved time when month is locked + * Uses a precondition employee (Glip Glop) to test that a timesheet saved in a month + * that becomes Timesheet locked will go from saved to approved. + * @author Andrew McGrail + */ + +package com.bluesource; + +import org.testng.ITestContext; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Optional; +import org.testng.annotations.Parameters; +import org.testng.annotations.Test; + +import com.orasi.bluesource.Admin; +import com.orasi.bluesource.EmployeePage; +import com.orasi.bluesource.Employees; +import com.orasi.bluesource.Header; +import com.orasi.bluesource.LoginPage; +import com.orasi.utils.TestReporter; +import com.orasi.web.WebBaseTest; + +public class PendingTimeShouldBeConverted extends WebBaseTest { + + @BeforeMethod + @Parameters({ "runLocation", "browserUnderTest", "browserVersion", + "operatingSystem", "environment" }) + public void setup(@Optional String runLocation, String browserUnderTest, + String browserVersion, String operatingSystem, String environment) { + setApplicationUnderTest("BLUESOURCE"); + setBrowserUnderTest(browserUnderTest); + setBrowserVersion(browserVersion); + setOperatingSystem(operatingSystem); + setRunLocation(runLocation); + setEnvironment(environment); + setThreadDriver(true); + testStart(""); + } + + @AfterMethod + public void close(ITestContext testResults){ + endTest("TestAlert", testResults); + } + + @Test + public void testPendingTimeShouldBeConverted() { + String month = "March"; + String successfulCreateMessage = "Timesheet Lock Created"; + String successfulDestryoMessage = "Timesheet Lock destroyed"; + String employeeName = "Glip Glop"; + + Header header = new Header(getDriver()); + LoginPage loginPage = new LoginPage(getDriver()); + Employees employees = new Employees(getDriver()); + Admin admin = new Admin(getDriver()); + EmployeePage employeePage = new EmployeePage(getDriver()); + + // Step 1 Precondition: Have an employee that has time saved to a project but not submitted. + //GlipGlop + // Step 2 Open Browser + // Step 3 Navigate to testing URL: http://10.238.243.127 + // Step 4 Log in as admin user + loginPage.AdminLogin(); + // Step 5 Click 'Admin' in Nav bar + // Step 6 Select 'Timesheet Locks' + header.navigateTimesheetLocks(); + TestReporter.assertTrue(admin.verifyCreateLock(), "Successfully landed on the Timesheet Lock Page"); + // Step 7 Select month that the saved timesheet is in from the 'Month' dropdown + admin.selectMonth(month); + // Step 8 Click 'Create Lock' bar + admin.clickCreateLock(); + TestReporter.assertTrue(admin.verifySuccessMessage(successfulCreateMessage), "Verifying the success message after creating a timesheet lock"); + // Step 9 Click Employees from Nav Bar + header.navigateEmployees(); + TestReporter.assertTrue(employees.verifyPageIsLoaded(), "Successfully landed on Employees page"); + // Step 10 Search for Employee with saved timesheet + employees.employeeSearch(employeeName); + TestReporter.assertTrue(employees.verifySearchBar(employeeName), "Verifying "+employeeName+" was searched for"); + // Step 11 Click Employees name + employees.clickFirstEmployeeName(); + TestReporter.assertTrue(employeePage.verifyEmployeeName(employeeName), "Successfully landed on "+employeeName+"'s page"); + // Step 12 Click Manage button for Project Info + employeePage.clickManageProject(); + TestReporter.assertTrue(employeePage.verifyTimesheetPage(), "Successfully landed on "+employeeName+"'s timesheet page"); + // Step 13 Select the month for the saved timsheet from the 'Month' dropdown + employeePage.setMonth(month); + // Step 14 Click Go button + employeePage.clickTimesheetGo(); + TestReporter.assertTrue(employeePage.verifyTimesheetTitle(month), "Verifying the correct month's timesheet is being displayed"); + // Step 15 Verify that timesheets are listed as locked + TestReporter.assertTrue(employeePage.verifyTimesheetLocked("Locked"), "Verifying all weeks of the timesheet are 'Locked'"); + // Step 16 Click 'Admin' in Nav bar + // Step 17 Select 'Timesheet Locks' + header.navigateTimesheetLocks(); + TestReporter.assertTrue(admin.verifyCreateLock(), "Successfully landed on the Timesheet Lock Page"); + // Step 18 Click red X next to the month that was previously Locked + admin.clickCloseTimesheet(month); + TestReporter.assertTrue(admin.verifySuccessMessage(successfulDestryoMessage), "Verifying the success message after destroying a timesheet lock"); + // Step 19 Click Employees from Nav Bar + header.navigateEmployees(); + TestReporter.assertTrue(employees.verifyPageIsLoaded(), "Successfully landed on Employees page"); + // Step 20 Search for Employee with saved timesheet + employees.employeeSearch(employeeName); + TestReporter.assertTrue(employees.verifySearchBar(employeeName), "Verifying "+employeeName+" was searched for"); + // Step 21 Click Employees name + employees.clickFirstEmployeeName(); + TestReporter.assertTrue(employeePage.verifyEmployeeName(employeeName), "Successfully landed on "+employeeName+"'s page"); + // Step 22 Click Manage button for Project Info + employeePage.clickManageProject(); + TestReporter.assertTrue(employeePage.verifyTimesheetPage(), "Successfully landed on "+employeeName+"'s timesheet page"); + // Step 23 Select the month for the saved timsheet from the 'Month' dropdown + employeePage.setMonth(month); + // Step 24 Click Go button + employeePage.clickTimesheetGo(); + TestReporter.assertTrue(employeePage.verifyTimesheetTitle(month), "Verifying the correct month's timesheet is being displayed"); + // Step 25 Verify that timesheets are listed as Approved + TestReporter.assertTrue(employeePage.verifyTimesheetLocked("Approved"), "Verifying all weeks of the timesheet are 'Locked'"); + } +} \ No newline at end of file diff --git a/src/test/resources/drivers/chromedriver.exe b/src/test/resources/drivers/chromedriver.exe new file mode 100644 index 0000000..28a4067 Binary files /dev/null and b/src/test/resources/drivers/chromedriver.exe differ diff --git a/src/test/resources/sandbox.xml b/src/test/resources/sandbox.xml index d3793a8..94abdd2 100644 --- a/src/test/resources/sandbox.xml +++ b/src/test/resources/sandbox.xml @@ -13,7 +13,7 @@ - +