A JavaScript Appium smoke test proves that the Node client can create a mobile session, drive one visible screen, and close the session without leaving the device busy. Use this check after the Appium server and Android driver are installed, or before moving the same capability set into a larger WebdriverIO suite.
WebdriverIO is the JavaScript client recommended by the Appium quickstart. A small Mocha project keeps the session options, capabilities, locator, action, and assertion visible in one test file without generating a full test-runner scaffold.
This smoke test targets the Android Settings app through the UiAutomator2 driver. The Appium server must be listening at http://127.0.0.1:4723 with an emulator or device already available; if the server was started with the legacy /wd/hub base path, set the client path value to match that server.
Related: How to install Appium
Related: How to install the Appium Android driver
Related: How to start the Appium server
Related: How to configure Appium capabilities
$ mkdir appium-js-smoke
$ cd appium-js-smoke
$ npm init --yes
$ npm install --save-dev webdriverio mocha
WebdriverIO provides the remote() client used to open the Appium session, and Mocha supplies the test command and pass/fail output.
{
"scripts": {
"test": "mocha \"test/**/*.test.js\" --timeout 20000"
}
}
$ mkdir test
const assert = require('node:assert/strict'); const { remote } = require('webdriverio'); const capabilities = { platformName: 'Android', 'appium:automationName': 'UiAutomator2', 'appium:deviceName': 'Android', 'appium:appPackage': 'com.android.settings', 'appium:appActivity': '.Settings', }; describe('Android Settings Appium smoke test', function () { let driver; afterEach(async function () { if (driver) { await driver.deleteSession(); driver = undefined; } }); it('opens Battery settings', async function () { driver = await remote({ hostname: process.env.APPIUM_HOST || '127.0.0.1', port: Number(process.env.APPIUM_PORT || 4723), path: process.env.APPIUM_PATH || '/', logLevel: 'error', capabilities, }); const battery = await driver.$('//*[@text="Battery"]'); await battery.click(); const title = await driver.$('//*[@text="Battery"]'); assert.equal(await title.getText(), 'Battery'); }); });
Use a locator that exists on the target device if its Settings app does not show Battery on the first screen.
$ appium --address 127.0.0.1 --port 4723 --log-level info [Appium] Welcome to Appium v3.5.0 [Appium] Appium REST http interface listener started on http://127.0.0.1:4723
Keep this terminal open while the test runs. Install the uiautomator2 driver first if the server cannot create an Android session.
Related: How to start the Appium server
Related: How to install the Appium Android driver
$ npm test
> test
> mocha "test/**/*.test.js" --timeout 20000
Android Settings Appium smoke test
✔ opens Battery settings (579ms)
1 passing (585ms)
A passing result means WebdriverIO opened the Appium session, clicked the selected Settings element, read its text, and deleted the session in cleanup.