无法开始执行通过Java API动态创建的功能文件

时间:2018-01-05 10:39:59

标签: java web-services selenium cucumber

我使用以下java代码以编程方式创建要素文件。

// This method will be invoked by 'constructFeatureFile()'
public static void createFeatureFile(String strFeatureFilePath, String strFeatureFileContent, String runnableFile)
{
    try
    {
        if (strFeatureFilePath.trim().length() > 0 && strFeatureFileContent.trim().length() > 0)
        {
            // First time file creation
            if (!Files.exists(Paths.get(strFeatureFilePath)))
            {
                FileWriter fw = new FileWriter(new File(strFeatureFilePath));
                Writer wr = new BufferedWriter(fw);
                wr.write(strFeatureFileContent);
                wr.close();
            } //If the exists, delete that file and create with fresh data
            else if(Files.exists(Paths.get(strFeatureFilePath)))
            {
                Files.delete(Paths.get(strFeatureFilePath));

                FileWriter fw = new FileWriter(new File(strFeatureFilePath));
                Writer wr = new BufferedWriter(fw);
                wr.write(strFeatureFileContent);
                wr.close();
            }

            // Call Runner to run feature file
            runner(runnableFile);
        }
    }
    catch(Exception e)
    {
        System.out.print(e);
    }
}

// Invoke feature file to execute
public static void runner(String runnableFile)
{
    Map<String, Object> args = new HashMap<String,Object>();
    args.put("name", "API Testing");

    Map<String, Object> getResponse = CucumberRunner.runClasspathFeature(runnableFile, args, true);
    getResponse = null;
}

问题是,在创建功能文件后,我正在调用 Runner()方法来执行功能文件。它抛出以下异常。

java.lang.RuntimeException: file not found: country//getMembersDetails.feature

但是,在刷新文件夹(创建特征文件的位置)并重新运行相同的脚本之后,它将使用相同的特征文件完美地执行。

我不明白为什么会这样,我在这里犯了什么错误,有人请提供建议。

谢谢!

1 个答案:

答案 0 :(得分:1)

看起来createFeatureFile()正在忙于写入strFeatureFilePath,但随后调用了runner(runnableFile)。没有写入runnableFile?