jasmine - Protractor Jasmine Reporter + BDD + Azure DevOps

标签 jasmine protractor azure-devops bdd

我想以 BDD 风格编写 Jasmine End 2 结束测试。据我了解,这意味着我有差不多 4 个方面:

  • 特色
  • 场景
  • 刺激或事件
  • 要确保的结果

从我天真的观点来看,我会像这样为“个人详细信息”功能创建一个测试:

// Feature
describe('Showing Individual Details', () => {
  let individualDetailsPage: IndividualDetailsPage;

  beforeEach(() => {
    individualDetailsPage = new IndividualDetailsPage();
  });

  // Scenario - New Individual
  describe('Given a new Individual', () => {
    beforeEach(async () => {
      await individualDetailsPage.navigateToDetails('-1');
    });

    // Incoming Event
    describe('When the Details are loaded', () => {
      // Ensure outcome
      it('Then all Controls are empty', async () => {
        expect(individualDetailsPage.firstNameInput.text).toBe('');
        expect(individualDetailsPage.lastNameInput.text).toBe('');
        expect(individualDetailsPage.birthdateInput.text).toBe('');
      });

      // Ensure outcome
      it('Then the save button is disabled', () => {
        expect(individualDetailsPage.saveButton.isEnabled).toBe(false);
      });
    });
  });
});

因此,对于 Individual Details 功能,如果设置了新的 Individual,则 Controls 应该为空,并且禁用保存按钮。 仍然从天真的角度来看,这似乎没问题。同时运行测试,我看到:

enter image description here

这看起来不错。现在是有趣的部分:我想将此更改发布到 Azure DevOps,因此我在 Protractor 配置中使用以下代码:

  onPrepare() {
    require('ts-node').register({
      project: require('path').join(__dirname, './tsconfig.e2e.json')
    });
    var jasmineReporters = require('jasmine-reporters');
    var junitReporter = new jasmineReporters.JUnitXmlReporter({
      savePath: 'testresults',
      filePrefix: 'e2e-tests',
      consolidateAll: true
    });

    jasmine.getEnv().addReporter(junitReporter);
  }

不幸的是,XML 看起来像这样:

 <testsuite name="Showing Individual Details" timestamp="2019-02-04T18:23:33" hostname="localhost" time="2.035" errors="0" tests="0" skipped="0" disabled="0" failures="0">
 </testsuite>
 <testsuite name="Showing Individual Details.Given a new Individual" timestamp="2019-02-04T18:23:33" hostname="localhost" time="2.033" errors="0" tests="0" skipped="0" disabled="0" failures="0">
 </testsuite>
 <testsuite name="Showing Individual Details.Given a new Individual.When the Details are loaded" timestamp="2019-02-04T18:23:33" hostname="localhost" time="2.033" errors="0" tests="2" skipped="0" disabled="0" failures="0">
  <testcase classname="Showing Individual Details.Given a new Individual.When the Details are loaded" name="Then all Controls are empty" time="1.106" />
  <testcase classname="Showing Individual Details.Given a new Individual.When the Details are loaded" name="Then the save button is disabled" time="0.927" />
 </testsuite>

由于 Azure DevOps 似乎只检查名称,因此我看到:

enter image description here

我的问题:我不确切地知道我的问题出在哪里。我没有找到任何关于 Jasmine 的“真实”BDD 的好资源,而且 Jasmine Reporter 似乎不能配置那么多:https://github.com/larrymyers/jasmine-reporters

因此,我的代码是完全错误的,还是实际上是报告者?如果是这种情况,是否有替代方案或者我是否需要以某种方式“扁平化”XML?

最佳答案

我同意上面的评论,创建您自己的记者声音是可行的方法。您可以根据需要格式化内容。

我最近回复了另一个关于 Jasmine 记者的问题here .我将我的测试结果重新格式化为一个 JSON 对象,并在每次测试完成后将它们存储在 amazons dynamoDB 中。

如有任何问题,请告诉我。

关于jasmine - Protractor Jasmine Reporter + BDD + Azure DevOps,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54522498/

相关文章:

javascript - 在测试中执行函数 n 次并检查 jasmine 异步代码中的每个结果的智能方法

javascript - Click() 和 then() 不起作用 - Protractor

AngularJS 测试 $scope 方法是否被调用

angular - 函数在 5000 毫秒后超时 - Angular 4 - Protractor 和 cucumber

azure - 交换槽设置错误 发布管理 Visual Studio Team Services

angular - Jasmine 编译/创建与 beforeAll/beforeEach 表现奇怪的组件

node.js - 如何在 javascript 中获取全局 npm 模块的路径?

google-chrome - 安装特定/旧版 chrome 浏览器的任何方式

azure - 如何在运行 Linux 的 Azure 应用服务上运行 PowerShell 脚本?

azure - "Count of dead-lettered messages in a Queue/Topic. (Preview)"Azure 的指标名称