What is @wdio/shared-store-service?
@wdio/shared-store-service is a service for WebdriverIO that allows you to share data between different browser sessions and processes. This can be particularly useful for end-to-end testing scenarios where you need to maintain state or share information across different test runs.
What are @wdio/shared-store-service's main functionalities?
Set Data in Shared Store
This feature allows you to set a key-value pair in the shared store. The data can then be accessed by other browser sessions or processes.
await browser.sharedStore.set('key', 'value');
Get Data from Shared Store
This feature allows you to retrieve a value from the shared store using a key. This is useful for accessing data that was set in a different session or process.
const value = await browser.sharedStore.get('key');
Delete Data from Shared Store
This feature allows you to delete a key-value pair from the shared store. This can be useful for cleaning up data after tests have run.
await browser.sharedStore.delete('key');
Other packages similar to @wdio/shared-store-service
webdriverio
WebdriverIO is a popular testing framework for Node.js. While it does not have built-in shared store functionality, it offers a wide range of plugins and services that can be used to extend its capabilities, including state management and data sharing.
selenium-webdriver
Selenium WebDriver is a widely-used tool for automating web applications. It does not natively support shared stores, but you can implement similar functionality using external storage solutions like Redis or a database.
cypress
Cypress is an end-to-end testing framework that offers a different approach to testing compared to WebdriverIO. While it does not have a built-in shared store, it provides various ways to manage state and share data between tests, such as using environment variables or custom commands.
WebdriverIO Shared Store Service
Exchange data between main process and workers (specs).
Installation
The easiest way is to keep @wdio/shared-store-service
as a devDependency in your package.json
.
{
"devDependencies": {
"@wdio/shared-store-service": "^6.1.4"
}
}
You can simple do it by:
npm install @wdio/shared-store-service --save-dev
Instructions on how to install WebdriverIO
can be found here.
Usage
Get/set a value (plain object) to/from the store by key (string).
browser.sharedStore.set('key', 'value')
set value to store
browser.sharedStore.get('key')
get value from store (returns 'value'
)
IMPORTANT! Every spec file should be atomic and isolated from others specs.
The idea of the service is to deal with very specific environment setup issues.
Please avoid sharing test execution data!
Configuration
Just add shared-store
to services list and the sharedStore
object will be accessible to you in your test.
export.config = {
services: ['shared-store'],
};