question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question]How to add cookie to cookie.json and which elements are required?

See original GitHub issue
  • env:
    • node: V8.9.4, BackstopJS v3.1.19, tomcat : 7.0.85
  • test flow:
  1. config tomcat-user , startup tomcat , listening port :8080, and service is working, tomcat-user can access tomcat example system;

  2. execute “backstop init” to generate test project and config backstop.json : ` { “id”:“backstop_default”, “viewports”:[ { “label”:“tablet”, “width”:1024, “height”:768 } ], “onBeforeScript”:“chromy/onBefore.js”, “onReadyScript”:“chromy/onReady.js”, “scenarios”:[ { “label”:“Tomcat Homepage”, “cookiePath”:“backstop_data/engine_scripts/cookies.json”, “url”:“http://localhost:8080/manager/status”, “referenceUrl”:“”, “readyEvent”:“”, “readySelector”:“”, “delay”:10, “hideSelectors”:[

         ],
         "removeSelectors":[
    
         ],
         "hoverSelector":"",
         "clickSelector":"",
         "postInteractionWait":"",
         "selectors":[
    
         ],
         "selectorExpansion":true,
         "misMatchThreshold":0.1,
         "requireSameDimensions":true
     }
    

    ], “paths”:{ “bitmaps_reference”:“backstop_data/bitmaps_reference”, “bitmaps_test”:“backstop_data/bitmaps_test”, “engine_scripts”:“backstop_data/engine_scripts”, “html_report”:“backstop_data/html_report”, “ci_report”:“backstop_data/ci_report” }, “report”:[ “browser” ], “engine”:“chrome”, “engineFlags”:[

    ], “asyncCaptureLimit”:5, “asyncCompareLimit”:50, “debug”:true, “debugWindow”:true }

`

  1. config cookie.json file : `

[ { “domain”:“.127.0.0.1:8080”, “path”:“/”, “name”:“tomcat”, “value”:“tomcat”, “expirationDate”:1551261424, “hostOnly”:false, “httpOnly”:false, “secure”:false, “session”:false } ]

` 4. executed “backstop reference”, and debugWindow notice to input tomcat-user and password. image

  1. change context of cookie.json to “SESSIONID” (copy from browser) jsessionid image cookies

  2. run “backstop reference” and notice authorization. but it works successfully in browser. image

  • my question:
  1. how to set cookies in cookie.json file and what elements are required?
  2. are the username and password fields which in cookie.json parts of page submit-form?
  3. can backstopJS work with cookie-info generated by browser?

thanks~

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
Kenithcommented, Mar 1, 2018

@heaven1025 your cookies is right. If you use chrome, try to find the backstop_data/chromy/loadCookies.js, replace the cookie.url = 'https://' + cookie.domain; => cookie.url = 'http://' + cookie.domain;

Here is the full sample:

var fs = require('fs');

module.exports = function (chromy, scenario) {
  var cookies = [];
  var cookiePath = scenario.cookiePath;

  // READ COOKIES FROM FILE IF EXISTS
  if (fs.existsSync(cookiePath)) {
    cookies = JSON.parse(fs.readFileSync(cookiePath));
  }

  // MUNGE COOKIE DOMAIN FOR CHROMY USAGE
  cookies = cookies.map(cookie => {
    cookie.url = 'http://' + cookie.domain;
    delete cookie.domain;
    return cookie;
  });

  // SET COOKIES VIA CHROMY
  chromy.setCookie(cookies);
  console.log('Cookie state restored with:', JSON.stringify(cookies, null, 2));
};

1reaction
heaven1025commented, Mar 5, 2018

@Kenith thanks for help at first!! And it works successfully after changing “https” to “http” protocol. Thanks very much~

But I want to know reasons, is user authentication specified by the Chrome browser?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating cookies from Json file - does the type of the value ...
Cookie () constructor accepts only strings as Value and so I am not able to add integers, booleans and not nullable elements, 'cause...
Read more >
Everything You Need to Know About Cookies for Web ...
Here's how to make it so a cookie only works on the about page at /about : document. cookie = 'dark_mode=true; path=/about'; Now...
Read more >
Cookies, Sessions, JSON Web Tokens (JWT) and More
Let's learn about cookies, CSRF protection, sessions, JSON Web Tokens, and localStorage as ways of having a server be able to "remember" or ......
Read more >
HTTP Cookies in Node.js
Cookies have various functionality, they can be used for maintaining sessions and adding user-specific features in your web app.
Read more >
JavaScript Cookies
Cookies let you store user information in web pages. What are Cookies? Cookies are data, stored in small text files, on your computer....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found