Невозможно прочитать свойство 'Base' с неопределенной ошибкой, используя mocha-allure-reporter в Cypress - PullRequest
0 голосов
/ 11 января 2019

Я пытаюсь использовать mocha-allure-reporter in Cypress . Я установил mocha и mocha-allure-reporter как зависимости dev и упомянул mocha-allure-reporter как репортер в cypress.json.

Я попробовал приведенный ниже код, указанный в разделе пример страницы mocha allure :

require('mocha-allure-reporter');

describe("simple test demo", () => {
  const testStep = allure.createStep("initial", () => {
    console.log("First Test")
  });

  it("simple passed test", () => {
    testStep();
  });
}

Однако я получаю следующую ошибку:

Uncaught TypeError: Невозможно прочитать свойство 'Base' из неопределенного

... в самой первой строке:

require('mocha-allure-reporter')

При взгляде на консоль я вижу, что ошибка возникает в строке - var Base = require("mocha").reporters.Base в репортере Allure:

var Base = require("mocha").reporters.Base;
var Allure = require("allure-js-commons");
...
...
global.allure = new Runtime(allureReporter);

/**
 * Initialize a new `Allure` test reporter.
 *
 * @param {Runner} runner
 * @param {Object} opts mocha options
 * @api public
 */
function AllureReporter(runner, opts) {
...
...

Обратите внимание, что следующий выходной xml-файл создается в каталоге allure-results после выполнения.

<?xml version='1.0'?>
<ns2:test-suite xmlns:ns2='urn:model.allure.qatools.yandex.ru' start='1547481439243' stop='1547481439477'>
    <name></name>
    <title></title>
    <test-cases>
        <test-case start='1547481439282' status='broken' stop='1547481439460'>
            <name>An uncaught error was detected outside of a test</name>
            <title>An uncaught error was detected outside of a test</title>
            <labels/>
            <parameters/>
            <steps/>
            <attachments/>
            <failure>
                <message>Cannot read property 'Base' of undefined

                This error originated from your test code, not from Cypress.

                When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.

                Cypress could not associate this error to any specific test.

                We dynamically generated a new test to display this failure.</message>
                <stack-trace>Uncaught TypeError: Cannot read property 'Base' of undefined

                This error originated from your test code, not from Cypress.

                When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.

                Cypress could not associate this error to any specific test.

                We dynamically generated a new test to display this failure.
                    at Object.&lt;anonymous> (http://localhost:61925/__cypress/tests?p=cypress\integration\Tests\Test.spec.js-289:15125:38)
                    at Object.98.allure-js-commons (http://localhost:61925/__cypress/tests?p=cypress\integration\Tests\Test.spec.js-289:15201:4)
                    at o (http://localhost:61925/__cypress/tests?p=cypress\integration\Tests\Test.spec.js-289:1:265)
                    at http://localhost:61925/__cypress/tests?p=cypress\integration\Tests\Test.spec.js-289:1:316
                    at Object.40.mocha-allure-reporter (http://localhost:61925/__cypress/tests?p=cypress\integration\Tests\Test.spec.js-289:7566:1)
                    at o (http://localhost:61925/__cypress/tests?p=cypress\integration\Tests\Test.spec.js-289:1:265)
                    at r (http://localhost:61925/__cypress/tests?p=cypress\integration\Tests\Test.spec.js-289:1:431)
                    at http://localhost:61925/__cypress/tests?p=cypress\integration\Tests\Test.spec.js-289:1:460</stack-trace>
            </failure>
        </test-case>
    </test-cases>
</ns2:test-suite>

Пожалуйста, ведите меня. Спасибо!

1 Ответ

0 голосов
/ 12 января 2019

Я смог использовать mocha-allure-reporter , просто установив его (вместе с мокко),

npm install mocha mocha-allure-reporter

и настройку скрипта в package.json, следуя рекомендациям Cypress для репортеров npm здесь

"scripts": {
  ...
  "cypress:run": "cypress run --reporter mocha-allure-reporter"

Обратите внимание, я думаю, что эти репортеры работают только с командой Cypress 'run', а не с командой Cypress 'open'.

Выводом является папка с именем 'allure-results', которая содержит несколько файлов xml. Я полагаю, что они могут быть отображены с помощью инструмента Allure Framework.

Пример выходного файла:

<?xml version='1.0'?>
<ns2:test-suite xmlns:ns2='urn:model.allure.qatools.yandex.ru' start='1547254197911' stop='1547254201289'>
    <name>Tasks Page</name>
    <title>Tasks Page</title>
    <test-cases>
        <test-case start='1547254199721' status='passed' stop='1547254199815'>
            <name>should have a title</name>
            <title>should have a title</title>
            <labels/>
            <parameters/>
            <steps/>
            <attachments/>
        </test-case>
    </test-cases>
</ns2:test-suite>

Запустить код очарования в cy.task ()

Для запуска кода очарования вам необходимо получить доступ к контексту nodejs через cy.task.

Например,

/ кипарис / плагины / index.js

require('mocha-allure-reporter');

module.exports = (on) => {
  on('task', {
    allureTestStep () {
      const testStep = allure.createStep("initial", () => {
        console.log("First Test")
      });
      testStep()

      return null
    }
  })
}

спецификация

describe("simple test demo", () => {

  it("simple passed test", () => {
    cy.task('allureTestStep')
  });
})

Обратите внимание, что это создает журнал консоли в командном окне, где вы запускаете Cypress, а не консоль браузера.

Однако вы можете передать значение обратно из задачи в тест, в зависимости от того, что вы на самом деле пытаетесь сделать (см. Документацию).

...