简体   繁体   English

我是否必须使用Spectron测试Electron?

[英]Do I have to use Spectron to test Electron?

Recently I found some difficulty to plan automation testing for our application using Electron. 最近我发现使用Electron为我们的应用程序规划自动化测试存在一些困难。 I've tried to use Spectron, which looks like the official framework to test Electron apps, however, I found the documentation was very hard to understand on their website. 我试过使用Spectron,它看起来像是测试Electron应用程序的官方框架,然而,我发现他们的网站上很难理解文档。

I know there are some famous apps using Electron, eg Slack, Wordpress and Github Desktop. 我知道有一些着名的应用程序使用Electron,例如Slack,Wordpress和Github Desktop。 I wonder if they are really using Spectron or something else as automation to test their apps. 我想知道他们是否真的使用Spectron或其他东西作为自动化测试他们的应用程序。

Pretty much I just want to figure out if Spectron is the only way to test Electron. 我只是想知道Spectron是否是测试Electron的唯一方法。

In terms of end to end testing I would say that Spectron is the way to go. 在端到端测试方面,我会说Spectron是最佳选择。 It can be pretty hard to get up and running, but Spectron is built upon WebdriverIO and there you'll find a lot of documentation. 启动和运行起来非常困难,但Spectron建立在WebdriverIO之上 ,你会发现很多文档。

To get up and running I would propose the following. 为了启动和运行,我建议如下。

npm install spectron mocha --save-dev

my-first-test-case.e2e.js 我先试case.e2e.js

const electron = require('electron');

describe('my first test case', function () {

  beforeEach(() => {
    this.app = new Application({
      path: electron,
      args: ['.'],
    });

    return this.app.start();
  });

  afterEach(() => {
    if (this.app && this.app.isRunning()) {
      return this.app.stop();
    }
  });

  it('creates a new tab when account is added', function () {
    const accountName = 'awesomeMail';

    return this.app.client.waitUntilWindowLoaded()
      .waitForVisible('h1')
      .getText('h1')
      .then(text => expect(text).toEqual('Welcome'));
  });
});

And then you run 然后你跑了

mocha my-first-test-case.e2e.js

Or if you dont have mocha installed globally 或者,如果您没有全局安装mocha

node_modules/.bin/mocha my-first-test-case.e2e.js

I tried to test electron app with java for a while but I just came back to Spectron again because of my applications structure. 我尝试用java测试电子应用程序一段时间,但由于我的应用程序结构,我又回到了Spectron。 If you want to test your electron app with other options(java,phyton and selenium) you can set browser options and capabilities for it as you can see in the below. 如果您想使用其他选项(java,phyton和selenium)测试您的电子应用程序,您可以为其设置浏览器选项和功能,如下所示。

Example of Java code: Java代码示例:

 ChromeOptions options = new ChromeOptions();
    options.setBinary(binaryPath);
    options.addArguments("--app=" + argPath);
    options.setCapability("chromeOptions", options);
    driver = new ChromeDriver(options);   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM