【问题标题】:Spectron test sequential actionsSpectron 测试顺序动作
【发布时间】:2017-05-04 16:22:46
【问题描述】:

我正在使用 spectron 测试电子应用程序。我在文档示例中找到了有关如何获取窗口数量的信息,这非常简单。但我正在寻找的是在我点击另一个元素后如何检查一个元素的状态。在这里,我试图检查应用程序在最小化后是否可见。但是这个测试总是通过,无论真假。

     it('should minimize the application', () => {
        return this.app.client.click('.minimize').then(() => {
          this.app.client.browserWindow.isVisible().then((isVisible) => {
            expect(isVisible).to.be.equal(true);
          });
        });
      })

我正在使用带有 chai 断言的 mocha。

请告知我在单击另一个元素后如何检查应用程序(或特定元素是否可见)。

【问题讨论】:

    标签: javascript testing electron spectron


    【解决方案1】:

    你需要return你的回调函数的结果。

    it('should minimize the application', () => {
      return this.app.client.click('.minimize').then(() => {
        return this.app.client.browserWindow.isVisible().then((isVisible) => {
          return expect(isVisible).to.be.equal(true);
        });
      });
    });
    

    或者,去掉环绕的花括号,arrow function 将自动返回结果。

    it('should minimize the application', () =>
      this.app.client.click('.minimize').then(() => 
        this.app.client.browserWindow.isVisible().then((isVisible) => 
          expect(isVisible).to.be.equal(true);
        );
      );
    );
    

    我认为这不是那么可读,但可能只是我自己。

    【讨论】:

      【解决方案2】:

      您可以链接您的承诺

      我是这样用的

      Return this.app.client.click('.minimize').browserWindow.isVisible().should.be.equal(true)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-22
        • 1970-01-01
        • 1970-01-01
        • 2019-04-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多