2017-05-04 37 views
1

我正在用spectron测试电子应用。我在文档中找到了如何获取窗口数量的例子,这是相当简单的。但是我看到的是如何在点击另一个元素后检查一个元素的状态。在这里,我试图在最小化应用程序后检查应用程序是否可见。但是这个测试总是通过,为真和假。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); 
      }); 
     }); 
     }) 

我使用摩卡与柴断言。

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

回答

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); 
    ); 
); 
); 

我不认为这很可读,但那可能就是我。