Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jasmine异步回调未在指定的超时内调用_Javascript_Node.js_Angularjs_Jasmine_Protractor - Fatal编程技术网

Javascript jasmine异步回调未在指定的超时内调用

Javascript jasmine异步回调未在指定的超时内调用,javascript,node.js,angularjs,jasmine,protractor,Javascript,Node.js,Angularjs,Jasmine,Protractor,我不熟悉量角器和javascript。我知道关于这个错误有很多问题和解决方案。但是没有一个解决方案让我对异步回调有一个清晰的理解,这个错误对我来说仍然存在 我使用的是页面对象模型。请参考我自己设计的以下代码: elements.js: var pageElements = function(){}; pageElements.prototype = Object.create({},{ usernameField:{get: function(){return element(by.id(

我不熟悉量角器和javascript。我知道关于这个错误有很多问题和解决方案。但是没有一个解决方案让我对异步回调有一个清晰的理解,这个错误对我来说仍然存在

我使用的是页面对象模型。请参考我自己设计的以下代码:

elements.js:

var pageElements = function(){};

pageElements.prototype = Object.create({},{
  usernameField:{get: function(){return element(by.id('username'));}},
  passwordField:{get: function(){return element(by.id('password'));}},
  signinButton:{get: function(){return element(by.xpath("xpath"));}},
  formField1:{get: function(){return element(by.xpath("xpath1"));}},
  formField2:{get: function(){return element(by.xpath("xpath2"));}},
});

module.exports = pageElements;
var EC = protractor.ExpectedConditions;
var controls = require('../Controls/controls.js');

exports.waitForElementById = async function(id){
  debugger;
  var isVisible = EC.visibilityOf(id);
  await browser.wait(isVisible,50000);
  browser.sleep(3000);
};

exports.waitForElementByXpath = async function(xpaths){
  var isVisible = EC.visibilityOf(xpaths);
  await browser.wait(isVisible,50000);
  browser.sleep(3000);
};

exports.sendKeysById = async function(ids, value){
  controls.waitForElementById(ids);
  var isVisible;
  for(i = 1; i<5; i++){
    isVisible = EC.visibilityOf(ids);
    if(isVisible){
        return await ids.sendKeys(value).then(function(){
            browser.sleep(500);
        }) .catch(error => {
            console.log('---------Error: Element not sent by id-----------');

            throw error;
        });
    }
  }
}

exports.clickElementById = async function(id){
  controls.waitForElementById(id);
  var isClickable;
  var processingBar;
  var check;
  for(i = 1; i<5; i++){
    isClickable = EC.elementToBeClickable(id);
    processingBar = EC.invisibilityOf(element(by.xpath("//*[contains(@id,'exterroLoader')]")));
    check = EC.and(isClickable,processingBar);
    if(check){
        return await id.click().then(function(){
            browser.sleep(500);
        }) .catch(error => {
            console.log('---------Error: Element not clicked by id-----------');
            throw error;
        });
    }
  }
};
controls.js:

var pageElements = function(){};

pageElements.prototype = Object.create({},{
  usernameField:{get: function(){return element(by.id('username'));}},
  passwordField:{get: function(){return element(by.id('password'));}},
  signinButton:{get: function(){return element(by.xpath("xpath"));}},
  formField1:{get: function(){return element(by.xpath("xpath1"));}},
  formField2:{get: function(){return element(by.xpath("xpath2"));}},
});

module.exports = pageElements;
var EC = protractor.ExpectedConditions;
var controls = require('../Controls/controls.js');

exports.waitForElementById = async function(id){
  debugger;
  var isVisible = EC.visibilityOf(id);
  await browser.wait(isVisible,50000);
  browser.sleep(3000);
};

exports.waitForElementByXpath = async function(xpaths){
  var isVisible = EC.visibilityOf(xpaths);
  await browser.wait(isVisible,50000);
  browser.sleep(3000);
};

exports.sendKeysById = async function(ids, value){
  controls.waitForElementById(ids);
  var isVisible;
  for(i = 1; i<5; i++){
    isVisible = EC.visibilityOf(ids);
    if(isVisible){
        return await ids.sendKeys(value).then(function(){
            browser.sleep(500);
        }) .catch(error => {
            console.log('---------Error: Element not sent by id-----------');

            throw error;
        });
    }
  }
}

exports.clickElementById = async function(id){
  controls.waitForElementById(id);
  var isClickable;
  var processingBar;
  var check;
  for(i = 1; i<5; i++){
    isClickable = EC.elementToBeClickable(id);
    processingBar = EC.invisibilityOf(element(by.xpath("//*[contains(@id,'exterroLoader')]")));
    check = EC.and(isClickable,processingBar);
    if(check){
        return await id.click().then(function(){
            browser.sleep(500);
        }) .catch(error => {
            console.log('---------Error: Element not clicked by id-----------');
            throw error;
        });
    }
  }
};
TestCases.js

browser.ignoreSynchronization = true;
var controls = require('./controls.js');
var pageElements = require('./elements.js');
var e;

exports.form1 = async function(){
    e = new pageElements();
    browser.get("https://form.htm");
    await controls.sendKeysById(e.usernameField);
    await controls.sendKeysById(e.passwordField);
    await controls.clickByXpath(e.signinButton);
    await controls.sendKeysById(e.formField1);
};

exports.form2 = async function(){
    e = new pageElements();
    browser.get("https://form.htm");
    await controls.sendKeysById(e.usernameField);
    await controls.sendKeysById(e.passwordField);
    await controls.clickByXpath(e.signinButton);
    await controls.sendKeysById(e.formField2);
};
var ignore = function(exp){return{it:((typeof exp==='function')?exp():exp)?function(){}:it}};

describe('Automation', function() {
var controls = require('./controls.js');
browser.ignoreSynchronization = true;
browser.get('https://prre2eauto.exterrocloud.info');

it('Form 1', async function(){
    var a = require('./formOperations.js');
    await a.form1();
});

it('Form 2', async function(){
    var a = require('./formOperations.js');
    await a.form2();
});

});
上面给出了一个示例代码,但我使用的模型完全相同

我真正面对的是

  • form1已成功执行,没有任何错误
  • form2已成功执行,但出现以下错误:

    Jasmine spec timed out. Resetting the WebDriver Control Flow.
    Message:
    [31m    Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.[0m
    Stack:
    Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
    at ontimeout (timers.js:498:11)
    at tryOnTimeout (timers.js:323:5)
    at Timer.listOnTimeout (timers.js:290:5)
    
  • 请在这方面提供帮助,因为这需要更长的时间让我理解。

    请尝试下面的方法

    var controls = require('./controls.js');
    describe('Automation', function() {
    
    beforeEach(async() =>{ //This block will be executed before every `it` block
    await browser.waitForAngualrEnabled(true);
    await browser.get('https://prre2eauto.exterrocloud.info');
    });
    
    it('Form 1', async function(){
        var a = require('./formOperations.js');
        await a.form1();
    });
    
    it('Form 2', async function(){
        var b = require('./formOperations.js');
        await b.form2();
    });
    
    });
    

    希望对您有所帮助

    您是否在
    配置中添加了
    jasmine.DEFAULT\u TIMEOUT\u INTERVAL
    file@Madhan是的,我试过了。此外,我还尝试了expect。谢谢@Madhan。但我的应用程序是有角度和无角度的。我现在面对的这个场景是非角度的。已尝试使用ignoreSync选项。但是没有使用选项。@Bala
    ignoreSync
    现在不推荐使用。你能试试上面的答案,看看考试是否通过吗。