[英]protractor :don't wait for repeater elements to appears in Dom
I do end to end test using protractor. 我确实使用量角器进行端到端测试。 I don't used Selenium WebDriver .I connected directly to charm browser.
我没有使用Selenium WebDriver。我直接连接到了魅力浏览器。 When I start up the test 2 errors occurred.the first one:
当我启动测试时,发生了2个错误。第一个错误:
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测试菜单0项应将注释数显示为消息:预期为0等于5。堆栈:错误:预期失败
the second one: 第二个:
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:
conFusion App E2E测试菜单0项应显示第一个评论作者为消息:失败:使用定位符未找到任何元素:by.model(“ FiltText”)堆栈:
I used JSON server serve up the REST API for accessing the JSON data by my Angular application.there are five comments and filter to order the comments. 我使用JSON服务器提供了REST API,以便通过Angular应用程序访问JSON数据。有五个注释并过滤以对这些注释进行排序。 also I used gulp to serve up the Angular application.
我也用gulp来服务Angular应用程序。 When I type in a terminal gulp watch every-things worked right.but protractor is failed.
当我输入终端装甲时,请注意一切正常,但量角器失败。
How can I make the protractor wait until element appears in the DOM? 如何让量角器等到元素出现在DOM中?
the corresponding protractor configuration code is : 相应的量角器配置代码为:
exports.config = {
allScriptsTimeout:11000,
specs: [
'e2e/*.js'
],
capabilities: {
'browserName': 'chrome'
},
baseUrl: 'http://localhost:3001/',
framework: 'jasmine',
directConnect: true,
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000
}
};
scenarios.js code that contain e2e test 包含e2e测试的visions.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');
});
});
The partial code of Html page that I want to test : 我要测试的HTML页面的部分代码:
<h4> Customer Comments
<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>
You use protractor.ExpectedConditions.visibilityOf or presenceOf() methods for waiting until element visible on UI or present in DOM. 您使用protractor.ExpectedConditions.visibilityOf或presentOfOf()方法来等待元素在UI上可见或出现在DOM中。 Follow the below code:
请遵循以下代码:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.