2016-05-04 74 views
0

我正在運行此測試,看起來當測試進入到我的describe塊的函數部分時,它跳過了整個事物並給出了傳遞的誤報。Webdriverio Node.js Mocha Chai測試跳過描述塊

// required libraries 
var webdriverio = require('webdriverio'); 
var describe = require('describe'); 
var after = require('after'); 

console.log("Lets begin"); 

describe('Title Test for google site', function() { 

console.log("MARTY!!"); 
// set timeout to 10 seconds 
this.timeout(10000); 
var driver = {}; 

console.log("before we start"); 
// hook to run before tests 
before(function (done) { 
// load the driver for browser 
console.log("before browser"); 
driver = webdriverio.remote({ desiredCapabilities: {browserName: 'firefox'}  }); 
driver.init(done); 
}); 

it('should load correct page and title', function() { 
// load page, then call function() 
return driver 
.console.log("before site") 
    .url('http://www.ggogle.com') 
    // get title, then pass title to function() 
    .getTitle().then(function (title) { 
    // verify title 
    (title).should.be.equal("google"); 
    // uncomment for console debug 
    // console.log('Current Page Title: ' + title); 
    }); 
    }); 
    }); 
    // a "hook" to run after all tests in this block 
    after(function(done) { 
    driver.end(done); 
    }); 


    console.log ("Fin"); 

這是輸出我得到

讓我們開始

[在0.4秒完成]

正如你可以看到它跳過一切。

回答

0

這是錯誤的,應予刪除:

var describe = require('describe'); 
var after = require('after'); 

摩卡的describeafter被添加到由摩卡測試文件的全球空間。你不需要導入它們。看看摩卡網站上的所有例子,你不會在任何地方發現他們告訴你導入describe及其兄弟姐妹。

要讓Mocha添加describe及其兄弟姐妹,您需要通過mocha運行測試。直接在測試文件上運行node將不起作用。而mocha是可以找到它必須在您的PATH。如果您在本地安裝它,它很可能不在您的PATH中,因此您必須提供完整路徑./node_modules/.bin/mocha

+0

是的,我曾經這樣做過,它是輸出描述和未定義之後。 – Lupin

+0

你如何運行你的測試?你的命令行是什麼? – Louis

+0

iTerminal中的node testname.js或者我只是在Sublime中運行代碼 – Lupin

相關問題