Zipping XML file in Jmeter - jmeter

I need to create a xml file and then zip and upload.
I am able to create xml file and upload but fail to zip the file.
Can we zip xml files using Jmeter. Please let me know if anyone has a working code

There are multiple ways of archiving the file in JMeter, the easiest is calling 3rd-party program like zip or 7zip console archiver using OS Process Sampler.
Alternatively you can use
JSR223 Test Elements
Groovy language
and java.util.zip API
for generating a zip archive on the fly programmatically, example code would be something like:
import org.apache.commons.io.IOUtils
def xml = new File('/path/to/your/file.xml')
def zip = new File('/path/to/created/archive.zip')
def out = new java.util.zip.ZipOutputStream(new FileOutputStream(zip))
out.putNextEntry(new java.util.zip.ZipEntry(xml.getName()))
xml.withInputStream {
IOUtils.copy(it, out)
}
IOUtils.closeQuietly(out)

Related

Cypress: How to attachFile from different folder

I have to upload a file from a different folder than /fixtures.
If I use attachFile it always adds the path cypress/fixtures in front of it.
cy.get('input[type="file"]').attachFile(this.uploadFileName );
cy.get('#file-submit').click();
Where this.uploadFileName has an absolute path to the file.
The file is generated before, so it is not really a fixture anyway.
Currently, attachFile can only import file from the fixtures folder. Hence, the generated file has to be imported into the fixture file (via task and fs.copy()).

How to modify the file on the fly while copying from one location to other in gradle

I want to modify the contents of file while making the .jar out of it. To do so i am trying to modify the "processResources" task like below -
processResources{
println 'process resources..'
from('./dist'){
into('static')
}
}
Here i have some html files under "dist" folder which I want to modify while copying it into .jar
I have copied the file but didn't get any solution to modify the file while copying.
This is spring boot project along with gradle build tool.
Any help much appreciated!!
Gradle offers out of the box a number of options for changing files during a Copy operation.
I recommend having a look at the relevant documentation and in particular the filter {} block, which can look at files content line by line.
Found the nice documentation which covers the file operations in gradle in great details-
https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch01.html
the solution to my problem is like this >>
processResources{
println 'process resources..'
from('./dist'){
into('static')
filter{
line -> line.replace("old-string","new-string")
}
}
}

Run tag-dependent Python script on Sphinx build

I need to run a simple Python script to copy a set of files from one directory to another during the build-phase of my Sphinx documentation.
Copying function:
location: source/_plugins/copy_firmware_files.py
import json, os, sys
from pathlib import Path
import shutil
def copy_firmware_files(device):
# copy firmware files
I'm currently importing this module into my conf.py as the Configuration File contains the device name, which would make it a simple way to execute the code. I'm currently doing this as below:
Configuration File (conf.py)
location: source/conf.py
sys.path.append(os.path.abspath("_plugins"))
from copy_firmware_files import *
# initialize files depending on build
copy_firmware_files(device_name)
The above works as intended, i.e. the relevant files are copied to their respective folders before the build. However, I'm unsure if it's the "proper" way to do so. Is there a more correct way of achieving the same result?
There are several ways, but it sounds like two are most appropriate. They are static files and could be treated as such by Sphinx.
html_extra_path is one option.
If you want to present links to download the files, you can use the download directive.
See :download:`this example script <../example.py>`.

Qt Installer project: how to generate package.xml and config.xml

I try to make my Qt Installer project more comfortable.
I need to centralize information about my application and components (config.xml and package.xml) in one file. I don't want to jump on different files with same name and search for changeable elements between xml tags.
My first thougt is doing it right in *.pro file of installer project. I place sections of variables in header of installer project file. But where I need to place the code for xml generating?
What is the better (native / comfortable / crossplatform) way to do this?
The answer is simple here: you cannot generate XML files for Qt Installer: you write them manually, as explained in the documentation.
This section describes the following tasks that you must accomplish to create the installer:
Create a package directory that will contain all the configuration files and installable packages.
Create a configuration file that contains information about how to build the installer binaries and online repositories.
Create a package information file that contains information about the installable components.
Create installer content and copy it to the package directory.
Use the binarycreator tool to create the installer.
However, if you look closer at the examples, you can still generate the installer in the *.pro file. Let's pick an example randomly, System Info:
TEMPLATE = aux
INSTALLER = installer
INPUT = $$PWD/config/config.xml $$PWD/packages
example.input = INPUT
example.output = $$INSTALLER
example.commands = ../../bin/binarycreator -c $$PWD/config/config.xml -p $$PWD/packages ${QMAKE_FILE_OUT}
example.CONFIG += target_predeps no_link combine
QMAKE_EXTRA_COMPILERS += example
OTHER_FILES = README
If you want to apply this to your project, I think you'll have to modify the ../../bin/binarycreator line and make it system aware, by changing your PATH. It might be possible to call an external script and parse XML files, and make the substitutions you would like to do, but you'd move the complexity to another place.
Instead of maintaining plain good old XML files, you would be creating something between XSLT and XML. Maybe you could just write XSLT (or XSL or XQUERY) and generate XML but I don't know anyone who is using it anymore. Last time I used it was when I was learning Computer Science a long time ago :)
This is possible using the QMAKE_SUBSTITUTES feature which will substitute qmake variables into the given input files and put the output in the build folder.
This runs at qmake time rather than at build time. If this is suitable then you just need to add a target to copy the generated files from the build dir to your source dir.
If you need it to run at build time then you can create a .pri file containing QMAKE_SUBSTITUTES and a target in the main .pro file that will run qmake on this file during the build process.
Main .pro file:
create_xml.commands += $(QMAKE) $$shell_quote($$PWD/config/generate_xml.pri) $$escape_expand(\n\t)
create_xml.commands += $(COPY) $$shell_quote($${OUT_PWD}/config.xml) $$shell_quote($$PWD/config) $$escape_expand(\n\t)
create_xml.commands += $(COPY) $$shell_quote($${OUT_PWD}/package.xml) $$shell_quote($$PWD/packages/my.app.id/meta) $$escape_expand(\n\t)
create_xml.depends = $$PWD/version.pri
QMAKE_EXTRA_TARGETS += create_xml
generate_xml.pri:
TEMPLATE = aux
message("Generating $$OUT_PWD/config.xml and $$OUT_PWD/package.xml")
# Get the version number
include(version.pri)
APP_VERSION = $$VERSION
QMAKE_SUBSTITUTES += package.xml.in config.xml.in
config.xml.in: Note that you need to escape the quotes.
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<Installer>
<Name>MyApp</Name>
<Version>$$APP_VERSION</Version>
...

Include docx file in asciidoc?

I am using asciidoc with asciidoctor to create documentation for a current project.
I notice there is a markup to include files in the documentation like so:
link:index.html
or
link:protocol.json[Open the JSON file]
Is it possible to include a docx file as a link so that it would open externally or be able to downloaded?
Also can I put this file in a folder inside my asciidoc directory (for the sake of organization) and still be able to properly reference it?
You write something like this:
Open this link:somefile.docx[Word file] should work.
Or this link:file:///C:/Users/xxx/docs/otherfile.docx[second file].
It works with relative path or absolute path.
You need to ensure that the path to your file will be correct for the reader of your document.
Example: if you put the HTML files produced by Asciidoctor on a webserver (public or intranet), having a path referencing your local C: is not a good idea.
It is hard to tell you what to do without knowledge of your publication/distribution toolchain.

Resources