在硒自动化中以CSV格式添加数据

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在硒自动化中以CSV格式添加数据相关的知识,希望对你有一定的参考价值。

我在自动化脚本的参考资料中有一个CSV文件,我需要将一个单元格值修改为通过在站点中创建一个文件夹而获得的参数值,我运行了这段代码,但随后出现错误:

"(The process cannot access the file because it is being used by another process)".

有人可以让我知道如何将我的参数值写入CSV文件单元格吗?TIA

方法:

 public static void writeCSV(String filePath, String separator) throws IOException {
        try (OutputStream fileStream = new BufferedOutputStream(new FileOutputStream(filePath));
             Writer outStreamWriter = new OutputStreamWriter(fileStream, StandardCharsets.UTF_8);
             BufferedWriter buffWriter = new BufferedWriter(outStreamWriter)) {
            buffWriter.append("https://mobile/sample_v4.zip");
            buffWriter.append(separator);
            buffWriter.append(createdTitle);
            buffWriter.append(separator);
            buffWriter.append("http://2-title-conversion/documentlibrary");
            buffWriter.append(separator);
            buffWriter.append("TRUE");
            buffWriter.append(separator);
            buffWriter.append("TRUE");
            buffWriter.flush();
        }


@Test segment,

loginPg.writeCSV("C:\Users\urathya\Documents\Automation\03-11\resources\CS.csv",",");
答案

您没有关闭输出流,请关闭它,它将关闭文件,您可以使用同一文件来追加数据。

以上是关于在硒自动化中以CSV格式添加数据的主要内容,如果未能解决你的问题,请参考以下文章