Skip to content

Commit 3bf0f5d

Browse files
committed
Fixed Download file error and updated README
1 parent 08ad5e6 commit 3bf0f5d

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

Diff for: README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Scenario('Compare CPU Usage Images', async (I) => {
102102
});
103103
```
104104
The generated output and diff images can also be directly uploaded to AWS S3 by using the `upload` method which will upload both the output as well as diff image generated.
105-
The files will be uploaded to a folder named output inside of the bucket.
105+
The screenshot file will be uploaded to a folder named output and the diff file(if it exists) inside a folder named diff inside the bucket.
106106
```
107107
I.upload("AccessKeyId", "secretAccessKey", "region", "bucketName", "baseImage");
108108
```
@@ -112,6 +112,7 @@ Moreover, the base images can also be downloaded from S3 with the `download` met
112112
I.download("AccessKeyId", "secretAccessKey", "region", "bucketName", "baseImage");
113113
```
114114
You will need to store these base images inside a folder named base inside the bucket.
115+
Make sure to give correct file type extensions to both the `I.upload` and `I.download` methods.
115116

116117

117118

Diff for: index.js

+13-15
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const fs = require('fs');
33
const assert = require('assert');
44
const mkdirp = require('mkdirp');
55
const getDirName = require('path').dirname;
6-
const AWS = require('aws-sdk');
6+
const AWS = require("aws-sdk");
77

88
/**
99
* Resemble.js helper class for CodeceptJS, this allows screen comparison
@@ -104,7 +104,7 @@ class ResembleHelper extends Helper {
104104
*/
105105

106106
async upload(accessKeyId, secretAccessKey, region, bucketName, baseImage) {
107-
console.log("Entered upload");
107+
console.log("Starting Upload... ");
108108
const s3 = new AWS.S3({
109109
accessKeyId: accessKeyId,
110110
secretAccessKey: secretAccessKey,
@@ -149,24 +149,22 @@ class ResembleHelper extends Helper {
149149
*/
150150

151151
async download(accessKeyId, secretAccessKey, region, bucketName, baseImage) {
152-
console.log("Entered download");
153-
const s3 = new AWS.S3({region: region});
152+
console.log("Starting Download... ");
153+
const s3 = new AWS.S3({
154+
accessKeyId: accessKeyId,
155+
secretAccessKey: secretAccessKey,
156+
region: region
157+
});
154158
const params = {
155159
Bucket: bucketName,
156160
Key: `base/${baseImage}`
157161
};
158162

159-
const outStream = fs.createWriteStream(this.config.baseFolder + baseImage);
160-
const awsStream = s3.getObject(params, (uerr, data) => {
161-
if(uerr) throw uerr;
162-
console.log(`Base file downloaded successfully!`)
163-
}).createReadStream();
164-
165-
awsStream.pipe(outStream);
166-
awsStream.on('end', function() {
167-
console.log("successfully Downloaded");
168-
}).on('error', function() {
169-
console.log("Some error occured while downloading");
163+
s3.getObject(params, (err, data) => {
164+
if(err) console.error(err);
165+
console.log(this.config.baseFolder + baseImage);
166+
fs.writeFileSync(this.config.baseFolder + baseImage, data.Body);
167+
console.log(`Base Image Downloaded Successfully at ${this.config.baseFolder} as ${baseImage}`);
170168
});
171169
}
172170

0 commit comments

Comments
 (0)