我正在运行一个脚本来使用 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);
}
};
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/