【发布时间】:2016-05-18 16:53:53
【问题描述】:
控制量角器测试执行顺序的最佳方法是什么?
问题案例 1:量角器滑动角度页面太快以至于无法操作(填充)输入数据。 (滑动逻辑是从不可见转换为可见,并将它们转换为窗口可见区域)。因此量角器看不到窗外和不透明度为 0 的那些。为了测试我只能填写第一页。其他的刷得太快(或异步)。
问题案例2:在我填写第一页并提交表单后,数据被保存并且警报显示确认消息。然后量角器必须单击下拉列表,浏览器应导航到显示保存数据的页面。问题是量角器在保存数据之前单击下拉列表,因为警报稍后触发(必须等待警报)。
问题是:有没有办法控制在量角器中按给定顺序执行的测试?有没有办法按住滑动来填写日期(否则量角器看不到它)?这是简化的代码:
it('should fill in form and send data', function() {
// fill in textarea field
element.all(by.css('textarea')).first().clear().sendKeys('test');
// goes to page 2
browser.executeScript("angular.element(document.documentElement)
.injector().get('$rootScope').$broadcast('nextPage', {direction: 'next'});");
// Here is Problem 1. Though i can see this page when testing,
// the input is not visible for protractor.
// fill in input-field
element.all(by.css('input')).first().clear().sendKeys('test');
// goes to page 1
browser.executeScript("angular.element(document.documentElement)
.injector().get('$rootScope').$broadcast('prevPage', {direction: 'prev'});");
// submit form
element(by.css('button[type=submit]')).click();
// Here is problem 2. The following test is executed earlier
// than the following alert.
//browser.wait(protractor.ExpectedConditions.alertIsPresent(), 3000);
var alertDialog = browser.switchTo().alert();
expect(alertDialog.getText()).toEqual('Saved');
alertDialog.accept();
});
it('should click drop-down-list', function() {
// click drop-down list
element(by.css('.drop-down-list')).click();
});
【问题讨论】:
-
在测试之间添加等待
-
亲爱的 Emna,这个额外的等待会阻止警报并且警报永远不会显示。或者我做错了什么。您能否展示一个工作代码示例?
-
我什至试过 browser.controlFlow().timeout(3000);但它也会阻止警报。也许我应该考虑 browser.controlFlow().execute(function() { browser.controlFlow().execute(test); });但不知道如何将幽灵传递给它以便他们应该被看到。
-
添加
browser.sleep(3000); -
当我将 browser.sleep(3000) 添加到第二个测试时,它只是冻结了整个测试,当测试恢复时,一切都会发生。
标签: angularjs testing protractor