【问题标题】:How to call a function in another function in protractor如何在量角器的另一个函数中调用一个函数
【发布时间】:2015-10-23 20:00:37
【问题描述】:

第一个函数

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 

    });

我想在“第二个函数”中调用“第一个函数”,请帮帮我怎么做

【问题讨论】:

    标签: javascript jasmine protractor


    【解决方案1】:

    您作为第一个函数编写的内容不是您可以调用或调用的内容。 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();
    });
    

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2017-11-04
      • 2018-07-02
      • 2018-12-02
      • 1970-01-01
      • 1970-01-01
      • 2018-07-27
      • 1970-01-01
      • 2011-05-30
      • 2019-09-17
      相关资源
      最近更新 更多