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

时间:2015-11-09 08:53:31

标签: javascript selenium protractor

在我的js文件中,我定义了一堆测试用例,其中一些有时会失败,我想重新运行这些失败。 任何人都可以建议我可以使用的一些现成功能或其他解决方案吗?再一次运行所有内容真的很不方便且耗时。以下示例可能会向您展示我的规范是什么样的。

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")
        }
    });
});

1 个答案:

答案 0 :(得分:4)

NickTomlin提出了一个有点成熟的解决方案 量角器

Protractor-flake是“ 量角器的包装器,可以针对特定次数的尝试自动重新运行失败的规格 ”,请查看这两个链接,了解有关如何操作的步骤实施它:

  1. https://www.npmjs.com/package/protractor-flake
  2. https://github.com/NickTomlin/protractor-flake/blob/master/docs/cucumber.md
  3. 注意上面NPM链接下的警告部分

    <强> *注意事项

    尚未使用Protractor + Mocha进行测试。它的功能应该相似。如果不是这样,请更新问题或PR。

    如果使用不记录堆栈跟踪的自定义报告器以进行失败的测试,则测试将无法正常重新运行(所有测试都将每次运行)。例如,如果您在Jasmine 2.0中使用jasmine-spec-reporter,请确保设置displayStacktrace:'specs'或displayStacktrace:'all'。*

相关问题