ICommandlib
ICommandlib 是一个交互式命令行运行器,旨在(与 pexpect 不同)能够在虚拟终端窗口中运行命令行应用程序并截取屏幕截图。
它是为构建自重写、文档生成测试而设计的,例如,用于使用 hitchstory 为交互式命令行应用程序进行测试。
ICommandLib 可以截取终端文本截图和“stripshots” - 终端截图,其中屏幕右侧和下方的所有空白都被去除。
示例
favoritecolor.py
answer = input("favorite color:")
print(f"Your favorite color is {answer}")
answer = input("favorite movie:")
print(f"Your favorite color is {answer}")
带有代码
from icommandlib import ICommand
from commandlib import python
from pathlib import Path
process = ICommand(python("favoritecolor.py")).run()
process.wait_until_output_contains("favorite color:")
process.send_keys("red\n")
process.wait_until_output_contains("favorite movie:")
process.send_keys("the usual suspects\n")
process.wait_until_on_screen("favorite color")
process.wait_for_successful_exit()
Path("stripshot.txt").write_text(process.stripshot())
- 当代码运行完成时。
然后,stripshot.txt
文件的内容将为
favorite color:red
Your favorite color is red
favorite movie:the usual suspects
Your favorite color is the usual suspects
安装
$ pip install icommandlib