屏幕尺寸
您可以在终端中以您选择的屏幕尺寸运行交互式命令。
默认情况下,宽度为 80,高度为 24。
helloworld.py
import time
for _ in range(150):
print("hello world")
print("goodbye world")
time.sleep(1)
import sys
import time
answer = input("favorite color:")
sys.stdout.write(answer.upper())
sys.stdout.flush()
time.sleep(1)
使用代码
from icommandlib import ICommand
from commandlib import python
缩小
process = ICommand(python("favoritecolor.py")).screensize(5, 10).run()
process.wait_until_output_contains("favorite color:")
process.send_keys("red\n")
process.wait_until_output_contains("RED")
with open("screenshot.txt", "w") as handle:
handle.write(process.screenshot())
process.wait_for_finish()
- 当代码运行完成时。
screenshot.txt
文件的内容将是
favor
ite c
olor:
red
RED
展开
process = ICommand(python("helloworld.py")).screensize(80, 160).run()
process.wait_until_output_contains("goodbye world")
with open("screenshot.txt", "w") as handle:
handle.write(process.screenshot())
process.wait_for_finish()
- 当代码运行完成时。
screenshot.txt
文件的内容将是
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
hello world
goodbye world
可执行规范
从 screensize.story storytests 自动生成的文档。