- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果调用 Protractor elementArrayFinder 的 map
函数,它会立即在 DOM 中搜索要映射的元素,这与 $$
的行为不同等到需要子 elementArrayFinder 求值以找到原始元素及其后代。
我需要延迟 map 函数执行的原因是为了抽象的目的,我想在我的测试文件之外的文件中预先定义它。我目前的尝试是:
Question.array = function(elementArrayFinder) {
function delayedPromise(executor) {
this.executor = executor;
}
delayedPromise.prototype.then = function(onFulfilled, onRejected) {
console.log('locating elements');
return (new Promise(this.executor)).then(onFulfilled, onRejected);
};
return new delayedPromise(function(resolve, reject) {
elementArrayFinder.map(function(omniTask) {
return new Question(omniTask);
}).then(resolve, reject);
});
};
这工作了一段时间,但是当我今天重构测试文件时(不是包含这个函数的文件,这个函数有一段时间没有改变),JavaScript 开始出现与这个函数相关的内存问题:
<--- Last few GCs --->
133580 ms: Mark-sweep 1354.3 (1421.2) -> 1354.3 (1437.2) MB, 2608.1 / 0.0 ms [allocation failure] [GC in old space requested].
136052 ms: Mark-sweep 1354.3 (1437.2) -> 1354.3 (1437.2) MB, 2471.9 / 0.0 ms [allocation failure] [GC in old space requested].
138829 ms: Mark-sweep 1354.3 (1437.2) -> 1355.7 (1421.2) MB, 2775.8 / 0.0 ms [last resort gc].
141436 ms: Mark-sweep 1355.7 (1421.2) -> 1357.0 (1421.2) MB, 2606.6 / 0.0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x13c845cfb51 <JS Object>
1: enqueue [/Users/thasisclaus/omnistack/node_modules/selenium-webdriver/lib/promise.js:~2742] [pc=0x27de9185871b] (this=0x2b9531847931 <an EventEmitter with map 0x17526dabf9e9>,task=0x17b6b944f181 <a Deferred with map 0x17526dac0649>)
2: addCallback_ [/Users/thasisclaus/omnistack/node_modules/selenium-webdriver/lib/promise.js:~1328] [pc=0x27de919c1a75] (this=0x17b6b944eeb9 <a ManagedPro...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: node::Abort() [/usr/local/bin/node]
2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/usr/local/bin/node]
3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node]
4: v8::internal::Factory::NewFixedArray(int, v8::internal::PretenureFlag) [/usr/local/bin/node]
5: v8::internal::Handle<v8::internal::TypeFeedbackMetadata> v8::internal::TypeFeedbackMetadata::New<v8::internal::FeedbackVectorSpec>(v8::internal::Isolate*, v8::internal::FeedbackVectorSpec const*) [/usr/local/bin/node]
6: v8::internal::(anonymous namespace)::EnsureFeedbackVector(v8::internal::CompilationInfo*) [/usr/local/bin/node]
7: v8::internal::(anonymous namespace)::GenerateBaselineCode(v8::internal::CompilationInfo*) [/usr/local/bin/node]
8: v8::internal::(anonymous namespace)::GetUnoptimizedCodeCommon(v8::internal::CompilationInfo*) [/usr/local/bin/node]
9: v8::internal::Compiler::Compile(v8::internal::Handle<v8::internal::JSFunction>, v8::internal::Compiler::ClearExceptionFlag) [/usr/local/bin/node]
10: v8::internal::Accessors::FunctionLengthGetter(v8::Local<v8::Name>, v8::PropertyCallbackInfo<v8::Value> const&) [/usr/local/bin/node]
11: v8::internal::PropertyCallbackArguments::Call(void (*)(v8::Local<v8::Name>, v8::PropertyCallbackInfo<v8::Value> const&), v8::internal::Handle<v8::internal::Name>) [/usr/local/bin/node]
12: v8::internal::Object::GetPropertyWithAccessor(v8::internal::LookupIterator*) [/usr/local/bin/node]
13: v8::internal::Object::GetProperty(v8::internal::LookupIterator*) [/usr/local/bin/node]
14: v8::internal::Builtin_Impl_FunctionPrototypeBind(v8::internal::(anonymous namespace)::BuiltinArguments<(v8::internal::BuiltinExtraArguments)0>, v8::internal::Isolate*) [/usr/local/bin/node]
15: v8::internal::Builtin_FunctionPrototypeBind(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
16: 0x27de909092a7
17: 0x27de9185871b
18: 0x27de919c1a75
19: 0x27de919c202c
20: 0x27de912d1b27
21: 0x27de90909895
22: 0x27de912dee53
>> FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
>> 1: node::Abort() [/usr/local/bin/node]
>> 2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/usr/local/bin/node]
>> 3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node]
>> 4: v8::internal::Factory::NewFixedArray(int, v8::internal::PretenureFlag) [/usr/local/bin/node]
>> 5: v8::internal::Handle<v8::internal::TypeFeedbackMetadata> v8::internal::TypeFeedbackMetadata::New<v8::internal::FeedbackVectorSpec>(v8::internal::Isolate*, v8::internal::FeedbackVectorSpec const*) [/usr/local/bin/node]
>> 6: v8::internal::(anonymous namespace)::EnsureFeedbackVector(v8::internal::CompilationInfo*) [/usr/local/bin/node]
>> 7: v8::internal::(anonymous namespace)::GenerateBaselineCode(v8::internal::CompilationInfo*) [/usr/local/bin/node]
>> 8: v8::internal::(anonymous namespace)::GetUnoptimizedCodeCommon(v8::internal::CompilationInfo*) [/usr/local/bin/node]
>> 9: v8::internal::Compiler::Compile(v8::internal::Handle<v8::internal::JSFunction>, v8::internal::Compiler::ClearExceptionFlag) [/usr/local/bin/node]
>> 10: v8::internal::Accessors::FunctionLengthGetter(v8::Local<v8::Name>, v8::PropertyCallbackInfo<v8::Value> const&) [/usr/local/bin/node]
>> 11: v8::internal::PropertyCallbackArguments::Call(void (*)(v8::Local<v8::Name>, v8::PropertyCallbackInfo<v8::Value> const&), v8::internal::Handle<v8::internal::Name>) [/usr/local/bin/node]
>> 12: v8::internal::Object::GetPropertyWithAccessor(v8::internal::LookupIterator*) [/usr/local/bin/node]
>> 13: v8::internal::Object::GetProperty(v8::internal::LookupIterator*) [/usr/local/bin/node]
>> 14: v8::internal::Builtin_Impl_FunctionPrototypeBind(v8::internal::(anonymous namespace)::BuiltinArguments<(v8::internal::BuiltinExtraArguments)0>, v8::internal::Isolate*) [/usr/local/bin/node]
>> 15: v8::internal::Builtin_FunctionPrototypeBind(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
>> 16: 0x27de909092a7
>> 17: 0x27de9185871b
>> 18: 0x27de919c1a75
>> 19: 0x27de919c202c
>> 20: 0x27de912d1b27
>> 21: 0x27de90909895
>> 22: 0x27de912dee53
我今天更改的测试文件中的上下文是:
fit('Should have the right number of assignment questions initially', function(done) {
var done = browserHelper.strictDone(done),
self = this;
self.communityQuestions = self.myQuestions = [];
console.log(self.assignmentQuestions.length, self.communityQuestions.length, self.myQuestions.length)
assignmentPage.assignmentQuestions.then(function(assignmentQuestions) {
expect(assignmentQuestions.length).toEqual(self.assignmentQuestions.length);
assignmentPage.communityQuestionsTab.click();
assignmentPage.communityQuestions.then(function(communityQuestions) {
expect(communityQuestions.length).toEqual(self.communityQuestions.length);
assignmentPage.myQuestionsTab.click();
assignmentPage.myQuestions.then(function(myQuestions) {
console.log(myQuestions);
expect(myQuestions.length).toEqual(self.myQuestions.length);
done();
});
});
});
});
我不知道错误实际上是由函数引起的还是函数碰巧遇到的一些外部变化。无论如何,我认为可能有更好的方法来延迟 map 功能,很可能是通过直接与 Protractor 的控制流交互。
最佳答案
即使我没有返回带有 map 的元素(而是返回由元素构造的对象),我认为这与 map 挂起的错误有关:https://github.com/angular/protractor/issues/2227
为了解决这个问题,我只是将我的 map
更改为 reduce
并相应地更改了传递的函数,效果很好。
我很确定 map
是更新较少的 elementArrayFinder 迭代函数之一,因为与 reduce
和 lodash 函数不同,map
没有最后一个参数是集合,因此遵循旧的约定。
关于javascript - 延迟执行 Protractor elementArrayFinder.map,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43188677/
我正在学习 Protractor ,到目前为止这是一段疯狂的旅程,因为我对 Javascript 也很陌生。到目前为止,我了解到 Protractor 对所有 promise 进行排队,并且可以使用
我是使用 Protractor 编写端到端 Javascript 测试的初学者。我一直在尝试识别具有与之关联的文本属性的元素数组。我可以使用 来定位他们 groupedNodeNumbers : El
我们有一个表示为 ul->li 的菜单列表(简化): Menu Item 1 ... Menu Item 2 在
是否可以将 element.all(....) 的结果返回的 ElementArrayFinder 转换为通用数组? 目标是将元素存储在数组中,并使用 push() 从另一个 element.all(
看书学AngularJS,有一个简单 Protractor 测试的例子: it('Should redirect to #/posts/1/sample-title1', function (
是否有官方方法来确定我从函数接收的输入是 ElementFinder(单个 Web 元素)还是 ElementArrayFinder(一组网络元素)。 到目前为止我已经知道了。 if (_.isFun
如果调用 Protractor elementArrayFinder 的 map 函数,它会立即在 DOM 中搜索要映射的元素,这与 $$ 的行为不同等到需要子 elementArrayFinder
这是 Take elements while a condition evaluates to true (extending ElementArrayFinder) 的后续问题特别是主题和@cvak
我正在用 Protractor 编写一个函数来获取列表的所有行元素。该函数检查多种类型的列表。它使用方法 isPresent() 来检查是否存在一种类型的列表。如果不是,它将移至下一个类型。由于 is
我在 Protractor 中遇到一种情况,我想将 ElementArrayFinder getTexts 存储在数组中并从方法返回数组。到目前为止我已经写了这样的方法: static getAllT
我在我的页面对象中声明了这个: this.paginationPageNumberList = element.all(by.repeater("page in pages track by $ind
我正在使用 TypeScript 来自动化 E2E 测试。如果我做一些事情,比如self.all(by.xpath(".//thead/tr/th|.//thead/tr/td")).then...
我正在使用 Protractor 在 Angular 8 应用程序中进行 e2e 测试,目前我无法根据需要使“每个”循环正常工作。在我的页面对象中,我创建了一个返回 ElementArrayFinde
在过去的几年里,我一直在使用以下函数来过滤元素数组,并启用了 Webdriver 的控制流: filterElementsByText (elemList, comparator, locator)
我是 Protractor 的新手,我将它与 chai 和 chai-as-promised 结合使用。目前,当我的 ElementArrayFinder 不包含我需要的元素时,我正试图弄清楚如何最好
我是一名优秀的程序员,十分优秀!