My spectron app.client doesn't contains all the methods

708 Views Asked by At

I'm trying to test my electron app using spectron and mocha, here is my file 'first.js' containing my tests:

const assert = require('assert');
const path = require('path');
const {Application} = require('spectron');
const electronPath = require('electron');


describe('GULP Tests', function () {
    this.timeout(30000)

    const app = new Application({
        path: electronPath,
        args: [path.join(__dirname, '..', 'main.js')]
    });


    //Start the electron app before each test
    before(() => {

        return app.start();
    });

    //Stop the electron app after completion of each test
    after(() => {
        if (app && app.isRunning()) {
            return app.stop();
        }
    });

    it('Is window opened', async () => {
        const count = await app.client.getWindowCount();
        return assert.equal(count, 1);
    });

    it('Clicks on the project creation button', async () => {
       await app.client.waitUntilWindowLoaded();
       const title = await app.client.
       console.log(title);
       return assert.equal(title, 'Welcome to GULP, !');
    });

});

My first test is passing, but for the second one i'd like to do a click on an element, but my app.client does not contain a .click methods, and also no getText or getHTML. I've tried to import browser from webdriverio but it was the same problem, I get an error when testing saying me that those methods doesn't exists. I've red the spectron documentation and they're using .click and .getText methods regularly, why I don't get them ? I've imported spectron as it's said in the documentation to.

Thanks.

1

There are 1 best solutions below

0
On

I have struggled with the same issue for a while. After much trial and error i changed my async methods to normal functions.

it('Clicks on the project creation button', function() {
   app.client.waitUntilWindowLoaded();
   const title = await app.client.
   console.log(title);
   return assert.equal(title, 'Welcome to GULP, !');
});

Strange but it worked for me. hopefully it helps.