为茉莉花事件创建自定义侦听器,以使用规范名称添加浏览器名称

时间:2018-12-18 12:08:44

标签: javascript angularjs jasmine protractor allure

我正在使用带有JasmineRunner的量角器框架进行我的应用程序测试。我有一个测试用例,名称为0030测试正确的login.e2e-spec.ts。现在,我已经实施了诱人报告,以便在Web上查看报告统计信息。问题是诱惑力显示仅针对一个浏览器的报告。但是我需要为两个浏览器生成报告以及两个浏览器的屏幕截图。我听说,通过添加浏览器名称在茉莉花报告https://jasmine.github.io/tutorials/custom_reporter中创建自定义侦听器,将为一个测试用例创建两个单独的结果。但是我不知道如何通过创建自定义侦听器来添加浏览器名称。到目前为止,我的代码可以获取浏览器名称。但是如何在运行时添加该名称。

我的量角器配置

const JasmineConsoleReporter = require('jasmine-console-reporter');
const reporter = new JasmineConsoleReporter({
    colors: 1,           // (0|false)|(1|true)|2
    cleanStack: 1,       // (0|false)|(1|true)|2|3
    verbosity: 4,        // (0|false)|1|2|(3|true)|4|Object
    listStyle: 'indent', // "flat"|"indent"
    timeUnit: 'ms',      // "ms"|"ns"|"s"
    timeThreshold: { ok: 500, warn: 1000, ouch: 3000 }, // Object|Number
    activity: false,     // boolean or string ("dots"|"star"|"flip"|"bouncingBar"|...)
    emoji: true,
    beep: true
});
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');
    // get the browser name
    var capsPromise = browser.getCapabilities();
    var prePendStr;
    capsPromise.then(function(caps) {
        console.log(caps);
        var browserName = caps.get('browserName');
        var browserVersion = caps.get('version');
        prePendStr = browserName + "-" + browserVersion + "-";
        console.log(prePendStr);
    });

    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();
        })
    });


    }));
}

我的一个示例测试用例是

    describe('0030 Test for correct login , function () {

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

// 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 () {
       enter(correctPassword, into(passwordField));

        })
});

// 6.
it('Login button is clicked and home page is opened with Machine on left top menu', async() => {
    await click.onto(loginButton);
    await expect(ContentPage.leftTopMenuItem.getText()).toContain('Homepage');
});

0 个答案:

没有答案