diff --git a/src/main/java/com/orasi/bluesource/AccountBurndownDataReportForm.java b/src/main/java/com/orasi/bluesource/AccountBurndownDataReportForm.java new file mode 100644 index 0000000..bdf0ceb --- /dev/null +++ b/src/main/java/com/orasi/bluesource/AccountBurndownDataReportForm.java @@ -0,0 +1,74 @@ +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.Listbox; +import com.orasi.web.webelements.impl.internal.ElementFactory; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; + +import java.util.ArrayList; +import java.util.List; + +public class AccountBurndownDataReportForm { + private OrasiDriver driver = null; + + /**Page Elements**/ + @FindBy(xpath = "//div[contains(text(),'Select All')]") private Element elmSelectAll; + @FindBy(xpath = "//input[@name='commit']") private Element elmGenerateReport; + @FindBy(xpath = "//select[@id='account_select']") private Listbox lstAccountSelect; + + /** + * Constructor + **/ + public AccountBurndownDataReportForm(OrasiDriver driver) { + this.driver = driver; + ElementFactory.initElements(driver, this); + } + + /**Page Interactions**/ + + /** + * @author David Grayson + * @return {@link Boolean} Returns true if key elements of the form are loaded + */ + public boolean verifyFormLoaded(){ + return PageLoaded.isElementLoaded(this.getClass(),driver,elmGenerateReport,5) && + PageLoaded.isElementLoaded(this.getClass(),driver,lstAccountSelect,5) && + PageLoaded.isElementLoaded(this.getClass(),driver,elmSelectAll,5); + } + + public void clickGenerateReport(){ + if (canInteract(elmGenerateReport)) + elmGenerateReport.click(); + } + + /** + * @author David Grayson + * @return {@link List} Returns a List of all the accounts that can be selected + */ + public List getAllAccounts(){ + ArrayList allAccounts = new ArrayList<>(); + if (canInteract(lstAccountSelect)){ + for(WebElement elm:lstAccountSelect.getOptions()){ + allAccounts.add(elm.getText()); + } + } + return allAccounts; + } + + public void clickSelectAll(){ + if (canInteract(elmSelectAll)) + elmSelectAll.click(); + } + + /** + * @author David Grayson + * @param elm {@link Element} The element to check + * @return {@link Boolean} Returns true if it can be interacted with, throws an error otherwise + */ + private boolean canInteract(Element elm){ + return elm.syncEnabled(5) && elm.syncVisible(5); + } +} \ No newline at end of file diff --git a/src/main/java/com/orasi/bluesource/Accounts.java b/src/main/java/com/orasi/bluesource/Accounts.java index e24471f..ca417f8 100644 --- a/src/main/java/com/orasi/bluesource/Accounts.java +++ b/src/main/java/com/orasi/bluesource/Accounts.java @@ -55,6 +55,31 @@ public Accounts(OrasiDriver driver){ /**Page Interactions**/ + /** + * @author David Grayson + * @param strAccount {@link String} The name of the account to check + * @return {@link Boolean} Returns true if the Account passed has active projects, false otherwise + */ + public boolean doesAccountHaveActiveProjects(String strAccount){ + clickAccountLink(strAccount); + + if (tblProjects.getRowCount() == 0 || tblProjects.findElements(By.xpath("//tr[@class='closed-project']")).size() == tblProjects.getRowCount()){ + driver.navigate().back(); + return false; + } else { + driver.navigate().back(); + return true; + } + } + + /** + * @author David Grayson + * @return {@link Boolean} Returns true if the Accounts table is loaded, false otherwise. + */ + public boolean verifyAccountsPageIsLoaded(){ + return PageLoaded.isElementLoaded(this.getClass(),driver,tblAccounts,5); + } + /* * Click on accounts tab * Make sure that the correct page loads @@ -155,7 +180,7 @@ public void sort_by_industry() public void clickAccountLink(String strAccount){ String xpathExpression; - xpathExpression = "//td//a[contains(text(),'" + strAccount + "')]"; + xpathExpression = "//td//a[text()='" + strAccount + "']"; Link lnkAccount = driver.findLink(By.xpath(xpathExpression)); lnkAccount.click(); } diff --git a/src/main/java/com/orasi/bluesource/Header.java b/src/main/java/com/orasi/bluesource/Header.java index 1c09b5a..c10ece8 100644 --- a/src/main/java/com/orasi/bluesource/Header.java +++ b/src/main/java/com/orasi/bluesource/Header.java @@ -29,6 +29,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..c301fee --- /dev/null +++ b/src/main/java/com/orasi/bluesource/Report.java @@ -0,0 +1,74 @@ +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 + * @param column {@link Integer} the column to check + * @return {@link Boolean} Returns true if the specified column has empty values, false otherwise + */ + public boolean doesColumnHaveEmptyValues(int column){ + for (int i = 1; i <= tblReport.getRowCount(); i++){ + if (tblReport.getCell(i,column).getText().isEmpty()) + return true; + } + return false; + } + + /** + * @author David Grayson + * @return {@link List} Returns a List of all Accounts in the report + */ + public List getAllAccounts(){ + ArrayList accounts = new ArrayList<>(); + for (int i = 1; i <= tblReport.getRowCount(); i++){ + if (!accounts.contains(tblReport.getCell(i,1).getText())) + accounts.add(tblReport.getCell(i,1).getText()); + } + TestReporter.log(accounts.toString()); + return accounts; + } +} \ No newline at end of file diff --git a/src/main/java/com/orasi/bluesource/ReportingNavBar.java b/src/main/java/com/orasi/bluesource/ReportingNavBar.java new file mode 100644 index 0000000..353444f --- /dev/null +++ b/src/main/java/com/orasi/bluesource/ReportingNavBar.java @@ -0,0 +1,62 @@ +package com.orasi.bluesource; + +import com.orasi.web.OrasiDriver; +import com.orasi.web.webelements.Element; +import com.orasi.web.webelements.Link; +import com.orasi.web.webelements.impl.internal.ElementFactory; +import org.openqa.selenium.support.FindBy; + +public class ReportingNavBar { + private OrasiDriver driver = null; + + /**Page Elements**/ + @FindBy(xpath = "//h1[text()='Welcome']") private Element elmWelcome; + @FindBy(xpath = "//span[contains(text(),'Account Reports')]/..") private Link lnkAccountReportsDropdown; + @FindBy(xpath = "//span[contains(text(),'Account Reports')]/../..//a[contains(text(),'Burn Down Data')]") private Link lnkAccountReportsBurnDownData; + + /** + * Constructor + **/ + public ReportingNavBar(OrasiDriver driver) { + this.driver = driver; + ElementFactory.initElements(driver, this); + } + + /**Page Interactions**/ + + /** + * @author David Grayson + * @return {@link Boolean} Returns true if on the Reporting Home page. + */ + public boolean verifyHomePageIsDisplayed(){ + return elmWelcome.syncVisible(5,false); + } + + /** + * This method clicks Burn Down Data link under the Account Reports drop down menu + * @author David Grayson + */ + public void clickAccountBurnDownData(){ + if (canInteract(lnkAccountReportsBurnDownData)) + lnkAccountReportsBurnDownData.click(); + } + + /** + * This method expands the Projects Reports drop down + * @author David Grayson + */ + public void clickAccountReports(){ + if (canInteract(lnkAccountReportsDropdown)) + lnkAccountReportsDropdown.click(); + } + + /** + * 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); + } +} \ No newline at end of file diff --git a/src/test/java/com/bluesource/reports/SelectAllForProjectsAndAccountsBlueSourceReports.java b/src/test/java/com/bluesource/reports/SelectAllForProjectsAndAccountsBlueSourceReports.java new file mode 100644 index 0000000..e6b6390 --- /dev/null +++ b/src/test/java/com/bluesource/reports/SelectAllForProjectsAndAccountsBlueSourceReports.java @@ -0,0 +1,141 @@ +package com.bluesource.reports; + +import com.orasi.bluesource.*; +import com.orasi.utils.TestReporter; +import com.orasi.web.WebBaseTest; +import org.bouncycastle.jce.provider.symmetric.TEA; +import org.testng.ITestContext; +import org.testng.annotations.*; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +public class SelectAllForProjectsAndAccountsBlueSourceReports 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("Select all for Projects and Accounts BlueSource Reports"); + } + + @AfterMethod + public void close(ITestContext testResults) { + endTest("TestAlert", testResults); + } + + @Test + public void selectAllForProjectsAndAccountsBlueSourceReports() { + //Test Variables + SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); + String reportTitle = "Account Burndown Data Report: " + sdf.format(new Date()); //comparison title with current date + List allAccounts; + int columnBudget = 6; + int columnReported = 7; + + //Page Models + LoginPage loginPage = new LoginPage(getDriver()); + Header header = new Header(getDriver()); + ReportingNavBar reportingNavBar = new ReportingNavBar(getDriver()); + AccountBurndownDataReportForm form = new AccountBurndownDataReportForm(getDriver()); + Report report = new Report(getDriver()); + + TestReporter.logStep("Navigating to BlueSource Reporting"); + 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("Clicking 'Account Reports'"); + reportingNavBar.clickAccountReports(); + + TestReporter.logStep("Clicking 'Burn Down Data'"); + reportingNavBar.clickAccountBurnDownData(); + + TestReporter.assertTrue(form.verifyFormLoaded(),"Verifying Account Burndown Data Report form loaded"); + + TestReporter.logStep("Storing all selectable accounts"); + allAccounts = form.getAllAccounts(); + + TestReporter.logStep("Clicking Select All"); + form.clickSelectAll(); + + TestReporter.logStep("Clicking Generate Report"); + form.clickGenerateReport(); + + TestReporter.assertTrue(report.verifyReportIsLoaded(),"Verifying report is loaded"); + + TestReporter.assertEquals(reportTitle,report.getTitle(),"Verifying report title"); + + TestReporter.assertFalse(report.doesColumnHaveEmptyValues(columnReported),"Verifying 'Reported $' column has no empty values"); + + TestReporter.assertFalse(report.doesColumnHaveEmptyValues(columnBudget),"Verifying 'Budget $' column has no empty values"); + + TestReporter.assertTrue(checkAccounts(allAccounts,report.getAllAccounts()),"Verifying all accounts are displayed"); + } + + /** + * @author David Grayson + * @param reference {@link List} The selectable accounts + * @param displayed {@link List} The account displayed in the report + * @return {@link Boolean} Returns true if no accounts were missing from the report + * OR if all the missing accounts don't have active projects + */ + private boolean checkAccounts(List reference, List displayed) { + ArrayList missing = new ArrayList<>(); + for (String s : reference) { + if (!displayed.contains(s)) { + TestReporter.log("displayed didn't contain: " + s); + missing.add(s); + } + } + return missing.size() <= 0 || checkMissing(missing); + } + + /** + * @author David Grayson + * @param missing {@link ArrayList} the Accounts that were selectable but not displayed in the burn down report + * @return {@link Boolean} Returns true if the missing accounts don't have active projects + */ + private boolean checkMissing(ArrayList missing) { + TestReporter.logStep("Checking that missing Accounts don't have Projects"); + + //Page Models + LoginPage loginPage = new LoginPage(getDriver()); + Header header = new Header(getDriver()); + Accounts accounts = new Accounts(getDriver()); + + TestReporter.logStep("Navigating to BlueSource"); + getDriver().get("http://10.238.243.127/login"); + + TestReporter.assertTrue(loginPage.verifyPageIsLoaded(),"Verifying BlueSource login page is loaded"); + + TestReporter.logStep("Logging in as Admin"); + loginPage.AdminLogin(); + + TestReporter.logStep("Navigating to Accounts"); + header.navigateAccounts(); + + TestReporter.assertTrue(accounts.verifyAccountsPageIsLoaded(), "Verifying Accounts page is loaded"); + + for (String s:missing){ + TestReporter.assertTrue(accounts.verifyAccountLink(s),"Verifying account ["+s+"] link"); + TestReporter.assertFalse(accounts.doesAccountHaveActiveProjects(s),"Verifying account ["+s+"] doesn't have projects"); + } + + return true; + } +} \ No newline at end of file diff --git a/src/test/resources/sandbox.xml b/src/test/resources/sandbox.xml index d3793a8..86e397c 100644 --- a/src/test/resources/sandbox.xml +++ b/src/test/resources/sandbox.xml @@ -13,7 +13,7 @@ - +