{"__v":0,"_id":"56b936d0578edc0d0023cfa5","category":{"__v":21,"_id":"56b8b0f7ddeb231700e69825","pages":["56b8b1b30094520d006b3c7b","56b8b1b39fc0de1700b60a20","56b8b1b386d2b0190070bd33","56b8b1b3578edc0d0023cefc","56b8b1b386d2b0190070bd34","56b8b1ec43bbd10d0081d15d","56b8b1ec9fc0de1700b60a21","56b8b1ec38b1070d002891fa","56b8b1ec0094520d006b3c7c","56b8b1ec578edc0d0023cefe","56b8b285ddeb231700e69829","56b8b28538b1070d002891fb","56b8b2855d75fe0d00fbcc6e","56b8b2850094520d006b3c7e","56b8b2850094520d006b3c7f","56b8b2d014feef0d00824140","56b8b2d08a9e7c0d004bb173","56b8b2d0ddeb231700e6982a","56b8b2d086d2b0190070bd3e","56b8b2d086d2b0190070bd3f","56b936d0578edc0d0023cfa5"],"project":"568fde81b700ce0d002f4b43","version":"568fde82b700ce0d002f4b46","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-02-08T15:15:03.713Z","from_sync":false,"order":2,"slug":"utilities","title":"Utilities"},"parentDoc":null,"project":"568fde81b700ce0d002f4b43","user":"568fffce769f210d0013258f","version":{"__v":23,"_id":"568fde82b700ce0d002f4b46","project":"568fde81b700ce0d002f4b43","createdAt":"2016-01-08T16:06:26.373Z","releaseDate":"2016-01-08T16:06:26.373Z","categories":["568fde82b700ce0d002f4b47","568ff0e504440a1700e4cbbd","569002f19ebef90d0087289d","569004f4769f210d00132599","5690056d9ebef90d008728a0","569005d394c5030d0028813a","5690067804440a1700e4cbe2","569137eb3c4f510d00ec9b92","56913815e56a790d008dbfe3","569138ba3c4f510d00ec9b93","5691392f3c4f510d00ec9b94","56913bbe72f2810d007e4cb0","56933b8d6ebadc0d005b71d2","56933b8d6ebadc0d005b71d3","569564facaa32519009c41e6","5696a319b6d61f0d00acfb40","5696a319a857080d0082e8e8","5697efe43503e40d0061f4d1","5697efe48d2a770d00d2fd16","569e9597ffccd10d00a05c59","56a7a1523d33bc2100793d5c","56a7a32ecf6d771700baeee8","56b8b0f7ddeb231700e69825"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":false,"codename":"bar","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-02-09T00:46:08.954Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"auth":"required","params":[],"url":""},"isReference":false,"order":4,"body":"# [Cypress.Blob.method()](#setion-usage)\n\nCypress proxies a [`Blob Utilities`](https://github.com/nolanlawson/blob-util) library and exposes it as `Cypress.Blob`.\n\nUse `Cypress.Blob` to convert `base64` strings to `blob` objects. Useful for testing uploads.\n\n***\n\n# Usage\n\n## Using an image fixture\n\n[block:code]\n{\n    \"codes\": [\n        {\n            \"code\": \"// programmatically upload the logo\\ncy\\n  .fixture(\\\"images/logo.png\\\").as(\\\"logo\\\")\\n  .get(\\\"input[type=file]\\\").then(function($input){\\n\\n    // convert the logo base64 string to a blob\\n    return Cypress.Blob.base64StringToBlob(this.logo, \\\"image/png\\\").then(function(blob){\\n\\n      // pass the blob to the fileupload jQuery plugin\\n      // which initiates a programmatic upload\\n      $input.fileupload(\\\"add\\\", {files: blob})\\n    })\\n  })\\n\",\n            \"language\": \"javascript\"\n        }\n    ]\n}\n[/block]\n\n## Getting dataUrl string\n\n[block:code]\n{\n    \"codes\": [\n        {\n            \"code\": \"return Cypress.Blob.imgSrcToDataURL(\\\"/assets/img/logo.png\\\").then(function(dataUrl){\\n\\n  // create an <img> element and set its src to the dataUrl\\n  var img = Cypress.$(\\\"<img />\\\", {src: dataUrl})\\n\\n  cy\\n    .get(\\\".utility-blob\\\").then(function($div){\\n      // append the image\\n      $div.append(img)\\n    })\\n    .get(\\\".utility-blob img\\\").click().should(\\\"have.attr\\\", \\\"src\\\", dataUrl)\\n})\\n\",\n            \"language\": \"javascript\"\n        }\n    ]\n}\n[/block]","excerpt":"Convert base64 strings to blob objects","slug":"cypress-blob","type":"basic","title":"Blob"}

Blob

Convert base64 strings to blob objects

# [Cypress.Blob.method()](#setion-usage) Cypress proxies a [`Blob Utilities`](https://github.com/nolanlawson/blob-util) library and exposes it as `Cypress.Blob`. Use `Cypress.Blob` to convert `base64` strings to `blob` objects. Useful for testing uploads. *** # Usage ## Using an image fixture [block:code] { "codes": [ { "code": "// programmatically upload the logo\ncy\n .fixture(\"images/logo.png\").as(\"logo\")\n .get(\"input[type=file]\").then(function($input){\n\n // convert the logo base64 string to a blob\n return Cypress.Blob.base64StringToBlob(this.logo, \"image/png\").then(function(blob){\n\n // pass the blob to the fileupload jQuery plugin\n // which initiates a programmatic upload\n $input.fileupload(\"add\", {files: blob})\n })\n })\n", "language": "javascript" } ] } [/block] ## Getting dataUrl string [block:code] { "codes": [ { "code": "return Cypress.Blob.imgSrcToDataURL(\"/assets/img/logo.png\").then(function(dataUrl){\n\n // create an <img> element and set its src to the dataUrl\n var img = Cypress.$(\"<img />\", {src: dataUrl})\n\n cy\n .get(\".utility-blob\").then(function($div){\n // append the image\n $div.append(img)\n })\n .get(\".utility-blob img\").click().should(\"have.attr\", \"src\", dataUrl)\n})\n", "language": "javascript" } ] } [/block]