Protractor-Cucumber-Framework:如何仅运行一个测试?

发布于 2025-02-03 00:17:31 字数 3265 浏览 2 评论 0原文

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

Angular项目中,我们在E2E测试中使用量角黄瓜框架

我不知道如何仅通过标签运行一个测试。 您应该能够在Cucumberopts 属性 protractor.conf.js file属性的属性中编辑tags。但是,当我在那里添加标签@TestonLyThis,然后将该标签添加到.feature文件中的测试中,然后运行npm运行e2e:ci(根据package.json,运行“ protractor ./ e2e/protractor.conf.js”),量角器仍在我们套件中运行每个E2E测试。 protractor.conf.js文件中的其他更改已生效,但是编辑标签似乎具有零效果。

什么给?

protractor.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 });
  },
};

FYI, none of the other Stackoverflow questions/answers have resolved this for me.

In an Angular project, we're using Protractor Cucumber Framework for our E2E tests.

I can't figure out how to run only one single test via tags.
You're supposed to be able to edit the tags inside of the cucumberOpts property of the protractor.conf.js file. But when I add a tag @testOnlyThis there, then add that tag to a test in a .feature file, then run npm run e2e:ci (which, according to package.json, runs "protractor ./e2e/protractor.conf.js"), Protractor still runs every single E2E test in our suite. Other changes made in the protractor.conf.js file take effect, but editing the tags seems to have zero effect.

What gives?

protractor.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 });
  },
};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深白境迁sunset 2025-02-10 00:17:31

嗨,尝试宣布这样的标签,如果有帮助

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

Hi Try declaring your tags like this, if that helps

cucumberOpts: {
         tags: '@Smoke,@Intgr'
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文