【问题标题】:How to specify spec names to screenshots for each test run in protractor如何为量角器中每个测试运行的屏幕截图指定规格名称
【发布时间】:2019-08-19 21:23:54
【问题描述】:

我正在使用量角器框架和 jasmine-allure-reporter 来创建报告并截图。

jasmine.getEnv().addReporter(new AllureReporter({
      resultsDir: 'allure-results'
    }));
    jasmine.getEnv().afterEach(function (done) {
      browser.takeScreenshot().then(function (png) {
        allure.createAttachment('Screenshot', function () {
          return new Buffer(png, 'base64')
        }, 'image/png')();
        done();
      })
    });
  }

是否有规定为每个测试自定义屏幕截图名称?目前它有一些随机数作为图像名称(0a8bbc5e-35ee-4d7f-be8b-532fe4a1b4a8-attachment.png),而不是我想要这样的东西(<specname>.png)。有可能这样做吗?有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: jasmine protractor allure


    【解决方案1】:
    var today = new Date();
        var timeStamp = today.getMonth() + 1 + '-' + today.getDate() + '-' + today.getFullYear() + '-' + today.getHours() + 'h-' + today.getMinutes() + 'm-' + today.getSeconds() + 's';
        ScreenShotName = 'MaGE_Admin' + '-' + timeStamp;
        jasmine.getEnv().addReporter(reporter);
        jasmine.getEnv().topSuite().afterEach({
            fn: async function () {
                try {
                    await browser.takeScreenshot().then(function (png) {
                        allure.createAttachment(ScreenShotName, new Buffer.from(png, 'base64'));
                    });
                } catch (e) {
                    console.log(e);
                }
            }
        });
    

    【讨论】:

    • 请提供更多关于您的答案如何解决问题的信息。
    【解决方案2】:

    你可以这样做:

    jasmine.getEnv().addReporter(new AllureReporter({
          resultsDir: 'allure-results'
        }));
        jasmine.getEnv().afterEach(function (done) {
          browser.takeScreenshot().then(function (png) {
            allure.createAttachment(exports.config.multiCapabilities.name, function () {
              return new Buffer(png, 'base64')
            }, 'image/png')();
            done();
          })
        });
      }
    

    这对我有用。

    【讨论】:

    • 看到我使用了多重功能,但如果您只使用功能,请替换它并且应该也可以使用。 > export.config.capabilities.name
    猜你喜欢
    • 2018-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-16
    • 2018-10-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多