### Write iOS Test Scripts with WebdriverIO Source: https://context7.com/browserstack/webdriverio-appium-app-browserstack/llms.txt Create test scripts for iOS applications using accessibility identifiers and WebdriverIO's element interaction methods. This example verifies that the displayed output text matches the entered input text. ```javascript // first_test.js - iOS text verification test var assert = require('assert'); describe('Text Verification', () => { it('should match displayed text with input text', async () => { // Navigate to text input section var textButton = await $(`~Text Button`); await textButton.waitForDisplayed({ timeout: 30000 }); await textButton.click(); // Enter text in input field var textInput = await $(`~Text Input`); await textInput.waitForDisplayed({ timeout: 30000 }); await textInput.click() await textInput.addValue("hello@browserstack.com"+"\n"); // Verify output matches input var textOutput = await $(`~Text Output`); await textOutput.waitForDisplayed({ timeout: 30000 }); var value = await textOutput.getText(); if (value === "hello@browserstack.com") assert(true) else assert(false) }); }); ``` -------------------------------- ### Configure Local Testing with BrowserStack Tunnel Source: https://context7.com/browserstack/webdriverio-appium-app-browserstack/llms.txt Enable BrowserStack Local to test apps accessing resources behind firewalls. Uses lifecycle hooks to start and stop the local tunnel. ```javascript // local.conf.js - Local testing with BrowserStack tunnel var browserstack = require('browserstack-local'); exports.config = { user: process.env.BROWSERSTACK_USERNAME || 'BROWSERSTACK_USERNAME', key: process.env.BROWSERSTACK_ACCESS_KEY || 'BROWSERSTACK_ACCESS_KEY', updateJob: false, specs: [ './examples/run-local-test/specs/local_test.js' ], exclude: [], capabilities: [{ project: "First Webdriverio Android Project", build: 'Webdriverio Android Local', name: 'local_test', device: 'Samsung Galaxy S22 Ultra ', os_version: "12.0", app: process.env.BROWSERSTACK_APP_ID || 'bs://', 'browserstack.local': true, 'browserstack.debug': true }], logLevel: 'info', coloredLogs: true, screenshotPath: './errorShots/', baseUrl: '', waitforTimeout: 10000, connectionRetryTimeout: 90000, connectionRetryCount: 3, framework: 'mocha', mochaOpts: { ui: 'bdd', timeout: 20000 }, // Code to start browserstack local before start of test onPrepare: (config, capabilities) => { console.log("Connecting local"); return new Promise( (resolve, reject) => { exports.bs_local = new browserstack.Local(); exports.bs_local.start({'key': exports.config.key }, (error) => { if (error) return reject(error); console.log('Connected. Now testing...'); resolve(); }); }); }, // Code to stop browserstack local after end of test onComplete: (capabilties, specs) => { console.log("Closing local tunnel"); return new Promise( (resolve, reject) => { exports.bs_local.stop( (error) => { if (error) return reject(error); console.log("Stopped BrowserStackLocal"); resolve(); }); }); } }; ``` -------------------------------- ### Write Android Test Scripts with WebdriverIO Source: https://context7.com/browserstack/webdriverio-appium-app-browserstack/llms.txt Create Mocha test suites for Android applications using WebdriverIO's element selectors. This example demonstrates searching Wikipedia using accessibility IDs and Android UiSelector queries, and verifying search results. ```javascript // first_test.js - Android Wikipedia search test var assert = require('assert'); describe('Search Wikipedia Functionality', () => { it('can find search results', async () => { // Select element using accessibility id var searchSelector = await $(`~Search Wikipedia`); await searchSelector.waitForDisplayed({ timeout: 30000 }); await searchSelector.click(); // Select element using Android UiSelector var insertTextSelector = await $('android=new UiSelector().resourceId("org.wikipedia.alpha:id/search_src_text")'); await insertTextSelector.waitForDisplayed({ timeout: 30000 }); await insertTextSelector.addValue("Browsertack"); await browser.pause(5000); // Select multiple elements by class name var allProductsName = await $$(`android.widget.TextView`); assert(allProductsName.length > 0); }); }); ``` -------------------------------- ### Load Multiple Test Files Sequentially Source: https://context7.com/browserstack/webdriverio-appium-app-browserstack/llms.txt Organizes and executes multiple test files by requiring them in a single entry point file, ensuring sequential loading of individual test modules. ```javascript // multiple_test.js - Load and run multiple test files var specs = [ './multiple/test_01.js', './multiple/test_02.js', './multiple/test_03.js' ]; for (var i = specs.length - 1; i >= 0; i--) { require(specs[i]); } ``` -------------------------------- ### Environment Variables for BrowserStack Credentials Source: https://context7.com/browserstack/webdriverio-appium-app-browserstack/llms.txt Sets up BrowserStack credentials and app identifiers using environment variables for secure authentication, avoiding hardcoding sensitive information. ```bash # Set BrowserStack credentials export BROWSERSTACK_USERNAME="your_username" export BROWSERSTACK_ACCESS_KEY="your_access_key" # Set the uploaded app ID from BrowserStack export BROWSERSTACK_APP_ID="bs://hashed-app-id-from-upload" # Then run tests cd android && npm test ``` -------------------------------- ### Configure WebdriverIO for BrowserStack App Automate Source: https://context7.com/browserstack/webdriverio-appium-app-browserstack/llms.txt Set up WebdriverIO to connect to BrowserStack App Automate by defining credentials, device capabilities, and test specifications. Ensure BrowserStack username, access key, and app ID are set as environment variables or replaced with actual values. ```javascript // first.conf.js - Basic Android test configuration exports.config = { user: process.env.BROWSERSTACK_USERNAME || 'BROWSERSTACK_USERNAME', key: process.env.BROWSERSTACK_ACCESS_KEY || 'BROWSERSTACK_ACCESS_KEY', updateJob: false, specs: [ './examples/run-first-test/specs/first_test.js' ], exclude: [], capabilities: [{ project: "First Webdriverio Android Project", build: 'Webdriverio Android', name: 'first_test', device: 'Samsung Galaxy S22 Ultra ', os_version: "12.0", app: process.env.BROWSERSTACK_APP_ID || 'bs://', 'browserstack.debug': true }], logLevel: 'info', coloredLogs: true, screenshotPath: './errorShots/', baseUrl: '', waitforTimeout: 10000, connectionRetryTimeout: 90000, connectionRetryCount: 3, framework: 'mocha', mochaOpts: { ui: 'bdd', timeout: 20000 } }; ``` -------------------------------- ### Configure Android Parallel Tests Source: https://context7.com/browserstack/webdriverio-appium-app-browserstack/llms.txt Define multiple Android device capabilities and use commonCapabilities for shared settings. maxInstances controls concurrent test execution. ```javascript // parallel.conf.js - Android parallel test configuration exports.config = { user: process.env.BROWSERSTACK_USERNAME || 'BROWSERSTACK_USERNAME', key: process.env.BROWSERSTACK_ACCESS_KEY || 'BROWSERSTACK_ACCESS_KEY', updateJob: false, specs: [ './examples/run-parallel-test/specs/single_test.js' ], exclude: [], maxInstances: 10, commonCapabilities: { project: "First Webdriverio Android Project", build: 'Webdriverio Android Parallel', name: 'parallel_test', app: process.env.BROWSERSTACK_APP_ID || 'bs://', 'browserstack.debug': true }, capabilities: [{ device: 'Samsung Galaxy S22 Ultra ', os_version: "12.0" }, { device: 'Google Pixel 8 Pro', os_version: "14.0" }], logLevel: 'info', coloredLogs: true, screenshotPath: './errorShots/', baseUrl: '', waitforTimeout: 10000, connectionRetryTimeout: 90000, connectionRetryCount: 3, framework: 'mocha', mochaOpts: { ui: 'bdd', timeout: 20000 } }; // Code to support common capabilities exports.config.capabilities.forEach(function(caps){ for(var i in exports.config.commonCapabilities) caps[i] = caps[i] || exports.config.commonCapabilities[i]; }); ``` -------------------------------- ### Configure iOS Parallel Tests Source: https://context7.com/browserstack/webdriverio-appium-app-browserstack/llms.txt Configure parallel testing for iOS devices with different iPhone models and iOS versions running the same test suite simultaneously. ```javascript // parallel.conf.js - iOS parallel test configuration exports.config = { user: process.env.BROWSERSTACK_USERNAME || 'BROWSERSTACK_USERNAME', key: process.env.BROWSERSTACK_ACCESS_KEY || 'BROWSERSTACK_ACCESS_KEY', updateJob: false, specs: [ './examples/run-parallel-test/specs/single_test.js' ], exclude: [], maxInstances: 10, commonCapabilities: { project: "First Webdriverio iOS Project", build: 'Webdriverio iOS Parallel', name: 'parallel_test', app: process.env.BROWSERSTACK_APP_ID || 'bs://', 'browserstack.debug': true }, capabilities: [{ device: "iPhone 14 Pro Max ", os_version: "16" }, { device: "iPhone 15", os_version: "17" }], logLevel: 'info', coloredLogs: true, screenshotPath: './errorShots/', baseUrl: '', waitforTimeout: 10000, connectionRetryTimeout: 90000, connectionRetryCount: 3, framework: 'mocha', mochaOpts: { ui: 'bdd', timeout: 40000 } }; // Code to support common capabilities exports.config.capabilities.forEach(function(caps){ for(var i in exports.config.commonCapabilities) caps[i] = caps[i] || exports.config.commonCapabilities[i]; }); ``` -------------------------------- ### npm Scripts for Test Execution Source: https://context7.com/browserstack/webdriverio-appium-app-browserstack/llms.txt Defines npm scripts in package.json to execute various test configurations, including single tests, parallel runs, local testing, and all tests sequentially. ```bash # Install dependencies cd android # or cd ios npm install # Run single first test npm run first # Equivalent to: ./node_modules/.bin/wdio examples/run-first-test/first.conf.js # Run parallel tests on multiple devices npm run parallel # Equivalent to: ./node_modules/.bin/wdio examples/run-parallel-test/parallel.conf.js # Run local testing with tunnel npm run local # Equivalent to: ./node_modules/.bin/wdio examples/run-local-test/local.conf.js # Run multiple test files npm run multiple # Equivalent to: ./node_modules/.bin/wdio examples/run-multiple-test/multiple.conf.js # Run all tests sequentially npm test # Equivalent to: npm run first && npm run local && npm run parallel ``` -------------------------------- ### Local Tunnel Testing with Screenshot on Failure Source: https://context7.com/browserstack/webdriverio-appium-app-browserstack/llms.txt Verifies BrowserStack Local tunnel connectivity and captures a screenshot if the expected element is not found, aiding in debugging network issues. ```javascript // local_test.js - Verify BrowserStack Local tunnel connection var path = require('path'); var assert = require('assert'); describe('BrowserStack Local Testing', () => { it('can check tunnel working', async () => { var searchSelector = await $('android=new UiSelector().resourceId("com.example.android.basicnetworking:id/test_action")'); await searchSelector.waitForDisplayed({ timeout: 30000 }); await searchSelector.click(); var insertTextSelector = await $(`android.widget.TextView`); await insertTextSelector.waitForDisplayed({ timeout: 30000 }); var testElement = null; try { var textElement = await $('android=new UiSelector().textContains("active connection is")'); await textElement.waitForDisplayed({ timeout: 30000 }); testElement = textElement; } catch { // Capture screenshot on failure for debugging var screenshotPath = path.resolve(__dirname, 'screenshot.png'); await browser.saveScreenshot(screenshotPath); console.log('Screenshot stored at ' + screenshotPath); throw new Error('Cannot find the needed TextView element from app'); } var matchedString = await testElement.getText(); console.log(matchedString); assert(matchedString.indexOf('The active connection is wifi') !== -1); assert(matchedString.indexOf('Up and running') !== -1); }); }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.