如何在量角器中调用另一个函数中的函数 [英] How to call a function in another function in protractor

查看:98
本文介绍了如何在量角器中调用另一个函数中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一个功能

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 

    });

我想在第二功能中调用第一功能,怎么做请帮帮我

I want to call "first function" in "second function", how to do it please help me

推荐答案

你写的第一个函数不是你可以调用或调用的东西。 describe 是一个全局Jasmine函数,用于按照解释性/人类可读的方式对测试规范进行分组以创建测试套件。您必须编写一个函数来在测试规范中调用它或。下面是一个示例 -

What you have written as the first function is not something that you can call or invoke. describe is a global Jasmine function that is used to group test specs to create a test suite, in an explanatory/human readable way. You have to write a function to call it in your test spec or it. Here's an example -

//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
};

在测试规范中调用上面定义的函数 -

Call the function defined above in your test spec -

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

您还可以在页面对象文件中编写此函数,然后从测试规范中调用它。这是一个例子 -

You can also write this function in a page object file and then invoke it from your test spec. Here's an example -

//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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆