3

我试图找到位于另一个元素下的元素,而量角器似乎无法获得正确的值。

这是一个详细的描述。

我有以下 HTML:

<div ng-repeat="stageRow in stageModel" debugId="stage-row">
  <div>
    <span debugId="stage-name-text">{{ stageRow.name }}</span>
  </div>
  <div>
    <span debugId="stage-count-text">{{ stageRow.count }}</span>
  </div>
</div>

然后我使用以下量角器代码来查找一行:

var allStages = element.all(by.css('[debugId="stage-row"]'));
var stage01 = allStages.get(0);

然后我尝试链接定位器以找到某个单元格:

var count01 = stage01.$('[debugId="stage-count-text"]');

然后我做一个期望:

expect(count01.getText()).to.eventually.equal('1')

这就是我得到的:

  + expected - actual

  +"1"
  -""

即使我清楚地将“1”作为舞台的计数。我知道这是因为:

  1. 我亲眼所见:)
  2. 我在预期之前停止在调试模式,并检查 HTML 以查看该跨度的文本确实是“1”。
  3. 然后我试试这个:

我在期望之前放置了 HTML 的打印输出:

stage01.getOuterHtml().then(function(result) {
  console.log(result);
});

我看到了预期的 HTML:

<div ng-repeat="stageRow in stagingModel" class="ng-scope" debugid="stage-row">
  <div>
    <span debugid="stage-name-text" class="ng-binding">nuziba</span>
  </div>
  <div>
    <span debugid="stage-count-text" class="ng-binding">1</span>
  </div>
</div>

在那之后,我手动尝试这个:

stage01.element(by.css('[debugId="stage-count-text"]')).getText().then(function(count) {
  console.log(count);
});

我在打印输出中得到“”...

然后我尝试使用不同的方法来定位元素 - 使用 by.repeater 而不是 by.css。得到了同样的结果。

这里会发生什么?显然,HTML 包含正确的标记。为什么量角器无法正确提取它?

作为记录,我使用的是量角器版本 1.4.0,跑步者是 mocha 1.18.2,而不是 Jasmine。

非常感谢,丹尼尔

4

1 回答 1

0

您至少需要量角器 1.7 才能使用当前版本为 2.0 的预期条件,因此如果您仍然遇到问题,您应该能够执行此类操作。

在这里,您可以让量角器等到元素中包含文本“1”,然后期望在满足该条件之前不会检查

var count01HasText = EC.textToBePresentInElement(count01, '1');
browser.wait(count01HasText, 5000,);
expect(count01.getText()).toEqual('1');
于 2015-04-14T19:14:20.347 回答