How to modify or validate XML files

Modification of XML file content

If you have an XML file that you would like to modify as part of a test case, you can follow the steps below:

1. Download the file from this link

2. Upload the same file to Repositories > File Uploads

3. Go to Repositories > Code Snippets and create a new Code Snippet

4. Select the file you uploaded in step 2 from Dependencies

5. Next to Class, enter com.subject7.ModifyXml

6. Save the Code Snippet and go to your test case

7. Create 3 steps with the command Set_Var where each will use the following variable name:

  • xmlFilePath this is where you can add the path to the file. For example: C:/Users/Admin/Downloads/file.xml
  • tagToModify  this is where you can specify the tag you would like to modify in the XML file. 
  • newValue this is where you can add the new value that you will replace the existing one with

8. Create a step with Execute_Java command and select the snippet you created earlier

9. Next to Method, enter modify

10. You can now run your test to modify the XML file

 

Validation of XML file content

If you have an XML file that you would like to validate and get a failure if the value does not match the tag, you can follow the steps below:

1. Download the file from this link

2. Upload the same file to Repositories > File Uploads

3. Go to Repositories > Code Snippets and create a new Code Snippet

4. Select the file you uploaded in step 2 from Dependencies

5. Next to Class, enter com.subject7.VerifyXml

6. Save the Code Snippet and go to your test case

7. Create 3 steps with the command Set_Var where each will use the following variable name:

  • xmlFilePath this is where you can add the path to the file. For example: C:/Users/Admin/Downloads/file.xml
  • tagName this is where you can specify the tag you would like to validate
  • tagValue this is where you can add the value that the tag should have

8. Create a step with Execute_Java command and select the snippet you created earlier

9. Next to Method, enter verify

10. You can now run your test to modify the XML file

Was this article helpful?
1 out of 1 found this helpful
Have more questions? Submit a request

Comments

Please sign in to leave a comment.