2016-01-21 34 views
1

我將webdriver-io與Mocha(和JavaScript)結合使用。我希望在另一個測試用例中調用特定的測試用例。如何在摩卡的TestCase中調用另一個TestCase

假設我們有下面的代碼:

describe('TestSuite', function(){ 

    it('TestCase A', function(){ 
     return browser 
      .getTitle() 
      .then(function(title) { 
       (title).should.equal('title'); 
      }); 
    }); 

    it('TestCase B', function() { 
     // call 'TestCase A' 
    }); 
}); 

有沒有一種可能調用 '的TestCase A' 的 'TestCase的B' 內? 我感謝任何幫助。

回答

2

摩卡沒有「調用測試用例」的概念。但是你正在使用JavaScript並可以利用它。將通用代碼變爲函數並從多個測試中調用它:

describe('TestSuite', function(){ 

    function checkTitle() { 
     return browser 
      .getTitle() 
      .then(function(title) { 
       (title).should.equal('title'); 
      }); 
    } 

    it('TestCase A', function() { 
     return checkTitle(); 
    }); 

    it('TestCase B', function() { 
     return checkTitle().then(...); 
    }); 
}); 
+0

您的解決方案有效。 非常感謝您的回答! :) –