【发布时间】:2016-08-25 20:10:24
【问题描述】:
嘿,我是使用 protractorJS 测试在 angularJS 中完成的主页的自动化测试的新手。到目前为止我编写的代码已经解决了问题是 我无法将键发送到搜索字段 运行代码后我得到 Message: Failed: Timed out waiting for Protractor to synchronize with the page 11 秒后
我认为我的元素语法有问题:
element(by.css("input[name='search_query']")).sendKeys('Virginia Beach VA');
--- HTML code block ----
<div ng-transclude>
<input parse-search-query="" type="text" tabindex="1" name="search_query" autocomplete="off" placeholder="Search by City ST, Zip, or Address" data-ng-model="searchQueryFieldCtrl.searchFormController.searchParams.search_query" data-ng-change="searchQueryFieldCtrl.searchFormController.clearErrors()" data-focus-on="focusQuery || form.search_query.$error" data-uib-typeahead="suggestion as suggestion.label for suggestion insearchQueryFieldCtrl.getSuggestions($viewValue)" data-typeahead-focus-first="false" data-typeahead-min-length="0" data-typeahead-wait-ms="300" data-typeahead-on-select="searchQueryFieldCtrl.setSearch($item)" class="ng-pristine ng-untouched ng-valid ng-scope" aria-autocomplete="list" aria-expanded="false" aria-owns="typeahead-69-6255">
</div>
---homeshptest.js file ----
describe('New stack hompage test', function() {
it('should test search form', function() {
browser.ignoreSynchronization = true;
browser.get('http://localhost:3000/');
browser.sleep(5000);
element(by.css("input[name='search_query']")).sendKeys('Virginia Beach VA');
browser.sleep(5000);
VA');
}); }); ---------------
【问题讨论】:
-
你能贴出那个元素的html代码吗?
-
我没有看到
ng-app明确定义,这让我觉得这是一个手动引导应用程序。如果是这种情况,您可能处于这种情况:github.com/angular/protractor/issues/66。 -
此 angualrjs 代码用于企业级。这是来自像 apartments.com 这样的网站的代码,我正在尝试为它创建一个自动化测试。
-
我在上面简化了我的问题和细节。
-
我会添加 browser.sleep(10000);在 browser.get 之后,我强烈建议更改您的 css 选择器,它会在您与输入字段交互的那一刻中断(尝试 element(by.css("input[name='search_query']"))并分隔 .clear()从 .sendKeys() 到单独的操作。如果仍然出现同步错误,则需要删除角度同步。理论上,Angular 应用程序是 Angular 应用程序,但实际上很多事情都会破坏量角器同步。
标签: javascript angularjs protractor automated-tests