Reputation: 294
I am using WebdriverIO to run a file-uploading .exe
created with AutoIt.
I am running the script inside a browser.execute
command. The file needs to run from the local drive and execute wd in Chrome browser.
Here is the code :
this.open("https://smallpdf.com/word-to-pdf");
this.SubmitClick("//div[@class='l0v3m7-3 hIetmU']");
this.BrowserSleep(2000);
scr.runAutoItScript('C:\\test\\desktopApp\\autoit', 'fileUpload.exe')
//scr have the child process:
const { execFile } = require('child_process').execFile;
module.exports = {
runAutoItScript(pathToScript, scriptName) {
console.info(`\n> Started execution of ${pathToScript} / ${scriptName} ...`);
execFile(`${pathToScript}/${scriptName}`, (error, stdout, stderr) => {
if (error) {
throw error;
} else {
console.info(`\n> Finished execution of ${scriptName}! | Output: ${stdout}`);
}
});
}
}
Upvotes: 0
Views: 1125
Reputation: 4112
I remember doing something like this in the past and I used NodeJS's child_process.execFile command. The documentation is heavy on child_process, so read carefully.
You should end up with something along the lines of:
const execFile = require('child_process').execFile;
let runAutoItScript = function(pathToScript, scriptName) {
console.info(`\n> Started execution of ${scriptName} ...`);
execFile(`${pathToScript}/${scriptName}`, (error, stdout, stderr) => {
if (error) {
throw error;
} else {
// > do something with the script output <
console.info(`\n> Finished execution of ${scriptName}! | Output: ${stdout}`);
}
});
}
runAutoItScript('/this/is/a/valid/path', 'AwesomeScript.exe');
Next step would be to minify it and make it run inside browser.execute
call.
You can find a lot of child_process examples online, just leverage the resources available to run the simplest script. Develop from there.
Upvotes: 1