javascript - 如何自动化使用Electron框架开发的桌面应用程序?

标签 javascript node.js electron ui-automation spectron

我们的应用程序是使用 Electron 框架开发的。它是一个独立的应用程序。我已经看到spectron是用于自动化 Electron 应用程序的框架。但我不确定它是否适用于桌面应用程序。请确认是否相同。

我已经安装了nodejs和spectron。 我已经编写了一个代码启动应用程序,如以下站点中所述 https://electron.atom.io/spectron/

文件名:First.js

var Application = require('spectron').Application
var assert = require('assert')

var app = new Application({
  path: 'C:\Users\ramass\AppData\Local\Programs\ngsolutions\ngsolutions.exe'
})

app.start().then(function () {
  // Check if the window is visible
  return app.browserWindow.isVisible()
}).then(function (isVisible) {
  // Verify the window is visible
  assert.equal(isVisible, true)
}).then(function () {
  // Get the window's title
  return app.client.getTitle()
}).then(function (title) {
  // Verify the window's title
  assert.equal(title, 'My App')
}).then(function () {
  // Stop the application
  return app.stop()
}).catch(function (error) {
  // Log any failures
  console.error('Test failed', error.message)
})

我尝试使用命令运行脚本

node First.js

但是我收到错误消息

C:\spectronprgs>node First.js

Error: Cannot find module 'spectron'

请让我知道我是否走在正确的道路上 如何使用spectron框架启动.exe文件 如何运行脚本

最佳答案

从命令行运行以下命令。

npm install --save-dev spectron

然后看看是否可以找到该模块。您在帖子中从未提及如何安装 Spectron。

关于javascript - 如何自动化使用Electron框架开发的桌面应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46377495/

相关文章:

angularjs - 在 Electron 应用程序中单击菜单更改 AngularJS 状态

electron - 根据 CSS 规则测量文本高度 – _无需浏览器渲染_ – 与虚拟化列表一起使用,提前指定高度

javascript - Nightmare Js 多次评估后评估超时

javascript - 检查是否加载了 html 5 垫片

javascript - AngularJS $http 不起作用?

javascript:处理服务器尚未为其分配 id 的客户端发起的对象

image - ExpressJS/Node : 404 images

javascript - React/Flux/React-Router : How to call to store data when re-routing?

javascript - Vue.js - 将 JSON 对象写入本地文件

javascript - 为了使我的代码正常工作,我必须更改 Cheerio 的一些核心功能,如何将其保留在我的模块中?