3

这是我正在使用的代码

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 函数属性,waitFor=15000但这也无济于事。

也许我应该换成摩卡咖啡,也许这对我更好

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

4

0 回答 0