量角器e2e测试在浏览器中引发错误.executeAsyncScript_

时间:2019-01-07 09:17:12

标签: angular protractor e2e-testing

我正在尝试为我们的应用程序实施e2e测试。 但是后来我的第一个测试用例失败,并出现以下错误。

Failed: Error while running testForAngular: javascript error: Unexpected 
identifier
  JavaScript stack:
  SyntaxError: Unexpected identifier
      at callback (eval at executeAsyncScript (:457:5), <anonymous>:5:5)
      at check (eval at executeAsyncScript (:457:5), <anonymous>:50:7)
      at eval (eval at executeAsyncScript (:457:5), <anonymous>:53:3)
      at eval (eval at executeAsyncScript (:457:5), <anonymous>:54:4)
      at eval (eval at executeAsyncScript (:457:5), <anonymous>:55:63)
      at executeAsyncScript (<anonymous>:457:26)
      at <anonymous>:473:29
      at callFunction (<anonymous>:361:33)
      at <anonymous>:371:23
      at <anonymous>:372:3
    (Session info: chrome=71.0.3578.98)
    (Driver info: chromedriver=2.45.615291 (ec3682e3c9061c10f26ea9e5cdcf3c53f3f74387),platform=Windows NT 6.1.7601 SP1 x86_64)

任何人都可以帮助我如何解决此错误?

错误来自browser.js,来自promise this.executeAsyncScript_(clientSideScripts.testForAngular,msg('test for angular'),Math.floor(timeout / 1000),this.ng12Hybrid)。

可以肯定的是,我尝试使用角度站点进行测试并且该测试用例已通过,但是测试我的应用程序中当前页面的测试用例失败了

import { browser, by, element } from 'protractor';

import { protractor } from 'protractor/built/ptor';

describe('Testing abc', () => {

  beforeEach(() => {
  });

  it('should open the page', () => {
      browser.get('/abc');
      browser.getCurrentUrl().then(function(actualUrl) {
          expect(actualUrl).toContain('/abc');
      });
  });

 it('should display page', () => {
    browser.get('https://angular.io');
    expect(browser.getCurrentUrl()).toBe('https://angular.io/');
 });

});

在第一个测试用例中,promise browser.getCurrentUrl()之后的块未执行。 请帮助我

1 个答案:

答案 0 :(得分:-1)

  1. 什么是actualUrl?您定义了吗?
  2. 据我所知,browser.get地址应仅是协议的绝对路径,例如browser.get('https://angular.io/'),而不是browser.get('/something')