在 Electron 中使用量角器

编程入门 行业动态 更新时间:2024-10-26 22:25:17
本文介绍了在 Electron 中使用量角器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试为使用 Electron 运行的应用程序设置单元测试和 e2e 测试,并使用 量角器.我一直在参考许多不同的帖子(这个确实有帮助),但我仍然得到一个我不明白的错误:

I am trying to set up unit tests and e2e tests for an application I have running with Electron using Protractor. I've been refering to many different posts (this one did help), but I still get an error I don't understand :

Message: Error while waiting for Protractor to sync with the page: "angular could not be found on the window" Stacktrace: undefined

我的 conf.js 文件如下所示:

My conf.js file looks like this:

exports.config = { directConnect : true, seleniumAddress: 'localhost:4444/wd/hub', baseUrl:"file://home/me/workspace/testing-project/main.js", capabilities: { browserName: "chrome", chromeOptions: { binary: "/home/me/.linuxbrew/lib/node_modules/electron-prebuilt/dist/electron", args: ["--test-type=webdriver"] } }, specs: ['todo-specs.js'], onPrepare: function(){ browser.resetUrl = "file://"; browser.driver.get("file://"); } };

考虑到 Protractor 网站上给出的文档,我的印象是我不需要安装其他任何东西(例如茉莉花).令我惊讶的是,即使 ma​​in.js(根据 Electron 的规范启动应用程序)的路径是正确的,我在弹出的 Electron 窗口中看不到任何内容.大家有遇到过这个问题吗?你解决了吗?

Considering the documentation given on the Protractor website, I am under the impression that I don't need to install anything else (Jasmine for example). What surprises me is that even though the path to the main.js (that starts the application accordingly to Electron's specifications) is correct, I can't see anything in the Electron window that pops up. Did any of you encountered this issue? Did you manage to resolve it?

推荐答案

显然,使用电子二进制文件不足以真正启动您的应用程序.但是,通过构建您的应用程序的二进制文件并将其链接到您的 conf.js 文件中是可行的.我已经能够将我的文件缩减为:conf.js

Apparently, using the electron binary is not enough to actually launch your application. However, by building the binary for your application and linking it into your conf.js file works. I have been able to reduce my file to this: conf.js

exports.config = { seleniumAddress: 'localhost:4444/wd/hub', specs: ['test-spec.js'], capabilities: { browserName: "chrome", chromeOptions: { binary: "./dist/myAwesomeApp/myAwesomeAppBinary" } }, onPrepare: function () { browser.resetUrl = "file://"; } };

通过这种方式,不需要描述 baseUrl 或使用 browser.get() 或 browser.driver.get() 在 Electron 中启动应用程序.但是,我宁愿不必构建应用程序二进制文件,但我认为现在不可能.

By doing it this way, there is no need to describe a baseUrl or to use browser.get() nor browser.driver.get() to start the app in Electron. However, I would have preferred not to have to build the app binary, but I don't think it is possible for now.

更多推荐

在 Electron 中使用量角器

本文发布于:2023-11-23 03:36:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619938.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:量角器   Electron

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!