cypress-plugin-store
v1.3.4
Published
Store values during the executions and retrieve them in any test case in the same spec file.
Downloads
30
Maintainers
Readme
cypress-plugin-store
Store values during the executions and retrieve in any test case in the same spec file.
Note: Support with both CSS Selectors and Xpath
Please install and configure the Xpath plugin as below:
https://www.npmjs.com/package/@cypress/xpath
install
npm i -D cypress-plugin-store
# or
yarn add -D cypress-plugin-store
use
Simple
Include from your Cypress support file or individual spec (cypress > support > e2e.js)
import 'cypress-plugin-store/commands'
Then use the custom command cy.storePluginSetup()
to initialize the plugin.
Note: Recommended inside the before
hook.
before(() => {
cy.storePluginSetup();
})
Then use the custom command cy.storeValue
Note: Support with both CSS Selectors and Xpath
cy.storeValue(element_locator,variable_Name)
Example:
it('Store the Variables', () => {
cy.visit('cypress/index.html')
cy.get('#fname').type('John')
cy.get('#lname').type('Doe')
cy.storeValue('#fname','firstName')
cy.storeValue('#lname','lastName')
cy.storeValue(`//input[@id='city']`,'city')
})
Then use the custom command cy.retrieveValue
cy.retrieveValue(variable_Name).then((var_) => {
// Do something with the var_
})
Example:
it('retrieve First name the elements', () => {
cy.retrieveValue('firstName').then((firstName) => {
cy.log('This is First Name'+firstName);
})
})
it('retrieve Last name the elements', () => {
cy.retrieveValue('lastName').then((lastName) => {
cy.log('This is '+lastName);
})
})
it('retrieve city the xpath elements', () => {
cy.retrieveValue('city').then((city) => {
cy.log('This is '+city);
})
})
Finally, use the custom command cy.clearPluginSetup()
to clear the plugin. (IF needed)
Note: Recommended inside the after
hook.
after(() => {
cy.clearPluginSetup();
})
Small print
Author: Lasitha Wijenayake <[email protected]> © 2022
License: MIT - do anything with the code, but don't blame me if it does not work.
Support: if you find any problems with this module, email open issue on Github
MIT License
Copyright (c) 2022 Lasitha Wijenayake <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.