admin管理员组文章数量:1363053
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:
<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'.
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.
passed data:
{"type":"msax-cc-result","value":"{\"Transaction\":\"Tokenize\",\"CardToken\":\"ba9c609f-45fc-49aa-b8b2-ecaffbc56d43\"}"}
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:
<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'.
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.
passed data:
{"type":"msax-cc-result","value":"{\"Transaction\":\"Tokenize\",\"CardToken\":\"ba9c609f-45fc-49aa-b8b2-ecaffbc56d43\"}"}
Share
Improve this question
asked Mar 4, 2016 at 14:32
kennanwhokennanwho
1711 gold badge3 silver badges14 bronze badges
1
- Possible duplicate of In protractor test is there a way to wait between test run – SlashmanX Commented Mar 4, 2016 at 14:39
1 Answer
Reset to default 8Usually this is browser.sleep(N)
, but it is generally speaking not remended to introduce hardcode delays between browser actions. 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. Comparing to browser.sleep()
, browser.wait()
would stop waiting immediately after the wait condition bees truthy.
For instance, if you know what text to wait for,textToBePresentInElement
should fit:
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:
browser.wait(EC.not(EC.textToBePresentInElement(elm, "waiting...")), 5000);
where 5000
is a timeout in milliseconds.
本文标签: javascriptwait for a few seconds before running next step protractorStack Overflow
版权声明:本文标题:javascript - wait for a few seconds before running next step protractor - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743813975a2543578.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论