如何使用Selenium WebDriver测试Electron应用程序 [英] How to test an Electron app with selenium webdriver

查看:320
本文介绍了如何使用Selenium WebDriver测试Electron应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了文档,并且已逐步按照教程进行操作,而我仅设法运行了该应用程序.

I have read the documentation and I have followed the tutorial step by step and I only have managed to run the app.

与chromedriver的连接无法启动,当我启动测试并尝试单击一个简单的按钮时,会显示以下内容:

The connection with chromedriver I cannot make it work, when I launch the test and try click a simple button I get this:

错误:ChromeDriver在错误(自然)的5000毫秒内未启动
在node_modules/spectron/lib/chrome-driver.js:58:25处Request._callback(node_modules/spectron/lib/chrome-driver.js:116:45)在Request.self.callback(node_modules/spectron/node_modules/request/request.js:200:22)在要求.(node_modules/spectron/node_modules/request/request.js:1067:10)在传入消息.(node_modules/spectron/node_modules/request/request.js:988:12)在_combinedTickCallback上的endReadableNT(_stream_visible.js:913:12)(internal/process/next_tick.js:74:11)在process._tickCallback(内部/进程/next_tick.js:98:9)

Error: ChromeDriver did not start within 5000ms at Error (native)
at node_modules/spectron/lib/chrome-driver.js:58:25 at Request._callback (node_modules/spectron/lib/chrome-driver.js:116:45) at Request.self.callback (node_modules/spectron/node_modules/request/request.js:200:22) at Request. (node_modules/spectron/node_modules/request/request.js:1067:10) at IncomingMessage. (node_modules/spectron/node_modules/request/request.js:988:12) at endReadableNT (_stream_readable.js:913:12) at _combinedTickCallback (internal/process/next_tick.js:74:11) at process._tickCallback (internal/process/next_tick.js:98:9)

我的代码:

"use strict";
require("co-mocha");
var Application = require('spectron').Application;
var assert = require('assert');

const webdriver = require('selenium-webdriver');

const driver = new webdriver.Builder()
  .usingServer('http://127.0.0.1:9515')
  .withCapabilities({
    chromeOptions: {
      binary: "./appPath/app"
    }
  })
  .forBrowser('electron')
  .build();

describe('Application launch', function () {
  this.timeout(100000);
  var app;
  beforeEach(function () {
    app = new Application({
      path: "./appPath/app"
    });
    return app.start();
  });

  afterEach(function () {
    if (app && app.isRunning()) {
      return app.stop();
    }
  });

  it('click a button', function* () {
    yield driver.sleep(5000);
    yield driver.findElement(webdriver.By.css(".classSelector")).click();
  });
});

非常抱歉,我的英语水平.

Thanks and sorry for my English.

推荐答案

首先,Spectron(它是WebdriverIO的包装器)和WebdriverJS(是Selenium-Webdriver的一部分)是两个不同的框架,您只需要使用其中之一供您测试.

First off, Spectron (which is a wrapper for WebdriverIO) and WebdriverJS (which is part of Selenium-Webdriver) are two different frameworks, you only need to use one of them for your tests.

如果您使用的是WebdriverJS,则需要在此步骤中运行 ./node_modules/.bin/chromedriver :

If you are using WebdriverJS, then you need to run ./node_modules/.bin/chromedriver in this step: http://electron.atom.io/docs/tutorial/using-selenium-and-webdriver/#start-chromedriver

这篇关于如何使用Selenium WebDriver测试Electron应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆