【问题标题】:Protractor test a bootstrap modal - not angular page - timeout量角器测试引导模式 - 不是角度页面 - 超时
【发布时间】:2016-11-26 11:11:19
【问题描述】:

我正在尝试对未使用角度插件的引导模式进行 UI 测试,它是一个普通的引导模式。我收到此错误:

失败:等待异步 Angular 任务完成超时 11 秒后。这可能是因为当前页面不是 角应用。有关更多详细信息,请参阅常见问题解答: https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular 在等待带有定位器的元素时 - 定位器:By(css 选择器, h2.modal-title)✗

是否有解决方法或者无法使用量角器测试 vanilla bootstrap 模态?

这是我的完整测试:

import { browser, element, by, By, $, $$, ExpectedConditions } from 'protractor';
import { E2EUtilities } from './utilities.spec'

    describe('Result Details', function () {
       it(`Shows result details modal when clicking on a result`, function () {
          E2EUtilities.navigateToResultsPage();
          element(by.id('result0')).isPresent().then(function (result) {
             if (result) {
                element(by.id('result0')).click();
                browser.sleep(3000);
                expect(element(by.css('h2.modal-title')).isPresent()).toBe(true);
             } else {
                expect(element(by.css('h2.modal-title')).isPresent()).toBe(false);
             }
          });
       });
    });

请注意,我已将E2EUtilities.navigateToResultsPage(); 隐藏起来,因为我知道问题不在于它,因为代码通过了所有这些,并且可以通过肉眼看到更进一步。

【问题讨论】:

    标签: angular protractor bootstrap-modal


    【解决方案1】:

    您可能会更幸运暂时关闭同步

    element(by.id('result0')).isPresent().then(function (result) {
      if (result) {
        browser.ignoreSynchronization = true;
    
        element(by.id('result0')).click();
        browser.sleep(3000);  // TODO: use ExpectedConditions?
        expect(element(by.css('h2.modal-title')).isPresent()).toBe(true);
      } else {
        expect(element(by.css('h2.modal-title')).isPresent()).toBe(false);
      }
    });
    
    browser.ignoreSynchronization = false;
    

    【讨论】:

    • 你知道为什么会这样吗?只有一项基本测试有同样的问题
    • @genuinefafa 可能有多种原因 - 通常是在角度应用程序本身中使用 $timeout。
    • 对我来说,它是 TimerObservable 创建一个间隔。如果我评论本节,测试将照常运行。 setTimeout() 也会发生这种情况。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多