npm install --save-dev spectron-window
import SpectronWindow from 'spectron-window'
export default class Login extends SpectronWindow {
// require
get path () {
return 'login.html'
}
username (val) {
if (val) {
return this.browser.setValue('#username', val)
} else {
return this.browser.getValue('#username')
}
}
password (val) {
if (val) {
return this.browser.setValue('#password', val)
} else {
return this.browser.getValue('#password')
}
}
async login (u, p) {
await this.username(u)
await this.password(p)
return this.submit()
}
async submit () {
await this.click('#login-btn')
}
//...
}
const Application = require('spectron').Application
const app = new Application({
path: '....',
startTimeout: 15000,
quitTimeout: 10000,
waitTimeout: 20000
})
await app.start()
await app.client.waitUntilWindowLoaded()
const loginWin = new LoginWin(app)
check full demo spectron-window-demo
wrap spectron.client, but auto foucs window.
- focus to window
- check the window isExist
MIT