Sorry,
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import internal.GlobalVariable as GlobalVariable
import org.apache.poi.ss.usermodel.Cell as Cell
import org.apache.poi.ss.usermodel.Row as Row
import org.apache.poi.ss.usermodel.FormulaEvaluator as FormulaEvaluator
import org.apache.poi.xssf.usermodel.XSSFSheet as XSSFSheet
import org.apache.poi.xssf.usermodel.XSSFWorkbook as XSSFWorkbook
import org.apache.poi.xssf.usermodel.XSSFRow as XSSFRow
import org.apache.poi.ss.usermodel.WorkbookFactory as WorkbookFactory
import com.kms.katalon.core.logging.KeywordLogger
import java.util.HashMap
import java.util.LinkedHashMap
import java.util.List
import java.util.logging.Level
import java.util.logging.Logger
import static utilidades5.FuncionesExcel.*
import static utilidades5.FuncionesGestionFicheros.*
import utilidades5.entidades.TestEntidad as TestEntidad
import utilidades5.entidades.Validacion as Validacion
import utilidades5.entidades.Pestania
import utilidades5.entidades.Campo as Campo
//FileInputStream ficheroCampos = new FileInputStream(getPathDatosCompartidos('TestFiles5/' + getCarpetaCasos() + '/' + EXCELCASOPRUEBA + '.xlsx'))
FileInputStream ficheroCampos = new FileInputStream('C:/proyectos/DatosCompartidos/TestFiles5pre/CasosPruebaProcesos/FSN_EMITIR_PROCESO.xlsx')
XSSFWorkbook excelCampos = new XSSFWorkbook(ficheroCampos)
FormulaEvaluator evaluator = excelCampos.getCreationHelper().createFormulaEvaluator()
WebUI.comment('Iniciando carga de datos...')
//Desactivamos el log durante la carga de datos
KeywordLogger log = new KeywordLogger()
log.logger.setLevel(Level.OFF)
GlobalVariable.datosTest = new LinkedHashMap<String, TestEntidad>()
setDatosTest(excelCampos, GlobalVariable.datosTest, evaluator)
//Activamos de nuevo el log
log.logger.setLevel(Level.INFO)
WebUI.comment('Carga de datos finalizada')
/*---------------------------------------------------------------------------------------------------------------------------------------------*/
private String getCarpetaCasos() {
switch (TIPOENTIDAD) {
case 'Abono':
case 'Factura':
return 'CasosPruebaFacturas'
case 'Pedido':
case 'Vale':
return 'CasosPruebaPedidos'
case 'ProveedorAplicacion':
case 'Proveedor':
return 'CasosPruebaProveedores'
case 'Solicitud':
return 'CasosPruebaSolicitudes'
case 'Proceso':
return 'CasosPruebaProcesos'
}
}
private void setDatosTest(XSSFWorkbook excelCampos, LinkedHashMap<String, TestEntidad> test, FormulaEvaluator evaluator) {
getTestFromExcel(excelCampos.getSheetAt(0), test)
for (int i = 1; i < excelCampos.getNumberOfSheets(); i++) {
XSSFSheet pestania = excelCampos.getSheetAt(i)
switch (pestania.getSheetName()) {
case 'Datos':
break
case 'Validaciones':
getValidacionesFromExcel(pestania, test)
break
case 'ValidacionesLineas':
getValidacionesLineasFromExcel(pestania, test)
break
case 'Notificaciones':
getNotificacionesFromExcel(pestania, test)
break
case 'Filtros':
getFiltrosFromExcel(pestania, test)
break
case 'Proceso':
getCamposPestaniaProcesoFromExcel(pestania, test, evaluator)
break
default:
getCamposPestaniaFromExcel(pestania, test, evaluator)
break
}
}
}
private void getTestFromExcel(XSSFSheet pestaniaTest, LinkedHashMap<String, TestEntidad> test) {
for (int numFila = 1; numFila <= pestaniaTest.getLastRowNum(); numFila++) {
XSSFRow fila = pestaniaTest.getRow(numFila)
String nombreTest = getValorCelda(fila.getCell(1))
TestEntidad testEntidad = new TestEntidad(getValorCelda(fila.getCell(0)), getValorCelda(fila.getCell(1)), getValorCelda(fila.getCell(2, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL)), getValorCelda(fila.getCell(3, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL)), getValorCelda(fila.getCell(4, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL)), getValorCelda(fila.getCell(5, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL)), getValorCelda(fila.getCell(6, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL)), getValorCelda(fila.getCell(7)))
testEntidad.setEntidad(TIPOENTIDAD, getValorCelda(fila.getCell(8, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL)))
test.put(nombreTest, testEntidad)
}
List<TestEntidad> testList = new ArrayList<String>(test.values());
for (int i = 0; i < testList.size(); i++) {
if (i == testList.size() - 1) {
testList.get(i).setCerrarSesion(true)
} else {
if (testList.get(i + 1).getUrl() == null) {
testList.get(i).setCerrarSesion(false)
} else {
testList.get(i).setCerrarSesion(true)
}
}
testList.get(i).setCerrarSesionPorTipo(TIPOENTIDAD)
testList.get(i).setCerrarSesionPorAccion()
}
}
private void getValidacionesFromExcel(XSSFSheet pestaniaValidaciones, LinkedHashMap<String, TestEntidad> test) {
for (int numFila = 1; numFila <= pestaniaValidaciones.getLastRowNum(); numFila++) {
XSSFRow fila = pestaniaValidaciones.getRow(numFila)
String nombreTest = getValorCelda(fila.getCell(0))
String accionTest = getValorCelda(fila.getCell(1))
Validacion validacion = new Validacion(getValorCelda(fila.getCell(2)), getValorCelda(fila.getCell(3, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL)), getValorCelda(fila.getCell(4, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL)), getValorCelda(fila.getCell(5, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL)))
TestEntidad testEntidad = test.get(nombreTest)
if (testEntidad != null) {
testEntidad.setValidacionTipo(accionTest, validacion)
}
}
}
private void getValidacionesLineasFromExcel(XSSFSheet pestaniaValidacionesLineas, LinkedHashMap<String, TestEntidad> test) {
int numColumnas = pestaniaValidacionesLineas.getRow(0).lastCellNum
for (int numFila = 1; numFila <= pestaniaValidacionesLineas.getLastRowNum(); numFila++) {
XSSFRow fila = pestaniaValidacionesLineas.getRow(numFila)
String nombreTest = getValorCelda(fila.getCell(0))
String grupo = numColumnas == 9 ? null : getValorCelda(fila.getCell(1, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL))
String pestania = getValorCelda(fila.getCell(grupo == null ? 1 : 2)).equals('Principal') ? '%PRINCIPAL%' : getValorCelda(fila.getCell(2))
String grid = getValorCelda(fila.getCell(grupo == null ? 2 : 3))
String linea = getValorCelda(fila.getCell(grupo == null ? 3 : 4, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL))
String detalle = getValorCelda(fila.getCell(grupo == null ? 4 : 5, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL))
Validacion validacion = new Validacion(getValorCelda(fila.getCell(grupo == null ? 5 : 6)), getValorCelda(fila.getCell(grupo == null ? 6 : 7, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL)), getValorCelda(fila.getCell(grupo == null ? 7 : 8, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL)), getValorCelda(fila.getCell(grupo == null ? 8 : 9, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL)))
TestEntidad testEntidad = test.get(nombreTest)
if (testEntidad != null) {
if (grupo == null) {
if (linea != null) {
testEntidad.getCabecera().getPestania(pestania).setValidacionLinea(grid, linea, detalle, validacion)
} else {
testEntidad.getCabecera().getPestania(pestania).setValidacionGrid(grid, validacion)
}
} else {
if (linea != null) {
testEntidad.getGrupo(grupo).getPestania(pestania).setValidacionLinea(grid, linea, detalle, validacion)
} else {
testEntidad.getGrupo(grupo).getPestania(pestania).setValidacionGrid(grid, validacion)
}
}
}
}
}
private void getCamposPestaniaFromExcel(XSSFSheet pestaniaExcel, LinkedHashMap<String, TestEntidad> test, FormulaEvaluator evaluator) {
String nombrePestania = pestaniaExcel.getSheetName().equals('Principal') ? '%PRINCIPAL%' : pestaniaExcel.getSheetName()
for (int numFila = 1; numFila <= pestaniaExcel.getLastRowNum(); numFila++) {
XSSFRow fila = pestaniaExcel.getRow(numFila)
String nombreTest = getValorCelda(fila.getCell(0))
TestEntidad testEntidad = test.get(nombreTest)
if (testEntidad != null) {
String grid = getValorCelda(fila.getCell(1, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL))
Campo campo = new Campo(getValorCelda(fila.getCell(4, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL)), getValorCelda(fila.getCell(5, Row.CREATE_NULL_AS_BLANK), evaluator), getValorCelda(fila.getCell(6, Row.CREATE_NULL_AS_BLANK), evaluator), getValorCelda(fila.getCell(7)), getValorCelda(fila.getCell(8)))
if (grid != null) {
String numLinea = getValorCelda(fila.getCell(2))
String detalle = getValorCelda(fila.getCell(3, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL))
if (nombrePestania.equals('%PRINCIPAL%')) {
testEntidad.getCabecera().setLineaGrid(grid, numLinea, detalle, campo)
} else {
testEntidad.getCabecera().getPestania(nombrePestania).setLineaGrid(grid, numLinea, detalle, campo)
}
} else {
if (nombrePestania.equals('%PRINCIPAL%')) {
testEntidad.getCabecera().setCampo(campo)
} else {
testEntidad.getCabecera().getPestania(nombrePestania).setCampo(campo)
}
}
}
}
}
private void getCamposPestaniaProcesoFromExcel(XSSFSheet pestaniaExcel, LinkedHashMap<String, TestEntidad> test, FormulaEvaluator evaluator) {
for (int numFila = 1; numFila <= pestaniaExcel.getLastRowNum(); numFila++) {
XSSFRow fila = pestaniaExcel.getRow(numFila)
String nombreTest = getValorCelda(fila.getCell(0))
TestEntidad testEntidad = test.get(nombreTest)
if (testEntidad != null) {
String grupo = getValorCelda(fila.getCell(1, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL))
String pestania = getValorCelda(fila.getCell(2, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL))
String grid = getValorCelda(fila.getCell(3, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL))
String numLinea = getValorCelda(fila.getCell(4))
String detalle = getValorCelda(fila.getCell(5, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL))
Campo campo = new Campo(getValorCelda(fila.getCell(6, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL)), getValorCelda(fila.getCell(7, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK), evaluator), getValorCelda(fila.getCell(8, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK), evaluator), getValorCelda(fila.getCell(9)), getValorCelda(fila.getCell(10)))
if (grupo == null) {
if (pestania == null) {
if (grid != null) {
testEntidad.getCabecera().setLineaGrid(grid, numLinea, detalle, campo)
} else {
testEntidad.getCabecera().setCampo(campo)
}
} else {
if (grid != null) {
testEntidad.getCabecera().getPestania(pestania).setLineaGrid(grid, numLinea, detalle, campo)
} else {
testEntidad.getCabecera().getPestania(pestania).setCampo(campo)
}
}
} else {
if (pestania != null) {
if (grid != null) {
testEntidad.getGrupo(grupo).getPestania(pestania).setLineaGrid(grid, numLinea, detalle, campo)
} else {
testEntidad.getGrupo(grupo).getPestania(pestania).setCampo(campo)
}
} else {
testEntidad.getGrupo(grupo).setCampo(campo)
}
}
}
}
}
private void getNotificacionesFromExcel(XSSFSheet pestaniaValidaciones, LinkedHashMap<String, TestEntidad> test) {
for (int numFila = 1; numFila <= pestaniaValidaciones.getLastRowNum(); numFila++) {
XSSFRow fila = pestaniaValidaciones.getRow(numFila)
String nombreTest = getValorCelda(fila.getCell(0))
TestEntidad testEntidad = test.get(nombreTest)
if (testEntidad != null) {
testEntidad.setMarcadorNotificacion(getValorCelda(fila.getCell(1)), getValorCelda(fila.getCell(2)), getValorCelda(fila.getCell(3, Row.CREATE_NULL_AS_BLANK)))
}
}
}
private void getFiltrosFromExcel(XSSFSheet pestaniaFiltros, LinkedHashMap<String, TestEntidad> test) {
for (int numFila = 1; numFila <= pestaniaFiltros.getLastRowNum(); numFila++) {
XSSFRow fila = pestaniaFiltros.getRow(numFila)
String nombreTest = getValorCelda(fila.getCell(0))
TestEntidad testEntidad = test.get(nombreTest)
if (testEntidad != null) {
Campo campo = new Campo(getValorCelda(fila.getCell(1)), getValorCelda(fila.getCell(2, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK)), getValorCelda(fila.getCell(3, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL)))
testEntidad.setFiltro(campo)
}
}
}