Skip to content Skip to sidebar Skip to footer

Simple Example Of Electron App With Spectron Test

I am trying to learn how to test apps, build with electron, using spectron. for this I took an example application from the web with a simple header, counter label, and incrementer

Solution 1:

Create your browser window like this.

win=newBrowserWindow({width:800,height:600,webPreferences: {
        nodeIntegration:true
    }
})

Then this will resolve the undefined require issue.

Solution 2:

after googling and trying for a few days I found that disabling "devtools" seems to resolve the "TypeError: Cannot read property 'waitUntilWindowLoaded' of undefined"

How can this be related?

Solution 3:

i added more steps to the test flow and keep running into similar problems. now my "index.js" contains a test like this:

it('click button', async () => {
    await app.client.waitUntilWindowLoaded()
    awaitsleep(1000)
    const btnH = await app.client.$('#countbtn')
    await btnH.click()
    awaitsleep(1000)
    app.client.$('#countbtn').click()
    awaitsleep(1000)
    const txt = await app.client.$('#click-counter').getText()
    return assert.equal(txt, '2')
})

for some reason i get the error

TypeError: btnH.click is not a function at Context. (test\index.js:38:20) at processTicksAndRejections (internal/process/task_queues.js:93:5)

If I execute the click() directly on the app.client.$('#countbtn') it works. But if I store the result in a variable first I get the error.

Post a Comment for "Simple Example Of Electron App With Spectron Test"