简体   繁体   English

如何仅在量角器中运行失败的测试

[英]How to run only failed tests in protractor

In my js file I have defined a bunch of test case, some of them sometimes fails and I would like to re-run just these failed. 在我的js文件中,我定义了一堆测试用例,其中一些有时会失败,我想重新运行这些失败的例子。 Anyone could advise some ready feature which I could use or some another solution? 任何人都可以建议一些我可以使用的现成功能或其他解决方案? It's really inconvenient and time-consuming running everything once again. 再次运行所有内容确实很不方便且耗时。 The below example may show you how my spec looks like. 以下示例可以向您展示我的规格。

describe('Test -> Users table with admin privileges', function () {
var EC = protractor.ExpectedConditions;
var welcomePage = new WelcomePage();
var usersPage = new UsersPage();

beforeEach(function () {
    LogIn.asAdmin1();
    clickWithWait(welcomePage.usersButton);
    browser.wait(hasNonZeroCount(usersPage.allRows), WAIT_TIMEOUT, 'users list did not appear');
});

afterEach(function () {
    welcomePage.logout();
});

it('verifies counter on active tab', function () {
    browser.wait(EC.elementToBeClickable(usersPage.allRows.first()), WAIT_TIMEOUT, 'firstRow was not visible ');
    usersPage.allRows.count().then(function (count) {
        expect(usersPage.activeTab.getText()).toContain('Active' + ' (' + count + ')');
    });
});

it('verifies counter on archived tab', function () {
    browser.wait(EC.elementToBeClickable(usersPage.allRows.first()), WAIT_TIMEOUT, 'firstRow was not visible ');
    // Initial condition for case of none archived user have to be added here (it will remove if statement).
    clickWithWait(usersPage.archivedTab);
    usersPage.allRows.count().then(function (count) {
        if (count > 0) {
            expect(usersPage.archivedTab.getText()).toContain('Archived' + ' (' + count + ')');
        } else {
            console.log("Test Ignored due to none records")
        }
    });
});

A somewhat mature solution was proposed by NickTomlin with protractor-flake NickTomlin用量角器片提出了一种比较成熟的解决方案

Protractor-flake is " a wrapper for protractor to automatically re-run failed specs for a specific number of attempts ", check out these two links for steps on how to implement it: Protractor-flake是“ 用于量角器针对特定数量的尝试自动重新运行失败的规范的包装器 ”,请查看以下两个链接以获取有关如何实现它的步骤:

  1. https://www.npmjs.com/package/protractor-flake https://www.npmjs.com/package/protractor-flake
  2. https://github.com/NickTomlin/protractor-flake/blob/master/docs/cucumber.md https://github.com/NickTomlin/protractor-flake/blob/master/docs/cucumber.md

Please pay attention to the Caveat section under that NPM link above: 注意上方NPM链接下的“警告”部分

*Caveats *注意事项

This has not yet been tested with Protractor + Mocha. 尚未通过量角器+摩卡测试。 It should function similarly. 它的功能应类似。 Please update with an issue or PR if this is not the case. 如果不是这种情况,请更新问题或PR。

Tests will not re-run properly (all tests will run each time) if you use a custom reporter that does not log stacktraces for failed tests. 如果您使用的自定义报告程序不记录失败测试的堆栈跟踪,则测试将无法正确重新运行(每次都会运行所有测试)。 For example, if you are using jasmine-spec-reporter with Jasmine 2.0, make sure to set displayStacktrace: 'specs' or displayStacktrace: 'all'.* 例如,如果您将Jasmine-spec-reporter与Jasmine 2.0一起使用,请确保设置displayStacktrace:'specs'或displayStacktrace:'all'。*

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM