### Search for Capability Examples Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/DOCUMENTATION_MANIFEST.md Use grep to find examples related to browser capabilities. ```bash grep -r "browserName" /workspace/home/output/ ``` -------------------------------- ### Basic BrowserStack Service Setup Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/INDEX.md A minimal configuration for integrating the BrowserStack service with WebDriverIO. ```javascript // wdio.conf.js exports.config = { // ... other configurations user: process.env.BROWSERSTACK_USERNAME, key: process.env.BROWSERSTACK_ACCESS_KEY, services: ["browserstack"], // ... other configurations }; ``` -------------------------------- ### Browser Capabilities Example Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/configuration.md Specifies the capabilities for a specific browser, including its name, version, and operating system details. This example shows configuration for Chrome on Windows. ```javascript { browserName: 'chrome', browserVersion: 'latest', 'bstack:options': { os: 'Windows', osVersion: '10' } } ``` -------------------------------- ### Local Test Execution Example Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/INDEX.md Illustrates a local test execution scenario. This snippet is part of the test framework guide. ```javascript describe("My local test suite", () => { it("should run a local test", async () => { // Local test logic here await expect(true).toBe(true); }); }); // This is a 10-line example from local_test.js ``` -------------------------------- ### Example Usage of Global Expect Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/api-reference-webdriverio.md Demonstrates how to use the globally available expect function for making assertions in tests. ```javascript expect(actualValue).to.equal(expectedValue); expect(array).to.include(item); ``` -------------------------------- ### Parallel Test Capabilities Example Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/element-selection-guide.md Example of parallel test capabilities for different browsers and devices. Ensure element selectors are robust for cross-platform compatibility. ```javascript capabilities: [ { browserName: 'chrome', /* Windows */ }, { browserName: 'safari', /* macOS */ }, { browserName: 'chrome', 'bstack:options': { deviceName: 'Samsung Galaxy S20' } } ] ``` -------------------------------- ### BrowserStack Service Configuration for Local Testing Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/INDEX.md Configuration example for the BrowserStack service to enable local testing with a named tunnel. ```javascript // wdio.conf.js exports.config = { // ... other configurations user: process.env.BROWSERSTACK_USERNAME, key: process.env.BROWSERSTACK_ACCESS_KEY, services: [ ["browserstack", { // Enable BrowserStack Local tunnel browserstackLocal: true, // Configure local tunnel options opts: { localIdentifier: "my_named_tunnel", forcelocal: true } }] ], // ... other configurations }; ``` -------------------------------- ### Capability Merge Logic Example Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/wdio-configuration-detailed.md Illustrates the logic for merging common capabilities into individual capabilities. Individual capability values take precedence in case of conflicts. ```javascript exports.config.capabilities.forEach(function (caps) { for (var i in exports.config.commonCapabilities) caps[i] = { ...caps[i], ...exports.config.commonCapabilities[i]}; }); ``` ```javascript // Input: capability + commonCapabilities { browserName: 'chrome', 'bstack:options': { os: 'Windows', osVersion: '10' } } + { 'bstack:options': { buildName: 'build' } } // Output: merged capability { browserName: 'chrome', 'bstack:options': { os: 'Windows', osVersion: '10', buildName: 'build' } } ``` -------------------------------- ### Local Testing Setup Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/INDEX.md Enable and configure BrowserStack Local for testing internal websites or staging environments. ```javascript services: [['browserstack', { browserstackLocal: true, opts: { localIdentifier: 'tunnel-1' } }]] ``` -------------------------------- ### Run WebdriverIO with Default Configuration Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/wdio-configuration-detailed.md Execute WebdriverIO tests using the default configuration file (conf/wdio.conf.js or conf/test.conf.js). This is the simplest way to start your test runs. ```bash npx wdio ``` -------------------------------- ### macOS Safari Capability Configuration Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/browserstack-capabilities.md Example capability configuration for running tests on the latest Safari browser on macOS Big Sur. ```javascript { browserName: 'safari', browserVersion: 'latest', 'bstack:options': { os: 'OS X', osVersion: 'Big Sur' } } ``` -------------------------------- ### Run WebdriverIO with Specific Configuration Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/wdio-configuration-detailed.md Execute WebdriverIO tests by explicitly providing the path to a specific configuration file. This allows for flexible test setups. ```bash npx wdio conf/test.conf.js ``` ```bash npx wdio conf/local-test.conf.js ``` -------------------------------- ### Console Output Example Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/test-execution-guide.md WebDriverIO logs connection details, test progress, and results to the console during test execution. ```text [0-0] RUNNING in chrome - /tests/specs/test.js [0-0] PASSED in chrome - /tests/specs/test.js (45.123s) ``` -------------------------------- ### BrowserStack Service Configuration for Parallel Tests Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/INDEX.md Example configuration for the BrowserStack service to enable parallel test execution with a dynamic build identifier. ```javascript // wdio.conf.js exports.config = { // ... other configurations user: process.env.BROWSERSTACK_USERNAME, key: process.env.BROWSERSTACK_ACCESS_KEY, services: [ ["browserstack", { // Enable BrowserStack parallel tests browserstackLocal: true, // Set build identifier using environment variables buildIdentifier: `${process.env.BUILD_NUMBER} - ${process.env.JOB_NAME}` }] ], // ... other configurations }; ``` -------------------------------- ### Parallel Test Execution Example Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/INDEX.md Demonstrates parallel test execution using Mocha BDD. This snippet is part of the test framework guide. ```javascript describe("My parallel test suite", () => { it("should run a test in parallel", async () => { // Test logic here await expect(true).toBe(true); }); it("should run another test in parallel", async () => { // Another test logic await expect(false).toBe(false); }); }); describe("Another suite", () => { it("should also run in parallel", async () => { await expect(1).toBe(1); }); }); // This is a 23-line example from test.js ``` -------------------------------- ### Expect Assertion Style Examples Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/test-framework-guide.md Demonstrates common assertion patterns using Chai's expect style. Ensure expect is imported globally or locally before use. ```javascript expect(value).to.equal(expected); expect(array).to.include(item); expect(value).to.be.true; ``` -------------------------------- ### Error Handling Example Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/test-execution-guide.md Example of an error message indicating a failed test condition, such as a title mismatch. ```text Error: Condition failed: Title didn't match with BrowserStack at Browser. (path/to/file.js:line) ``` -------------------------------- ### Set BrowserStack Credentials and Run Tests Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/test-framework-guide.md Configures essential BrowserStack environment variables for authentication and initiates the test execution command. This is a common setup for CI/CD pipelines. ```bash export BROWSERSTACK_USERNAME=username export BROWSERSTACK_ACCESS_KEY=key npm run test ``` -------------------------------- ### Navigate to URL and Get Title Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/INDEX.md Use `browser.url()` to navigate to a web page and `browser.getTitle()` to retrieve the page's title. ```javascript await browser.url("https://example.com"); const title = await browser.getTitle(); ``` -------------------------------- ### Initialize Chai Assertions Globally Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/test-framework-guide.md Sets up Chai's expect and should assertion styles globally for use in tests. This is typically done in the global setup section of the configuration file. ```javascript global.expect = chai.expect; chai.Should(); ``` -------------------------------- ### Parallel Testing with BStackDemo Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/test-framework-guide.md Example of a test case that adds a product to the cart on BStackDemo. Includes URL navigation, title verification, element interaction, and waiting for cart updates. ```javascript describe("Testing with BStackDemo", () => { it("add product to cart", async () => { await browser.url("https://bstackdemo.com/"); await browser.waitUntil( async () => (await browser.getTitle()).match(/StackDemo/i), 5000, "Title didn't match with BrowserStack" ); const productOnScreen = await $("//*[@id=\"1\"]/p"); const productOnScreenText = await productOnScreen.getText(); const addToCart = await $("//*[@id=\"1\"]/div[4]"); await addToCart.click(); const productInCart = await $("//*[@id=\"__next\"]/div/div/div[2]/div[2]/div[2]/div/div[3]/p[1]"); await browser.waitUntil(async () => ( await productInCart.getText()).match(productOnScreenText), { timeout: 5000 } ); }); }); ``` -------------------------------- ### Get Page Title with browser.getTitle Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/api-reference-webdriverio.md Retrieve the title of the current web page. Useful for verifying page loads. ```javascript const title = await browser.getTitle(); ``` ```javascript const title = await browser.getTitle(); if (title.match(/StackDemo/i)) { console.log("Page loaded successfully"); } ``` -------------------------------- ### Should Assertion Style Examples Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/test-framework-guide.md Illustrates assertion patterns using Chai's should style. This style is enabled in the configuration and allows chaining assertions directly on values. ```javascript value.should.equal(expected); (function () {}).should.be.a('function'); ``` -------------------------------- ### Wait for Elements Before Interaction Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/element-selection-guide.md Always wait for an element to be displayed before interacting with it to prevent errors due to timing issues. This example waits for 5 seconds. ```javascript await element.waitForDisplayed({ timeout: 5000 }); await element.click(); ``` -------------------------------- ### Service Integration Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/wdio-configuration-detailed.md Integrate external tools and modify WebDriverIO's behavior by specifying services and their configurations in an array. Example shows BrowserStack and local-runner integration. ```javascript services: [['browserstack']], ``` ```javascript services: [ ['browserstack', { buildIdentifier: '#123' }], ['local-runner'] ] ``` -------------------------------- ### Jenkins Pipeline for BrowserStack Tests Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/test-execution-guide.md Set up a Jenkins pipeline to manage your BrowserStack test execution. This includes installing dependencies, running parallel tests, and executing local tests, with credentials securely managed by Jenkins. ```groovy pipeline { agent any stages { stage('Install') { steps { sh 'npm install' } } stage('Parallel Tests') { environment { BROWSERSTACK_USERNAME = credentials('browserstack-username') BROWSERSTACK_ACCESS_KEY = credentials('browserstack-access-key') BUILD_NUMBER = "${BUILD_NUMBER}" } steps { sh 'npm run test' } } stage('Local Tests') { environment { BROWSERSTACK_USERNAME = credentials('browserstack-username') BROWSERSTACK_ACCESS_KEY = credentials('browserstack-access-key') } steps { sh 'npm run local' } } } } ``` -------------------------------- ### Parallel Test Execution Flow Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/test-execution-guide.md Illustrates the flow for running tests in parallel across different capabilities. This setup is ideal for maximizing test coverage and reducing execution time. ```text ┌─────────────────────────────────────┐ │ WebDriverIO Test Runner │ ├─────────────────────────────────────┤ │ Load: conf/test.conf.js │ │ Capabilities: 3 │ │ maxInstances: 10 └────────────┬────────────────────────┘ │ ┌────────┴────────┐ │ │ ┌───▼───────┐ ┌─────▼────┐ ┌──────────┐ │ Chrome │ │ Safari │ │ Mobile │ │ Windows │ │ macOS │ │ Android │ │ Instance │ │ Instance │ │ Instance │ └───┬───────┘ └─────┬────┘ └──────────┘ │ │ └────────┬───────┘ │ ┌────────▼────────────────┐ │ Test Specs: │ │ - Navigate URL │ │ - Wait for title match │ │ - Find element │ │ - Click element │ │ - Assert visibility │ └────────┬────────────────┘ │ ┌────────▼────────────────┐ │ Upload Results to │ │ BrowserStack Dashboard │ └────────────────────────┘ ``` -------------------------------- ### GitHub Actions for BrowserStack Tests Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/test-execution-guide.md Configure GitHub Actions to install dependencies, run parallel tests, and execute local tests with BrowserStack. Ensure your BrowserStack credentials and build number are set as environment variables. ```yaml name: Run BrowserStack Tests on: [push, pull_request] jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Setup Node.js uses: actions/setup-node@v2 with: node-version: '14' - name: Install dependencies run: npm install - name: Run parallel tests env: BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }} BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} BUILD_NUMBER: ${{ github.run_number }} run: npm run test - name: Run local tests env: BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }} BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} run: npm run local ``` -------------------------------- ### Configure BrowserStack Local Tunnel Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/configuration.md Use this configuration to enable the BrowserStack Local tunnel for testing local or internal applications. Ensure the 'browserstack' service is installed. ```javascript services: [ [ 'browserstack', { browserstackLocal: true, buildIdentifier: '#${BUILD_NUMBER}', opts: { forcelocal: false, localIdentifier: 'webdriverio-browserstack-repo' } }, ] ] ``` -------------------------------- ### Search for Configuration Options Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/DOCUMENTATION_MANIFEST.md Use grep to find specific configuration options within the documentation files. ```bash grep -r "maxInstances" /workspace/home/output/ ``` -------------------------------- ### Navigate to Application Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/test-framework-guide.md Load the specified URL in the browser. ```javascript await browser.url("https://bstackdemo.com/"); ``` -------------------------------- ### Run All Tests Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/test-framework-guide.md Execute all tests using the default configuration. ```bash npm run test ``` -------------------------------- ### Search for API Method Documentation Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/DOCUMENTATION_MANIFEST.md Use grep to locate documentation for specific API methods. ```bash grep -r "browser.url" /workspace/home/output/ ``` -------------------------------- ### View Specific Reference Document Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/DOCUMENTATION_MANIFEST.md Use this command to view the content of a specific reference document, such as the configuration or API reference. ```bash # View specific reference cat /workspace/home/output/configuration.md ``` ```bash cat /workspace/home/output/api-reference-webdriverio.md ``` -------------------------------- ### Organize Tests with Describe and It Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/INDEX.md Structure your tests using `describe` for test suites and `it` for individual test cases. ```javascript describe("Feature", () => { it("does something", async () => { // test code }); }); ``` -------------------------------- ### Get Page Title in WebDriverIO Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/INDEX.md Retrieve the title of the current web page using the `browser.getTitle()` method. This is often used for verification purposes. ```javascript const title = browser.getTitle(); ``` -------------------------------- ### View Master Index Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/DOCUMENTATION_MANIFEST.md Use this command to view the master index file, which contains links to all other documents in the project. ```bash # View master index cat /workspace/home/output/INDEX.md ``` -------------------------------- ### Get Element Text Content Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/api-reference-webdriverio.md The getText() method retrieves the visible text content of a WebElement. This is useful for asserting or displaying text associated with an element. ```javascript const text = await productElement.getText(); ``` ```javascript const productOnScreenText = await productOnScreen.getText(); const productInCartText = await productInCart.getText(); ``` -------------------------------- ### Get Element Text in WebDriverIO Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/INDEX.md Retrieve the inner text content of a WebElement using the `WebElement.getText()` method. This is useful for verifying text displayed on the page. ```javascript const text = element.getText(); ``` -------------------------------- ### Use Descriptive Console Logging Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/debugging-testing-guide.md Demonstrates good and bad practices for console logging, emphasizing clarity and context. ```javascript // Good console.log('Found product element with text:', productText); // Bad console.log('test'); ``` -------------------------------- ### Local Testing with BrowserStack Tunnel Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/test-framework-guide.md Demonstrates how to test local connections by navigating to a specific URL and verifying the page title to ensure the BrowserStack Local tunnel is working. ```javascript describe('BStack Local Testing', () => { it('can check tunnel working', async () => { await browser.url('http://bs-local.com:45454'); await browser.waitUntil( async () => (await browser.getTitle()).match(/BrowserStack Local/i), 5000, "Failed to connect local tunnel" ); }); }); ``` -------------------------------- ### Get Element Text Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/element-selection-guide.md Retrieves the visible text content of a selected element. Returns an empty string for hidden elements and includes text from child elements. ```javascript const text = await element.getText(); ``` ```javascript const productOnScreen = await $('//*[@id="1"]/p'); const productOnScreenText = await productOnScreen.getText(); ``` -------------------------------- ### Complex XPath for Specific Element Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/element-selection-guide.md This XPath expression targets a specific paragraph element by navigating through a series of nested divs, starting from an element with the ID '__next'. ```javascript '//*[@id="__next"]/div/div/div[2]/div[2]/div[2]/div/div[3]/p[1]' ``` -------------------------------- ### Extend Base Configuration Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/test-framework-guide.md Shows how to extend the base configuration file with specific settings for parallel or local testing. This pattern is used to create distinct configuration files for different testing scenarios. ```javascript const { config: baseConfig } = require('./base.conf.js'); exports.config = { ...baseConfig, ...parallelConfig }; ``` -------------------------------- ### Browser Capabilities Configuration Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/INDEX.md Define the browser and operating system environment for your tests. ```javascript capabilities: [{ browserName: 'chrome', browserVersion: 'latest', 'bstack:options': { os: 'Windows', osVersion: '10' } }] ``` -------------------------------- ### Basic Mocha Test File Structure Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/test-framework-guide.md Illustrates the fundamental structure of a test file using Mocha's describe and it functions for organizing test suites and cases. ```javascript describe("Test Suite Name", () => { it("test case description", async () => { // Test implementation }); it("another test case", async () => { // Test implementation }); }); ``` -------------------------------- ### WebDriver Error: Session not created Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/debugging-testing-guide.md Indicates invalid credentials or unreachable BrowserStack. Verify BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY. ```text Error: Request failed with status 403 ``` -------------------------------- ### CSS Selectors for Element Selection Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/element-selection-guide.md Although not used in the repository examples, WebDriverIO supports CSS selectors for finding elements by class name, tag name with class, or ID. ```javascript const element = await $('.product-name'); ``` ```javascript const button = await $('button.primary'); ``` ```javascript const input = await $('#email-field'); ``` -------------------------------- ### Navigate to URL with browser.url Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/api-reference-webdriverio.md Use this to navigate the browser to a specific URL. It accepts a full URL or a relative path. ```javascript await browser.url("https://example.com/"); ``` ```javascript describe("Navigation test", () => { it("navigates to BStackDemo", async () => { await browser.url("https://bstackdemo.com/"); }); }); ``` -------------------------------- ### Merging BrowserStack Capabilities Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/browserstack-service.md Demonstrates how base capabilities are merged with common capabilities, including BrowserStack-specific options like buildName and source. ```javascript // Base capability { browserName: 'chrome', browserVersion: 'latest', 'bstack:options': { os: 'Windows', osVersion: '10' } } // With merged commonCapabilities { browserName: 'chrome', browserVersion: 'latest', 'bstack:options': { os: 'Windows', osVersion: '10', buildName: 'browserstack build', source: 'webdriverio:sample-master:v1.2' } } ``` -------------------------------- ### Increase Mocha Test Timeout Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/test-execution-guide.md Increase the `mochaOpts.timeout` value to allow more time for tests to complete, useful when application response times are slow. Example sets timeout to 120 seconds. ```javascript mochaOpts: { timeout: 120000 } // 120 seconds ``` -------------------------------- ### Configure BrowserStack Service with Options Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/configuration.md Configures the BrowserStack service with custom build identifiers and local testing options. ```javascript services: [ [ 'browserstack', { buildIdentifier: '#${BUILD_NUMBER}', browserstackLocal: true, opts: { /* local options */ } } ] ] ``` -------------------------------- ### Define a Test Suite with Mocha's describe Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/api-reference-webdriverio.md Creates a test suite using the 'describe' function provided by the Mocha framework. Use this to group related test cases. ```javascript describe("Testing with BStackDemo", () => { // test cases here }); ``` -------------------------------- ### Basic Mobile Capability Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/browserstack-capabilities.md Use this capability to specify a mobile device for testing. It requires the browser name and the device name within 'bstack:options'. ```javascript { browserName: 'chrome', 'bstack:options': { deviceName: 'Samsung Galaxy S20' } } ``` -------------------------------- ### Run Single Test Configuration Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/debugging-testing-guide.md Command to execute WebDriverIO tests using a specific configuration file designed for single test execution. ```bash npx wdio conf/single-test.conf.js ``` -------------------------------- ### Logging Configuration Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/wdio-configuration-detailed.md Configure the verbosity level for logs using 'logLevel' and enable colored output for better readability with 'coloredLogs'. ```javascript logLevel: 'warn', coloredLogs: true, ``` -------------------------------- ### Run WebDriverIO with Debug Configuration Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/debugging-testing-guide.md Execute WebDriverIO tests using a specific debug configuration file. This command will output detailed logs as configured. ```bash npx wdio conf/debug.conf.js ``` -------------------------------- ### Run Local Tests Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/test-framework-guide.md Execute tests with BrowserStack Local tunnel for internal applications. ```bash npm run local ``` -------------------------------- ### Configure Mocha Framework Options Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/configuration.md Sets user interface and timeout options for the Mocha test framework. ```javascript mochaOpts: { ui: 'bdd', timeout: 60000 } ``` -------------------------------- ### BrowserStack Capabilities for Local Testing Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/browserstack-capabilities.md Configure capabilities for local testing with BrowserStack. This includes specifying browser details and 'bstack:options' for build and source tracking. ```javascript capabilities: [ { browserName: 'chrome', browserVersion: 'latest', 'bstack:options': { buildName: 'browserstack build', source: 'webdriverio:sample-master:v1.2' } } ] ``` -------------------------------- ### Common BStack Options Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/browserstack-capabilities.md These options can be included in 'bstack:options' to configure build and session details. They help in organizing and tracking tests on the BrowserStack dashboard. ```javascript 'bstack:options': { buildName: 'browserstack build', source: 'webdriverio:sample-master:v1.2', projectName: 'My Project', buildTag: 'release-1.0', sessionName: 'Test Session' } ``` -------------------------------- ### Run Specific Test Case Configuration Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/debugging-testing-guide.md Command to execute WebDriverIO tests with a configuration that filters tests by a specific pattern. ```bash npx wdio conf/debug-single.conf.js ``` -------------------------------- ### browser.url(url) Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/api-reference-webdriverio.md Navigates to a specified URL in the current browser window. It accepts a full URL or a relative path and resolves when the navigation is complete. Throws an error if navigation fails or times out. ```APIDOC ## browser.url(url) ### Description Navigate to a URL in the current browser window. ### Method Not applicable (SDK method) ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript await browser.url("https://example.com/"); ``` ### Response #### Success Response - `Promise` - Resolves when navigation completes #### Response Example None explicitly provided beyond the return type. ### Throws - WebDriverError if navigation fails or times out ``` -------------------------------- ### Local Testing Configuration Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/browserstack-service.md Configure the BrowserStack service to enable local testing. This requires the BrowserStack Local binary to be running and creates an encrypted tunnel. ```javascript services: [ [ 'browserstack', { browserstackLocal: true, opts: { localIdentifier: 'webdriverio-browserstack-repo' } }, ], ], specs: ['./tests/specs/local_test.js'] ``` -------------------------------- ### Base URL Configuration Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/wdio-configuration-detailed.md Set a 'baseUrl' to prepend to relative URLs used in navigation calls. This simplifies testing against a specific domain. ```javascript baseUrl: 'https://example.com' ``` -------------------------------- ### Server Configuration Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/wdio-configuration-detailed.md Define the WebDriver server hostname, port, and path. These are often pre-configured by services like the browserstack-service. ```javascript hostname: 'hub.browserstack.com', ``` -------------------------------- ### Use Structured Data for Logging Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/debugging-testing-guide.md Logs test metadata using a structured object, including timestamps and actions. ```javascript const metadata = { timestamp: new Date().toISOString(), element: 'product-title', action: 'getText' }; console.log('Test metadata:', metadata); ``` -------------------------------- ### Parallel Execution Configuration Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/browserstack-service.md Configure parallel test execution by setting 'maxInstances' and defining multiple browser capabilities. The service manages concurrent sessions. ```javascript maxInstances: 10, capabilities: [ { browserName: 'chrome', /* ... */ }, { browserName: 'safari', /* ... */ }, { /* mobile device */ } ] ``` -------------------------------- ### Dynamic Build Identifier Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/browserstack-capabilities.md Use dynamic build naming with environment variable placeholders like BUILD_NUMBER for CI/CD environments. ```javascript buildIdentifier: '#${BUILD_NUMBER}' ``` -------------------------------- ### BrowserStack Build Metadata Configuration Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/browserstack-service.md Set build name and source for organizing tests on the BrowserStack dashboard. These are part of the 'bstack:options' capability. ```javascript 'bstack:options': { buildName: 'browserstack build', source: 'webdriverio:sample-master:v1.2' } ``` -------------------------------- ### Run WebdriverIO Tests via npm Scripts Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/wdio-configuration-detailed.md Utilize npm scripts defined in `package.json` to run tests with specific configurations. 'npm run test' executes 'conf/test.conf.js', and 'npm run local' executes 'conf/local-test.conf.js'. ```bash npm run test # Runs conf/test.conf.js ``` ```bash npm run local # Runs conf/local-test.conf.js ``` -------------------------------- ### Set BrowserStack Credentials Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/README.md Export your BrowserStack username and access key as environment variables. This is required before running tests. ```sh export BROWSERSTACK_USERNAME= && export BROWSERSTACK_ACCESS_KEY= ``` -------------------------------- ### Configure Connection Timeout and Retries Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/test-execution-guide.md Set the timeout in milliseconds for establishing a connection and the number of retry attempts. Default connection timeout is 120000ms with 3 retries. ```javascript connectionRetryTimeout: 120000, connectionRetryCount: 3 ``` -------------------------------- ### Define Nested Test Suites with describe Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/test-framework-guide.md Use the 'describe' function to create test suites and group related test cases. Nested suites allow for hierarchical organization of tests. ```javascript describe("Parent Suite", () => { describe("Nested Suite", () => { it("test in nested suite", async () => { // test code }); }); }); ``` -------------------------------- ### Configure Network Throttling for Slow Networks Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/debugging-testing-guide.md Sets up network throttling to simulate slow network conditions, such as 4G, for testing. ```javascript // conf/slow-network.conf.js const { config: baseConfig } = require('./base.conf.js'); exports.config = { ...baseConfig, capabilities: [{ browserName: 'chrome', 'bstack:options': { networkProfile: '4g' // Throttle to 4G } }] }; ``` -------------------------------- ### Timeout Settings Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/wdio-configuration-detailed.md Configure default wait timeouts for element interactions ('waitforTimeout') and connection retries ('connectionRetryTimeout', 'connectionRetryCount'). ```javascript waitforTimeout: 10000, connectionRetryTimeout: 120000, connectionRetryCount: 3, ``` -------------------------------- ### Set and Access Custom Environment Variables Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/test-execution-guide.md Define custom environment variables in your configuration file using `process.env` and access them within your test specs. ```javascript // conf/custom.conf.js process.env.CUSTOM_VAR = 'value'; ``` ```javascript describe("Using env vars", () => { it("accesses custom variable", async () => { console.log(process.env.CUSTOM_VAR); // 'value' }); }); ``` -------------------------------- ### Import Base WebDriverIO Configuration Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/api-reference-webdriverio.md Imports the base configuration object for WebDriverIO. This configuration is essential for setting up the test runner, browser connections, and test execution parameters. ```javascript const { config: baseConfig } = require('./base.conf.js'); ``` -------------------------------- ### Configure Single Capability for Local Testing Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/wdio-configuration-detailed.md Define a single browser capability for a simplified local testing scenario. This configuration includes browser name, version, and BrowserStack specific options. ```javascript capabilities: [ { browserName: 'chrome', browserVersion: 'latest', 'bstack:options': { buildName: 'browserstack build', source: 'webdriverio:sample-master:v1.2' } }, ], ``` -------------------------------- ### Select and Verify Visibility Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/element-selection-guide.md A common pattern to select an element, check if it's displayed, and then retrieve its text content if visible. ```javascript const element = await $('selector'); const isDisplayed = await element.isDisplayed(); if (isDisplayed) { const text = await element.getText(); console.log(text); } ``` -------------------------------- ### Set Log Level to Warn Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/test-execution-guide.md Configure the minimum log level for WebDriverIO output. Use 'warn' for general information during normal runs. ```javascript logLevel: 'warn', ``` -------------------------------- ### Define Test Case with it and Async/Await Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/test-framework-guide.md Define individual test cases using the 'it' function. Test callbacks should use 'async' syntax to handle WebDriverIO's promise-based API for operations like navigating to URLs and retrieving page titles. ```javascript it("test case", async () => { await browser.url("https://example.com"); const title = await browser.getTitle(); }); ``` -------------------------------- ### Initialize Chai Before Hook Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/configuration.md Executes once before all tests to initialize the Chai assertion library for global use in test specs. ```javascript before: function () { var chai = require('chai'); global.expect = chai.expect; chai.Should(); } ``` -------------------------------- ### Set CI/CD Build Identification Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/test-execution-guide.md Export the `BUILD_NUMBER` environment variable to automatically identify builds in the BrowserStack dashboard. The configuration uses this to format the build identifier. ```bash export BUILD_NUMBER=123 npm run test ``` ```javascript buildIdentifier: '#${BUILD_NUMBER}' ``` -------------------------------- ### Capability Merging Strategy Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/browserstack-capabilities.md Demonstrates how common capabilities are merged with individual capabilities to form the effective capability set for tests. ```javascript commonCapabilities: { 'bstack:options': { buildName: 'browserstack build', source: 'webdriverio:sample-master:v1.2' } } capabilities: [ { browserName: 'chrome', browserVersion: 'latest', 'bstack:options': { os: 'Windows', osVersion: '10' } } ] // After merge, effective capability is: // { // browserName: 'chrome', // browserVersion: 'latest', // 'bstack:options': { // os: 'Windows', // osVersion: '10', // buildName: 'browserstack build', // source: 'webdriverio:sample-master:v1.2' // } // } ``` ```javascript exports.config.capabilities.forEach(function (caps) { for (var i in exports.config.commonCapabilities) caps[i] = { ...caps[i], ...exports.config.commonCapabilities[i]}; }); ``` -------------------------------- ### BrowserStack Authentication Credentials Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/browserstack-service.md Configure your BrowserStack username and access key. These are typically set as environment variables for security. ```javascript user: process.env.BROWSERSTACK_USERNAME || 'BROWSERSTACK_USERNAME', key: process.env.BROWSERSTACK_ACCESS_KEY || 'BROWSERSTACK_ACCESS_KEY', ``` -------------------------------- ### Local WebDriver Configuration Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/debugging-testing-guide.md Configure WebDriverIO to use a local WebDriver instance instead of BrowserStack. Ensure the BrowserStack service is not included. ```javascript // conf/local.conf.js exports.config = { runner: 'local', // Don't include BrowserStack service // Use chromedriver or other local driver }; ``` -------------------------------- ### Click on an Element Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/api-reference-webdriverio.md Use the click() method on a WebElement to simulate a user click. Ensure the element is clickable before invoking this method to avoid errors. ```javascript await addToCartButton.click(); ``` ```javascript const addToCart = await $"//*[@id=\"1\"]/div[4]"; await addToCart.click(); ``` -------------------------------- ### List Error Screenshots Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/debugging-testing-guide.md Use this command to list all error screenshots saved for failed tests in the specified directory. ```bash ls -la ./errorShots/ ``` -------------------------------- ### Configuration Inheritance in WebdriverIO Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/wdio-configuration-detailed.md Extend a base WebdriverIO configuration with custom settings for specific environments. Properties in the custom configuration override those in the base configuration. ```javascript const { config: baseConfig } = require('./base.conf.js'); const customConfig = { maxInstances: 10, capabilities: [ /* ... */ ] }; exports.config = { ...baseConfig, ...customConfig }; ``` -------------------------------- ### Test Specification: File Paths Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/wdio-configuration-detailed.md Define the paths to test specification files using an array of strings or glob patterns. An 'exclude' array can be used to omit specific files from execution. ```javascript specs: ['./tests/specs/test.js'], exclude: [] ``` ```javascript specs: ['./tests/specs/**/*test.js'], exclude: ['./tests/specs/skip/**/*test.js'] ``` -------------------------------- ### $(selector) Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/api-reference-webdriverio.md Finds a single element by CSS or XPath selector and returns a WebElement object. ```APIDOC ## $(selector) ### Description Find a single element by CSS or XPath selector. Returns a WebElement object. ### Method N/A (Function Call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters #### selector (string) - Yes - CSS selector or XPath expression ### Returns - `Promise` - WebElement object for the matched element ### Throws - WebDriverError if element not found in some contexts ### Example ```javascript const productElement = await $("//*[@id=\"1\"]/p"); ``` ``` -------------------------------- ### BrowserStack Service Retry Configuration Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/browserstack-service.md Configure retry settings for connection failures, including timeout and the number of retry attempts. ```javascript connectionRetryTimeout: 120000, // Max 120 seconds connectionRetryCount: 3 // Up to 3 attempts ``` -------------------------------- ### Common Capabilities Structure Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/configuration.md Defines capabilities that are shared across all browser and device combinations for a build. This includes setting the build name and source identifier for BrowserStack. ```javascript commonCapabilities: { 'bstack:options': { buildName: 'browserstack build', source: 'webdriverio:sample-master:v1.2' } } ``` -------------------------------- ### Timeout Settings Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/INDEX.md Set various timeout durations for element waits, connection retries, and test execution. ```javascript waitforTimeout: 10000 // Element waits connectionRetryTimeout: 120000 // Initial connection mochaOpts.timeout: 60000 // Test timeout ``` -------------------------------- ### Configure WebDriverIO to Run Specific Tests Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/test-execution-guide.md Defines a custom WebDriverIO configuration file to specify which test files should be executed. This is an alternative to command-line overrides for selecting tests. ```javascript // conf/custom.conf.js const { config: baseConfig } = require('./base.conf.js'); exports.config = { ...baseConfig, specs: ['./tests/specs/specific-test.js'] }; ``` -------------------------------- ### Enable BrowserStack Service Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/configuration.md Enables the BrowserStack service integration for WebDriverIO tests. ```javascript services: [['browserstack']] ``` -------------------------------- ### Local Test Execution Flow Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/test-execution-guide.md Details the process for running tests against a local application using BrowserStack Local. This involves setting up a tunnel to securely connect your local environment to BrowserStack. ```text ┌─────────────────────────────────┐ │ WebDriverIO Test Runner │ ├─────────────────────────────────┤ │ Load: conf/local-test.conf.js │ │ Service: BrowserStack Local │ └────────────┬────────────────────┘ │ ┌────────▼──────────────────┐ │ Start BrowserStack Local │ │ Binary (if not running) │ └────────┬───────────────────┘ │ ┌────────▼──────────────────┐ │ Create Tunnel │ │ localhost <-> BrowserStack │ └────────┬───────────────────┘ │ ┌────────▼──────────────────┐ │ Create Chrome Session │ │ (routing through tunnel) │ └────────┬───────────────────┘ │ ┌────────▼──────────────────┐ │ Run Test Specs: │ │ - Navigate to local app │ │ - Test internal features │ └────────┬───────────────────┘ │ ┌────────▼──────────────────┐ │ Close Tunnel │ │ Stop Local Binary │ └────────┬───────────────────┘ │ ┌────────▼──────────────────┐ │ Upload Results │ └────────────────────────────┘ ``` -------------------------------- ### Capture Screenshot and Page Source Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/debugging-testing-guide.md Capture a screenshot of the current page and save it to a file. Also, retrieve and log the entire HTML source of the page for inspection. ```javascript const screenshot = await browser.takeScreenshot(); fs.writeFileSync('./debug.png', screenshot, 'base64'); ``` ```javascript const source = await browser.getPageSource(); console.log(source); ``` -------------------------------- ### WebDriver Error: No such element Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/debugging-testing-guide.md Occurs when a selector does not match any element. Verify the selector works in browser developer tools. ```text Error: no such element (Session info: chrome=90.0.4430.85) ``` -------------------------------- ### Configure Build Identifier Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/browserstack-service.md Set a custom build ID for your BrowserStack runs using environment variables. ```javascript services: [ [ 'browserstack', { buildIdentifier: '#${BUILD_NUMBER}' } ] ] ``` -------------------------------- ### Structure Capabilities Array Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/wdio-configuration-detailed.md Define the array of capabilities, where each object represents a separate test run. This allows for testing across different browsers, operating systems, and versions. ```javascript capabilities: [ { browserName: 'chrome', browserVersion: 'latest', 'bstack:options': { os: 'Windows', osVersion: '10', }, }, // ... more capabilities ] ``` -------------------------------- ### Measure Test Performance Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/debugging-testing-guide.md Logs the time taken for navigation, element selection, and click actions during a test. ```javascript it("measure test performance", async () => { const startTime = Date.now(); await browser.url("https://bstackdemo.com/"); console.log('Navigation took:', Date.now() - startTime, 'ms'); const selectionStart = Date.now(); const element = await $("//*[@id=\"1\"]/p"); console.log('Element selection took:', Date.now() - selectionStart, 'ms'); const clickStart = Date.now(); await element.click(); console.log('Click took:', Date.now() - clickStart, 'ms'); }); ``` -------------------------------- ### Navigate to URL in WebDriverIO Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/INDEX.md Use the `browser.url()` method to navigate to a specific web page. This is a fundamental step for most browser automation tasks. ```javascript browser.url("https://www.example.com"); ``` -------------------------------- ### Enable BrowserStack Local Tunnel Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/browserstack-service.md Enable the BrowserStack Local tunnel for testing internal or private applications. Configure tunnel options like `forcelocal` and `localIdentifier`. ```javascript services: [ [ 'browserstack', { browserstackLocal: true, opts: { forcelocal: false, localIdentifier: 'webdriverio-browserstack-repo' } } ] ] ``` -------------------------------- ### Select Button by Text and Click Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/element-selection-guide.md Selects a button element based on its exact text content using an XPath selector and then clicks it. ```javascript // Find button containing specific text const button = await $('//button[text()="Add to Cart"]'); await button.click(); ``` -------------------------------- ### browser.waitUntil(condition, options) Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/api-reference-webdriverio.md Waits until a specified asynchronous condition evaluates to true or a timeout is reached. It accepts a condition function, optional timeout settings, and an error message. Resolves when the condition is met, otherwise throws an error. ```APIDOC ## browser.waitUntil(condition, options) ### Description Wait until a condition is true or timeout is reached. ### Method Not applicable (SDK method) ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript await browser.waitUntil( async () => (await browser.getTitle()).match(/StackDemo/i), 5000, "Title didn't match with BrowserStack" ); ``` ### Response #### Success Response - `Promise` - Resolves when condition becomes true #### Response Example None explicitly provided beyond the return type. ### Throws - WebDriverError with provided message if timeout exceeded ``` -------------------------------- ### WebElement.click() Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/api-reference-webdriverio.md Performs a click action on a WebElement. ```APIDOC ## WebElement.click() ### Description Click on an element. ### Method N/A (Method Call) ### Parameters None ### Returns - `Promise` - Resolves when element is clicked ### Throws - WebDriverError if element is not clickable ### Example ```javascript const addToCart = await $("//*[@id=\"1\"]/div[4]"); await addToCart.click(); ``` ``` -------------------------------- ### BrowserStack Authentication Environment Variables Source: https://github.com/browserstack/webdriverio-browserstack/blob/master/_autodocs/browserstack-service.md Set BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY as environment variables for authentication. The BUILD_NUMBER variable can be used with buildIdentifier. ```javascript BROWSERSTACK_USERNAME=john_doe BROWSERSTACK_ACCESS_KEY=abc123xyz BUILD_NUMBER=123 ```