How do I run only Test 3 from the following tests?
module.exports = {
'Test 1':function(){},
'Test 2':function(){}
'Test 3':function(){}
}
A new parameter --testcase has been added to run a specified testcase.
nightwatch.js --test tests\demo.js --testcase "Test 1"
It's a new feature since the v0.6.0
https://github.com/beatfactor/nightwatch/releases/tag/v0.6.0
You must use specific tags before function and separate all functions in diferent files under tests directory, and then call command with --tag argument. See wiki nightwatch tags page and watch this example:
// --- file1.js ---
module.exports = {
tags: ['login'],
'Test 1':function(){
//TODO test 1
}
};
// --- file2.js ---
module.exports = {
tags: ['special', 'createUser'],
'Test 2':function(){
//TODO test 2
},
};
// --- file3.js ---
module.exports = {
tags: ['logoff', 'special'],
'Test 3':function(){
//TODO test 3
},
}
If you run:
nightwatch.js --tag login
only runs Test 1, however if you run:
nightwatch.js --tag special
Test 2 and Test 3 will be executed.
You can specific more than one tag
nightwatch.js --tag tag1 --tag tag2
Separate each test function is mandatory because Nightwatch handled with filematcher each file. See Github code.
PD: If file has syntax errors, is possible that test don't run or test hasn't been found
The --testcase flag can since version 0.6 be used to run a single test from the commandline, e.g.
nightwatch.js --test tests\demo.js --testcase "Test 1"
This could be done using either test groups or test tags. You can also execute a single test with the --test flag, e.g.
nightwatch.js --test tests\demo.js
For me, it only works with:
npm run test -- tests/01_login.js --testcase "Should login into Dashboard"
npm run <script> -- <test suite path> --testcase "<test case>"
my script in package.json:
"test": "env-cmd -f ./.env nightwatch --retries 2 --env selenium.chrome",
at nightwatch version 1.3.4
You can also use tags:
npm run <script> -- <enviroment> <tag>
npm run test -- --env chrome --tag login
just add it to your test case:
module.exports = {
'#tags': ['login', 'sanity', 'zero1'],
...
}
you can do somthing like:
node nightwatch.js -e chrome --test tests/login_test --testcase tc_001
Another possible way of doing so, would be to use the following on each test case that you want to omit:
'#disabled': true,
This can simply be set to false or removed if you wish to test it.
Related
Within a Jenkinsfile, I am running regression tests in pytest and using the --junitxml flag to produce test output.
Each regression test runs in its own stage and captures an .xml file with the test output, I then stash these xml files (as each stage runs on a different agent). After all the regression tests have been run, the stashed files are then recovered for reporting once all tests are done.
Please see below:
stage ('Regression 01') {
agent {
label 'rhel1'
}
steps {
sh "cd /directory1/appServer && /home/appServer/py/venvs/*/bin/python -m " +
"pytest -m fast test-dir/regression_test.py -c conf.cfg --junitxml /share/01.xml"
stash includes: '01.xml', name: 'test01'
}
}
stage ('Regression 02') {
agent {
label 'rhel2'
}
steps {
sh "cd /directory1/appServer && /home/appServer/py/venvs/*/bin/python -m " +
"pytest -m fast test-dir/regression_test.py -c conf.cfg --junitxml /share/1.xml"
stash includes: '02.xml', name: 'test02'
}
}
post {
always {
unstash 'test01'
unstash 'test02'
junit "*.xml"
...
}
}
I have a total of 10 regression tests running which each stash a unique .xml file, I am also looking to add more, therefore hardcoding the XML test names is not feasible.
How can I create some sort of automation or logic within my Jenkinsfile that will do the XML naming, stashing and unstashing?
How to combine result of some mvn tests Jenkinsfile? For example I need to execute cross-browser testing and run three mvn commands on parallel, I need to combine test result of all of them. Are there any ways to achieve that?
steps {
script {
if (browser.equals("chrome")) {
echo 'chrome'
sh 'mvn clean -Dselenide.browser=chrome test'
}
if (browser.equals("all")) {
echo 'all'
parallel(
a: {
sh 'mvn clean -Dselenide.browser=chrome test'
},
b: {
sh 'mvn clean -Dselenide.browser=firefox test'
},
c: {
sh 'mvn clean -Dselenide.browser=edge test'
}
)
}
}
}```
We have a dockerized maven project where we deploy it to the kubernetes via Jenkins and Helm.So the thing that I would like to do is, pass below shell script as a command in deployment.yaml like as below to initate selenium tests while pod is creating. But somehow before I deploy the service, I need to update the variables in shell script according to the conditional statements(jenkins parameters) and then pass to update shell script to the kubernetes pod.
So, is there anyway to add if statements and update variables according to the jenkins parameters and pass through to pod with proper values ?
Shell Script
#!/bin/sh
mvn --projects {$projectName} --also-make clean test -Dcucumber.filter.tags="#${servicename} or #${tag}" -Denvironment=test -Ddhc=true -Djavax.net.ssl.trustStore=/usr/java/openjdk-14/lib/security/cacerts
Deployment.yaml
env:
{{- range $key, $value := .Values.extraEnv }}
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
command: ["/test-script.sh"]
Jenkinsfile
parameters {
string(name: 'projectName', defaultValue: "Xx", description: 'Which project do you want to test?')
string(name: "service_name", defaultValue: 'Yy', description: 'Selenium tag for service name')
string(name: "tag", defaultValue: 'must')
//string(name:'branchName', defaultValue: "origin/development", description: 'Environment for selenium tests')}
stage('Deploy to dev'){
steps{
script{
sh """
helm upgrade --install --debugtest-service --values values.${ENV}.yaml --namespace ${namespace} --set image.tag=${env.BUILD_NUMBER} .
"""
}
}
EDIT-1
ı just added my question according to the below answer. So after running sed and update the script, how can I add a if statement to check value of service name parameter? Or can I use something like
if [ <PROJECTNAME> == "xx]
Here is the steps that I would like to do.
projectName=$1
serviceName=$2
tag=$3
if [ "$serviceName" == "xx" ]
then
echo "Tests are running "..
mvn --projects <PROJECTNAME> --also-make clean test -Dcucumber.filter.tags=""#<SERVICENAME> or #<TAG>""
else
echo 'All test scenarios are running on stage environment'
mvn --projects <PROJECTNAME> --also-make clean test -Dcucumber.filter.tags="#<SERVICENAME> or #<SERVICENAME>" -
fi
You can keep placeholders for such values which requires to be updated dynamically at build time.
I'd keep the shell-script as below with placeholders instead of variables:
#!/bin/sh
mvn --projects <PROJECTNAME> --also-make clean test -Dcucumber.filter.tags="#<SERVICENAME> or #<TAG>" -Denvironment=test -Ddhc=true -Djavax.net.ssl.trustStore=/usr/java/openjdk-14/lib/security/cacerts
And then add a sed line within the sh block above your helm upgrade ... command to replace the placeholders with build time values so that it can passed to the next set of actions.
sh """
sed -i \"s/<PROJECTNAME>/${projectName}/g; s/<SERVICENAME>/${service_name}/g; s/<TAG>/${tag}/g\" /path/to/test-script.sh
helm upgrade . . .
"""
EDIT-1:
Example:
if (serviceName == 'xx') {
env.TAG = serviceName
}
sh """
.... other actions
"""
I created 3 jenkins jobs linked to the same github project, i'm using wdio v5 and cucumber, i want to run each job on a different port this is why i'm trying to pass the port from the jenkins post-build task : execute shell
I tryed this -- --seleniumArgs.seleniumArgs= ['-port', '7777']
then this
-- --seleniumArgs.seleniumArgs= ["-port", "7777"]
then
-- --seleniumArgs.seleniumArgs= '-port: 7777'
but nothing works
i found a solution :
so this is the wdio.conf.js file :
var myArgs = process.argv.slice(2);
Port= myArgs[1]
exports.config = {
////////////////////////
services: ['selenium-standalone'],
seleniumArgs: {
seleniumArgs: ['-port', Port]
},
//////////////////////
}
myArg will receive an array with the arguments passed in the command line
and this is the command
npm test 7777 -- --port 7777
the 7777 is the argument number 2, thus the index 1 in the array,
the index 0 is : wdio.conf.js, which is in the "test" script in package.json
===> "test": "wdio wdio.conf.js"
I just started ts-node utilizing. It is the a very convenient tool. Run time looks clear. But it does not work for CLI solutions. I can not pass arguments into a script compiled.
ts-node --preserve-symlinks src/cli.ts -- printer:A
It does not work. I am asking for a help.
You did not provide your script, so I can only guess at how you are extracting the arguments. This is how I have made it work with my own test script args.ts:
const a = process.argv[2];
const b = process.argv[3];
const c = process.argv[4];
console.log(`a: '${a}', b: '${b}', c: '${c}'`);
Called from package.json like this:
"scripts": {
"args": "ts-node ./args.ts -- 4 2 printer:A"
}
This will give me output like this:
a: '4', b: '2', c: 'printer:A'
command
ts-node ./test.ts hello stackoverflow
ts file
console.log("testing: >>", process.argv[2], process.argv[3]);
output
$ testing: >> hello stackoverflow
Happy coding
Try this:
node --preserve-symlinks -r ts-node/register src/cli.ts printer:A
NODE_OPTIONS
For the case of node options, in addition to -r ts-node/register mentioned at https://stackoverflow.com/a/60162828/895245 they now also mention in the docs the NODE_OPTIONS environment variable: https://typestrong.org/ts-node/docs/configuration/#node-flags
NODE_OPTIONS='--trace-deprecation --abort-on-uncaught-exception' ts-node ./index.ts
A quick test with:
main.ts
(async () => { throw 'asdf' })()
and run:
NODE_OPTIONS='--unhandled-rejections=strict' ts-node main.ts
echo $?
which gives 1 as expected.
Tested on Node v14.16.0, ts-node v10.0.0.