javascript - 无法使用 Protractor 从 mailosaur 获取值,尽管使用 node.js 也是如此

标签 javascript node.js promise protractor angular-promise

我正在尝试将 Protractor 代码与 mailosaur 集成以处理电子邮件功能,但在 Protractor 中编码时无法获取值。当我在 node.js 中尝试相同的代码时,它工作正常并且我能够获取该值。下面是代码:

在 Node.js 文件中:

var Mailosaur = require("mailosaur")("Your_API_Key");
var mailbox = new Mailosaur.Mailbox("MailboxID");
console.log("Here it begins!");
mailbox.getEmails(function(err, emails) {
console.log(err);
console.log(emails);
console.log("Are you even going inside?");});

在cmd中运行:node filename.js

结果:在cmd中显示Json格式的数据。

与 Protractor 代码相同的事情不起作用,下面是代码。

describe('Test Mail', function() {
it('should display the data', function(){
    var Mailosaur = require("mailosaur")("Your_API_Key");
    var mailbox = new Mailosaur.Mailbox("MailboxID");

    console.log("Here it begins!");
    mailbox.getEmails(function(err, emails) {
    console.log(err);
    console.log(emails);
    console.log("Are you even going inside?");});})});

使用提及相应规范文件的配置文件运行它:protractor config.js

结果:只显示顶部日志,即“这里开始!”,而不是像上面的 Node.js 那样显示邮件内容。

请提出建议,以防我遗漏了什么。

最佳答案

这里的技巧是,您实际上并没有为 Protractor 控制流安排一些操作,因此 jasmine 认为测试已完成。

检查这个 - http://www.protractortest.org/#/control-flow

Protractor adapts Jasmine so that each spec automatically waits until the control flow is empty before exiting.

对于你的代码来说,这样的东西可能会有所帮助 - 只需将 promise 控制流程即可:

describe('Test Mail', function() {
    it('should display the data', function(){
        var deferred = protractor.promise.defer();
        var Mailosaur = require("mailosaur")("Your_API_Key");
        var mailbox = new Mailosaur.Mailbox("MailboxID");

        console.log("Here it begins!");
        mailbox.getEmails(function(err, emails) {
            console.log(err);
            console.log(emails);
            console.log("Are you even going inside?");
            deferred.resolve();
        });
    })
});

关于javascript - 无法使用 Protractor 从 mailosaur 获取值,尽管使用 node.js 也是如此,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37957799/

相关文章:

node.js - hsts 已弃用 "includeSubdomain"参数已弃用

node.js - 如何使用 node.js 从 stdin 逐行流式传输并发送到客户端?

node.js - 在 Node.js 中使用 async/await 处理 promise 拒绝的正确方法是什么?

javascript - promise "then"方法内的范围更改

javascript - SAPUI5 为 TreeTable/空行创建 JSON

javascript - 将一个对象属性值除以另一个(AngularJS)?

database - 为 NodeJS : are these features supported? Sequelize

reactjs - 如何在 React 上呈现异步内容?

Javascript 'select' 更改时转到 anchor ( anchor ID 是选择值)

javascript - 使用 javascript 隐藏和显示文本