2017-05-04 68 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); 
    ); 
); 
); 

我不認爲這很可讀,但那可能就是我。