nathanboktae / mocha-phantomjs

:coffee: :ghost: Run client-side mocha tests in the command line through phantomjs
MIT License
954 stars 112 forks source link

phantom doesn't have cookie(?) #256

Closed davayd closed 7 years ago

davayd commented 7 years ago

Hi, when i run GET request $.get('http://localhost:5000/api/user/login', {userName:'test', password:'test'}, console.log) to my ASP.NET server from Chrome browser, the server automatically add to request HEADER Cookie

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding:gzip, deflate, br
Accept-Language:ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Cookie:.AspNetCore.Antiforgery.4-glfaPqMo0=CfDJ8KlDKt0PFQxOv7weDcqR4Tdj-x-rRo498n5ZjJ9PxXFz0ppITWZ5oTR9IjdvbAjn7aDOPX9mv9uy1bDTfpI1uIpX9R-Gaw5gjB4OXqE9dDpnGmaIBdQsNNdbMXi3UkIJl8DfvcnQCj7Fj-aV46iqNyE
Host:localhost:5000
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36

BUT, When I do the same operation with mocha-phantomjs

describe('Auth', function() {
    before(function() {
$.get('http://localhost:5000/api/user/login',  {userName:'test', password:'test'}, console.log);
var c = $.cookie();
     console.log(c);
}
}

i get {} cookie object. How can i get the Authorization Cookie?

nathanboktae commented 7 years ago

each phantomjs run is clean, and cookies need to be persisted yourself to a file, then you can run mocha-phantomjs with a cookies file via --cookies or -c flag.

Also see the cookies tests for an example usage of the format.