node.js - 在光谱测试中选择选项

标签 node.js unit-testing electron spectron

我正在使用 Electron 和 NodeJS 开发一个桌面应用程序,它具体是什么并不重要。我正在使用 Spectron 来测试我的 Electron 应用程序。我已经实现了通过带有选项的下拉列表在不同的已保存数据库之间进行选择的功能。在下拉列表中选择数据库后,带有登录凭据的 json 文件将更新以匹配所选数据库。我想编写一个测试来检查选择另一个选项时 json 文件是否发生更改。我的主要问题是模拟从下拉菜单中选择另一个选项。

    // Psuedo code for what how I want to solve this
it("DB connection file is updated correctly", function() {
    read in json file with currently selected db credentials as a "before reference".
    simulate the selection of another db in the dropdown list so that json file from before is changed.
    read in changed json file
    assert.notDeepEqual(beforeFile, updatedFile);
});

我一直坚持的事情是我必须在下拉列表中选择另一个选项来更改当前数据库的部分。我已经阅读了 Spectron 文档和 webdriverIO 文档,但我仍然无法让它工作。

下拉菜单中始终会列出 3 个默认数据库作为选项。我将在下面列出下拉列表的 html 代码:

                        <div id="list-container">
                        <form>
                            <label id="dropdown-label" for="connection-dropdown"><b>Database</b>:</label>
                            <fieldset id="dropdown-fset">
                                <select name="database" id="connection-dropdown">
                                </select>
                            </fieldset>
                        </form>
                    </div>

已经被困一个多星期了,我也找不到任何在线解决方法。很多问题如何使用 Spectron 做事,但这次没有答案对我有帮助。我可能忘记提及一些事情,所以请询问是否需要更多信息。

谢谢!

最佳答案

您可以收集元素,您可以在#list-container下收集“选择”元素,然后您就可以使用这些元素。

关于node.js - 在光谱测试中选择选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49453602/

相关文章:

Node.js 聊天 - 存储 session.id 以供以后使用?

javascript - 我什么时候应该在独立的 node.js 上使用 express.js

node.js - 尝试构建phonegap应用程序时出现错误

unit-testing - 使用 Spring 注入(inject) EasyMock 模拟导致 ClassCastException

unit-testing - 你在哪里保存你的测试数据文件?

electron - 调用autoUpdater.checkForUpdates时Electron应用程序崩溃

node.js - 有没有办法只根据pm2中的关键字显示日志?

unit-testing - Subversion 和 DBUnit - 如何下载特定的快照版本

electron - 具有SDL的macOS上的 Electron 优先级高DPI支持

javascript - Spectron 测试顺序 Action