Javascript 如何在量角器中调用另一个函数中的函数

Javascript 如何在量角器中调用另一个函数中的函数,javascript,jasmine,protractor,Javascript,Jasmine,Protractor,第一功能 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

第一功能

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 

    });

我想在“第二个函数”中调用“第一个函数”,如何操作请帮助我

您编写的第一个函数不是您可以调用或调用的<代码>描述是一个全局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
};
//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();
});
调用上面在测试规范中定义的函数-

it('Click on candidate status Screened', function () {
    //Call the first function 
    clickCandidate();
});
您还可以在页面对象文件中编写此函数,然后从测试规范中调用它-

//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
};
//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();
});
希望能有帮助