diff --git a/.classpath b/.classpath index 62a6877..ace8266 100644 --- a/.classpath +++ b/.classpath @@ -6,7 +6,7 @@ - + @@ -17,7 +17,7 @@ - + diff --git a/pom.xml b/pom.xml index 57f10b1..98d3b57 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ 1.1.2 jar - 1.8.5 + 1.8.13 ${env.BUILD_ID} ${env.BUILD_NUMBER} ${env.BUILD_TAG} diff --git a/src/main/java/com/orasi/bluesource/AddRoleType.java b/src/main/java/com/orasi/bluesource/AddRoleType.java new file mode 100644 index 0000000..2958ad4 --- /dev/null +++ b/src/main/java/com/orasi/bluesource/AddRoleType.java @@ -0,0 +1,179 @@ +package com.orasi.bluesource; + +import org.openqa.selenium.By; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.Select; +import org.openqa.selenium.support.ui.WebDriverWait; + +import com.orasi.web.OrasiDriver; +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.Link; +import com.orasi.web.webelements.Listbox; +import com.orasi.web.webelements.Textbox; +import com.orasi.web.webelements.Webtable; +import com.orasi.web.webelements.impl.internal.ElementFactory; + +public class AddRoleType { + + private OrasiDriver driver = null; + + @FindBy(linkText = "Admin") private Link lnkAdminTab; + @FindBy(linkText = "Role Types") private Link lnkRoleTypes; + @FindBy(linkText = "Add New Role Type") private Link lnkAddNewRoleTypeButton; + @FindBy(id = "role_type_name") private Textbox txtRoleName; + @FindBy(id = "role_type_billable") private Checkbox billableCheckBox; + @FindBy(name = "commit") private Button btnCreateRoleType; + @FindBy(css = "table.table-responsive.table-bordered") private Webtable rolesTable; + @FindBy(xpath = "//*[@id=\'new_role\']/div[1]/div/div") private Element billingLbl; + @FindBy(css = "table.table-striped.table-hover") private Webtable projectsTable; + @FindBy(xpath = "//*[@id=\"accordion\"]/div/div[13]/div/div[1]/button[1]") private Button newRoleButton; + @FindBy(xpath = "//*[@id=\"new_role\"]/div[1]/div/div") private Label lblBilling; + @FindBy(id = "role_role_type_id") private Listbox listRoleTypes; + @FindBy(xpath = "//input[@value='Create Role']") private Button btnAssignRoleType; + + private String newRoleTypeName; + + public AddRoleType(OrasiDriver driver){ + this.driver = driver; + ElementFactory.initElements(driver, this); + } + + public void openRoleType() { + + if (lnkAdminTab.isDisplayed() == true) + { + lnkAdminTab.click(); + lnkRoleTypes.click(); + } + } + + public void click_AddNewRoleTypeButton() { + + if (lnkAddNewRoleTypeButton.isDisplayed() == true) + { + + lnkAddNewRoleTypeButton.click(); + } + } + + public void createNewRole(String roleType) { + + this.newRoleTypeName = roleType; + + if (txtRoleName.isDisplayed()==true) { + txtRoleName.sendKeys(newRoleTypeName); + billableCheckBox.uncheck(); + + Select select = new Select(driver.findElement(By.name("role_type[permission]"))); + select.selectByValue("View"); + + btnCreateRoleType.click(); + } + } + + + public boolean verifyNewRole() { + + Boolean verify = true; + + if (rolesTable.isDisplayed() == verify) { + + if (rolesTable.getRowWithCellText(newRoleTypeName) > 0) { + System.out.println("New Role Type is created"); + } + else { + System.out.println("New role type is not created"); + verify = false; + } + } + + return verify; + } + + public int getProjectsTableRows() { + int rowCount = 0; + try + { + rowCount = projectsTable.getRowCount(); + } + catch(NullPointerException e) + { + System.out.println("Null pointer exception, no accounts found \n" + e.getLocalizedMessage()); + } + return (rowCount); + } + + public void openFirstProject() { + if (projectsTable.isDisplayed() == true) { + + if (getProjectsTableRows() > 0) { + projectsTable.getCell(2, 1).findElement( + By.xpath("//*[@id=\'panel_body_1\']/div/table/tbody/tr[1]/td[1]/a")).click(); + } + else { + System.out.println("Projects not found"); + } + } + } + + public void clickNewRole() { + if (newRoleButton.isDisplayed() == true) { + newRoleButton.click(); + } + else { + System.out.println("New Role Button was not found"); + } + } + + public void toggleBilling() { + if (lblBilling.isEnabled() == true) { + String str = lblBilling.getAttribute("class"); + if (str.contains("toggle btn btn-xs btn-primary")) { + lblBilling.jsClick(); + System.out.println("New Label is : " + lblBilling.getAttribute("class")); + } + else { + System.out.println("No need to change because it is already: " + + lblBilling.getAttribute("class")); + } + + } + } + + public void assignNewRole() { + + listRoleTypes.syncVisible(5); + + listRoleTypes.select(newRoleTypeName); + + btnAssignRoleType.click(); + } + + + + + + + + + + + + + + + + + + + + + + + + +} diff --git a/src/main/java/com/orasi/bluesource/LockedTimesheet.java b/src/main/java/com/orasi/bluesource/LockedTimesheet.java new file mode 100644 index 0000000..db3d168 --- /dev/null +++ b/src/main/java/com/orasi/bluesource/LockedTimesheet.java @@ -0,0 +1,312 @@ +package com.orasi.bluesource; + +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebElement; +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.Link; +import com.orasi.web.webelements.Listbox; +import com.orasi.web.webelements.Textbox; +import com.orasi.web.webelements.Webtable; +import com.orasi.web.webelements.impl.internal.ElementFactory; + +public class LockedTimesheet { + + private OrasiDriver driver = null; + + /**Page Elements**/ + @FindBy(linkText = "Admin") private Link lnkAdminTab; + @FindBy(linkText = "Timesheet Locks") private Link lnkTimesheetLocks; + @FindBy(linkText = "Logout") private Link lnkLogout; + @FindBy(linkText = "Manage") private Link lnkManage; + @FindBy(linkText = "February") private Link lnkChangeMonth; + @FindBy(linkText = "Employee Reports") private Link lnkEmployeeReports; + @FindBy(linkText = "Time by Project") private Link lnkTimeByProject; + @FindBy(linkText = "Time by Role") private Link lnkTimeByRole; + @FindBy(linkText = "Time by Time Sheet") private Link lnkTimeByTimeSheet; + @FindBy(linkText = "Billing by Project") private Link lnkBillingByProject; + @FindBy(linkText = "Billing by Role") private Link lnkBillingByRole; + @FindBy(linkText = "Combined Total Hours") private Link lnkCombinedTotalHours; + @FindBy(id = "date_month") private Listbox listMonths; + @FindBy(id = "flavor") private Listbox listBillingType; + @FindBy(xpath = "//*[@id='employee_list']/div/span/span[1]/span/span[2]") private Button btnDownArrow; + @FindBy(xpath = "//input[@class='select2-search__field']") private Textbox txtEmployee; + @FindBy(xpath = "//input[@value='Create Lock']") private Button btnCreateLock; + @FindBy(xpath = "//*[@id='notification-area']/div") private Label lblSuccessAlert; + @FindBy(xpath = "//*[@id='reportTable']//*[text()='No results returned by this report']") private Label lblEmployeeReport; + @FindBy(id = "select_date_range") private Button btnGo; + @FindBy(name = "commit") private Button btnGenerateReport; + @FindBy(xpath = "//table[@class='time-summary-table table']/tbody/tr[4]/td/a") private Button btnAdd; + @FindBy(xpath = "//input[@type='submit' and @value='Submit']") private Button submitTimesheet; + @FindBy(id = "start_date") private Textbox startDateSelector; + @FindBy(id = "end_date") private Textbox endDateSelector; + @FindBy(id = "DataTables_Table_0") private Webtable tblTimesheet; + + + /**Constructor**/ + public LockedTimesheet(OrasiDriver driver){ + this.driver = driver; + ElementFactory.initElements(driver, this); + } + + /** + * Click on accounts tab and then click on timesheet locks + * @author shahrukh.rehman + */ + public boolean clickTimesheetLocks() { + + if (lnkAdminTab.syncVisible(10)) + { + lnkAdminTab.click(); + lnkTimesheetLocks.click(); + return true; + } + else { + return false; + } + } + + /** + * Create a locked timesheet + * @author shahrukh.rehman + */ + public boolean createLockedTimesheet(String month) { + + if (listMonths.syncVisible(5)) + { + listMonths.select(month); + btnCreateLock.click(); + return true; + } + else { + return false; + } + + } + + /** + * Verify successful timesheet lock + * @author shahrukh.rehman + */ + public boolean verifySuccessAlert() { + + driver.switchTo().alert().accept(); + + if (lblSuccessAlert.syncVisible(10)) { + return true; + } + else { + return false; + } + } + + /** + * Click on logout tab + * @author shahrukh.rehman + */ + public void logout() { + lnkLogout.syncVisible(10); + lnkLogout.click(); + } + + public boolean clickManageButton() { + if (lnkManage.syncVisible(5)) { + lnkManage.jsClick(); + return true; + } + else { + return false; + } + } + + public boolean selectMonthWithLockedTimesheet(String month) { + if (listMonths.syncVisible(5)) { + listMonths.select(month); + btnGo.click(); + return true; + } + else { + return false; + } + } + + /** + * Add new timesheet for the employee + * @param billingType {@link String} + * @author shahrukh.rehman + */ + public void addNewTimesheet(String billingType) { + + if (btnAdd.syncVisible(10)) { + btnAdd.click(); + } + if (listBillingType.syncVisible(10)) { + listBillingType.select(billingType); + } + + for (int i = 2; i < 7; i++) { + WebElement cellText = driver.findElement(By.xpath("//*[@class=\"time-row\"]/td[" + i + "]/div/input[2]")); + cellText.click(); + cellText.sendKeys("8"); + } + + submitTimesheet.click(); + } + + /** + * Verify timesheet is created + * @author shahrukh.rehman + */ + public boolean verifySecondSuccessAlert() { + + if (lblSuccessAlert.syncVisible(10)) { + return true; + } + else { + return false; + } + } + + /** + * Different Login + * @author shahrukh.rehman + */ + public void newLogin (OrasiDriver driver){ + driver.get("http://10.238.243.127:8080/reporting/login"); + } + + public void clickEmployeeReportsTab() { + + lnkEmployeeReports.syncVisible(10); + lnkEmployeeReports.click(); + } + + /** + * Check time by project + * @author shahrukh.rehman + */ + public void checkTimeByProjectTab(String employeeFullName, String startDate, String endDate) { + clickEmployeeReportsTab(); + lnkTimeByProject.syncVisible(10); + lnkTimeByProject.click(); + generateReport(employeeFullName, startDate, endDate); + } + + /** + * Check time by Role + * @author shahrukh.rehman + */ + public void checkTimeByRoleTab(String employeeFullName, String startDate, String endDate) { + clickEmployeeReportsTab(); + lnkTimeByRole.syncVisible(10); + lnkTimeByRole.click(); + generateReport(employeeFullName, startDate, endDate); + } + + /** + * Check time by Timesheet + * @author shahrukh.rehman + */ + public void checkTimeByTimeSheetTab(String employeeFullName, String startDate, String endDate) { + clickEmployeeReportsTab(); + lnkTimeByTimeSheet.syncVisible(10); + lnkTimeByTimeSheet.click(); + generateReport(employeeFullName, startDate, endDate); + } + + /** + * Check billing by project + * @author shahrukh.rehman + */ + public void checkBillingByProjectTab(String employeeFullName, String startDate, String endDate) { + clickEmployeeReportsTab(); + lnkBillingByProject.syncVisible(10); + lnkBillingByProject.click(); + generateReport(employeeFullName, startDate, endDate); + } + + /** + * Check billing by role + * @author shahrukh.rehman + */ + public void checkBillingByRoleTab(String employeeFullName, String startDate, String endDate) { + clickEmployeeReportsTab(); + lnkBillingByRole.syncVisible(10); + lnkBillingByRole.click(); + generateReport(employeeFullName, startDate, endDate); + } + + /** + * Check combined total hours + * @author shahrukh.rehman + */ + public void checkCombinedTotalHoursTab(String employeeFullName, String startDate, String endDate) { + clickEmployeeReportsTab(); + lnkCombinedTotalHours.syncVisible(10); + lnkCombinedTotalHours.click(); + + btnDownArrow.syncVisible(10); + btnDownArrow.click(); + + txtEmployee.set(employeeFullName); + txtEmployee.sendKeys(Keys.RETURN); + + startDateSelector.set(startDate); + + endDateSelector.set(endDate); + + btnGenerateReport.click(); + + } + + /** + * Total hours table displayed + * @author shahrukh.rehman + */ + public boolean totalHoursTableDisplayed() { + if (tblTimesheet.syncVisible(10)) { + + return true; + } + else { + return false; + } + } + + /** + * Generate reports for each selection + * @author shahrukh.rehman + */ + public void generateReport(String employeeFullName, String startDate, String endDate) { + + btnDownArrow.syncVisible(10); + btnDownArrow.click(); + + txtEmployee.set(employeeFullName); + txtEmployee.sendKeys(Keys.RETURN); + + startDateSelector.set(startDate); + + endDateSelector.set(endDate); + + btnGenerateReport.click(); + } + + /** + * No results are displayed + * @author shahrukh.rehman + */ + public boolean noReportsMsgDisplayed() { + if (lblEmployeeReport.syncVisible(10)) { + + return true; + } + else { + return false; + } + } + +} diff --git a/src/test/java/com/bluesource/Admin/Add_Role_Type.java b/src/test/java/com/bluesource/Admin/Add_Role_Type.java new file mode 100644 index 0000000..34e7d15 --- /dev/null +++ b/src/test/java/com/bluesource/Admin/Add_Role_Type.java @@ -0,0 +1,69 @@ +package com.bluesource.Admin; + +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.Accounts; +import com.orasi.bluesource.AddRoleType; +import com.orasi.bluesource.LoginPage; +import com.orasi.utils.TestReporter; +import com.orasi.web.WebBaseTest; + +public class Add_Role_Type 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("Create_Basic_Employee"); + } + + @AfterMethod + public void close(ITestContext testResults){ + endTest("TestAlert", testResults); + } + + @Test(groups = {"smoke"} ) + public void addNewRoleType() { + + TestReporter.setDebugLevel(2); + + TestReporter.logScenario("Add Role Type"); + + setPageURL("http://10.238.243.127/login"); + + testStart("Add Role Type"); + + LoginPage loginPage = new LoginPage(getDriver()); + Accounts accounts = new Accounts(getDriver()); + loginPage.LoginWithCredentials("company.admin", "anything"); + + AddRoleType addNewRoleType = new AddRoleType(getDriver()); + addNewRoleType.openRoleType(); + addNewRoleType.click_AddNewRoleTypeButton(); + addNewRoleType.createNewRole("Automation Tester"); + + if (addNewRoleType.verifyNewRole() == true) { + accounts.click_accounts_tab("company.admin"); + + accounts.clickFirstAccountLink(); + addNewRoleType.openFirstProject(); + addNewRoleType.clickNewRole(); + addNewRoleType.toggleBilling(); + addNewRoleType.assignNewRole(); + } + } + +} diff --git a/src/test/java/com/bluesource/Admin/Locked_Timesheet.java b/src/test/java/com/bluesource/Admin/Locked_Timesheet.java new file mode 100644 index 0000000..1cdfa55 --- /dev/null +++ b/src/test/java/com/bluesource/Admin/Locked_Timesheet.java @@ -0,0 +1,86 @@ +package com.bluesource.Admin; + +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.LockedTimesheet; +import com.orasi.bluesource.LoginPage; +import com.orasi.utils.TestReporter; +import com.orasi.web.WebBaseTest; + +public class Locked_Timesheet 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("Test Locked Timesheet"); + } + + @AfterMethod + public void close(ITestContext testResults){ + endTest("TestAlert", testResults); + } + + @Test(groups = {"smoke"} ) + public void testLockedTimesheet() { + TestReporter.setDebugLevel(2); + + TestReporter.logScenario("Test Locked Timesheet"); + + setPageURL("http://10.238.243.127/login"); + + testStart("Test Locked Timesheet"); + + LoginPage loginPage = new LoginPage(getDriver()); + LockedTimesheet lockedTimesheet = new LockedTimesheet(getDriver()); + + TestReporter.assertTrue(loginPage.verifyPageIsLoaded(), "Page Loaded"); + + //admin login + loginPage.LoginWithCredentials("company.admin", "anything"); + + TestReporter.assertTrue(lockedTimesheet.clickTimesheetLocks(), "Timesheet Locks link clicked"); + TestReporter.assertTrue(lockedTimesheet.createLockedTimesheet("February"), "Lock Timesheet"); + TestReporter.assertTrue(lockedTimesheet.verifySuccessAlert(), "Timesheet Locked Successfully"); + lockedTimesheet.logout(); + TestReporter.assertTrue(loginPage.verifyPageIsLoaded(), "Successfully logged out"); + + //employee login + loginPage.LoginWithCredentials("wwww", "anything"); + TestReporter.assertTrue(lockedTimesheet.clickManageButton(), "Manage button clicked"); + TestReporter.assertTrue(lockedTimesheet.selectMonthWithLockedTimesheet("February"), "Month Selected"); + lockedTimesheet.addNewTimesheet("Bench"); + TestReporter.assertTrue(lockedTimesheet.verifySecondSuccessAlert(), "Locked timesheet created"); + lockedTimesheet.logout(); + + //Employee reports + lockedTimesheet.newLogin(getDriver()); + loginPage.LoginWithCredentials("company.admin", "anything"); + + lockedTimesheet.checkTimeByProjectTab("wwww bbbb", "02/05/2018", "02/11/2018"); + TestReporter.assertTrue(lockedTimesheet.noReportsMsgDisplayed(), "No results are displayed"); + lockedTimesheet.checkTimeByRoleTab("wwww bbbb", "02/05/2018", "02/11/2018"); + TestReporter.assertTrue(lockedTimesheet.noReportsMsgDisplayed(), "No results are displayed"); + lockedTimesheet.checkTimeByTimeSheetTab("wwww bbbb", "02/05/2018", "02/11/2018"); + TestReporter.assertTrue(lockedTimesheet.noReportsMsgDisplayed(), "No results are displayed"); + lockedTimesheet.checkBillingByProjectTab("wwww bbbb", "02/05/2018", "02/11/2018"); + TestReporter.assertTrue(lockedTimesheet.noReportsMsgDisplayed(), "No results are displayed"); + lockedTimesheet.checkBillingByRoleTab("wwww bbbb", "02/05/2018", "02/11/2018"); + TestReporter.assertTrue(lockedTimesheet.noReportsMsgDisplayed(), "No results are displayed"); + lockedTimesheet.checkCombinedTotalHoursTab("wwww bbbb", "02/05/2018", "02/11/2018"); + TestReporter.assertTrue(lockedTimesheet.totalHoursTableDisplayed(), "Table is displayed"); + } +} diff --git a/src/test/resources/sandbox.xml b/src/test/resources/sandbox.xml index d3793a8..ef62043 100644 --- a/src/test/resources/sandbox.xml +++ b/src/test/resources/sandbox.xml @@ -13,7 +13,9 @@ - + + +