angular - 我必须在加载时手动刷新页面,因为它可以在 Protractor 中工作

标签 angular selenium-webdriver protractor selenium-chromedriver gulp-protractor

好吧,我正在使用 Chrome 。
当我运行 Protractor 时,页面开始加载并且永远不会完成加载,直到我手动刷新页面然后一切正常。
我的页面使用 Angular2,是用 MEAN 堆栈构建的。

这是我的配置文件:

// @datatype_void
require('ts-node/register');

exports.config = {
  baseUrl: 'https://localhost:3000',

  // use `npm run e2e`
  specs: [
    '../test/*.e2e.*.js'
  ],
  suites: {
    dashboard: '../test/Dashboard.e2e.testcase.js'
  },

  exclude: [],

  framework: 'jasmine2',

  allScriptsTimeout: 40000,

  jasmineNodeOpts: {
    showTiming: true,
    showColors: true,
    isVerbose: false,
    includeStackTrace: false,
    defaultTimeoutInterval: 40000
  },
  directConnect: true,

  capabilities: {
    'browserName': 'chrome',
    'chromeOptions': {
      'args': ['show-fps-counter=true']
    }
  },

  onPrepare: function() {
    browser.ignoreSynchronization = true;
  },

  /**
   * Angular 2 configuration
   *
   * useAllAngular2AppRoots: tells Protractor to wait for any angular2 apps on the page instead of just the one matching
   * `rootEl`
   *
   */
   useAllAngular2AppRoots: true
};


这是在我的测试中运行的第一个:

describe('This is Dashboard.', () => {

    email = 'alexis.gonzalez@agilezip.mx';
    pass = 'laslos157';
    browser.get('/');
    browser.wait(protractor.ExpectedConditions.visibilityOf($('.abcRioButton.abcRioButtonBlue')), 10000);
    element(by.css('.abcRioButton.abcRioButtonBlue')).click();
    browser.getAllWindowHandles().then(function (handles) {
        browser.switchTo().window(handles[1]).then(function () {
            enterkeys(element(by.css('#Email')), email);
            element(by.css('#next')).click();
            browser.wait(protractor.ExpectedConditions.visibilityOf($('#Passwd')), 5000);
            enterkeys(element(by.css('#Passwd')), pass);
            element(by.css('#signIn')).click();
        });
    });
    browser.getAllWindowHandles().then(function (handles) {
        browser.switchTo().window(handles[0]);
    });
    browser.wait(protractor.ExpectedConditions.visibilityOf($$('.al-sidebar-list-link').get(0)), 10000);

最佳答案

好吧,我可以通过添加以下行来“修复”:

browser.waitForAngular();
browser.navigate().refresh();

但我不明白为什么我必须刷新页面。 :(

关于angular - 我必须在加载时手动刷新页面,因为它可以在 Protractor 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41490128/

相关文章:

angular - 如何处理 Angular 中的深层链接?

angular - 编写自定义 ngrx 运算符并返回源可观察类型

python - 带有 Selenium 错误 : Message: 'phantomjs' executable needs to be in PATH 的 PhantomJS

javascript - 如何使用 selenium 获取所有元素的直接子元素和 css 选择器?

gruntjs - 自 1.8.0 迁移以来,带有 Mocha/Chai 的 Protractor 不再显示错误

javascript - 使用 TypeScript 1.5 的 Angular 2 服务注入(inject)

angular - 为什么 Angular 8 路由器不能在带有 WkWebView 的 Cordova IOS 中工作?

java - TestNG 启动时发生内部错误

cookies - addCookie 方法抛出 'addCookie called with non-cookie parameter'

javascript - Protractor Promise 回调不显示内容。如何调用返回项的方法?