Protractor-cucumber-framework:如何只运行一个测试?

Protractor-cucumber-framework: how to run only one test?

提问人:Kyle Vassella 提问时间:5/31/2022 最后编辑:Kyle Vassella 更新时间:8/27/2022 访问量:262

问:

仅供参考,其他 Stackoverflow 问题/答案都没有为我解决这个问题。

在一个项目中,我们用于 E2E 测试。AngularProtractor Cucumber Framework

我无法弄清楚如何通过 . 您应该能够编辑文件属性的内部。但是当我在那里添加一个标签,然后将该标签添加到文件中的测试中,然后运行(根据package.json,运行),量角器仍然运行我们套件中的每个 E2E 测试。文件中所做的其他更改将生效,但编辑 似乎没有效果。tagstagscucumberOptsprotractor.conf.js@testOnlyThis.featurenpm run e2e:ci"protractor ./e2e/protractor.conf.js"protractor.conf.jstags

什么给了?

量角器.conf.js

// @ts-check
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
const path = require('path');
const fs = require('fs');
const cucumberJunit = require('protractor-cucumber-junit/lib/cucumber_junit');

const downloadsPath = path.resolve(__dirname, 'downloads');
const reportingPath = path.resolve(__dirname, 'reporting/protractor-cucumber-framework');

let startDate;
/**
 * @type { import("protractor").Config }
 */
exports.config = {
  allScriptsTimeout: 20000,
  specs: ['./src/features/**/**/**/**/**/*.feature'],
  resultJsonOutputFile: 'reporting/results.json',
  capabilities: {
    browserName: 'chrome',
    shardTestFiles: true,
    maxInstances: 1,
    chromeOptions: {
      prefs: {
        'plugins.always_open_pdf_externally': true,
        download: {
          directory_upgrade: true,
          prompt_for_download: false,
          default_directory: downloadsPath,
        },
      },
      args: [
        '--no-sandbox',
        '--test-type=browser',
        '--disable-gpu',
        '--log-level=1',
        '--disable-dev-shm-usage',
        // '--disk-cache-dir=null',
      ],
    },
  },
  directConnect: true,
  SELENIUM_PROMISE_MANAGER: false,
  noGlobals: true,
  baseUrl: 'https://mybaseurl.com',
  framework: 'custom',
  frameworkPath: require.resolve('protractor-cucumber-framework'),
  cucumberOpts: {
    require: ['./src/step-definitions/*steps.ts'],
    tags: ['@testOnlyThis', '~@ignore'],
    format: ['json:./reporting/protractor-cucumber-framework/results.json'],
    retry: 2,
  },
  onPrepare() {
    require('ts-node').register({
      project: require('path').join(__dirname, './tsconfig.json'),
    });
    const chai = require('chai');
    const chaiAsPromised = require('chai-as-promised');
    chai.use(chaiAsPromised);
  },
  beforeLaunch() {
    startDate = new Date().getTime();

    if (!fs.existsSync(downloadsPath)) {
      fs.mkdirSync(downloadsPath);
    }

    if (!fs.existsSync(reportingPath)) {
      fs.mkdirSync(reportingPath, { recursive: true });
    }

    console.log(`process.env.E2E_LANGUAGE is set to: '${process.env.E2E_LANGUAGE}'`);
  },
  afterLaunch() {
    const endDate = new Date().getTime();
    const duration = (endDate - startDate) / (60 * 1000);
    console.log(
      `ALL TESTS EXECUTION TIME: ${Math.floor(duration)}m${Math.round((duration % 1) * 60)}s`,
    );
    const file = fs.readFileSync('reporting/results.json', 'utf-8');
    // @ts-ignore
    const xml = cucumberJunit(file);
    fs.writeFileSync('e2e/reporting/results.xml', xml);
    fs.rmdirSync(reportingPath, { recursive: true });
  },
};
JavaScript 量角

评论


答:

0赞 Abhay Pratap Singh 6/2/2022 #1

嗨,如果有帮助,请尝试像这样声明您的标签

cucumberOpts: {
         tags: '@Smoke,@Intgr'
 }