javascript 如何在量角器的另一个函数中调用一个函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33301428/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to call a function in another function in protractor
提问by rts
first function
第一个函数
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);
});
})
Second function
第二个功能
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
我想在“第二个功能”中调用“第一个功能”,请帮助我怎么做
回答by Girish Sortur
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 -
您编写的第一个函数不是您可以调用或调用的东西。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
};
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();
});
Hope it helps.
希望能帮助到你。