Search code examples
webdriver-io

WebdriverIO - How to run .bat script using WebDriverIO


Is there a possibility to run .bat file (script) using WebdriverIO, preferable into before hook, located into WDIO.conf file?

before: function () {
        console.log("this is before");
    },

Solution

  • Yeah, it's possible you just need to import execFileSync and join methods and then you can run it like that:

    const { execFileSync } = require('child_process');
    const { join } = require('path');
    
    before: function () {
       execFileSync(join(__dirname, './script.bat'));
    }
    

    Read more about execFileSync method here