在角端到端测试获取浏览器路径导致异常 [英] Getting browser path in angular e2e test causes an exception

查看:112
本文介绍了在角端到端测试获取浏览器路径导致异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的端到端测试,以验证路由重定向作品

I have a simple e2e test to verify that route redirection works

<!doctype html>
<html lang="en">
  <head>
    <title>End2end Test Runner</title>
    <script src="../client/components/angular-scenario/angular-scenario.js" ng-autotest></script>
    <script src="e2e/scenarios.js"></script>
  </head>
  <body>
  </body>
</html>

scenarios.js

'use strict';

describe('e2e', function() {

  beforeEach(function() {
    browser().navigateTo('../../client/index.html');
  });

  it('should redirect to the main application home page with / is accessed', function() {
    browser().navigateTo('#!/');
    expect(browser().location().path()).toBe('/app');
  });
});

karma.conf.js

*snip*
files = [
  ANGULAR_SCENARIO,
  ANGULAR_SCENARIO_ADAPTER,
 './test/e2e/**/*.js',
];
*snip*

在此被运行,浏览器()位置()路径()将引发一个异常:

When this gets run, browser().location().path() will raise an exception:

TypeError: 'undefined' is not a function (evaluating '$document.injector()')

我已经确定了它的。路径()在这是造成问题,因为如果我这样做的浏览器()。位置()不会引发异常结束。

I've determined it's the .path() at the end that's causing the issue since if I do browser().location() no exception is raised.

然而,在浏览器控制台,这将返回一个angular.scenario.Future预期。

However in the browsers console this will return a angular.scenario.Future as expected.

为什么一个异常被提出?

Why is an exception being raised?

推荐答案

从我的头顶,这里有AngularJS端到端的最主要原因测试不工作

From the top of my head, here are the top reasons for AngularJS E2E tests not working


  1. 的AngularJS端到端测试,需要你有你的应用程序的HTML定义的NG-应用。如果手动白手创业,你需要将它自己加入 - 谷歌论坛讨论

  2. 确保您的代理正确定义,并确保您可以直接导航到它。在browser.navigateTo(右后您的测试中添加暂停()),并确保应用程序实际上是装载在AngularJS方案Runner在浏览器中。

  3. 调试最后一步,你得到的浏览器位置之前添加一个睡眠2到三秒钟。这可能是该angularJS喷油器不能正确地传达给你的AngularJS应用程序,从而导致它无法等待所需的时间。

这些希望有做的伎俩为您服务!

Hope one of these does the trick for you!

这篇关于在角端到端测试获取浏览器路径导致异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆