python - 无法在 RobotFramework 中写入现有文本文件
问题描述
无法在 RobotFramework 中写入现有文本文件。我的目标是从 for 循环获取输出并将值写入文本文件,目前我能够创建文本文件并从 for 循环打印输出值,但无法将值写入文本文件。
我试过的:
*** Settings ***
Library OperatingSystem
*** Variables ***
${PATH} ${CURDIR}/write_one_to_five.txt
*** Test Cases ***
For_Loop
Create File ${PATH} # Text file created at current directory
: FOR ${i} IN RANGE 1 6
\ Log ${i}
File Should Exist ${PATH} ${i}
Log Exited
解决方案
您可以使用来自操作系统库http://robotframework.org/robotframework/latest/libraries/OperatingSystem.html的关键字Append To File
使用Append To File关键字对您的代码进行了一些小修改,它起作用了!!
*** Settings ***
Library OperatingSystem
*** Variables ***
${PATH} ${CURDIR}/write_one_to_five.txt
*** Test Cases ***
For_Loop
Create File ${PATH} # Text file created at current directory
: FOR ${i} IN RANGE 1 6
\ log to console ${i}
\ ${b}= Convert To String ${i} #conversion was required as it was throwing encoding error for integer
\ Append To File write_one_to_five.txt ${b}
#File Should Exist ${PATH} ${i} #This was causing error to me, hence commented
Log Exited
推荐阅读
- pointers - Rust 中指向 Trait 的原始指针
- java - 项目计划建议
- spring-boot - SpringBoot:改变列长度
- php - 使用php从服务器中删除文件和数据
- python - 将文件上传到 Flask 时出现 KeyError
- python - 自动编码器输入形状:预期 input_1 的形状为 (256, 256, 3) 但得到的数组形状为 (256, 256, 4)
- elasticsearch - Elasticsearch geo_shape 点搜索返回错误的geometrycollection 文档
- python-3.x - 更新较新 Pytorch 的代码并获取 RuntimeError: Tensors must have same number of dimensions: got 2 and 1
- html - 如何从液体标签中写入有效的 HTML?
- reactjs - 如何传递属性,使用下一个 JS?