如何用量角器检查元素是否存在?(How to check if element is present with protractor?)
我为Angular2应用程序编写了以下量角器测试:
describe('Puppet container', () => { beforeEach(() => { browser.get('/#/puppet'); }); it('should display puppet summary', () => { browser.wait($('puppet-summary').isPresent, 1000); const subject = $('puppet-summary').isDisplayed(); const result = true; expect(subject).toEqual(result); }); });
它因以下原因而
Failed: Cannot read property 'parentElementArrayFinder' of undefined
:Failed: Cannot read property 'parentElementArrayFinder' of undefined
谁能告诉我为什么我会收到这个错误? 我有一个页面,只有在加载后端数据时才会显示
<puppet-summary>
元素。 这就是为什么我要检查它是否存在(它只在半秒左右后出现)。 要仅在有数据显示时显示,我使用以下HTML代码:<div *ngIf="puppetMasters.length"> <puppet-summary></puppet-summary> </div>
puppetMasters
是一个数组,一旦加载后端数据就会被填充。I wrote the following protractor test for an Angular2 app:
describe('Puppet container', () => { beforeEach(() => { browser.get('/#/puppet'); }); it('should display puppet summary', () => { browser.wait($('puppet-summary').isPresent, 1000); const subject = $('puppet-summary').isDisplayed(); const result = true; expect(subject).toEqual(result); }); });
It keeps failing with the following reason:
Failed: Cannot read property 'parentElementArrayFinder' of undefined
Can anybody tell me why I'm getting this error? I have a page which only shows the
<puppet-summary>
element when the data from the backend is loaded. That's why I'm checking for it to be present (it only becomes present after half a second or so). To show it only if there is data to display, I'm using the following HTML code:<div *ngIf="puppetMasters.length"> <puppet-summary></puppet-summary> </div>
puppetMasters
is an array which gets filled as soon as the data from the backend is loaded.
原文:https://stackoverflow.com/questions/37070489
最满意答案
引用的问题在于它们根本无法在该范围内找到,您可以做的是引入一个限定名称并在交叉引用中使用它并相应地更改您的语法,即: -
QualifiedName: ID ('.' ID)*; Relationship: name=ID ":" newEntityName=ID "->" refName=[Attribute|QualifiedName];
现在应该可以使用限定ID进行引用:
ENTITY_RELATIONSHIP { auction_lots : lot_id -> auctionHouse.lots.id0 auction_lots : auction_id -> auctionHouse.auctions.id1 }
如果您不能像这样更改语法以使用Xtext处理名称的默认方式,那么您需要考虑提供自己的限定名称,这是一篇很好的文章就是这个合格的名称文章
The problem with the references is that they simply cannot be found in that scope, what you could do is introduce a qualified name and use that in your cross-reference and change your grammar accordingly, ie:-
QualifiedName: ID ('.' ID)*; Relationship: name=ID ":" newEntityName=ID "->" refName=[Attribute|QualifiedName];
Now it should be possible to reference by using the qualified ID:
ENTITY_RELATIONSHIP { auction_lots : lot_id -> auctionHouse.lots.id0 auction_lots : auction_id -> auctionHouse.auctions.id1 }
If you can't change the grammar like this to make use of the default way Xtext handles names then you would need to look into providing your own qualified names, a great article for that is this Qualified Names Article
相关问答
更多-
Xtext(DSL文件)到Ecore(Xtext (DSL file) to Ecore)[2022-08-24]
您可以通过两种方式获得DSL的ecore元模型 在标准向导生成的Xtext-Project中,ecore元模型可以从您的语法中获得。 工作流生成器将生成的元模型保存到 [Project]/src-gen/[your-package]/[grammar-name].ecore 例如: org.xtext.example.mydsl/src-gen/org/xtext/example/mydsl/MyDsl.ecore 您也可以自己编写ecore元模型,并使用if语法。 这不是一个简单的过程,但它提供了更大 ... -
在Xtext中确定范围(Scoping in Xtext)[2023-07-15]
您正在使用交叉引用作为UseVar中的标识符。 我改变了 UseVar: ref=[DefVar] ';' 然后这个xtend片段适用于您的DSL。 override IScope getScope(EObject context, EReference ref){ if(context instanceof UseVar && ref == USE_VAR__REF){ val model = context.getContainerOfType(Model) ... -
将对象转换为Xtext DSL(Convert Object to Xtext DSL)[2022-05-05]
您可以使用Xtext的序列化。 与Java的默认序列化API不同,Xtext的实现创建了DSL。 代码看起来像这样: Injector injector = Guice.createInjector(new my.dsl.MyDslRuntimeModule()); Serializer serializer = injector.getInstance(Serializer.class); String s = serializer.serialize(eobj); 其中eobj是Syst ... -
MVC: Model | View | Controller; ... Controller: "controller" name=ID 'for' view=[View] "{" models+=ModelReference* actions+=Action* bindings+=Binding* "}"; ModelReference: "model" name=ID ":" type=[Entity] Action: "action" name=ID "on" button=[ ...
-
这可以通过简单的交叉引用来完成 Service: 'Service' att=STRING 'for' car=[Car] ('(' extras+=[Extra]+ ')')? ; 和相应的范围提供商 package org.xtext.example.mydsl.scoping import org.eclipse.emf.ecore.EReference import org.eclipse.xtext.scoping.IScope import org.eclipse.xtext.sco ...
-
您的问题似乎更侧重于DSL词法分析器如何避免在C ++代码中丢失。 基本答案是您需要匹配括号(例如,确保它们正确嵌套)。 我不知道如何定义Xtext / ANTLR词法规则来做到这一点; 我认为有一种丑陋的方式可以放入程序代码并逐个开始阅读字符。 这可能有一些并发症; 你的匹配逻辑可能不得不担心C ++代码中的各种类型的引用。 例如, { // this } isn't a match 和 { char x[]="} this isnt a match { ei ...
-
引用的问题在于它们根本无法在该范围内找到,您可以做的是引入一个限定名称并在交叉引用中使用它并相应地更改您的语法,即: - QualifiedName: ID ('.' ID)*; Relationship: name=ID ":" newEntityName=ID "->" refName=[Attribute|QualifiedName]; 现在应该可以使用限定ID进行引用: ENTITY_RELATIONSHIP { auction_lots : lot_id -> auct ...
-
那么这是一个很难给出一般答案的问题。 这在很大程度上取决于您的口译员做了什么以及如何提供反馈。 即使是逐行工作也可能根本没有意义,而只是简单地遍历模型内容。 当用户点击输入文件时,你可以想象在“自动编辑”上执行此操作。 这就是xtext随附的算术示例。 或者您可以使用编辑器切换视图 - 这就是乌龟示例所做的事情( https://github.com/xtext/seven-languages-xtext/blob/c04e8d56e362bfb8d6163f4b001b22ab878686ca/langu ...
-
你似乎是一个真正讨厌语法作业的人 Funcs: 'func' left=FuncName (bracket?='(' ')')? '=' right=[Name] ';'; Vars: 'var' varName=VarName ';'; 这是scopeprovider,对我来说很好 class MyDslScopeProvider extends AbstractMyDslScopeProvider { override getScope(EObject context, EReferenc ...
-
使用xtext通常没问题 将模型创建为ast 将其添加到资源 保存资源以使其序列化 如果您使用xbase和jvmmodelinferrrer构建ast,如果您从模型引用到推断的jvm元素或尝试构建xbase表达式,那么这可能是一种痛苦。这里是一个使用domainmodel示例的简单复杂示例 package org.eclipse.xtext.example.domainmodel.tests import com.google.inject.Injector import org.eclipse.emf. ...