Skip to content

Commit

Permalink
Increased timeout. Corrected functions to ensure promises resolved. E…
Browse files Browse the repository at this point in the history
…ncapsulate app stop in function to ensure best chance of app quitting. Used fake dialog functions in method as problems with slower OS and windows. Disable singleton and ensure focus for Windows with terminal window opening on command execution.
  • Loading branch information
Matthew Mulholland committed Jun 2, 2018
1 parent db33d01 commit aeddc89
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 24 deletions.
68 changes: 52 additions & 16 deletions test/features/support/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,60 @@ import { After, Before, Status, Given, When, Then } from 'cucumber'
import fakeDialog from 'spectron-fake-dialog'
import { expect, should, assert } from 'chai'

After({timeout: 10000}, async function (testCase) {
if (testCase.result.status === Status.FAILED) {
const imageBuffer = await this.app.browserWindow.capturePage()
await this.attach(imageBuffer, 'image/png')
async function stopAppRunning(app) {
try {
if (app && app.isRunning()) {
// console.log('Attempting to stop app...')
const result = await app.stop()
}
// this is just in case for slower OS/windows - catch any error and ignore
if (app && app.electron) {
const forceQuitResult = await this.app.electron.ipcRenderer.sendSync('forceQuit')
// console.log(`force quit?`, result3)
}
} catch (error) {
// console.log('error caught when stopping run. ignoring')
}
if (this.app && this.app.isRunning()) {
await this.app.stop()
}

After({timeout: 40000}, async function (testCase) {
try {
// console.log('Starting after hook....')
if (testCase.result.status === Status.FAILED) {
if (this.app && this.app.browserWindow) {
const imageBuffer = await this.app.browserWindow.capturePage()
await this.attach(imageBuffer, 'image/png')
// console.log('got attachment in', attachResult)
}
}
// stopAppRunning(this.app)
} catch (error) {
console.log('error in after hook', error)
} finally {
await stopAppRunning(this.app)
}
})

Before({timeout: 10000}, async function () {
this.rowNumber = null
this.colNumber = null
this.latestFilePath = null
this.pageTimeout = 5000
fakeDialog.apply(this.app)
await this.app.start()
// Auto-close message dialog : 1 = Quit (No Cancel No save)
fakeDialog.mock([{method: 'showMessageBox', value: 1}])
fakeDialog.mock([{method: 'showOpenDialog', value: this.openFileDialogReturned}])
Before({timeout: 20000}, async function (testCase) {
try {
// console.log('Starting before hook....')
console.log(`Starting test scenario: ${testCase.pickle.name} in: ${testCase.sourceLocation.uri}`)
// console.log(testCase.pickle.steps)
this.rowNumber = null
this.colNumber = null
this.latestFilePath = null
this.pageTimeout = 5000
await fakeDialog.apply(this.app)
await this.app.start()
await this.app.client.waitUntilWindowLoaded()
await this.app.electron.ipcRenderer.sendSync('unlockSingleton')
await this.app.client.browserWindow.focus()
const result = await this.app.client.browserWindow.isFocused()
expect(result).to.be.true
await this.app.electron.ipcRenderer.sendSync('SPECTRON_FAKE_DIALOG/SEND', [{method: 'showMessageBox', value: 1}])
await this.app.electron.ipcRenderer.sendSync('SPECTRON_FAKE_DIALOG/SEND', [{method: 'showOpenDialog', value: this.openFileDialogReturned}])
} catch (error) {
console.log('error in before hook', error)
await stopAppRunning(this.app)
}
})
26 changes: 18 additions & 8 deletions test/features/support/world.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
import { setWorldConstructor } from 'cucumber'
import { Application } from 'spectron'
import electron from 'electron'
// import fakeDialog from 'spectron-fake-dialog'
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'

chai.should()
chai.use(chaiAsPromised)

function CustomWorld ({attach, parameters}) {
// console.log('starting world...')
this.attach = attach
this.parameters = parameters
this.app = new Application({
if (!this.app) {
this.app = createApp()
this.hotParentSelector = '.tab-pane.active .editor.handsontable'
this.openFileDialogReturned = ['stubbedFilenameForMenuSteps.txt']
chaiAsPromised.transferPromiseness = this.app.transferPromiseness
} else {
console.log('WARNING: app already created...')
}
}

function createApp() {
return new Application({
path: electron,
args: ['dist/electron/main.js'],
startTimeout: 10000,
waitTimeout: 10000,
quitTimeout: 5000,
env: {
ELECTRON_ENABLE_LOGGING: true,
ELECTRON_ENABLE_STACK_DUMPING: true
},
webdriverLogPath: 'webdriver.log'
})
this.rowNumber = null
this.colNumber = null
this.latestFilePath = null
this.hotParentSelector = '.tab-pane.active .editor.handsontable'
this.openFileDialogReturned = ['stubbedFilenameForMenuSteps.txt']
chaiAsPromised.transferPromiseness = this.app.transferPromiseness
}

setWorldConstructor(CustomWorld)

0 comments on commit aeddc89

Please sign in to comment.