0

我需要断言我创建的元素已添加到列表中,但它被添加到列表的末尾并且是分页的。

我正在考虑通过以这种方式调用另一个任务来浏览每个页面:

export class CheckItem implements Task {
  static afterCreated(): CheckItem {
    return new CheckItem();
  }

  performAs(actor: PerformsTasks & UsesAbilities): PromiseLike<void> {
    return TakeNotes.as(actor).read('item-name')
      .then((itemName: string) => actor
        .attemptsTo(
          NavigateThroughItemList.untilFinds(itemName),
        ));
  }
}

我需要实施NavigateThrougItemList.

4

1 回答 1

0

好的,我通过使用递归调用找到了解决方案。也许有一个更好的解决方案,但这对我有用。

export class NavigateThroughItemList implements Task {
  static untilFinds(itemName: string): NavigateThroughItemList {
    return new NavigateThroughItemList(itemName);
  }

  constructor(private itemName: string) {
  }

  @step('{0} navigates through the list until #itemName is found')
  performAs(actor: PerformsTasks): PromiseLike<void> {
    return actor.attemptsTo(
      See.if(Text.ofAll(ItemList.items), include(this.itemName)),
    ).catch(() => actor
      .attemptsTo(
        See.if(
          WebElement.of(ItemList.nextButton),
          isEnabled(),
        ),
      )
      .then(() => actor
        .attemptsTo(
          Click.on(ItemList.nextButton),
        ))
      // Looping until it finds the item
      .then(() => this.performAs(actor)));
  }
}
于 2019-03-10T08:32:01.223 回答