XVFB,詹金斯,Selenium测试 - 所有页面的抓取屏幕截图 [英] Xvfb, Jenkins, Selenium tests - Capture Screenshots of all pages

查看:478
本文介绍了XVFB,詹金斯,Selenium测试 - 所有页面的抓取屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到如下问题的一些线索,并不能在网上找到很好的帮助。

我是一个Linux机器在无头模式下运行的Xvfb(X虚拟帧缓冲区),Firefox浏览器。 xvfb的主要服务是启动并运行DISPLAY变量设置。

 的/ usr / bin中/ Xvfb来:99 -ac -screen 0 1600x1200x16

我有一些自动化的基于Selenium测试,我正在使用运行摇篮(测试的gradle 的)。他们成功地运行和詹金斯,我能够获得通过Xvfb插件这个工作。 JUnit的岗位发布报告/结果的信息和摇篮的报告/测试/ index.html文件中显示成功试运行。

我只是运行在摇篮运行测试如下:
测试的gradle = -DsomePropConfigFileForEnv SomeSourceConfigFilewithPathvalue

我的问题:

1.我怎样才能得到所有的页面,这种自动化测试/运行被渲染(即登录页面,登录后的应用程序主界面的截图,用户点击主页上这里和那里(即开/点击各个选项卡,链接,表,按钮等),最后注销页面。

我能够从中获取的截图的 XVFB_SCREEN 的< N >文件,这是越来越-fbdir文件夹(我们通过同时运行的Xvfb指定下创建一詹金斯的工作),但截图是一个黑色的页面,如果测试运行成功(这可能是由于我以下提到的第2点)--OR这是一个有效的单页图像的截图(如果试运行过程中遇到的错误)。

我试图让所有的自动化Selenium测试渲染(我传递到摇篮作为-D参数配置文件的URL有/用户名/浏览器,版本等信息在里面)的网页。 PS:这不只是对我试图通过Xvfb显示虚拟帧缓冲区得到的图像截图一些随机的网址

<醇开始=2>
  • 在测试过程中,我看到有一个有效的虚拟帧缓存的文件,一个有效的大小。

  • 有关前:虽然詹金斯的工作正在进行中,运行摇篮测试任务的Xvfb插件已经开始了新的实例xvfb的,我看到:

    <$p$p><$c$c>/production/JSlaves/kobaloki2_1/xvfb-2015-02-04_01-16-37-6170319257811815857.fbdir/Xvfb_screen0

    但一旦测试完成(或错误,我们的),这个文件正从该xxxx.fbdir文件夹中删除有没有文件是在所有。

    为什么这个文件中获取删除即可。

    如果它会保留在那里,然后我可以使用XWD / xwud命令和其他工具(ImageMagick的转换等命令)创建一个图像文件作为后生成作用,甚至在后调用摇篮的步骤的BUILD部分。

    以下命令将创建Firefox的截图(只有一个页面的截图),并假设XVFB的PNG图片文件上显示运行= 107

      XWD -root -display:107 |转换XWD: -  /tmp/capture2.png

    和下面xvfb的过程(这仍在运行,包含在它的有效XVFB_SCREEN ****文件 - 这是由在那里的Xvfb插件配置有偏移底座100和图7的詹金斯作业创建为节点/建立数因此,使得:107显示号)

      u10002 30717 19950 1 01:16? 00:00:00的Xvfb:107 -screen 0 1024x768x8 -fbdir /production/JSlaves/kobaloki2_1/xvfb-2015-02-04_01-16-37-6170319257811815857.fbdir

    <醇开始=3>

  • 我没有运行的Xvfb / ImageMagick的等只得到一个URL的图像(例如:www.google.com),但试图让所有的东西在测试期间渲染背后的Xvfb内存虚拟帧缓存/文件的截图试运行。

  • 是否有任何其他工具(很简单的安装,而不与Linux服务器搞乱了),它可以达到同样的(所有页面的一个测试渲染背后xvf命令/火狐/ Linux服务器在无头的方式捕捉截图)?

    我也试过硒网格服务器,但FF是有演戏了(由于某些原因),所以我试图用运行詹金斯,摇篮,Xvfb来插件Linux服务器(无头模式)使用firefox浏览器,这些测试和规划有N无。执行人的运行这些测试的多次运行,最后每次运行捕获的结果。

    我的归档工件(如果有的话),并使用图片廊插件为好,但不具有对所有跑在后面硒的Xvfb / Firefox中呈现的页面图像。

    任何投入都很大AP preciated。

    感谢。


    解决方案

    OK,这是我做的。这种方法要求任何改变项目的源$ C ​​$ C。


    1. 已安装的ImageMagick(..ck)即的百胜在RHEL上安装ImageMagick的的。

    2. 创建在目标服务器上的脚本,它现在的作品。我所要做的就是,在詹金斯的工作,当我已经开始了的Xvfb实例(使用詹金斯的Xvfb插件),然后就一前第二通摇篮(或任何构建工具)运行硒GUI测试之前,我请拨打以下脚本并传递参数(如果DISPLAY变量的值是提供给詹金斯的工作,因为我们通过Xvfb插件的话)。在测试结束时,脚本会自动存在(如XWD命令没有得到任何更多的输入,所以它正常退出),最后我发布的图像和.mp4(视频)在詹金斯(文件作为边栏链接显示测试结果/视频)和归档中的工件(png格式使用图像Galary插件和.mp4文件)的图像文件。

    3. 注意:这需要你的机器有: ImageMagick的 XWD 的ffmpeg 安装。如果选项传递到任何命令不同ACC。您的操作系统的机器,然后相应地调整它。在ffmpeg的命令中的帧率值可以是分数,即1/5或0.5或15,或任何你想要的(尝试一下,看看你会得到什么)。

    4. 这是给你的,如果你想归档数据与否的这个大数额。你可以做到这一点,如果你有良好的空间,如果你的工作詹金斯有更好的旧版本干净的保留策略。


     #!斌/庆典
    ##
    ##这个脚本将捕获截图自动化的GUI(每0.1秒),(为前:Selenium测试)无头的Xvfb显示实例后面的测试运行。
    ##然后,它会创建一个使用捕获的一个截屏MP4格式的电影。
    ##
    在您运行此脚本##机,应该有:的Xvfb服务运行,通过詹金斯,XWD,ffmpeg的操作系统命令和ImageMagick的(公用事业)通过的Xvfb插件启动一个会话。
    ## - 对于离,试试这个RHEL上安装ImageMagick的:百胜安装的ImageMagick
    ##
    ##变量
    WS = $ 1; ##工作区文件夹位置
    D = $ 2; D = $(回声$ d个| TR -d:);通过Xvfb来插件从詹金斯的工作开始的Xvfb实例相关联的##号显示
    wscapdir = $ {} WS / capturebrowserss; ##工作区捕获浏览器的屏幕截图文件夹
    如果[[-n $ 3]];然后wscapdir = $ {wscapdir} / $ 3;网络##如果用户传递一个第三个参数,即一个詹金斯BUILD_NUMBER,然后创建一个使用该名称的子目录归档特定的运行。
    I = 1;
    RM -fr $ {} wscapdir 2 - ;的/ dev / null的|| (回声 - 呵呵呵呵..斜面删除$ {} wscapdir文件夹;回声-e - 仍然正常退出\\ n!;退出0);
    MKDIR -p $ {} wscapdir
    而:;做
     XWD -root -display:$ d个2 - ;的/ dev / null的|转换XWD: - $ {} wscapdir / capFile _ $ {D} _dispId`printf%08D$ i`.png 2 - ;的/ dev / null的;
     如果[[$ {PIPESTATUS [0]} -gt 0 || $ {PIPESTATUS [1]} -gt 0]];然后回声-e\\ N--东西XWD或ImageMagick的convert命令时遭遇不测,手动检查\\ n;退出0;科幻
     ((我+ +));睡0.1;
    DONE
    ffmpeg的-r 5 -i $ {} wscapdir $ /capFile_dispId_%08d.png {} wscapdir /out_byRateOf5.mp4 2 - ;的/ dev / null的||回声-e!\\ N--发生某些错误(可能太多打开的文件),优雅地退出\\ n;

    I'm trying to find some clues on the following issues and not able to find good help online.

    I'm running Xvfb (X virtual frame buffer), firefox on a Linux machine in headless mode. Xvfb main service is up and running and DISPLAY variable is set.

    /usr/bin/Xvfb :99 -ac -screen 0 1600x1200x16
    

    I have some automated selenium based tests which I'm running using Gradle (gradle test). They run successfully and in Jenkins I'm able to get this working using Xvfb plugin. JUnit post publish report/result info and Gradle's reports/test/index.html file is showing successful test run.

    I just run the following to run tests in Gradle: gradle test -DsomePropConfigFileForEnv=SomeSourceConfigFilewithPathvalue

    My questions:
    1. How can I get the screenshots of all the pages that this automated test/run is rendering (i.e. login page, application main page after login, user clicks on the main page here and there (i.e. opening/clicking on various tabs, links, tables, buttons etc) and finally log out page.

    I'm able to get the screenshot from the Xvfb_screen<N> file, which is getting created under -fbdir folder (what we specify while running Xvfb via a Jenkins job) but the screenshot is a Black page if test runs successfully (this can be due to the 2nd bullet I mentioned below) --OR it's a valid single page image screenshot (if an error is encountered during the test run).

    I'm trying to get all the pages which the automated Selenium tests are rendering (the config file I passed to Gradle as a -D parameter has URLs / user name / browser, version etc info in it). PS: It's not just for some random URL that I'm trying to get an image screenshot using Xvfb DISPLAY virtual frame buffer.

    1. During the test, I see there's a valid virtual framebuffer file, with a valid size.

    For ex: While Jenkins job is in progress and running Gradle test task and Xvfb plugin has started a new xvfb instance, I see:

    /production/JSlaves/kobaloki2_1/xvfb-2015-02-04_01-16-37-6170319257811815857.fbdir/Xvfb_screen0
    

    but as soon as the test is complete (or errors our), this file is getting deleted from this xxxx.fbdir folder and there's no file at all.

    Why is this file getting deleted.

    If it'll remain there, then I can use xwd/xwud command and other tools (imagemagick convert etc commands) to create an image file as a POST BUILD action or even within the BUILD section after "Invoke Gradle" step.

    The following command will create a .png image file of the firefox screenshot (only one page screenshot) and assuming xvfb is running on DISPLAY=:107

    xwd -root -display :107 | convert xwd:- /tmp/capture2.png
    

    and the following xvfb process (which is still running, containing a valid Xvfb_screen**** file in it - which was created by the Jenkins job where Xvfb plugin is configured with offset base 100 and 7 is the node/build number thus, making :107 as DISPLAY number).

    u10002  30717 19950  1 01:16 ?        00:00:00 Xvfb :107 -screen 0 1024x768x8 -fbdir /production/JSlaves/kobaloki2_1/xvfb-2015-02-04_01-16-37-6170319257811815857.fbdir
    

    1. I'm not running Xvfb / Imagemagick etc to just get an image of a URL (ex: www.google.com) but trying to get all the screenshots what a test is rendering behind Xvfb memory virtual framebuffer/file during the test run.

    Are there any other tools (simple enough to install without messing up with the Linux server) which can achieve the same (capturing screenshots of all the pages that a test is rendering behind Xvf/firefox/Linux server in Headless way)?

    I also tried Selenium Grid server, but FF is acting up there (due to some reason) thus I'm trying to run these tests using Jenkins, Gradle, Xvfb plugin on a Linux server (Headless mode) using firefox browser and planning to have N no. of executors to run multiple runs of these tests and finally capturing the results per run.

    I'm archiving the artifacts (if any) and using Image Gallery plugin as well, but don't have the images for all the rendered pages which ran in Selenium behind Xvfb/firefox.

    Any inputs are greatly appreciated.

    Thanks.

    解决方案

    OK, this is what I did. This approach doesn't require any change to the source code of the project.

    1. Installed imagemagick (..ck) i.e. yum install imagemagick on RHEL.
    2. Created a script on the target server and it works now. All I do is, in the Jenkins job, when I have already started the Xvfb instance (using Xvfb plugin in Jenkins), then just a second before before running the Selenium GUI tests via Gradle (or any build tool), I call the following script and pass the parameters (where DISPLAY variable value is available to the Jenkins job as we are using Xvfb plugin in it). At the end of tests, the script exists automatically (as xwd command doesn't get any more input so it exits gracefully) and finally I publish the images and .mp4 (video) file on Jenkins (as a side bar link to show Test results / video) and archive the artifacts (.png image files using "Image Galary Plugin" and .mp4 file).
    3. NOTE: This requires that your machine has: imagemagick, xwd and ffmpeg installed. If the options passed to any commands differs acc. to your OS machine, then tweak it accordingly. The framerate value in ffmpeg command can be a fraction i.e. 1/5 or 0.5 or 15 or anything you want (try it and see what you get).
    4. It's up to you, if you want to ARCHIVE this big amount of data or not. You can do it if you have good space and if your Jenkins job have a better old build clean retention policies.


    #!bin/bash
    ##
    ## This script will capture Screenshot (every 0.1 seconds) of an automated GUI (for ex: Selenium tests) tests running behind a HEADLESS Xvfb display instance.
    ## Then, it'll create a mp4 format movie using the captured screenshots.
    ##
    ## Machine where you run this script, should have: Xvfb service running, a session started by Xvfb plugin via Jenkins, xwd,ffmpeg OS commands and imagemagick (utilities).
    ## - For ex, try this on RHEL to install imagemagick:  yum install imagemagick
    ##
    ## Variables
    ws=$1;                                                  ## Workspace folder location
    d=$2; d=$(echo $d | tr -d ':');                         ## Display number associated with the Xvfb instance started by Xvfb plugin from a Jenkins job
    wscapdir=${ws}/capturebrowserss;                        ## Workspace capture browser's screen shot folder
    if [[ -n $3 ]]; then wscapdir=${wscapdir}/$3; fi        ## If a user pass a 3rd parameter i.e. a Jenkins BUILD_NUMBER, then create a child directory with that name to archive that specific run.
    i=1;
    rm -fr ${wscapdir} 2>/dev/null || ( echo - Oh Oh.. Cant remove ${wscapdir} folder; echo -e "-- Still exiting gracefully! \n"; exit 0);
    mkdir -p ${wscapdir}
    while : ; do
     xwd -root -display :$d 2>/dev/null | convert xwd:- ${wscapdir}/capFile_${d}_dispId`printf "%08d" $i`.png 2>/dev/null;
     if [[ ${PIPESTATUS[0]} -gt 0 || ${PIPESTATUS[1]} -gt 0 ]]; then echo -e "\n-- Something bad happened during xwd or imagemagick convert command, manually check it.\n"; exit 0; fi
     ((i++)); sleep 0.1;
    done
    ffmpeg -r 5 -i ${wscapdir}/capFile_dispId_%08d.png ${wscapdir}/out_byRateOf5.mp4 2>/dev/null || echo -e "\n-- Some error occurred (may be too many files opened), exiting gracefully!\n";
    

    这篇关于XVFB,詹金斯,Selenium测试 - 所有页面的抓取屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆