async get()

in lib/browser.ts [720:824]


  async get(destination: string, timeout = this.getPageTimeout) {
    destination = this.baseUrl.indexOf('file://') === 0 ? this.baseUrl + destination :
                                                          url.resolve(this.baseUrl, destination);
    if (!await this.waitForAngularEnabled()) {
      await this.driver.get(destination);
      await this.plugins_.onPageLoad(this);
      return;
    }

    let msg = (str: string) => {
      return 'Protractor.get(' + destination + ') - ' + str;
    };

    if (this.bpClient) {
      await this.bpClient.setWaitEnabled(false);
    }
    // Go to reset url
    await this.driver.get(this.resetUrl);

    // Set defer label and navigate
    await this.executeScriptWithDescription(
        'window.name = "' + DEFER_LABEL + '" + window.name;' +
            'window.location.replace("' + destination + '");',
        msg('reset url'));

    // We need to make sure the new url has loaded before
    // we try to execute any asynchronous scripts.
    await this.driver.wait(() => {
      return this.executeScriptWithDescription('return window.location.href;', msg('get url'))
          .then(
              (url: any) => {
                return url !== this.resetUrl;
              },
              (err: IError) => {
                if (err.code == 13 || err.name === 'JavascriptError') {
                  // Ignore the error, and continue trying. This is
                  // because IE driver sometimes (~1%) will throw an
                  // unknown error from this execution. See
                  // https://github.com/angular/protractor/issues/841
                  // This shouldn't mask errors because it will fail
                  // with the timeout anyway.
                  return false;
                } else {
                  throw err;
                }
              });
    }, timeout, 'waiting for page to load for ' + timeout + 'ms');

    // Run Plugins
    await this.plugins_.onPageLoad(this);

    let angularVersion: number;
    try {
      // Make sure the page is an Angular page.
      const angularTestResult: {ver: number, message: string} = await this.executeAsyncScript_(
          clientSideScripts.testForAngular, msg('test for angular'), Math.floor(timeout / 1000),
          this.ng12Hybrid);
      angularVersion = angularTestResult.ver;

      if (!angularVersion) {
        let message = angularTestResult.message;
        logger.error(`Could not find Angular on page ${destination} : ${message}`);
        throw new Error(
            `Angular could not be found on the page ${destination}. ` +
            `If this is not an Angular application, you may need to turn off waiting for Angular.
            Please see
            https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular-on-page-load`);
      }
    } catch (err) {
      throw new Error('Error while running testForAngular: ' + err.message);
    }

    // Load Angular Mocks
    if (angularVersion === 1) {
      // At this point, Angular will pause for us until angular.resumeBootstrap is called.
      let moduleNames: string[] = [];
      for (const {name, script, args} of this.mockModules_) {
        moduleNames.push(name);
        let executeScriptArgs = [script, msg('add mock module ' + name), ...args];
        await this.executeScriptWithDescription.apply(this, executeScriptArgs)
            .then(null, (err: Error) => {
              throw new Error('Error while running module script ' + name + ': ' + err.message);
            });
      }

      await this.executeScriptWithDescription(
          'window.__TESTABILITY__NG1_APP_ROOT_INJECTOR__ = ' +
              'angular.resumeBootstrap(arguments[0]);',
          msg('resume bootstrap'), moduleNames);
    } else {
      // TODO: support mock modules in Angular2. For now, error if someone
      // has tried to use one.
      if (this.mockModules_.length > 1) {
        throw 'Trying to load mock modules on an Angular v2+ app is not yet supported.';
      }
    }

    // Reset bpClient sync
    if (this.bpClient) {
      await this.bpClient.setWaitEnabled(!this.internalIgnoreSynchronization);
    }

    // Run Plugins
    await this.plugins_.onPageStable(this);
  }