【问题标题】:My spectron app.client doesn't contains all the methods我的 spectron app.client 不包含所有方法
【发布时间】:2020-08-04 09:54:22
【问题描述】:

我正在尝试使用 spectron 和 mocha 测试我的电子应用程序,这是我的文件“first.js”,其中包含我的测试:

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, !');
    });

});

我的第一个测试通过了,但第二个测试我想点击一个元素,但我的 app.client 不包含 .click 方法,也没有 getText 或 getHTML。我尝试从 webdriverio 导入浏览器,但这是同样的问题,我在测试时收到错误消息说这些方法不存在。我已经把 spectron 文档弄红了,他们经常使用 .click 和 .getText 方法,为什么我没有得到它们?我已经按照文档中的说明导入了 spectron。

谢谢。

【问题讨论】:

    标签: electron spectron


    【解决方案1】:

    我已经为同样的问题苦苦挣扎了一段时间。经过多次试验和错误,我将异步方法更改为正常功能。

    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, !');
    });
    

    奇怪,但它对我有用。希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 2018-07-28
      • 2016-03-25
      • 1970-01-01
      • 2015-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-15
      相关资源
      最近更新 更多