4

I'm trying puppeteer and browserless/chrome (https://hub.docker.com/r/browserless/chrome) to test some automation scripts. I'm currently just running a browserless/chrome instance locally, connecting puppeteer to it with browserWSEndpoint.

It's all running locally, all in the same machine.

Everything pretty much works except the file upload code. Without the browserless connection (just launching puppeteer and a chromium instance) the code can upload the images without a problem, however, when relaying it to a the websocket, it apparently can't find the files, even if I supply the full path.

Here is the code i'm using:

const browser = await puppeteer.connect({
    browserWSEndpoint: 'ws://localhost:32769',
    headless: true
})
const page = await browser.newPage();
await page.goto('http://localhost:8080', {waitUntil: 'networkidle2'});

// Do some things

let testUpload = async () => {
    const upload = await page.$("input");
    await upload.uploadFile('test.jpg');
    await page.screenshot({path: 'test_s_'+Date.now()+'.png'});
}

// Do more things

I'm 100% sure the DOM exists at that point, and that the file exists, in the same folder.

Any pointing in the right direction is very helpfull.

Cheers!

Joe Bone
  • 41
  • 3

1 Answers1

2

How far does it run before you hit a problem? Does it get to the first '//some stuff' bit? Ive had some trouble in the past using 'networkidle2' and as of 1.0.0 it looks as though its been removed

Amature101
  • 159
  • 3
  • I don't really hit problems with this setup until I try and upload the images through the webservice. The `networkidle` tag is the only one that actually work with me, after a few tests. – Joe Bone Jan 17 '18 at 17:51
  • It still doesnt solve the issue, now instead of `networkidle`, `networkidle2` is introduced. What can we do to upload local files to the web dynamically. What if I have a 100 files in a local system, then what syntax is needed to be followed to upload them all, or do I have to run a loop for each and every file making the code more complex. – Code_Ninja May 08 '19 at 08:08
  • Plus I am super new to this, I just tried to use this syntax from JS or Gulp etc. => `/directory/*.jpg`, and the error saying `/directory/*.jpg` is not found. So in this case, what should be done? Usually, all syntax have this feature in there API. – Code_Ninja May 08 '19 at 08:09