/* * 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){ _click(_link("Projects")); _click(_image("ico_add.png")); _setValue(_textbox(6), $name); _click(_cell("Accept")); _click(_image("ico_save.png")); } /* Delete a project */ function commonDeleteProject($name){ _click(_link("Projects")); _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))); } 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"))); } /* * Common functions for Worker */ 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 Calendar */ 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"); } /* * 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 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 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"); }