- WebdriverIO Tutorial
- WebdriverIO - Home
- WebdriverIO - Introduction
- WebdriverIO - Prerequisite
- WebdriverIO - Architecture
- WebdriverIO - Getting Started with NodeJS
- WebdriverIO - Installation of NPM
- WebdriverIO - VS Code Installation
- WebdriverIO - Package.json
- WebdriverIO - Mocha Installation
- Selenium Standalone Server Installation
- WebdriverIO - Configuration File generation
- WebdriverIO - VS Code Intellisense
- WebdriverIO - Wdio.conf.js file
- WebdriverIO - Xpath Locator
- WebdriverIO - CSS Locator
- WebdriverIO - Link Text Locator
- WebdriverIO - ID Locator
- WebdriverIO - Tag Name Locator
- WebdriverIO - Class Name Locator
- WebdriverIO - Name Locator
- Expect Statement for Assertions
- WebdriverIO - Happy Path Flow
- WebdriverIO - General Browser Commands
- WebdriverIO - Handling Browser Size
- WebdriverIO - Browser Navigation Commands
- Handling Checkboxes & Dropdowns
- WebdriverIO - Mouse Operations
- Handling Child Windows/Pop ups
- WebdriverIO - Hidden Elements
- WebdriverIO - Frames
- WebdriverIO - Drag & Drop
- WebdriverIO - Double Click
- WebdriverIO - Cookies
- WebdriverIO - Handling Radio Buttons
- Chai Assertions on webelements
- WebdriverIO - Multiple Windows/Tabs
- WebdriverIO - Scrolling Operations
- WebdriverIO - Alerts
- WebdriverIO - Debugging Code
- WebdriverIO - Capturing Screenshots
- WebdriverIO - JavaScript Executor
- WebdriverIO - Waits
- WebdriverIO - Running Tests in Parallel
- WebdriverIO - Data Driven Testing
- Running Tests from command-line parameters
- Execute Tests with Mocha Options
- Generate HTML reports from Allure
- WebdriverIO Useful Resources
- WebdriverIO - Quick Guide
- WebdriverIO - Useful Resources
- WebdriverIO - Discussion
Running Tests from command-line parameters
We can control running tests using the command-line parameters. Let us take a scenario, where we have four test files within the spec folder in the WebdriverIO project.
The following screen will appear on your computer −
Suppose we want to trigger only the files testcase1.js and testcase2.js using the command-line parameters. To do this we have to add a parameter called suites in the Configuration file wdio.conf.js file.
The details on how to create a Configuration file are discussed in detail in the Chapter titled Wdio.conf.js file and Chapter titled Configuration File generation.
Let us consider that the files testcase1.js and testcase2.js belong to a suite called the group1 and the files testcase3.js and testcase4.js belong to a suite called the group2. We need to add this information to the wdio.conf.js file under the suite parameter as given below.
suites: { group1: ['test/specs/testcase1.js', 'test/specs/testcase2.js'], group2: ['test/specs/testcase3.js', 'test/specs/testcase4.js'] },
The following screen will appear on your computer −
To trigger the test files testcase1.js and testcase2.js belonging to group1, we have to run the command given below −
npx wdio run wdio.conf.js --suite group1
The following screen will appear on your computer −
After the command has been executed successfully, we see only the two test files testcase1.js and testcase2.js under the specs folder have been triggered for execution.
Suppose we want to trigger only the file testcase3.js using the command-line parameters. To trigger only the test file testcase3.js, we have to run the following command −
npx wdio run wdio.conf.js --spec test/specs/testcase3.js
The following screen will appear on your computer −
After the command has been executed successfully, we see only the test file testcase3.js under the specs folder has been triggered for execution.
Besides, if we want to trigger multiple test files testcase3.js and testcase4.js, the command should be as follows −
npx wdio run wdio.conf.js --spec test/specs/testcase3.js, test/specs/testcase4.js
Suppose we want to exclude only the file testcase4.js from execution. To do this we have to add a relative path of the file that we want to exclude under the exclude parameter in the Configuration file wdio.conf.js file as given below.
exclude: [ // 'path/to/excluded/files' 'test/specs/testcase4.js' ],
The following screen will appear on your computer −
Then, we have to run the below command −
npx wdio run wdio.conf.js
The following screen will appear on your computer −
After the command has been executed successfully, we see the test file testcase4.js under the specs folder has been excluded from execution.
To Continue Learning Please Login
Login with Google