Take screenshot from Karma while running tests in PhantomJS 2?

后端 未结 2 2106
野性不改
野性不改 2021-02-15 11:10

I need a way to take a screenshot during a test which uses QUnit and Karma to run inside PhantomJS 2.0.1

I\'ve found this command:

window.top.callPhantom         


        
2条回答
  •  悲哀的现实
    2021-02-15 11:56

    My Karma entry for a customized phantomjs that takes snapshots looked like this:

    module.exports = function (config) {
      config.set({
        ..
        browsers: [ 'PhantomJSCustom'],
        customLaunchers: {
          'PhantomJSCustom': {
            base: 'PhantomJS',
            options: {
              onCallback: function(data){
                if (data.type === "render") {
                  // this function will not have the scope of karma.conf.js so we must define any global variable inside it
                  if (window.renderId === undefined) { window.renderId = 0; }
                  page.render(data.fname || ("screenshot_" + (window.renderId++) + ".png"));
                }
              }
            }
          }
        },
        phantomjsLauncher: {
          // Have phantomjs exit if a ResourceError is encountered (useful if karma exits without killing         // phantom)
          exitOnResourceError: true
        },
        ..
      })

提交回复
热议问题