robot framework中和screenshot有关的三个关键字的用法解析

在robot framework中 和屏幕截图有关的共有三个关键字,分别是:

1)Set Screenshot Directory关键字

Source:Screenshot <test library>
Arguments:[ path ]
Sets the directory where screenshots are saved. 
It is possible to use / as a path separator in all operating systems. Path to the old directory is returned. 
The directory can also be set in `importing`.

这个关键字只有一个path参数,用来设定屏幕截图的存放位置,用户可以自定义设定屏幕截图的存放位置,如D:/python_test目录下

 Set Screenshot Directory    D:/python_test


如果运行中的log中出现如下信息:

20160125 18:33:18.028 :  WARN : Keyword 'Set Screenshot Directory' found both from a custom test library 'Selenium2Library' and a standard library 'Screenshot'. The custom keyword is used. To select explicitly, and to get rid of this warning, use either 'Selenium2Library.Set Screenshot Directory' or 'Screenshot.Set Screenshot Directory'.
20160125 18:33:18.122 :  INFO : Screenshot saved to '<a href="screenshot_2.jpg">c:\users\my-pc\appdata\local\temp\RIDEr65zse.d\screenshot_2.jpg</a>'.
Ending test:   Win8 Test.Win8 Test.dictionary_test

说明了在不同的库中有相同关键字,产生了冲突,需要显示的加入到Screenshot库中。


2)Take Screenshot关键字

Source: Screenshot <test library>
Arguments: [ name=screenshot | width=800px ]

此关键字下的参数较多,如果不设定任何参数,默认是将截图嵌入到page中,并显示出来,生成的屏幕截图存放在和log信息

相同的目录 下 ,命名为screenshot_*.jpg,其中*从1开始,每次运行迭代后,增加1.

参数表格:

Examples: (LOGDIR is determined automatically by the library) 


Take Screenshot # LOGDIR/screenshot_1.jpg (index automatically incremented) //默认的命名,每次运行自动递增一
Take Screenshot mypic# LOGDIR/mypic_1.jpg (index automatically incremented)     //固定部分的截图名字,剩余部分在每次运行自动递增一
Take Screenshot ${TEMPDIR}/mypic# /tmp/mypic_1.jpg (index automatically incremented)  //设定某个目录下命名
Take Screenshot pic.jpg# LOGDIR/pic.jpg (always uses this file)  //固定截图文件名字
Take Screenshot images/login.jpg80%# Specify both name and width.  //设置截图名字和宽度
Take Screenshot width=550px# Specify only width.  // 设置截图宽度


3)Take Screenshot Without Embedding关键字

Takes a screenshot and links it from the log file. 
This keyword is otherwise identical to `Take Screenshot` but the saved screenshot is not embedded into the log file. The screenshot is linked so it is nevertheless easily available.

此关键字表示生成的屏幕截图不会显示在网页中,而是以超链接的方式出现。

实例:修改屏幕截图到d盘下的某个目录,并以非嵌入式的方式显示。

代码如下:

    comment    these two commands mean that to set a path for the screenshot without embeding into log file
    Screenshot.Set Screenshot Directory    D:/python_test
    Take Screenshot Without Embedding


在运行后,屏幕截图不会嵌入到log 中,并存放在了修改后的目录下,但是会以链接的方式显示,单击这个超链接即可显示:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值