例如,如果用户有一张礼品卡,我们希望断言礼品卡部分首先出现:
<section id="gift-card-section"> ... </section>
<section id="credit-card-section"> ... </section>否则,我们想断言信用卡部分是第一位的。在Magellan / Nightwatch中如何做到这一点?
我的想法是在N-th child中获得N ...并断言N1 < N2或反过来。在Magellan / Nightwatch中如何做到这一点?
发布于 2017-07-29 04:56:15
这是使用XPATH的一个很好的例子。显式,如果您知道这些应该是第一个和第二个section元素。
browser
.useXpath().assert.attributeContains('(//section)[1]', 'id', 'gift-card-section');
.useXpath().assert.attributeContains('(//section)[2]', 'id', 'credit-card-section');或者,如果它们不需要排序,并且它们在DOM中处于同一级别(如果它们是同级),则可以使用attribute equals:
browser
.useXpath().assert.attributeEquals("//section[@id='credit-card-section']/following-sibling:://section[@id='gift-card-section']", "id", "credit-card-section");第二个选项有点多余,但是如果您在Nightwatch中使用XPATH,还有很多其他选项。
https://stackoverflow.com/questions/45361847
复制相似问题