首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >量角器-黄瓜框架:如何只运行一个测试?

量角器-黄瓜框架:如何只运行一个测试?
EN

Stack Overflow用户
提问于 2022-05-30 19:48:05
回答 1查看 135关注 0票数 0

另外,没有其他的堆叠溢出问题/答案能帮我解决这个问题。

Angular项目中,我们使用Protractor Cucumber Framework进行E2E测试。

我不知道如何通过tags只运行一个测试。您应该能够在tags文件的cucumberOpts属性中编辑protractor.conf.js。但是,当我在那里添加标记@testOnlyThis,然后将该标记添加到.feature文件中的测试中,然后运行npm run e2e:ci (根据package.json的说法,运行"protractor ./e2e/protractor.conf.js"),Protractor仍然运行我们套件中的每个E2E测试。protractor.conf.js文件中的其他更改生效,但编辑tags似乎没有任何效果。

怎么回事?

protractor.conf.js

代码语言:javascript
复制
// @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 });
  },
};
EN

回答 1

Stack Overflow用户

发布于 2022-06-02 09:47:15

嗨,试着像这样声明你的标签,如果这有帮助的话。

代码语言:javascript
复制
cucumberOpts: {
         tags: '@Smoke,@Intgr'
 }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72439370

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档