All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cookercucumber_parser.fileGenerationFactory.TestRunnerGenerator Maven / Gradle / Ivy

Go to download

Derives smallest Feature File, Allows Data from Excel(xls and xlsx) and Also provides a clear and concise reporting

There is a newer version: 3.1.0
Show newest version
package cookercucumber_parser.fileGenerationFactory;

import common.fileFactory.FileUtility;
import cookercucumber_parser.kitchenShelf.Ingredients;

import java.io.IOException;
import java.util.Map;

/**
 * This Class is used to crate Test Runner
 */
public class TestRunnerGenerator {

    //Test Runner Extension
    private static final String TR_EXTENSION = ".java";
    ////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////
    //Get all Values from Ingredients Class
    private static String TestRunnerTemplateFullPath = Ingredients.getTrFullTempPath();


    /*
     * featurefilepath = [COOKER:FEATUREFILE] = Replace with feature file path enclosed with double quotes
     * stepdefnpath = [COOKER:GLUE] = Replace with step defination package enclosed with double quotes
     * classname = [COOKER:RUNNERCLASS] = Replace with featurename
     * random num = append with classname
     */

    /**
     * Static method that take all contents for Test Runner file and uses .template and replaces and crates a new TestRunner .java
     * 
Author : Manjunath Prabhakar ([email protected])
* * @param pPlaceHolders Place Holder * @param customPlaceHolder Custom Placeholder * @param RunnerFileName filename */ public static void genTestRunner(Map pPlaceHolders, Map customPlaceHolder, String RunnerFileName) { //Variable to hold Double Quote final String DOUBQUOT = "\""; //Get Values in Default PlaceHolders //Full Path of FeatureFile enclosed with String sFeatureFilePath = DOUBQUOT + pPlaceHolders.get("featurefilepath") + DOUBQUOT; /* REPLACE \ slash with / slash in Runner File */ sFeatureFilePath = sFeatureFilePath.replaceAll("\\\\", "/"); //Step Defination package Name ecnlosed with double quotes String sGluePackage = DOUBQUOT + pPlaceHolders.get("stepdefpackage") + DOUBQUOT; //Test Runner Class Name String sClassName = pPlaceHolders.get("fileName"); try { //Read and Get the Contents from TestRunner Template File String sTempData = FileUtility.readAndGetFileContent(TestRunnerTemplateFullPath); //Replace Default place Holders with its actual Value sTempData = sTempData.replace("[COOKER:FEATUREFILE]", sFeatureFilePath); sTempData = sTempData.replace("[COOKER:GLUE]", sGluePackage); sTempData = sTempData.replace("[COOKER:RUNNERCLASS]", sClassName); //Replace Custom place holders key with value for (String key : customPlaceHolder.keySet()) { // search for value String value = customPlaceHolder.get(key); sTempData = sTempData.replace(key, value); } //Add 'Auto Generated Line' sTempData = sTempData + "\n" + "// Auto Generated by Cooker Cucumber Maven Plugin"; //Create a new Test Runner File in Generated test Runner Directory //Needs Test Runner File Content, Full Path including name of TestRunner File FileUtility.writeAndCreateFile(sTempData, RunnerFileName + TR_EXTENSION); } catch (IOException e) { e.printStackTrace(); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy