使用zombie.js运行jasmine-node并获取超时错误

时间:2012-09-04 19:17:24

标签: node.js jasmine zombie.js

这是我正在使用的代码

var sys, zombie,site;
zombie = require('zombie');
sys = require('sys');
site = "https://somesite.co.il"

describe("testing site: "+site, function() {

  it('responds 200 OK', function() {
    zombie.visit(site, function(err, browser) {
      expect(browser.statusCode).toEqual(200);

      //This method is a part of jasmine-node
      asyncSpecDone();
    });
  });

  it('title should be a specfiic title', function() {
    zombie.visit(site, function(err, browser) {
      expect(browser.text('title')).toEqual('טקסט בעברית');
      //console.log(browser.text('title'));

      asyncSpecDone();
    });
  });

  it("should fail logging with wrong password", function(err, browser){

    zombie.visit(site,{debug:true},function(err,browser){
        browser.
            fill("#email","us...@gmail.com").
            fill("#password", "aaa").
            pressButton(".loginbutton", function(){


                //console.log(browser.text("#errorarealogin"));
                expect(browser.text("#errorarealogin")).toContain("שגויים");


                //assert.equal(browser.text("title"),"טקסט בעברית")
                //asyncSpecDone();
                expect(browser.html("#errorarealogin")).toBeDefined();  
                });
        expect(browser.text("#errorarealogin")).toContain("שגויים");
        expect(browser.html("#errorarealogin")).toBeDefined();       
     asyncSpecDone();        
    //console.log("should fail logging with wrong password");
    //asyncSpecDone();
    })
  })

  it("should succeedin logging in",function(){
    zombie.visit(site,{debug:true},function(err,browser){
        browser.
            fill("#email","us...@gmail.com").
            fill("#password", "password").
            pressButton(".loginbutton", function(){


                //assert.equal(browser.text("title"),"טקסט בעברית")
                });
            expect(browser.success).toBeTruthy();
            asyncSpecDone();
        })
  })

  afterEach(function() {
    //So is this.
    asyncSpecWait();
  });
});

这是我从jasmine-node获得的结果(没有调试网页信息):

testing site: https://somesites.co.il
  responds 200 OK
  title should be a specific title
  should fail logging with wrong password
  should succeedin logging in

Failures:

  1) should fail logging with wrong password
   Message:
     Expected '' to contain 'שגויים'.
   Stacktrace:
     Error: Expected '' to contain 'שגויים'.
    at new jasmine.ExpectationResult (D:\Users\Alonisser\AppData\Roaming\npm\node_modules\jasmine-node\lib\jasmine-node/
jasmine-2.0.0.rc1.js:102:32)
    at null.toContain (D:\Users\Alonisser\AppData\Roaming\npm\node_modules\jasmine-node\lib\jasmine-node/jasmine-2.0.0.r
c1.js:1171:29)
    at zombie.visit.debug (D:\Users\Alonisser\workspace\zombie\zombieSpec.js:47:49)
    at Browser.visit (D:\Users\Alonisser\node_modules\zombie\lib\zombie\browser.js:339:16)
    at Browser.wait (D:\Users\Alonisser\node_modules\zombie\lib\zombie\browser.js:192:16)
    at EventLoop.wait.done (D:\Users\Alonisser\node_modules\zombie\lib\zombie\eventloop.js:202:18)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)

  2) should fail logging with wrong password
   Message:
     timeout: timed out after 5000 msec waiting for spec to complete
   Stacktrace:
     undefined

Finished in 18.1 seconds
我做错了什么?我验证了div id是正确的,它确实包含了特定的文本但是即使我注释掉了整个期望的东西它也失败了,不能自己想出这个。谢谢你的帮助

更新:我知道这是一些异步问题,因为使用browser.log乱码代码(比如console.log)我可以看到pressButton内部处理后它下面的代码。但我无法弄清楚如何解决它,尝试在browser.wait()内添加pressButton()函数,但这也无济于事。我也尝试像这样waitFor=15000设置waitFor函数属性,但这也没有帮助。

也许我应该切换到摩卡,也许这对我来说更好

另一次更新:mocha没有帮助,因为这里或谷歌小组缺乏帮助我转移到casper.js(基于phantomjs),效果更好(至少对我来说) 。不要责怪任何人,除了我,但缺乏一个强大的社区在这里对我不利。猜这个问题已经结束了。如果一个人出现,我也会奖励正确答案,只是为了纯粹的好奇心

0 个答案:

没有答案