├── .gitignore ├── LICENSE ├── README.md ├── config ├── babel.config.js ├── wdio.androidBrowser.js └── wdio.conf.js ├── package-lock.json ├── package.json ├── sample.mjpeg └── test └── specs └── camera.injection.spec.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Alphabin Technology Consulting 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Appium Mobile UI Example 2 | Welcome to the mobile UI automation testing project using Appium. This guide will help you set up the project and execute mobile automation tests using Appium, WebdriverIO, and Node.js. 3 | 4 | ## Prerequisites 5 | Before getting started with the setup, ensure that you have the following prerequisites installed on your system: 6 | - Node.js: Install Node.js version 14.0 or higher from the official website. 7 | - Appium: Install the Appium server globally by running the following command in your terminal: 8 | ``` 9 | npm install -g appium 10 | ``` 11 | 12 | ## Setup and Start Appium server 13 | To set up and start the Appium server, follow the steps below: 14 | 1. Install the Appium server by running the following command in your terminal: 15 | ``` 16 | npm install -g appium 17 | ``` 18 | 2. Start the Appium server locally by running the following command in your terminal: 19 | ``` 20 | appium 21 | ``` 22 | Note: If you encounter a Chrome driver version mitmatch error message, use the following command to restart Appium with the `--allow-insecure chromedriver_autodownload` argument: 23 | ``` 24 | appium --allow-insecure chromedriver_autodownload 25 | ``` 26 | 27 | ## Setup code 28 | To set up the coode and project dependencies, follow the steps below: 29 | 30 | 1. Clone the repository: 31 | ``` 32 | git clone https://github.com/alphabin-01/appium-camera-injection 33 | ``` 34 | 2. Navigate to the project directory: 35 | ``` 36 | cd appium-camera-injection 37 | ``` 38 | 3. Install the project dependencies by running the following command: 39 | ``` 40 | npm install 41 | ``` 42 | 43 | ## Run the Tests 44 | To execute the mobile automation tests, run the following command: 45 | ``` 46 | npm run androidBrowser 47 | ``` 48 | This command will run the tets on an Android device using a web browser. 49 | 50 | Feel free to explore and enhance the Appium mobile automation testing project to suit your specific mobile testing needs. 51 | Happy testing! 😊 52 | -------------------------------------------------------------------------------- /config/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "presets": [ 3 | [ 4 | "@babel/preset-env", 5 | { 6 | "targets": { 7 | "node": "14" 8 | } 9 | } 10 | ] 11 | ] 12 | } -------------------------------------------------------------------------------- /config/wdio.androidBrowser.js: -------------------------------------------------------------------------------- 1 | const { config } = require('./wdio.conf'); 2 | 3 | config.capabilities = [ 4 | { 5 | maxInstances: 1, 6 | platformName: 'Android', 7 | "appium:platformVersion": '12', 8 | "appium:deviceName": 'emulator-5554', 9 | browserName: 'chrome', 10 | "appium:chromeOptions": { 11 | args: [ 12 | 'allow-file-access-from-files', 13 | 'use-fake-device-for-media-stream', 14 | 'use-file-for-fake-video-capture="/storage/emulated/0/Android/data/com.android.chrome/files/Download/sample.mjpeg"', 15 | 'use-fake-ui-for-media-stream', 16 | 'disable-translate', 17 | 'no-process-singleton-dialog', 18 | 'mute-audio', 19 | ] 20 | } 21 | } 22 | ]; 23 | 24 | exports.config = config; -------------------------------------------------------------------------------- /config/wdio.conf.js: -------------------------------------------------------------------------------- 1 | exports.config = { 2 | specs: [ 3 | './test/specs/**/camera.injection.spec.js' 4 | ], 5 | exclude: [ 6 | // 'path/to/excluded/files' 7 | ], 8 | maxInstances: 10, 9 | port: 4723, 10 | path: '/wd/hub', 11 | logLevel: 'info', 12 | bail: 0, 13 | baseUrl: 'https://webcamtests.com/', 14 | waitforTimeout: 10000, 15 | connectionRetryTimeout: 120000, 16 | connectionRetryCount: 3, 17 | framework: 'mocha', 18 | mochaOpts: { 19 | ui: 'bdd', 20 | timeout: 60000 21 | }, 22 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "demo-camera-injection", 3 | "version": "1.0.0", 4 | "description": "Camera Injection Demo", 5 | "main": "index.js", 6 | "scripts": { 7 | "wdio": "wdio config/wdio.conf.js", 8 | "androidBrowser": "wdio config/wdio.androidBrowser.js" 9 | }, 10 | "keywords": [ 11 | "camera-injection", 12 | "appium", 13 | "webdriverIO", 14 | "demo" 15 | ], 16 | "author": "", 17 | "license": "MIT", 18 | "devDependencies": { 19 | "@babel/core": "^7.17.5", 20 | "@babel/preset-env": "^7.16.11", 21 | "@babel/register": "^7.17.0", 22 | "@badisi/wdio-harness": "^1.0.3", 23 | "@wdio/appium-service": "^7.19.1", 24 | "@wdio/cli": "^7.16.16", 25 | "@wdio/local-runner": "^7.16.16", 26 | "@wdio/mocha-framework": "^7.16.15", 27 | "appium": "^1.22.3", 28 | "wdio-wait-for": "^2.2.2" 29 | }, 30 | "dependencies": { 31 | "chromedriver": "^91.0.1" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sample.mjpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alphabin-qa/appium-camera-injection/311f5ebe6966f27b90445ef2cfff9928ca5e14b7/sample.mjpeg -------------------------------------------------------------------------------- /test/specs/camera.injection.spec.js: -------------------------------------------------------------------------------- 1 | require("chromedriver") 2 | const fs = require("fs") 3 | const { config } = require('../../config/wdio.conf'); 4 | 5 | describe('Face camera demo', () => { 6 | it('should be able to interact with face camera in website', async () => { 7 | const videoObject = fs.readFileSync("sample.mjpeg") 8 | const encoded = new Buffer.from(videoObject).toString("base64") 9 | await driver.pushFile(`/storage/emulated/0/Android/data/com.android.chrome/files/Download/sample.mjpeg`, encoded) 10 | 11 | await browser.pause(2000) 12 | await browser.url(config.baseUrl) 13 | await browser.pause(6000) 14 | }); 15 | }); --------------------------------------------------------------------------------