访问变量外部函数而不使用then-Protractor

时间:2017-05-18 06:41:12

标签: javascript automation jasmine protractor

是否可以在函数外使用变量值而不使用then函数?

我正在尝试以下代码:

describe('My Test', function() {
    var index_global=0;
    it('Test starts', function() {
        browser.ignoreSynchronization = true;
        browser.get('https://www.w3schools.com/angular/');

        browser.sleep(5000).then(function(){ 
        });
        var results = element.all(by.css(".sidesection>p>a"));

        results.getText().then(function(text){
            var index=text.indexOf("HTML Includes");
            console.log("Index obtained is- "+index);
            index_global=index;
        })  
        console.log("Index i want outside the function - "+index_global);   
    })
})

原因是因为我必须在同一个IT块中的代码中多次使用此索引值,并且我无法在任何地方使用.then函数。有什么输入吗?

我知道如果我使用下面的代码,它会给我index_global值,但我想知道是否可以有任何替代解决方案:

.then(function(){
        console.log("Index i want outside the function - "+index_global);
    });

0 个答案:

没有答案