【问题标题】:Unable to retrieve email information in protractor无法在量角器中检索电子邮件信息
【发布时间】:2016-03-30 17:03:27
【问题描述】:

参考问题Fetching values from email in protractor test case中的信息,我仍然无法参考电子邮件。在我的测试用例中,'expect' 并没有因为某些未知的原因而被执行。

如果我使用这条线,

browser.controlFlow().await(getLastEmail()).then(...)

有一个'browser.controlFlow(...).await不是函数错误'

conf.js

var MailListener = require("mail-listener2")

exports.config = {
framework: 'jasmine2',
specs: ['./test.js'],
jasmineNodeOpts: { defaultTimeoutInterval: 360000 },
allScriptsTimeout: 60000,

onPrepare: function () {

    var mailListener = new MailListener({
        username: "username",
        password: "password",
        host: "imapPort",
        port: 993, // imap port
        secure: true,
        tls: true,
        tlsOptions: { rejectUnauthorized: false },
        mailbox: "INBOX", // mailbox to monitor
        searchFilter: ["UNSEEN", "FLAGGED"], // the search filter being used after an IDLE notification has been retrieved
        markSeen: true, // all fetched email willbe marked as seen and not fetched next time
        fetchUnreadOnStart: true, // use it only if you want to get all unread email on lib start. Default is `false`,
        mailParserOptions: {streamAttachments: true}, // options to be passed to mailParser lib.
        attachments: true, // download attachments as they are encountered to the project directory
        attachmentOptions: { directory: "attachments/" } // specify a download directory for attachments
    })

    mailListener.start()

    mailListener.on("server:connected", function(){
        console.log("Mail listener initialized")
    })

    mailListener.on("error", function(err){
      console.log(err)
    })

    mailListener.on("server:disconnected", function(){
      console.log("imapDisconnected")
    })

    global.mailListener = mailListener
},

onCleanUp: function () {
    mailListener.stop()
 }
}

测试用例:

describe('Email Testing', function () {

 it('should login with a registration code sent to an email', function () {
   //this line causes a 'browser.controlFlow(...).await is not a function' error
  // browser.controlFlow().await(getLastEmail()).then(function (email) {
  getLastEmail().then(function (email) {
    // The expect does not get executed as it should fail
    expect(email.subject).toEqual('My Subject')
   })
 })
})

 function getLastEmail () {
   var deferred = protractor.promise.defer()
   console.log('Waiting for an email...')

   mailListener.on('mail', function (mail) {
     console.log('No Console Log Here!')
     deferred.fulfill(mail)
   })
  return deferred.promise
 }

我不确定我的测试用例中缺少什么才能阅读电子邮件的主题或正文?

【问题讨论】:

  • 你用的是什么量角器版本?
  • 我正在使用量角器 3.1.1
  • 您好,我在使用量角器@3.1.1 时看到同样的错误“browser.controlFlow(...).await 不是函数”。如果有人已经对此有解决方案,请您提出建议。

标签: javascript email protractor e2e-testing


【解决方案1】:

今天遇到了同样的问题。结果是 webdriver 和 ControlFlow 的 API 已经更新,并且 await 已更改为 wait。是的,细微的差别。在此处查看新的 API 参考:https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/promise_exports_ControlFlow.html

要为等待条件安排任务,请将您的代码更改为如下所示:

browser.controlFlow().wait(getLastEmail()).then(...)

【讨论】:

    【解决方案2】:

    您基本上必须将该异步代码包装在一个承诺中,并将该承诺/函数传递给 flow.execute()

    var flow = protractor.promise.controlFlow();
    flow.execute( getLastEmail() ).then(function(email){
         text = email.text
    });
    

    【讨论】:

      猜你喜欢
      • 2017-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-27
      • 1970-01-01
      • 2012-01-12
      相关资源
      最近更新 更多