testing - 您如何在端到端测试中测试 AngularJS cookie?

标签 testing angularjs end-to-end

我有一个以 Angular 设置 cookie 的简单服务,但没有明显的方法来测试它们是否已在端到端测试中设置。

要测试的代码很简单

var splashApp = angular.module('splashApp', ['ngCookies']);
splashApp.controller('FooterController', function ($location, $cookies) {
    $cookies.some_cookie = $location.absUrl();
});

但是我找不到任何关于如何测试的文档。这是我的发现:

我也试过

angular.scenario.dsl('cookies', function() {
  var chain = {};
  chain.get = function(name) {
    return this.addFutureAction('get cookies', function($window, $document, done) {
      var injector = $window.angular.element($window.document.body).inheritedData('$injector');
      var cookies = injector.get('$cookies');
      done(null, cookies);
    });
  };
  return function() {
    return chain;
  }
});

但这只返回父浏览器的 cookie,而不是我要测试的页面。

关于如何做到这一点的任何例子?

最佳答案

看来你需要使用 PhantomJS .

PhantomJS is a headless WebKit scriptable with a JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG. --PhantomJS website

它在其 API 中支持自定义 cookie。 在测试方面,这可能是您的最佳选择。 您可能还想看看 CasperJS帮助测试页面导航。

关于testing - 您如何在端到端测试中测试 AngularJS cookie?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17910612/

相关文章:

angularjs - 测试使用 document.body.querySelectorAll 的代码

angularjs - Angular ng 重复。循环遍历字符串中的字母

selenium-webdriver - 复制并粘贴 Protractor js 以进行端到端测试

python-3.x - 封装外的模拟函数

javascript - 在客户端测试 Javascript

visual-studio - Visual Studio 测试项目可以处理事件和委托(delegate)吗?

iPhone Xcode 有没有办法在不加载模拟器的情况下测试方法?

android - 在 ionic 中每行显示 5 列

error-handling - 哪一行导致此 Protractor 错误?

javascript - 单击按钮捕获滚动