当我从事 Protractor 测试自动化工作并慢慢深入研究越来越高级的 JavaScript 功能时,我想知道如何利用 Protractor 测试自动化中的闭包功能。
What are those typical test automation situations where closures might prove a useful feature to use?
我纯粹是从 UI 测试自动化的 Angular 提出这个问题,而不是一般的 JavaScript 编程。我很想听听在大型项目中使用高级 Protractor 的资深人士的意见并分享他们的经验。
最佳答案
以下是我们在测试自动化项目中使用的一些闭包用例:
当页面对象方法有一个 promise 解析函数,您需要在其中访问其他页面对象字段或方法时,您需要创建一个闭包:
var SelectEnvironmentPage = function () { this.title = this.container.element(by.css("b.modal-title")); this.goButton = element(by.id("selEnvBtnGo")); this.passIfPresent = function () { var self = this; this.title.isPresent().then(function (isTitlePresent) { if (isTitlePresent) { self.goButton.click().then(function () { helpers.passMaxSessionPopup(); }); } }); }; };
当 extending
ElementArrayFinder
methods and defining thegetWebElements()
method
关于javascript - JavaScript 闭包如何帮助 Protractor 测试自动化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41528787/