diff --git a/.gitignore b/.gitignore index 69c4857..8476ab2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /bin/ /lib/ /src/test/resources/localRegression.xml +/.idea/ diff --git a/src/main/java/com/orasi/bluesource/EmployeeTimeByTimeSheetForm.java b/src/main/java/com/orasi/bluesource/EmployeeTimeByTimeSheetForm.java new file mode 100644 index 0000000..e20fea1 --- /dev/null +++ b/src/main/java/com/orasi/bluesource/EmployeeTimeByTimeSheetForm.java @@ -0,0 +1,108 @@ +package com.orasi.bluesource; + +import com.orasi.web.OrasiDriver; +import com.orasi.web.PageLoaded; +import com.orasi.web.webelements.Element; +import com.orasi.web.webelements.Textbox; +import com.orasi.web.webelements.Webtable; +import com.orasi.web.webelements.impl.internal.ElementFactory; +import org.openqa.selenium.support.FindBy; + +import java.util.List; + +public class EmployeeTimeByTimeSheetForm { + private OrasiDriver driver = null; + + /**Page Elements**/ + @FindBy(xpath = "//input[@id='start_date']") private Textbox txtStartDate; + @FindBy(xpath = "//input[@id='end_date']") private Textbox txtEndDate; + @FindBy(xpath = "//input[@name='commit']") private Element elmGenerateReport; + @FindBy(xpath = "//span[@class='select2-selection select2-selection--single']") private Element elmEmployeeSelect; + @FindBy(xpath = "//span[@class='select2-results']/ul/li") private List employeeOptions; + @FindBy(xpath = "//h4[@id='report-title']") private Element elmFormHeader; + @FindBy(xpath = "//span[@class='select2-dropdown select2-dropdown--below']") private Element elmEmployeeList; + @FindBy(xpath = "//table[@class='ui-datepicker-calendar']") private Webtable tblCalendarPopup; + + /**Constructor**/ + public EmployeeTimeByTimeSheetForm(OrasiDriver driver) { + this.driver = driver; + ElementFactory.initElements(driver,this); + } + + /**Page Interactions**/ + + /** + * This method clicks the Generate Report element + * @author David Grayson + */ + public void clickGenerateReport(){ + if (canInteract(elmGenerateReport)&& tblCalendarPopup.syncHidden(5)) + elmGenerateReport.click(); + } + + /** + * This method sets the End Date field + * @author David Grayson + * @param strEndDate {@link String} mm/dd/yyyy format + */ + public void setEndDate(String strEndDate){ + if (canInteract(txtEndDate)){ + txtEndDate.clear(); + txtEndDate.sendKeys(strEndDate); + elmFormHeader.click(); + } + } + + /** + * This method sets the Start Date field + * @author David Grayson + * @param strStartDate {@link String} mm/dd/yyyy format + */ + public void setStartDate(String strStartDate){ + if (canInteract(txtStartDate)){ + txtStartDate.clear(); + txtStartDate.sendKeys(strStartDate); + elmFormHeader.click(); //to make popups disappear + } + } + + /** + * This method provides standard checks that an element can be interacted with + * @author David Grayson + * @param elm {@link Element} Element to check + * @return {@link Boolean} Returns true if the element is enabled and visible, false otherwise + */ + private boolean canInteract(Element elm){ + return elm.syncEnabled(5) && elm.syncVisible(5); + } + + /** + * This method selects an employee from the list that appears + * @author David Grayson + * @param strEmployee {@link String} full name of employee to select + */ + public void selectEmployee(String strEmployee){ + if (canInteract(elmEmployeeSelect)){ + elmEmployeeSelect.click(); + for (Element employee:employeeOptions){ + if (employee.getText().equals(strEmployee)){ + employee.scrollIntoView(); + employee.click(); + break; + } + } + } + } + + /** + * This method check that the elements essential to filling out the form are loaded + * @author David Grayson + * @return {@link Boolean} Returns true if the the form is loaded, false otherwise + */ + public boolean verifyFormLoaded() { + return PageLoaded.isElementLoaded(this.getClass(),driver,elmEmployeeSelect,5) && + PageLoaded.isElementLoaded(this.getClass(),driver,txtEndDate,5) && + PageLoaded.isElementLoaded(this.getClass(),driver,txtStartDate,5) && + PageLoaded.isElementLoaded(this.getClass(),driver,elmGenerateReport,5); + } +} diff --git a/src/main/java/com/orasi/bluesource/Header.java b/src/main/java/com/orasi/bluesource/Header.java index 3522250..0568db8 100644 --- a/src/main/java/com/orasi/bluesource/Header.java +++ b/src/main/java/com/orasi/bluesource/Header.java @@ -1,13 +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.Link; import com.orasi.web.webelements.impl.internal.ElementFactory; +import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.support.FindBy; public class Header { private OrasiDriver driver = null; @@ -27,6 +24,16 @@ public Header(OrasiDriver driver){ /**Page Interactions**/ + /** + * This method navigates to the Reporting login page + * @author David Grayson + */ + public void navigateReporting(){ + MessageCenter messageCenter = new MessageCenter(driver); + messageCenter.closeMessageCenter(); + driver.get("http://10.238.243.127:8080/reporting/login"); + } + /** * This method navigates to Accounts page * @author Paul diff --git a/src/main/java/com/orasi/bluesource/Report.java b/src/main/java/com/orasi/bluesource/Report.java new file mode 100644 index 0000000..7e249d2 --- /dev/null +++ b/src/main/java/com/orasi/bluesource/Report.java @@ -0,0 +1,114 @@ +package com.orasi.bluesource; + +import com.orasi.utils.TestReporter; +import com.orasi.web.OrasiDriver; +import com.orasi.web.PageLoaded; +import com.orasi.web.webelements.Element; +import com.orasi.web.webelements.Webtable; +import com.orasi.web.webelements.impl.internal.ElementFactory; +import org.openqa.selenium.support.FindBy; + +import java.util.ArrayList; +import java.util.List; + +public class Report { + private OrasiDriver driver = null; + + /**Page Elements**/ + @FindBy(xpath = "//h3[@class='report-title']") private Element elmReportTitle; + @FindBy(xpath = "//table") private Webtable tblReport; + + /**Constructor**/ + public Report(OrasiDriver driver){ + this.driver = driver; + ElementFactory.initElements(driver,this); + } + + /**Page Interactions**/ + + /** + * @author David Grayson + * @return {@link Boolean} Returns true if the report is loaded, false otherwise. + */ + public boolean verifyReportIsLoaded(){ + return PageLoaded.isElementLoaded(this.getClass(),driver,elmReportTitle,5) && + PageLoaded.isElementLoaded(this.getClass(),driver,tblReport,5); + } + + /** + * @author David Grayson + * @return {@link String} Returns the title of the report + */ + public String getTitle(){ + return elmReportTitle.getText(); + } + + /** + * @author David Grayson + * @return {@link List} Returns all employees in the report + */ + public List getEmployees(){ + ArrayList employees = new ArrayList<>(); + for (int i = 1; i <= tblReport.getRowCount(); i++) { + String cell = tblReport.getCell(i,2).getText(); + if (!cell.equals("Total:") && !cell.isEmpty()){ + TestReporter.log(cell); + employees.add(cell); + } + } + return employees; + } + + /** + * @author David Grayson + * @return {@link Boolean} Returns true if all the sub totals and the grand total are correct, false otherwise. + */ + public boolean checkTotals(){ + int runningTotal = 0; + int sectionTotal = 0; + int rowBeginSection = 1; + int rowOfSectionTotal = 1; + + /* + The do while loop iterates over a report of any size and checks all the sub totals and the grand total + to make sure they add up correctly. + */ + do { + /* + This for loop find the row with the "Total:" line to set the ned point for the next section + */ + for (int i=rowBeginSection; itrue if on the Reporting Home page. + */ + public boolean verifyHomePageIsDisplayed(){ + return elmWelcome.syncVisible(5,false); + } + + /** + * This method expands the Employee Reports drop down + * @author David Grayson + */ + public void clickEmployeeReportsDropDown(){ + if (lnkEmployeeReportsDropDown.syncEnabled(5) && lnkEmployeeReportsDropDown.syncVisible(5)) + lnkEmployeeReportsDropDown.click(); + } + + /** + * This method clicks on the "Time by Time Sheet" link in the Employee Reports dropdown + * @author David Grayson + */ + public void clickEmployeeTimeByTimeSheet(){ + if (lnkEmployeeTimeByTimeSheet.syncEnabled(5) && lnkEmployeeTimeByTimeSheet.syncVisible(5)) + lnkEmployeeTimeByTimeSheet.click(); + } +} \ No newline at end of file diff --git a/src/test/java/com/bluesource/reports/EmployeeReportsTimeByTimeSheet.java b/src/test/java/com/bluesource/reports/EmployeeReportsTimeByTimeSheet.java new file mode 100644 index 0000000..ff4cdde --- /dev/null +++ b/src/test/java/com/bluesource/reports/EmployeeReportsTimeByTimeSheet.java @@ -0,0 +1,95 @@ +package com.bluesource.reports; + +import com.orasi.bluesource.*; +import com.orasi.utils.TestReporter; +import com.orasi.web.WebBaseTest; +import org.testng.ITestContext; +import org.testng.annotations.*; + +import java.util.List; + +public class EmployeeReportsTimeByTimeSheet 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 employeeReportsTimeByTimeSheet() { + //Test Variables + String firstName = "Holly"; + String lastName = "Barnett"; + String employee = firstName + " " + lastName; + String startDate = "12/01/2017"; + String endDate = "03/07/2018"; + List employees; + + //Page Models + LoginPage loginPage = new LoginPage(getDriver()); + Header header = new Header(getDriver()); + ReportingNavBar reportingNavBar = new ReportingNavBar(getDriver()); + EmployeeTimeByTimeSheetForm employeeTimeByTimeSheetForm = new EmployeeTimeByTimeSheetForm(getDriver()); + Report report = new Report(getDriver()); + + TestReporter.logStep("Navigating to BlueSource Reporting login page"); + header.navigateReporting(); + + TestReporter.assertTrue(loginPage.verifyPageIsLoaded(),"Verifying login page is loaded"); + + TestReporter.logStep("Logging in as Admin"); + loginPage.AdminLogin(); + + TestReporter.assertTrue(reportingNavBar.verifyHomePageIsDisplayed(),"Verifying BlueSource Reporting home page is displayed"); + + TestReporter.logStep("Expanding 'Employee Reports' in side nav bar"); + reportingNavBar.clickEmployeeReportsDropDown(); + + TestReporter.logStep("Clicking 'Time by Time Sheet' option under 'Employee Reports'"); + reportingNavBar.clickEmployeeTimeByTimeSheet(); + + TestReporter.assertTrue(employeeTimeByTimeSheetForm.verifyFormLoaded(),"Verifying Employee Time by Time Sheet form is loaded"); + + TestReporter.logStep("Selecting Employee"); + employeeTimeByTimeSheetForm.selectEmployee(employee); + + TestReporter.logStep("Setting the Start Date"); + employeeTimeByTimeSheetForm.setStartDate(startDate); + + TestReporter.logStep("Setting the End Date"); + employeeTimeByTimeSheetForm.setEndDate(endDate); + + TestReporter.logStep("Clicking Generate Form"); + employeeTimeByTimeSheetForm.clickGenerateReport(); + + TestReporter.assertTrue(report.verifyReportIsLoaded(),"Verifying Report is loaded"); + + TestReporter.assertEquals(report.getTitle(),"Time by Time Sheet: "+startDate+"-"+endDate,"Verifying Report is for correct time period"); + + TestReporter.assertTrue(report.checkTotals(),"Verifying report totals"); + + TestReporter.logStep("Getting Employees listed in report"); + employees = report.getEmployees(); + + employee = lastName + ", " + firstName; //refactoring for comparison + + TestReporter.assertTrue(employees.size() == 1,"Verifying there is only one employee in report"); + + TestReporter.assertEquals(employees.get(0),employee,"Verifying employee in report"); + } +} \ No newline at end of file