### Install Dependencies with npm Source: https://github.com/testingbot/webdriverio-examples/blob/main/webdriver/examples/upload/README.md This command installs all necessary project dependencies using npm. It's crucial to run this command in the correct project directory (`webdriverio/webdriver/examples/upload`) to ensure all required packages are downloaded and installed properly. ```bash npm install ``` -------------------------------- ### Local vs Cloud Configuration for WebdriverIO Source: https://context7.com/testingbot/webdriverio-examples/llms.txt Illustrates two distinct WebdriverIO configuration patterns: one for local execution using ChromeDriver and another for cloud-based execution with TestingBot. It includes NPM scripts for running tests and environment setup instructions for cloud credentials. ```javascript // Local configuration with ChromeDriver exports.config = { specs: ['./../runner-specs/*.test.js'], capabilities: [{ browserName: 'chrome', 'goog:chromeOptions': { args: [ '--no-sandbox', '--disable-infobars' ] } }], logLevel: 'silent', screenshotPath: 'screenshots', waitforTimeout: 10000, framework: 'mocha', services: [['chromedriver']], // Local ChromeDriver service reporters: ['dot'] } // Cloud configuration with TestingBot exports.config = { specs: ['./../runner-specs/*.test.js'], capabilities: [{ browserName: 'chrome', browserVersion: 'latest', // W3C format platformName: 'WIN10', // W3C format 'tb:options': { // TestingBot vendor prefix build: 'my-build-name', name: 'my-test-name' } }], logLevel: 'debug', screenshotPath: 'screenshots', waitforTimeout: 10000, framework: 'mocha', services: [['testingbot']], // TestingBot service user: process.env.TB_KEY, // Credentials key: process.env.TB_SECRET, reporters: ['dot'] } // NPM scripts for execution { "scripts": { "test.local": "wdio test/configs/wdio.local.conf.js", "test.testingbot": "wdio test/configs/wdio.testingbot.conf.js" } } // Environment setup // export TB_KEY=your_key_here // export TB_SECRET=your_secret_here // npm install // npm run test.testingbot ``` -------------------------------- ### Configure TestingBot Upload Capabilities Source: https://github.com/testingbot/webdriverio-examples/blob/main/webdriver/examples/upload/README.md This configuration snippet shows how to set up TestingBot capabilities for file uploads. It specifies the URL of the file to be uploaded and the desired path on the TestingBot VM. Ensure these capabilities are correctly defined within your WebDriverIO test setup. ```javascript 'tb:options': { upload: 'https://testingbot.com/assets/logo.png', uploadFilepath: 'C:\\test\\logo.png' } ``` -------------------------------- ### Run WebDriverIO Tests on TestingBot Source: https://github.com/testingbot/webdriverio-examples/blob/main/webdriver/examples/upload/README.md This command executes the WebDriverIO tests configured to run on the TestingBot grid. Before running, ensure that your TestingBot API key and secret are set as environment variables (`TB_KEY` and `TB_SECRET`). ```bash npm run test.testingbot ``` -------------------------------- ### WebdriverIO Browser Testing with Mocha Source: https://context7.com/testingbot/webdriverio-examples/llms.txt Demonstrates browser automation using WebdriverIO with the Mocha testing framework and BDD-style syntax. It includes test specifications and a TestingBot configuration file for running tests on the cloud. Dependencies include WebdriverIO CLI, Mocha framework, and the TestingBot service. ```javascript // webdriver/examples/mocha/test/runner-specs/mocha.test.js const assert = require('assert') describe('google page', async function() { it('should have the right title', async function () { await browser.url('https://www.google.com') const title = await browser.getTitle() assert.equal(title, 'Google') }) }) ``` ```javascript // Configuration: webdriver/examples/mocha/test/configs/wdio.testingbot.conf.js exports.config = { specs: ['./../runner-specs/mocha.test.js'], capabilities: [{ browserName: 'chrome', browserVersion: 'latest', platformName: 'WIN10' }], logLevel: 'silent', framework: 'mocha', services: [['testingbot']], user: process.env.TB_KEY, key: process.env.TB_SECRET, reporters: ['dot'], mochaOpts: { ui: 'bdd' } } ``` -------------------------------- ### WebdriverIO Browser Testing with CucumberJS (BDD Gherkin) Source: https://context7.com/testingbot/webdriverio-examples/llms.txt Implements behavior-driven development for WebdriverIO tests using Gherkin syntax with CucumberJS. This example includes feature files, step definitions, and a TestingBot configuration. Dependencies include WebdriverIO CLI, CucumberJS, and the TestingBot service. ```gherkin # webdriver/examples/cucumberjs/test/features/google.feature Feature: Example feature As a user of Google I should be able to go to Google and see its correct title Scenario: Get title of website Given I go on the website "https://www.google.com/" Then should the title of the page be "Google" ``` ```javascript // webdriver/examples/cucumberjs/test/step-definitions/sample.step-definitions.js const { Given, When, Then } = require('@cucumber/cucumber') const assert = require('assert') Given('I go on the website {string}', async (url) => { await browser.url(url) }) Then('should the title of the page be {string}', async (expectedTitle) => { assert.equal(await browser.getTitle(), expectedTitle) }) ``` ```javascript // Configuration: webdriver/examples/cucumberjs/test/configs/wdio.testingbot.conf.js exports.config = { specs: ['./../features/**/*.feature'], framework: 'cucumber', services: [['testingbot']], user: process.env.TB_KEY, key: process.env.TB_SECRET, cucumberOpts: { require: ['./test/step-definitions/**/*.step-definitions.js'] } } ``` ```bash # Setup environment variables # export TB_KEY=your_testingbot_key # export TB_SECRET=your_testingbot_secret ``` -------------------------------- ### Appium Mobile App Automation with WebdriverIO and TestingBot Source: https://context7.com/testingbot/webdriverio-examples/llms.txt This snippet illustrates mobile app automation for Android and iOS using Appium with WebdriverIO. It includes a test case for a calculator app and a configuration file that sets up parallel testing on both platforms. The example highlights the use of resource ID selectors prefixed with a tilde and TestingBot capabilities for mobile testing. ```javascript // appium-app/examples/app-automation/test/runner-specs/mocha.test.js const assert = require('assert') describe('calculator', function() { it('should calculate a sum', async () => { const inputA = await $('~inputA') await inputA.waitForDisplayed(5000) await inputA.click() try { await inputA.addValue('10') } catch (e) {} const inputB = await $('~inputB') await inputB.waitForDisplayed(5000) await inputB.click() try { await inputB.addValue('5') } catch (e) {} const sumElement = await $('~sum') const sum = await sumElement.getText() assert.equal(sum, '15') // 10 + 5 }) }) // Configuration: appium-app/examples/app-automation/test/configs/wdio.testingbot.conf.js exports.config = { specs: ['./../runner-specs/mocha.test.js'], capabilities: [ { // Android 'appium:deviceName': 'Pixel 9', 'appium:platformVersion': '15', 'appium:app': 'https://testingbot.com/appium/sample.apk', platformName: 'Android', 'tb:options': { build: `TestingBot W3C Mobile Web build-${new Date().getTime()}` } }, { 'appium:deviceName': 'iPhone 16', 'appium:platformVersion': '18.3', 'appium:app': 'https://testingbot.com/appium/sample.zip', platformName: 'iOS', 'tb:options': { build: `TestingBot W3C Mobile Web build-${new Date().getTime()}` } } ], connectionRetryTimeout: 480000, // 8 minutes for device startup framework: 'mocha', services: [['testingbot']], user: process.env.TB_KEY, key: process.env.TB_SECRET } // Selectors use resource IDs with tilde prefix: ~inputA, ~inputB, ~sum // Multiple capabilities allow parallel testing on Android and iOS ``` -------------------------------- ### WebdriverIO Browser Testing with Jasmine Source: https://context7.com/testingbot/webdriverio-examples/llms.txt Showcases browser automation with WebdriverIO using the Jasmine testing framework, featuring an extended timeout configuration. The example includes test scripts and a TestingBot configuration. Key dependencies are WebdriverIO CLI, Jasmine framework, and the TestingBot service. ```javascript // webdriver/examples/jasmine/test/runner-specs/jasmine.spec.js const assert = require('assert') describe('google page', function() { it('should have the right title', async function () { await browser.url('https://www.google.com') const title = await browser.getTitle() assert.equal(title, 'Google') }) }) ``` ```javascript // Configuration: webdriver/examples/jasmine/test/configs/wdio.testingbot.conf.js exports.config = { specs: ['./../runner-specs/jasmine.spec.js'], capabilities: [{ browserName: 'chrome', browserVersion: 'latest', platformName: 'WIN10' }], framework: 'jasmine', services: [['testingbot']], user: process.env.TB_KEY, key: process.env.TB_SECRET, jasmineNodeOpts: { defaultTimeoutInterval: 9999999 } } ``` ```json // Package dependencies { "devDependencies": { "@wdio/cli": "^9.5.0", "@wdio/jasmine-framework": "^9.5.0", "@wdio/testingbot-service": "^9.5.0" } } ``` -------------------------------- ### Core WebdriverIO Browser APIs Source: https://context7.com/testingbot/webdriverio-examples/llms.txt Demonstrates essential browser automation commands provided by WebdriverIO. This includes navigation, page information retrieval, element selection using various selectors (CSS, Appium resource ID), element interactions, and waiting mechanisms. Assertions using Node.js assert module are also shown. ```javascript // Navigation await browser.url('https://www.example.com') await browser.back() await browser.forward() await browser.refresh() // Page information const title = await browser.getTitle() const url = await browser.getUrl() const source = await browser.getPageSource() // Element selection (CSS selectors) const element = await $('#id-selector') const element = await $('.class-selector') const element = await $('button[type="submit"]') const elements = await $$('.multiple-elements') // Appium resource ID selectors (mobile) const mobileElement = await $('~resourceId') // Element interactions await element.click() await element.setValue('text content') await element.addValue('append text') await element.clearValue() const text = await element.getText() const value = await element.getValue() const isDisplayed = await element.isDisplayed() // Wait commands await element.waitForDisplayed(5000) await element.waitForExist(5000) await element.waitForClickable(5000) // Custom wait conditions await browser.waitUntil(async () => { const element = await $('#dynamic-element') return await element.isDisplayed() }, { timeout: 5000, timeoutMsg: 'Element not displayed after 5 seconds' }) // Assertions (Node.js assert module) const assert = require('assert') assert.equal(actualValue, expectedValue) assert.strictEqual(actualValue, expectedValue) assert.ok(value, 'value should be truthy') ``` -------------------------------- ### Appium Mobile Web Testing (W3C) Source: https://context7.com/testingbot/webdriverio-examples/llms.txt Tests web applications in mobile browsers using Appium with the W3C WebDriver protocol. This configuration allows testing on both Android and iOS devices via TestingBot. It utilizes the standard WebdriverIO API. ```javascript // appium-web/examples/w3c/test/runner-specs/mocha.test.js const assert = require('assert') describe('google page', async function() { it('should have the right title', async function () { await browser.url('https://www.google.com') const title = await browser.getTitle() assert.equal(title, 'Google') }) }) ``` ```javascript // Configuration: appium-web/examples/w3c/test/configs/wdio.testingbot.conf.js exports.config = { capabilities: [ { // Android Chrome 'appium:deviceName': 'Pixel 8', 'appium:platformVersion': '14', browserName: 'chrome', platformName: 'Android', 'tb:options': { build: `TestingBot W3C Mobile Web build-${new Date().getTime()}` } }, { // iOS Safari 'appium:deviceName': 'iPhone 15', 'appium:platformVersion': '17.2', browserName: 'safari', platformName: 'iOS', 'tb:options': { build: `TestingBot W3C Mobile Web build-${new Date().getTime()}` } } ], connectionRetryTimeout: 480000, services: [['testingbot']], user: process.env.TB_KEY, key: process.env.TB_SECRET } // Uses browserName instead of appium:app // Tests web content in mobile browsers, not native apps // Same WebdriverIO API as desktop browser testing ``` -------------------------------- ### File Upload Testing with WebdriverIO and TestingBot Source: https://context7.com/testingbot/webdriverio-examples/llms.txt This snippet demonstrates how to test file upload functionality using WebdriverIO. It involves interacting with a file input element, submitting the form, and verifying the upload. The configuration section shows how to set up TestingBot capabilities for file uploads, where TestingBot downloads a file from a URL and makes it available on the VM. ```javascript // webdriver/examples/upload/test/runner-specs/mocha.test.js const assert = require('assert') describe('upload a file', async function() { it('should be able to upload a file', async function () { await browser.url('http://the-internet.herokuapp.com/upload') const uploadField = await $('#file-upload') await uploadField.setValue('C:\\test\\logo.png') const uploadButton = await $('#file-submit') uploadButton.click() await browser.waitUntil(async () => (await $('#uploaded-files').getText()) === 'logo.png', { timeout: 5000, timeoutMsg: 'expected file to be uploaded after 5s' }) }) }) // Configuration with file upload capability exports.config = { capabilities: [{ browserName: 'chrome', browserVersion: 'latest', platformName: 'WIN10', 'tb:options': { upload: 'https://testingbot.com/assets/logo.png', uploadFilepath: 'C:\\test\\logo.png' // Windows path // For macOS/Linux: '/tmp/logo.png' } }], services: [['testingbot']], user: process.env.TB_KEY, key: process.env.TB_SECRET } // TestingBot downloads the file from 'upload' URL and saves it to 'uploadFilepath' // Test can then reference the file using the VM-local path ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.