【问题标题】:How JavaScript closures can help in Protractor test automation?JavaScript 闭包如何帮助 Protractor 测试自动化?
【发布时间】:2017-05-22 13:53:42
【问题描述】:

当我从事量角器测试自动化工作并逐渐深入研究更多更高级的 JavaScript 功能时,我想知道如何利用量角器测试自动化中的闭包功能。

可以证明闭包的典型测试自动化情况有哪些 有用的功能吗?

我纯粹是从 UI 测试自动化的角度提出这个问题,而不是一般的 JavaScript 编程。我很想听听在大型项目中使用高级量角器的资深人士的意见,并分享他们的经验。

【问题讨论】:

    标签: javascript protractor


    【解决方案1】:

    以下是我们在测试自动化项目中一直使用的一些闭包用例:

    • 当一个页面对象方法有一个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 the getWebElements() method

    【讨论】:

      猜你喜欢
      • 2014-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多