cypress-modifier-xml-plugin
v1.0.7
Published
A Cypress plugin for modifying XML fields within your tests.
Downloads
60
Readme
Cypress XML Modifier Plugin
Cypress is a powerful tool for testing web applications, and this plugin adds functionality to easily modify XML fields within your Cypress tests. It provides three custom commands: modifyXmlField
, modifyMultipleXmlFields
, and convertXmlToBase64
.
Installation
To install the plugin, run the following command:
npm install cypress-xml-modifier-plugin
Usage
First, import and register the plugin in your cypress/support/e2e.js
file:
import 'cypress-xml-modifier-plugin';
Available Commands
modifyXmlField
Modifies a single XML field.
Parameters:
filePath
(string): Path to the XML file.tagName
(string): Name of the tag to be modified.newValue
(string): New value for the tag.outputFilePath
(string): Path to save the modified XML file.
Usage Example:
cy.modifyXmlField('path/to/input.xml', 'TagName', 'NewValue', 'path/to/output.xml');
modifyMultipleXmlFields
Modifies multiple XML fields.
Parameters:
filePath
(string): Path to the XML file.modifications
(array of objects): List of modifications to be made. Each object should containtagName
andnewValue
.outputFilePath
(string): Path to save the modified XML file.
Usage Example:
const modifications = [
{ tagName: 'TagName1', newValue: 'NewValue1' },
{ tagName: 'TagName2', newValue: 'NewValue2' },
];
cy.modifyMultipleXmlFields('path/to/input.xml', modifications, 'path/to/output.xml');
convertXmlToBase64
Converts an XML file to a Base64 encoded string.
Parameters:
filePath
(string): Path to the XML file.
Usage Example:
cy.convertXmlToBase64('path/to/input.xml').then((base64String) => {
// Use the base64String as needed
});
Notes
- If the specified tag is not found in the XML, the test will fail immediately with an error message.
- Ensure that the paths to XML files are correct and that Cypress has permission to read from and write to these paths.
Credits
This plugin was conceptualized by Hiago due to a specific application requirement involving XML. I, Gabriel Logan, implemented the code.
Contributions
Contributions are welcome! Feel free to open issues and send pull requests. See the contribution guidelines for more details.
License
This project is licensed under the MIT License. See the LICENSE file for more details.