javascript - Protractor Debug模式给出 "FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory"

标签 javascript node.js protractor browser-automation

我正在运行一个脚本来使用 NodeJS 0.12.4、Protractor 2.1.0 自动登录网页。我的系统是 Win 8.1、i7 2.5 GHz、16 GB RAM,所以我认为不太可能我的内存不足了! 仅供引用,当我注释代码中除 browser.get() 之外的所有语句,并在开始时使用 browser.pause() 以交互模式逐一执行它们时,代码可以正常工作。 这是spec.js 文件的代码:

 describe('Web Page Login', function() {
  it('should login', function() {
    browser.get('http://URL_HERE'); // opens page
      
    //browser.pause();
      
    element(by.css('[ng-click="showLogin(true);"]')).click();// clicks the login link to open the login dialog
      
      
    var user = element(by.model('user.login.username'));// input user name
    user.sendKeys('user');
                       
    var pass = element(by.model('user.login.password')); // input password                
    pass.sendKeys('pass');

    element(by.css('[ng-click="login();"]')).click();// clicks the login button
      
    var userName = element(by.className('ng-binding'));// locates the logged in user from the player details element and store it in "userName"
    userName.getText();  //extracts the text that contains the user name
   
    expect(userName).toBe("user"); //compare the string obtained above with the one expected 

  });
});

这是conf.js 文件的代码:

var HtmlReporter = require('protractor-html-screenshot-reporter');

var reporter=new HtmlReporter({
    baseDirectory: './results', // the location to store the screen shots and results.
    docTitle: 'Login test result',
    docName:  'login-tests-report.html'
});


exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['login-spec.js'],
  onPrepare: function() {
        jasmine.getEnv().addReporter(reporter);
	}
  };
不幸的是,我无法发布我们网站的 URL,因为它是内部的,如果需要 HTML,我可以发布一些片段。 因此,如果我尝试运行它,输入

protractor conf.js

如果没有注释所有行,我会收到此错误:

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory

但是,如果我注释掉 spec.js 中除 browser.get() 之外的所有行,并且使用 repl 进入调试交互模式,并按照上面所述逐一键入代码中的每一行,我可以执行所有代码到最后,没有错误。 我两周前开始使用 Protractor 和 JavaScript,所以我可能会错过一些东西。 感谢您的帮助。

最佳答案

在与我的一位开发人员进行讨论之后,我有点弄清楚如何使代码正常工作,而不是是什么触发了该错误,我怀疑它可能是 Node 库中的某些内容。 改变我执行断言的方式消除了错误。 这是有效的代码:

describe('Web Page Login', function() {
  it('should login', function() {
    browser.get('http://URL_HERE');//opens Web page
      
    element(by.css('[ng-click="showLogin(true);"]')).click();//clicks the login link to open the login dialog     
 
    element(by.model('login.user.login.username')).sendKeys('username');//input user name          
    element(by.model('login.user.login.password')).sendKeys('password');//input password 
    element(by.css('[ng-click="login.login(false, loginForm.$valid);"]')).click(); //clicks the login button
    
    var userName = element(by.className('ng-binding'));// locates the logged in user from the player details element and store it in "userName"
    expect(userName.getText()).toContain('username');//compares the string found with the one expected and asserts if it's true or false
  });
});
如果我找到根本原因,我会将其发布在这里。

关于javascript - Protractor Debug模式给出 "FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30536861/

相关文章:

angular - 如何使用 Protractor typescript 在具有跨度的按钮上单击具有相似元素详细信息的元素

javascript - jQuery 修复点击后页面滚动到顶部

javascript - 拖动时没有重影图像?

javascript - Rickshaw RangeSlider - 默认放大

javascript - RSAwithSHA256 和 SHA256 之间的区别

node.js - 嵌套 mongodb 查询

node.js - Mongoose 嵌套文档

jquery - Node.js 上的 Javascript 框架

selenium - 规范远程时如何运行 Protractor 测试

javascript - Protractor 中的 untrackOutstandingTimeouts 设置是什么?