【发布时间】:2014-12-16 20:33:04
【问题描述】:
我正在尝试使用InternJS 对Google Polymer 项目进行功能测试。
Web-Components 部分如下所示:
<custom-element-one flex>
<custom-nested-element id="someId">
</custom-nested-element>
</custom-element-one>
问题是我无法在测试中访问Shadow DOM:
return this.remote
.get(require.toUrl('http://localhost:8500/test.html'))
.then(pollUntil('return document.querySelector("custom-element-one").shadowRoot;', 20000))
.findByTagName('custom-element-one')
.getProperty('shadowRoot')
.then(function (doc) {
console.log('1--------------------->>>>', doc);
console.log('2--------------------->>>>', doc.findByTagName('custom-nested-element'));
doc.findByTagName('custom-nested-element')
.getAttribute('id')
.then(function (doc) {
console.log('3--------------------->>>>', doc);
});
});
结果:
第一个日志返回以下内容:
1--------------------->>>> { _elementId: '8',
_session:
{ _sessionId: 'xxxx-xxxx-xxx',
_server:
{ url: 'http://localhost:4444/wd/hub/',
sessionConstructor: [Function: ProxiedSession] },
_capabilities:
{ applicationCacheEnabled: false, ...
2--------------------->>>> { cancel: [Function], then: [Function] }
Object #<Promise> has no method 'getAttribute'
欢迎提出任何建议。
我的猜测是 shadowRoot 还不是 leadFoot 库的一部分,并且无法访问嵌套上的影子 DOM
【问题讨论】:
-
我没有测试过。 Web 组件测试器使用 Polymer.whenReady() 等待聚合物完成所有微任务。也许你可以试试看。我的学习清单上还有实习生
-
Intern 的
pollUntil就是这样的。它一直等到元素在 DOM 中准备好。该元素已在 DOM 中准备就绪,只是由于 shadowRoot 无法访问。
标签: javascript testing polymer intern