2017-04-10 32 views
0

我使用量角器进行端到端测试。我没有使用Selenium WebDriver。我直接连接到魅力浏览器。当我开始了试验2个错误occurred.the第一招:量角器:不要等待中继器元素出现在Dom中

conFusion App E2E Testing menu 0 item should show the number of comments as Message: Expected 0 to equal 5. Stack: Error: Failed expectation

第二个:

conFusion App E2E Testing menu 0 item should show the first comment author as Message: Failed: No element found using locator: by.model("FiltText") Stack:

我使用JSON服务器成为了REST API通过我的角应用程序访问JSON数据有五个评论和过滤器来排序评论。 我也用gulp来提供Angular应用程序。当我输入一个终端吞吐表时,每件事情都正常工作,但量角器失败。

如何使量角器等到元素出现在DOM中?

相应量角器配置代码是:

exports.config = { 
allScriptsTimeout:11000, 

    specs: [ 
    'e2e/*.js' 
    ], 
    capabilities: { 
    'browserName': 'chrome' 
    }, 

    baseUrl: 'http://localhost:3001/', 

    framework: 'jasmine', 
    directConnect: true, 

    jasmineNodeOpts: { 
    showColors: true, 
    defaultTimeoutInterval: 30000 
    } 
}; 
包含E2E测试

scenarios.js代码

describe('menu 0 item', function() { 
    beforeEach(function() { 

    browser.get('index.html#/menu/0'); 


    }); 

    it('should have a name', function() { 
    var name = element(by.binding('dish.name')); 
    expect(name.getText()). 
    toEqual('Uthapizza Hot $4.99'); 
}); 

it('should show the number of comments as', function() { 

     expect(element.all(by.repeater('comment in dish.comments')) 
     .count()).toEqual(5); 


    }); 

    it('should show the first comment author as', function() { 
     element(by.model('FiltText')).sendKeys('author'); 

    expect(element.all(by.repeater('comment in dish.comments')) 
     .count()).toEqual(5); 

    var author = element.all(by.repeater('comment in dish.comments')) 
       .first().element(by.binding('comment.author')); 

    expect(author.getText()).toContain('25 Cent'); 

}); 
}); 

HTML页面的部分代码,我想测试:

<h4> Customer Comments &nbsp; 
       <span style="font-size:15px;">sorted by:<input type="text" ng-model="FiltText"></span></h4><blockquote ng-repeat="commet in dish.comments |orderBy:FiltText"> 
     <h5>{{commet.rating}} Stars</h5> 
     <h5>{{commet.comment}}</h5> 
     <footer>{{commet.author}}, <span>{{commet.date|date}}</span>. </footer> 

      </blockquote> 

回答

0

您可以使用protractor.ExpectedConditions.visibilityOf或presenceOf()方法等待g直到元素在UI上可见或出现在DOM中。请遵循以下代码:

var EC=protractor.ExpectedConditions; 
var targetEle=element(locator); 

browser.wait(EC.visibilityOf(targetEle),10000,'NOT VISIBLE'); //wait until 
//ele visible 
browser.wait(EC.presenceOf(targetEle),10000,'NOT PRESENT');//wait until 
//present in dom 
+0

是ExpectedConditions由Selenium WebDriver提供的吗?因为我没有使用Selenium WebDriver。我直接连接到魅力浏览器。 – munirah

+0

你能否特意确定我应该在哪里把ExpectedConditions方法放在我的代码中?我是新的量角器 – munirah

+0

我做了你的建议,但它告诉我这个消息:失败:不可见 等待10009ms后超时 – munirah

相关问题