hello_abhishek
hello_abhishek

Reputation: 545

Facing issuewhile uploading .jpg file in protractor

this.uploadFile = function() {

    var path = require('path');

    var fileToUpload = 'C:\\Users\\NEXTGEN\\Downloads\\images1.jpg',

    var absolutePath = path.resolve(__dirname, fileToUpload);

    element(by.css('input[type="file"]')).sendKeys(absolutePath);
    element(by.id('uploadButton')).click();
}

Error thrown in console:

var absolutePath = path.resolve(__dirname, fileToUpload);
            ^^^
SyntaxError: Unexpected token var

Any suggestion will be highly appreciable

Upvotes: 0

Views: 147

Answers (1)

AdityaReddy
AdityaReddy

Reputation: 3645

You have a , instead of ; and thus its unable to recognize it as end of line :)

Its here var fileToUpload = 'C:\\Users\\NEXTGEN\\Downloads\\images1.jpg',

Notice a , at the end. Since you posted this - one more suggestion. Since you are already providing the absolute path - you dont need this - var absolutePath = path.resolve(__dirname, fileToUpload);

Its needed only when you provide relative path & you need to convert to absolute before passing it onto upload element.Something like this

var fileToUpload = 'images1.jpg',
var absolutePath = path.resolve(__dirname, fileToUpload);

Upvotes: 2

Related Questions