How do you test AngularJS cookies in an end-to-end test?

I have a simple service that sets cookies in angular, but there is no obvious way to verify that they were set in an end-to-end test.

The code for testing is simple as

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

But I can not find any documents on how to test. Here is what I found:

I also tried

 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; } }); 

But this only returns cookies for the parent browser, not the page I want to check.

Any examples of how to do this?

+6
source share
1 answer

It seems you need to use PhantomJS .

PhantomJS is a mute WebKit script with a JavaScript API. It has fast and native support for various web standards: DOM processing, CSS selector, JSON, Canvas and SVG. - PhantomJS Website

It supports custom cookies in its API. Regarding testing, this is probably your best bet. You can also look at CasperJS to help check out page navigation.

0
source

Source: https://habr.com/ru/post/950470/


All Articles