量角器,完成和期待,我们为什么需要等待?

编程入门 行业动态 更新时间:2024-10-23 07:25:56
本文介绍了量角器,完成和期待,我们为什么需要等待?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我认为Done会让事情同步运行,这意味着在点击链接后,点击回拨会在点击后发生,显然不是因为这不起作用。

I thought Done would make things run synchronously, meaning after I click a link, the click call back would happen after the click, apparently not as this doesn't work.

browser.ignoreSynchronization = true; var firstURL = "www.google/?gws_rd=ssl"; describe("test", function () { browser.get("www.google"); it("Should be on google url", function () { expect(browser.getCurrentUrl()).toBe(firstURL); }); it("Should be able to type in text and click", function (done) { var ele = element.all(by.name("q")).first(); ele.sendKeys("Protractor API"); ele.click().then(function () { expect(true).toBe(true); done(); }); }); it("Should be on new page", function (done) { browser.driver.getCurrentUrl().then(function (url) { debugger; done(); }); }); });

代码底部的getCurrentUrl()返回第一页的URL。如果我在浏览器中看到它在测试中发生变化,如何获取当前URL?

The getCurrentUrl() at bottom of code returns the URL of the first page. How do I get the current URL when I can see it's changed in the browser from the test?

推荐答案

您认为点击更改url后,promise会得到解决,但由于您正在测试非角度页面而关闭同步,因此会立即解决。 您应该等待网址自行更改:

You assume that the click promise would get resolved after the url is changed but since you are testing a non-angular page and you turned off synchronization it gets resolved immediately. You should wait for the url to change yourself:

var urlChanged = function(expectedUrl) { return function() { return browser.getCurrentUrl().then(function(url) { return url.indexOf(expectedUrl) > -1; }); }; };

然后在测试中:

ele.click().then(function () { browser.wait(urlChanged('google'), 5000); done(); });

更多推荐

量角器,完成和期待,我们为什么需要等待?

本文发布于:2023-11-05 07:53:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560286.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:量角器   期待

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!