DEV Community

Prudhvi D
Prudhvi D

Posted on

Appium failed to start: spawn appium ENOENT

I am getting this error , can someone please help.

this is my wdio.conf.js:
const fs = require('fs');
const path = require('path');
const allure = require('allure-commandline');

exports.config = {
runner: 'local',
hostname: '127.0.0.1', // Use manual Appium server if running separately
port: 4723, // Default Appium port
path: '/',
waitStartTime: 6000,
command: 'appium.cmd',

services: [
    ['appium', {
        args: {
            address: '0.0.0.0',
            basePath: '/',
            port: 4723, // Match the port used manually
            logLevel: 'debug',
            commandTimeout: '7200',
            sessionOverride: true,
            debugLogSpacing: true,
        },
        logPath: './appium_logs',
    }]
],

specs: [path.resolve(__dirname, '../test/specs/AppLogout.js')],
exclude: [],
maxInstances: 1, // Adjust as needed for parallel testing

capabilities: [{
    platformName: 'Android',
    'appium:deviceName': 'Pixel 3 API 31',
    'appium:platformVersion': '12.0',
    'appium:automationName': 'UIAutomator2',
    'waitforTimeout': 30000,
    'commandTimeout': 30000,
    'appium:app': path.join(process.cwd(), './app-release.apk'), // Adjusted path for APK file
}],

logLevel: 'trace', // Set to trace for detailed logs

bail: 0,

baseUrl: 'http://localhost',

waitforTimeout: 60000,
connectionRetryTimeout: 400000,
connectionRetryCount: 3,

framework: 'mocha',

reporters: ['spec', [
    'allure', {
        outputDir: 'allure-results',
        disableWebdriverStepsReporting: false,
        disableWebdriverScreenshotsReporting: false,
    }
]],

mochaOpts: {
    ui: 'bdd',
    timeout: 600000,
    require: [
        '@babel/register',
    ],
},

afterTest: async function (test, context, { error }) {
    if (error) {
        console.error(`Test failed: ${test.title}`);
        await browser.takeScreenshot();
    }
},

onPrepare: function () {
    console.log('Starting Appium...');
    const appiumProcess = require('child_process').spawn('appium', [
        '--base-path', '/',
        '--address', '0.0.0.0',
        '--port', '4723'
    ], { stdio: 'inherit' });

    appiumProcess.on('error', (err) => {
        console.error('Appium failed to start:', err.message);
    });
},

onComplete: function () {
    const reportError = new Error('Could not generate Allure report');
    const allureResultsPath = path.join(__dirname, 'allure-results');
    const allureReportPath = path.join(__dirname, 'allure-report');

    if (fs.existsSync(allureReportPath)) {
        console.log('Deleting old Allure report...');
        fs.rmSync(allureReportPath, { recursive: true });
    } else {
        console.log('No existing Allure report directory to delete.');
    }

    if (fs.existsSync(allureResultsPath)) {
        const files = fs.readdirSync(allureResultsPath);
        if (files.length === 0) {
            console.error('Allure results directory is empty. Report generation will fail.');
            return Promise.reject(reportError);
        }
    } else {
        console.error('Allure results directory does not exist. Report generation will fail.');
        return Promise.reject(reportError);
    }

    console.log('Generating Allure report...');
    const generation = allure(['generate', allureResultsPath, '--clean']);

    return new Promise((resolve, reject) => {
        const timeout = setTimeout(() => reject(reportError), 10000);

        generation.on('exit', (exitCode) => {
            clearTimeout(timeout);

            if (exitCode !== 0) {
                console.error('Allure report generation failed with exit code:', exitCode);
                return reject(reportError);
            }

            console.log('Allure report successfully generated.');
            resolve();
        });
    });
},
Enter fullscreen mode Exit fullscreen mode

};

Top comments (1)

Collapse
 
prudhvi_d_13e7d4580e7b009 profile image
Prudhvi D

@rahulraut333 ,
could you please help me ..