所以我只是对某些东西感到好奇......看起来在使用Protractor进行e2e测试并执行“expect(element(by.css('。test'))。getText())。toBe( 'Some Text');“这仅适用于文档BODY部分中的元素,而不适用于HEAD部分。
例如,我修改了教程phonecatApp index.html,看起来像这样:
!doctype html>
<html lang="en" ng-app="phonecatApp">
<head>
<meta charset="utf-8">
<title class="appTitle">Google Phone Gallery</title>
<link rel="stylesheet" href="../bower_components/bootstrap/dist/css/bootstrap.css">
<link rel="stylesheet" href="css/app.css">
<link rel="stylesheet" href="css/animations.css">
<script src="../bower_components/jquery/jquery.js"></script>
<script src="../bower_components/angular/angular.js"></script>
<script src="../bower_components/angular-animate/angular-animate.js"></script>
<script src="../bower_components/angular-route/angular-route.js"></script>
<script src="../bower_components/angular-resource/angular-resource.js"></script>
<script src="js/app.js"></script>
<script src="js/animations.js"></script>
<script src="js/controllers.js"></script>
<script src="js/filters.js"></script>
<script src="js/services.js"></script>
</head>
<body>
<div class="test">Some Text</div>
<div class="view-container">
<div ng-view class="view-frame"></div>
</div>
</body>
</html>
然后我向scenario.js添加了一些简单的测试,如下所示:
it('should set the title to "Google Phone Gallery"', function () {
expect(element(by.css('.appTitle')).getText()).toBe('Google Phone Gallery');
});
it('should set the div.test to "Some Text"', function () {
expect(element(by.css('.test')).getText()).toBe('Some Text');
});
检查TITLE的第一个测试总是失败,“预期”将成为'Google Phone Gallery'。“但DIV测试工作正常。
在HEAD部分检查元素是否有任何特殊要求,或者这只是Protractor无法做到的事情?