簡體   English   中英

如何在量角器中調用另一個函數中的函數

[英]How to call a function in another function in 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(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 

    });

我想在“第二功能”中調用“第一功能”,如何做到請幫助我

你寫的第一個函數不是你可以調用或調用的東西。 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();
});

希望能幫助到你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM