使用量角器配置在Allure中为多个浏览器拍摄屏幕截图

时间:2018-12-17 10:38:58

标签: javascript angularjs jasmine protractor allure

在端到端测试环境中,我是一个新手。我正在使用Protractor框架(茉莉花赛跑者)进行我的应用测试。我使用Chrome和Internet Explorer运行测试。但是在“吸引人的报告”中,我只能看到针对一个浏览器的报告,而不能同时针对两个浏览器。另外,仅针对一个浏览器生成屏幕截图。是否有任何诱人的配置,通过它我可以查看两个浏览器的报告。

我的配置文件是

var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
require('protractor/built/logger').Logger.logLevel = 3;
exports.config = {
    troubleshoot: true, // for protractor
    allScriptsTimeout: 1200000,
    specs: [
        './e2e/tests/**/0030*.e2e-spec.ts',
    ],

    multiCapabilities:[
    {
            'browserName' : 'chrome',
            'chromeOptions': { 'args' : ['--disable-extensions']},
            'shardTestFiles': true,
            'maxInstances': 1,
            'unexpectedAlertBehaviour' : 'dismiss'
        },
        {
            'browserName': 'internet explorer',
            'se:ieOptions': {

                enablePersistentHover: true,
                'ie.ensureCleanSession': true,
            }
        }
        ],

      jvmArgs: ['-Dwebdriver.ie.driver=./node_modules/webdriver-manager/selenium/IEDriverServer3.141.0.exe'],


    baseUrl: 'http://localhost:4200/',
    framework: 'jasmine',
    jasmineNodeOpts: {
        isVerbose: true,
        showColors: true,
        defaultTimeoutInterval: 1200000
    },
    useAllAngular2AppRoots: true,
    beforeLaunch: function() {
    }

    onPrepare: function() {
    browser.manage().window().maximize();
    require('ts-node').register({
        project: 'e2e/tsconfig.json'
    });

    jasmine.getEnv().addReporter(reporter);

    var AllureReporter = require('jasmine-allure-reporter');

    capsPromise.then(function(caps) {
        console.log(caps);
        var browserName = caps.get('browserName');
        var browserVersion = caps.get('version');
        const prePendStr = browserName + "-" + browserVersion + "-";
        console.log(prePendStr);
    });

    jasmine.getEnv().addReporter(new AllureReporter({
        resultsDir: 'allure-results'
    }));
    jasmine.getEnv().addReporter(reporter);

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

    jasmine.getEnv().addReporter(new Jasmine2HtmlReporter({
        //savePath: './test/jasmine-nowshin/'
    }));
  }
};

测试中的更新代码

    let capsPromise = browser.getCapabilities();
let browserNameforSpec;
capsPromise.then(function(caps) {
    console.log(caps);
    let browserName = caps.get('browserName');
    let browserVersion = caps.get('version');
    browserNameforSpec = browserName + '-' + browserVersion + '-';
    console.log(browserNameforSpec);

});

describe( '0030 Test for login' + browserNameforSpec, function () { // this.browserNameforSpec value is undefined

    // 1.
    it('Navigate to the login page', async () => {
        await navigate.to.the(loginPage);
    });

    // 2
    it('Click onto language button', async() => {
        await click.onto(languageButton);
        await expect(languageDropdown.isDisplayed());
    });

    // 3
    it('English Language is selected', async() => {    
        await click.onto(englishLanguage);
        await expect(languageButton.getText()).toBe('English');
    });

    // 4.
    it('Correct user name is written into email field', async() => {
        await usernameField.click();
        await enter(correctUsername, into(usernameField));    
    });

    // 5.
    it('Correct password is written into password field', async() => {
            await passwordField.click().then(function () {
                passwordField.clear();
                enter(correctPassword, into(passwordField));
            })    
    });

    // 6.
    it('Login button is clicked and home page is opened', async() => {
        await click.onto(loginButton);
    });    
});

1 个答案:

答案 0 :(得分:2)

目前的吸引力不支持多浏览器报告。

如果测试名称为“ abc”,它将创建2个具有相同名称的报告并将其堆叠,但是在测试结束时,您只能看到1个报告。您可以在“历史记录”或“重试”标签中看到此报告。

您可以在测试开始时为茉莉花事件创建自定义侦听器,以添加浏览器名称,或为其他每次测试创建其他名称,以便区分它们。

有关创建自定义报告程序(侦听器)的信息 https://jasmine.github.io/tutorials/custom_reporter

您可以提取浏览器名称:

browser.getCapabilities().then((cap) => {
    browser.params.browserName = cap.get('browserName');
});