[英]wait for a few seconds before running next step protractor
What function do you use to wait for a few seconds before running next step in protractor. 在量角器中运行下一步之前,您使用什么功能等待几秒钟。 I have a span with a text and I want to wait for the text to be changed from an external source before I check for it again.
我有一个带有文本的跨度,我想等待在我再次检查之前从外部源更改文本。
HTML: HTML:
<div class="panel">
<button type="submit" onclick="promptTransaction()">Load Transaction</button>
<button type="submit" onclick="handleMessage()">Post Message</button>
<select name="messageType" class="messageType">
<option>Submit</option>
<option>Amount</option>
</select>
<div class="message-box"><b>Sending message to hosted page:</b><span class="message-out">waiting...</span></div>
<div class="message-box"><b>Receiving message from hosted page:</b><span class="message-in">waiting...</span></div>
</div>
so when I click the 'post message' button, I should receive a new text from external source and change the span with a classname 'message-in'. 因此,当我单击“发布消息”按钮时,我应该从外部源接收新文本,并使用类名“message-in”更改范围。
Currently, my test looks like this: 目前,我的测试看起来像这样:
element(by.cssContainingText('button','Post Message')).click().then(function() {
//WAIT FOR 10 seconds
element(by.css('.message-box .message-in')).getText().then(function (text) {
var response = JSON.parse(text);
expect(response.type).toBe('msax-cc-result');
expect(response.value.Transaction).toBe('Tokenize');
expect(response.value.CardToken).not.null();
})
});
Also, in the text result that is returned from external source, I converted it to json object, but can't since there is a '\\' on it, is there a way to remove it before converting it into an object. 另外,在从外部源返回的文本结果中,我将其转换为json对象,但由于它上面有'\\',所以有没有办法在将其转换为对象之前将其删除。
passed data: 传递数据:
{"type":"msax-cc-result","value":"{\"Transaction\":\"Tokenize\",\"CardToken\":\"ba9c609f-45fc-49aa-b8b2-ecaffbc56d43\"}"}
Usually this is browser.sleep(N)
, but it is generally speaking not recommended to introduce hardcode delays between browser actions. 通常这是
browser.sleep(N)
,但通常不建议在浏览器操作之间引入硬编码延迟。 A better mechanism is an Explicit Wait - waiting for a specific condition to be met on a page using browser.wait()
which would periodically check the expected condition status until a timeout happens. 一种更好的机制是显式等待 - 等待在页面上使用
browser.wait()
满足特定条件,这将定期检查预期条件状态,直到发生超时。 Comparing to browser.sleep()
, browser.wait()
would stop waiting immediately after the wait condition becomes truthy. 与
browser.sleep()
相比,在等待条件变为真实之后, browser.wait()
将立即停止等待。
For instance, if you know what text to wait for, textToBePresentInElement
should fit: 例如,如果您知道要等待的文本,
textToBePresentInElement
应该适合:
var EC = protractor.ExpectedConditions;
var elm = $(".message-out");
browser.wait(EC.textToBePresentInElement(elm, "Some message"), 5000);
Or, you may for instance, wait for waiting...
not to be present in element: 或者,例如,您可以
waiting...
不要出现在元素中:
browser.wait(EC.not(EC.textToBePresentInElement(elm, "waiting...")), 5000);
where 5000
is a timeout in milliseconds. 其中
5000
是超时(以毫秒为单位)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.