gpt4 book ai didi

node.js - Protractor 在 PhantomJS 上运行测试

转载 作者:IT老高 更新时间:2023-10-28 23:06:29 26 4
gpt4 key购买 nike

我似乎无法通过测试成功获得 PhantomJS。我试图将它集成到我的项目中,但在那之后我尝试只运行基本的 Angular Docs 示例并且我遇到了同样的问题。到目前为止我的步骤:

  • npm install -g phantomjs
  • phantomjs --webdriver=9515//... GhostDriver - Main - 在端口 9515 上运行
  • Protractor protractorConf.js

这与示例中的文件相同,只有 browserName 和 seleniumAddress 端口已更改:

// An example configuration file.
exports.config = {
// The address of a running selenium server.
seleniumAddress: 'http://localhost:9515',

// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'phantomjs'
},

// Spec patterns are relative to the current working directly when
// protractor is called.
specs: ['onProtractorRunner.js'],

// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true,
}
};

我收到以下错误消息:

UnknownError: Error Message => 'Detected a page unload event; asynchronous script execution does not work across page loads.'

我找到了 this issue on github ,这似乎是相关的。我以为我已经对他们的brower-setup.md 有了足够的了解。将其包含在我的 beforeEach 函数之一中。然后我找到了here ptor 无论如何只是包装驱动程序。哇,我知道我是 Protractor/ Selenium 领域的菜鸟,但信噪比非常具有说服力。我真的很想获得使用 PhantomJS 的性能优势,但是为此多花几个小时的前景让我很头疼。我使用的是 Windows 7 Enterprise 64 位,以防万一。谢谢!

最佳答案

实际上,这个修复为我解决了同样的问题:

https://github.com/pschwartau/protractor/commit/1eeff8b1b2e3e8f3b7c8152264411f26d4665a07

如本文最初所述:https://github.com/angular/protractor/issues/85#issuecomment-26846255通过 renanmartins


在 protractor/lib/protractor.js 里面替换

this.driver.get('about:blank');
this.driver.executeScript(
'window.name = "' + DEFER_LABEL + '" + window.name;' +
'window.location.href = "' + destination + '"');

  var driver = this.driver;
this.getCapabilities().then(function (capabilities) {
if (capabilities.caps_.browserName === 'phantomjs') {
driver.executeScript('window.name = "' + DEFER_LABEL + '" + window.name;');
driver.get(destination);
} else {
driver.get('about:blank');
driver.executeScript(
'window.name = "' + DEFER_LABEL + '" + window.name;' +
'window.location.href = "' + destination + '"');
}

// Make sure the page is an Angular page.
driver.executeAsyncScript(clientSideScripts.testForAngular, 10).
then(function(hasAngular) {
if (!hasAngular) {
throw new Error('Angular could not be found on the page ' +
destination);
}
});
});

关于node.js - Protractor 在 PhantomJS 上运行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20058910/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com