2015-10-23 44 views
3

第一功能如何调用一个函数在其他功能量角器

describe('Shortlisting page', function() { 
    it('Click on candidate status Screened', function() { 
     element(by.css('i.flaticon-leftarrow48')).click(); 
      browser.sleep(5000); 
      browser.executeScript('window.scrollTo(0,250);'); 
      element(by.partialButtonText('Initial Status')).click(); 
      browser.sleep(2000); 
      var screen = element.all(by.css('[ng-click="setStatus(choice, member)"]')).get(1); 
      screen.click(); 
      element(by.css('button.btn.btn-main.btn-sm')).click(); 
      browser.executeScript('window.scrollTo(250,0);'); 
      browser.sleep(5000); 

     }); 
    }) 

二级功能

it('Click on candidate status Screened', function() { 
     //Here i need to call first function 

    }); 

我想称之为“第一功能”,在“第二功能”,该怎么办呢,请帮我

回答

3

你写的第一个函数不是你可以调用或调用的东西。 describe是一个全球性的Jasmine函数,用于以解释性/人类可读的方式将测试规范分组来创建测试套件。你必须编写一个函数在你的测试规范或it中调用它。这里有一个例子 -

//Write your function in the same file where test specs reside 
function clickCandidate(){ 
    element(by.css('i.flaticon-leftarrow48')).click(); 
    //All your code that you want to include that you want to call from test spec 
}; 

呼叫在您的测试规范上面定义的函数 -

it('Click on candidate status Screened', function() { 
    //Call the first function 
    clickCandidate(); 
}); 

你也可以写在页面对象文件这一功能,然后从你的测试规范调用它。这里有一个例子 -

//Page object file - newPage.js 
newPage = function(){ 
    function clickCandidate(){ 
     //All your code that you want to call from the test spec 
    }); 
}; 
module.exports = new newPage(); 

//Test Spec file - test.js 
var newPage = require('./newPage.js'); //Write the location of your javascript file 
it('Click on candidate status Screened', function() { 
    //Call the function 
    newPage.clickCandidate(); 
}); 

希望它有帮助。

+0

谢谢,它正在工作 –

相关问题