4

I'm trying to set a cookie for an intern functional test, but the cookie data doesn't seem to be available on the page. Here's the setup:

registerSuite(function() {
    'test': function() {
        return this.remote 
           .get(require.toUrl("index.html")
           .setFindTimeout(5000)
           .setCookie({name: "foo", value: "bar"})
           .then(function() {
              //... test here ...
           });
    }
});

When accessing document.cookie inside index.html, there is no data. Any tips on what I am doing wrong?

Update:

I haven't solved the problem, but figured out that you need call setCookie() before get(). The way I'm hacking around this is to call get() on a noop URL, and then calling setCookie()

return this.remote 
       .get('/')
       .setCookie({name: "foo", value: "bar"})
       .get(require.toUrl("index.html")
       .setFindTimeout(5000)
       .setCookie({name: "foo", value: "bar"})
       .then(function() {
          //... test here ...
       });
Brian Tol
  • 4,149
  • 6
  • 24
  • 27
  • What browser/browser version are you running against? What version of Selenium? Are you using a cloud provider or your own Selenium installation? – C Snover Jul 27 '15 at 17:17
  • 1
    The example you have provided is not valid JavaScript, running it will cause syntax errors. Anyway intern docs suggest returning a configuration object if you use registerSuite with a callback, you should have something like that instead: ```registerSuite(function() { return { 'test': function() { // ... } }; });``` Let me know if it helps. Also please tell if there any errors in console, any timedout requests in network? What arguments does then callback get? – Olga Jul 27 '15 at 20:47

1 Answers1

-1

It would seem you did not include in your sample code any setup, teardown/after, beforeEach or afterEach. I would recommend making sure the functionality works at all before evaluating the cookie you expect it to create.

I am not terribly familiar with Intern.JS but I believe from what I read the tests are only a test and once completed they remove information from the test so the next test can be performed. So, maybe you are missing when the cookie is in existence and when the test is completed it gets destroyed.

Kenneth Salomon
  • 1,352
  • 11
  • 18