I am writing tests in protractor which a JS based framework and selenium test stack for running tests. I am facing an issue where I have to test file upload.
Problem
Thanks to @alecxe for his answer!
I just had this situation, trying to upload some files to BrowserStack. In my case I'm using Cucumber - Protractor - NodeJs - BrowserStack. This code is already tested, working in local env and BorwserStack.
let path = require('path');
let remote = require('selenium-webdriver/remote');
this.When(/^I upload a file$/, () => {
browser.setFileDetector(new remote.FileDetector());
var fileToUpload = '../image_with_title.jpg';
var absolutePath = path.join(__dirname, fileToUpload);
page.fileupload.sendKeys(absolutePath);
});
The magic line is:
let remote = require('selenium-webdriver/remote');