简体   繁体   English

CasperJS多个捕获屏幕快照:最新的屏幕快照将覆盖所有以前的对象

[英]CasperJS multiple capture screenshots: Latest screenshot overwrites all previous ojnes

I'm currently digging into CasperJS and really enjoying it. 我目前正在研究CasperJS并非常喜欢它。 However, maybe it's something I missed in the documentation, I seem to be having trouble with casper.capture(). 但是,也许这是我在文档中错过的东西,我似乎在使用casper.capture()时遇到了麻烦。 I've currently rigged mine up to capture whenever a test fails, and put it in a separate setup module as below 我目前已装配了我的设备,以便在测试失败时进行捕获,并将其放在下面的单独的设置模块中

function captureFailure(filename){
    casper.test.on("fail", function(failure){
        casper.viewport(1280, 1024);
        casper.capture("failedScreenshots/Failure-"+filename+".jpg", {
            top: 0,
            left: 0,
            width: 1280,
            height: 1024
        });
    });
}

exports.captureFailure = captureFailure;

This is then put into my tests like so: 然后将其放入我的测试中,如下所示:

.  .  .
// setup
setup.login();

// test
casper.test.begin("Complete new social campaign flow with image as a      signed in user.", 16, function suite(test) {
// setup captureFailure
    setup.captureFailure("SocialFlowImage");  

    casper.start(data.baseURL+'/campaigns/', function(){
        console.log("Campaign page loaded");
        this.click(campaignCreate);
        casper.waitForSelector(socialCampaignCreateModal, function(){
            test.assertExists(socialCampaignCreateModal, 'Modal pops up');
            test.assertTextExists('Deal', 'Deal button exists');
            test.assertTextExists('Marketing Email', 'Marketing Email button exists');
            test.assertTextExists('Facebook', 'Facebook button exists');
        });
    });
.  .  .

For the most part this was working on its own, but when I ran all of my tests in tandem to test multiple failures, screenshots were overwritten as they went along. 在大多数情况下,这是可以独立进行的,但是当我同时运行所有测试以测试多个失败时,屏幕快照会被覆盖。 In chronological order it looked something like this: 按照时间顺序,它看起来像这样:

test 1 -> test 1 failure -> Capture screenshot 1 -> test 2 -> test 2 failure -> Capture screenshot 2 and subsequently overwrite screenshot 1 测试1->测试1失败->捕获屏幕截图1->测试2->测试2失败->捕获屏幕截图2,随后覆盖屏幕截图1

And this resulted in 2 of the same screenshots but of different naming convention. 这样就产生了两个相同的屏幕截图,但命名约定不同。

Any ideas? 有任何想法吗?

Figured out that I had overlapping event handlers on the "fail" event. 弄清楚我在“失败”事件上有重叠的事件处理程序。 To remedy this, changed my casperjs test style to include the test object with setUp and tearDown functions, removed the event handles by doing 为了解决这个问题,更改了我的casperjs测试样式,使其包含带有setUp和tearDown函数的测试对象,并通过执行以下操作删除了事件句柄

casper.test.removeListener("fail", casper.test.listeners("fail")[0]);

Which is a bit hacky, but my custom event handler has a filename arg passed in for unique screenshot names and easier times debugging/identifying which test ran what. 这有点hacky,但是我的自定义事件处理程序传入了一个filename arg,以获取唯一的屏幕截图名称,并且调试/识别哪个测试运行了哪个更容易。 As a result I have to jimmy rig it since my setUp actually has an anonymous function that attaches it. 结果,由于我的setUp实际上有一个附加它的匿名函数,因此我不得不进行绑定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM