/* * This file is part of NavalPlan * * Copyright (C) 2011 Igalia, S.L. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ /* Function to login in NavalPlan */ function commonLogin($user, $password) { _setValue(_textbox("j_username"), $user); _setValue(_password("j_password"), $password); _click(_submit("Log in")); } /* Function to logout in NavalPlan */ function commonLogout() { _click(_link("[Log out]")); } /* Function to access to create form */ function commonCreate($something) { _click(_link($something)); _click(_cell("Create")); } /* Function to edit something */ function commonEdit($name, $cell) { _click(_image("ico_editar1.png", _in(_cell($cell, _near(_cell($name)))))); } /* Function to delete something */ function commonDelete ($something, $name, $cell) { _click(_link($something)); _click(_image("ico_borrar1.png", _in(_cell($cell, _near(_cell($name)))))); _click(_cell("OK")); } /* Create new project */ function commonCreateProject($name, $calendar){ _click(_link("Projects List")); _click(_image("ico_add.png")); _setValue(_textbox(0, _near(_span("Name"))), $name); if ($calendar != null){ _click(_italic(0, _near(_span("Calendar")))); _click(_cell($calendar)); } _click(_cell("Accept")); _click(_image("ico_save.png")); _click(_cell("OK")); } function commonEditProject($name){ _click(_link("Projects List")); _click(_image("ico_editar1.png", _in(_cell(8,_near(_cell($name)))))); } /* Delete a project */ function commonDeleteProject($name){ _click(_link("Projects List")); _click(_image("ico_borrar1.png", _in(_cell(8, _near(_cell($name)))))); _click(_cell("OK")); _assertExists(_div("Removed "+$name)); _assert(_isVisible(_div("Removed "+$name))); _assertEqual("Removed "+$name, _getText(_div("Removed "+$name))); } /* Create a task in a project */ function commonCreateTask($projectName, $name, $hours){ _click(_link("Projects List")); _click(_image("ico_editar1.png", _in(_cell(8,_near(_cell($projectName)))))); _setValue(_textbox(0, _near(_span("New task:"))), $name); _setValue(_textbox("z-intbox", _near(_span("Hours:"))), $hours); _click(_cell("Add")); _click(_image("ico_save.png")); _click(_cell("OK")); _log("Create a task", "custom1"); } function commonConfigurationChangeCheckboxMainPreferences($element){ _click(_link("NavalPlan Configuration")); _click(_checkbox(0, _near(_label($element)))); _click(_cell("Save")); commonSaveConfigurationValidation(); } /* * Common functions for Validations */ function commonSaveConfigurationValidation(){ _assertExists(_span("Changes saved")); _assert(_isVisible(_span("Changes saved"))); } function commonEmptyCodeValidation(){ _assertExists(_div("cannot be null or empty")); _assert(_isVisible(_div("cannot be null or empty"))); } /* test to check a correct save */ function commonSaveValidation($something, $name){ _assertExists(_div($something+" \""+$name+"\" saved")); _assert(_isVisible(_div($something+" \""+$name+"\" saved"))); _assertEqual($something+" \""+$name+"\" saved", _getText(_div($something+" \""+$name+"\" saved"))); } /* test to check a correct delete */ function commonDeleteValidation($something, $name){ _assertExists(_div($something+" \""+$name+"\" deleted")); _assert(_isVisible(_div($something+" \""+$name+"\" deleted"))); _assertEqual($something+" \""+$name+"\" deleted", _getText(_div($something+" \""+$name+"\" deleted"))); } /* * commmon functions for Workers, Machines and Virtual Workers */ function commonResourceEditAssignedCriteriaForm($element, $name, $cell, $criterion){ _click(_link($element)); commonEdit($name, $cell); _click(_span("Assigned criteria")); _click(_cell("Add", _near(_span("New criterion")))); _click(_cell("Save")); commmonResourceEmptyFields(); _click(_italic(0, _near(_tableHeader("Criterion name")))); _click(_div($criterion)); _click(_cell("Save")); _log("Assign the created Criterion", "custom1"); } function commonResourceEditAssignedCalendarForm($element, $name, $cell, $calendar){ _click(_link($element)); commonEdit($name, $cell); _click(_cell("Remove calendar")); _click(_span("Calendar")) _click(_italic(0, _near(_span("Select parent calendar")))); _click(_cell($calendar)); _click(_cell("Save")); _log("Assign the created calendar", "custom1"); } function commonResourceEditAssignedCostCategoryForm($element, $name, $cell, $ccategory){ _click(_link($element)); commonEdit($name, $cell); _click(_cell("Add new row")); _click(_cell("Save")); commonResourceEmptyCategoryName(); _click(_italic(0, _near(_div("Category name")))); _click(_cell($ccategory+"[1]")); _click(_cell("Save")); commonResourceEmptyCategoryDate(); _click(_italic(1, _near(_div("Category name")))); _click(_cell("z-calendar-wkday z-calendar-seld", _near(_div("Category name")))); _click(_cell("Save")); } function commmonResourceEmptyFields(){ _assertExists(_div("This field may not be empty or contain only spaces.")); _assert(_isVisible(_div("This field may not be empty or contain only spaces."))); } function commonResourceEmptyCategoryName(){ _assertExists(_div("A category must be selected")); _assert(_isVisible(_div("A category must be selected"))); } function commonResourceEmptyCategoryDate(){ _assertExists(_div("The init date cannot be empty")); _assert(_isVisible(_div("The init date cannot be empty"))); } function commonResourceTryDeleteAssignedValidation(){ _assertExists(_span("This worker cannot be deleted because it has assignments to projects or imputed hours")); _assert(_isVisible(_span("This worker cannot be deleted because it has assignments to projects or imputed hours"))); } /* * Common functions for Workers */ function commonWorkerCreate($name, $surName, $id) { commonCreate("Workers"); commonWorkerForm($name, $surName, $id); commonWorkerAcctionValidation("saved"); _log("Create a new worker", "custom1"); } function commonWorkerForm($name, $surName, $id) { _setValue(_textbox(0, _near(_span("First name"))), $name); _setValue(_textbox(0, _near(_span("Last name"))), $surName); _setValue(_textbox(0, _near(_span("ID"))), $id); _click(_cell("Save")); } function commonWorkerDelete($name){ commonDelete("Workers", $name, 5); commonWorkerAcctionValidation("deleted"); _log("Delete the worker", "custom1"); } function commonWorkerAcctionValidation($action){ _assertExists(_span("Worker "+$action)); _assert(_isVisible(_span("Worker "+$action))); } /* * Common functions for Machines */ function commonMachineCreate($name, $description) { commonCreate("Machines"); commonMachineForm($name, $description); commonSaveValidation("Machine", $name); _log("Create a new Machine", "custom1"); } function commonMachineForm($name, $description) { _setValue(_textbox(0, _near(_span("Name"))), $name); _setValue(_textbox(0, _near(_span("Description"))), $description); _click(_cell("Save")); } function commonMachineDelete($name){ commonDelete("Machines", $name, 4); commonDeleteValidation("Machine", $name); _log("Delete the machine", "custom1"); } /* * Common functions for Companies */ function commonCompanyCreate($name, $ID) { commonCreate("Companies"); commonCompanyForm($name, $ID); commonSaveValidation("Company", $name); _log("Create a company", "custom1"); } function commonCompanyForm($name, $ID) { _setValue(_textbox(0, _near(_span("Company name:"))), $name); _setValue(_textbox(0, _near(_span("Company ID:"))), $ID); _click(_checkbox(0, _near(_span("Client:")))); _click(_checkbox(0, _near(_span("Subcontractor:")))); _setValue(_textbox(0, _near(_span("User:"))), "wswriter"); _click(_checkbox(0, _near(_span("Interacts with applications:")))); _setValue(_textbox(0, _near(_span("Application URI:"))), "http://localhost:8080/navalplanner-webapp/"); _setValue(_textbox(0, _near(_span("Our company login:"))), "wswriter"); _setValue(_textbox(0, _near(_span("Our company password:"))), "wswriter"); _click(_cell("Save")); } function commonCompanyDelete($name){ commonDelete("Companies", $name, 5); commonDeleteValidation("Company", $name); _log("Delete a company", "custom1"); } /* * Common functions for Calendars */ function commonCalendarCreate($name) { commonCreate("Calendars"); commonCalendarForm($name); commonSaveValidation("Base calendar", $name); _log("Create a new calendar", "custom1"); } function commonCalendarForm($name) { _setValue(_textbox(0, _near(_span("Name"))), $name); _click(_cell("Save")); } function commonCalendarTryDeleteAssignedCalendar($name, $cell) { _click(_link("Calendars")); _click(_image("ico_borrar1.png", _in(_cell($cell, _near(_cell($name)))))); _assertExists(_span("Cannot delete calendar. It is being used at this moment by some resources.")); _assert(_isVisible(_span("Cannot delete calendar. It is being used at this moment by some resources."))); _log("Do not allow delete assigned calendar", "custom1"); } function commonCalendarDelete($name){ commonDelete("Calendars", $name, 3); commonCalendarDeleteValidation($name); _log("Delete de Calendar", "custom1"); } function commonCalendarDeleteValidation($name) { _assertExists(_span("Removed calendar \""+$name+"\"")); _assert(_isVisible(_span("Removed calendar \""+$name+"\""))); } /* * Common functions for Cost Category */ function commonCostCategoryCreate($name, $hworkName){ commonCreate("Cost Categories"); commonCostCategoryForm($name, $hworkName); commonSaveValidation("Cost Category", $name); _log("Create a Cost Category", "custom1"); } function commonCostCategoryForm($name, $hworkName){ _setValue(_textbox(0, _near(_span("Name:"))), $name); _click(_cell("Add new row")); _setSelected(_select(0), $hworkName); _click(_cell("Save")); } function commonCostCategoryDelete($name){ commonDelete("Cost Categories", $name, 2); commonDeleteValidation("Cost Category", $name); _log("Delete de cost category", "custom1"); } function commonCostCategoryTryDeleteAssignedCostCategory($cCategory, $cell){ _click(_link("Cost Categories")); _assertExists(_image("ico_borrar_out.png")); _assert(_isVisible(_image("ico_borrar_out.png"))); _log("Do not allow delete assigned cost category", "custom1"); } /* * Common functions for Progress */ function commonProgressCreate($name) { commonCreate("Progress"); commonProgressForm($name); commonSaveValidation("Progress Type", $name); _log("Create a progress", "custom1"); } function commonProgressForm($name) { _setValue(_textbox(0, _near(_div("Unit name"))), $name); _removeFocus(_textbox(0, _near(_div("Unit name")))); _click(_cell("Save & Continue")); } function commonProgressAssigned($projectName, $progressNewName){ commonCreateProject($projectName); commonProgressAssignProject($projectName, $progressNewName); _click(_link("Progress")); commonDeleteProject($projectName); } function commonProgressAssignProject($projectName, $progressNewName){ commonEditProject($projectName); _click(_span("Progress")); _click(_cell("Add new progress assignment")); _setValue(_textbox("z-combobox-inp", _near(_row("footer"))), $progressNewName); _click(_cell("z-button-cm", _near(_textbox("z-combobox-inp")))); _setValue(_textbox(0, _near(_parentTable(_div("Value")))), "30"); _click(_image("ico_save.png")); _click(_cell("OK")); _log("Progress assigned", "custom1"); } function commonProgressDelete($name){ commonDelete("Progress", $progressNewName, 3); commonDeleteValidation("Progress Type", $progressNewName); _log("Delete the progress", "custom1"); } /* * Common functions for Criteria */ function commonCriteriaCreate($type){ commonCreate("Criteria"); commonCriteriaForm($type); commonSaveValidation("Criterion Type", $type); _log("Create a new criterion", "custom1"); } function commonCriteriaEdit($oldName, $newName, $cell){ commonEdit($oldName, $cell); _setValue(_textbox(0, _near(_span("Name"))), $newName); _removeFocus(_textbox(0, _near(_span("Name"))), $newName); _click(_cell("Save & Continue")); commonSaveValidation("Criterion Type", $newName); _log("Edit a criterion", "custom1"); } function commonCriteriaForm($name){ _setValue(_textbox(0, _near(_span("Name"))), $name); _click(_checkbox(0, _near(_div("Multiple values per resource")))); _click(_checkbox(0, _near(_div("Hierarchy")))); _click(_cell("OK")); _setValue(_textbox(0, _near(_span("New criterion"))), $name); _click(_cell("Add")); _click(_cell("Save")); } function commonCriteriaDelete($criteriaName){ commonDelete("Criteria", $criteriaName, 4); commonDeleteValidation("Criterion Type", $criteriaName); _log("Delete the criteria", "custom1"); } function commonCriteriaTryDeleteAssigned($criteriaName){ _click(_link("Criteria")); _click(_image("ico_borrar1.png", _in(_cell(4, _near(_cell($criteriaName)))))); _assertExists(_span("This criterion type cannot be deleted because it has assignments to projects or resources")); _assert(_isVisible(_span("This criterion type cannot be deleted because it has assignments to projects or resources"))); _log("Do not allow criteria because it's assigned", "custom1"); } /* * Common functions for Labels */ function commonLabelCreate($type, $name){ commonCreate("Labels"); commonLabelForm($type, $name); commonSaveValidation("Label Type", $type); _log("Create a new label", "custom1"); } function commonLabelForm($name, $list){ _setValue(_textbox(0, _near(_span("Name"))), $name); if ($list != null){ for (var $i = 0; $i < $list.length; $i++){ _setValue(_textbox(0, _near(_span("New label"))), $list[$i]); _click(_cell("Add")); } } _click(_cell("Save")); } function commonLabelDelete($name){ commonDelete("Labels", $name, 2); commonDeleteValidation("Label Type", $name); _log("Label Deleted", "custom1"); } /* * Common functions for Work Report Model */ function commonWorkReportModelCreate($name, $type){ commonCreate("Work Report Models"); commonWorkReportModelForm($name, $type); commonSaveValidation("Work Report Type", $name); _log("Create a new Work Report Model", "custom1"); } function commonWorkReportModelForm($name, $type){ _setValue(_textbox(0, _near(_span("Name:"))), $name); _removeFocus(_textbox(0, _near(_div("Name:")))); _setSelected(_select(0, _near(_span("Task:"))), $type); _click(_cell("Add New Complementary Field")); _setValue(_textbox(0, _near(_div("Complementary text fields"))), $name); _setValue(_textbox(1, _near(_div("Complementary text fields"))), "12"); _click(_cell("Save")); } function commonWorkReportModelEdit($oldName, $newName, $cell){ commonEdit($oldName, $cell); commonWorkReportModelForm($newName); commonSaveValidation("Work Report Type", $newName); _log("Edit a Work Report Model", "custom1"); } function commonWorkReportModelDelete($name){ commonDelete("Work Report Models", $name, 1); commonDeleteValidation("Work Report Type", $name); _log("Delete the Work Report Model", "custom1"); } /* * Common functions for Work hours */ function commonWorkHourCreate($type, $price){ commonCreate("Work Hours"); commonWorkHourForm($type, $price); commonSaveValidation("Type of hours", $type); _log("Create a new Work Hour", "custom1"); } function commonWorkHourForm($name, $price){ _setValue(_textbox(0, _near(_span("Name"))), $name); _setValue(_textbox(0, _near(_span("Default price"))), $price); _click(_cell("Save")); } function commonWorkHourDelete($name){ commonDelete("Work Hours", $name, 4); commonDeleteValidation("Type of hours", $name); _log("Delete the Work Hour", "custom1"); }