e2e Angular 2 with protractor,element(by.id(' count'))。getText()显示null

时间:2017-08-03 04:36:29

标签: angular protractor integration-testing e2e-testing

我的测试运行因显示消息而失败 - 预期''等于101 。这个代码的问题可能是什么,在UI中我得到了正确的结果。加载页面时隐藏了id为SequenceMasterCount的div,点击搜索按钮后div开始显示内容api结果。

import { CleanUiPage } from './app.po';
import { browser, element, by } from 'protractor';    
describe('clean-ui App', () => {
  let page: CleanUiPage;

  beforeEach(() => {
    page = new CleanUiPage();
  });    

  it('should allow searching and Show the count', () => {

    const searchButton = element(by.className('list-ro-input'));
    const searchBox = element(by.className('list-RO-search'));
    searchBox.sendKeys('[PIMS]SYSTEM+GAP_FILL_TEST');
    searchButton.click().then(() => {    
      expect(element(by.id('SequenceMasterCount')).getText()).toEqual(101);

    });

  });

通过OP

添加评论中的HTML
 <section>  
 <input id="list-ro" class="list-ro-input" name="" type="text" #test /> 
 <span class="input-group-btn"> <a href="javascript: void(0);" id='list-ro-search-btn' class="list-RO-search btn btn-default" (click)=onSearch(test)></a> </span> 
  <div [hidden]="this.sequencemasters==0 && this.sequencemasterAlts==0"> 
  <div class="sequenceCount"> 
  <span class="cat__core__step__title">Sequence Master</span> <p id='sequenceMasterCount' class="count-bold">{{this.sequencemasters}}</p> 
 </div> 
 </div> 
 </section>

1 个答案:

答案 0 :(得分:0)

您的getText()方法应该解析承诺,因为getText()会返回需要解析的承诺

你需要添加这个

   searchButton.click().then(() => {    
   element(by.id('SequenceMasterCount'))getText().then(function(text){
       expect(text).toEqual(101);        
        });

});