首页 \ 问答 \ 如何用量角器检查元素是否存在?(How to check if element is present with protractor?)

如何用量角器检查元素是否存在?(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 undefinedFailed: 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
更新时间:2020-08-12 19:08

最满意答案

引用的问题在于它们根本无法在该范围内找到,您可以做的是引入一个限定名称并在交叉引用中使用它并相应地更改您的语法,即: -

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

相关问答

更多
  • 您可以通过两种方式获得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语法。 这不是一个简单的过程,但它提供了更大 ...
  • 您正在使用交叉引用作为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的序列化。 与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. ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。