How to add profile variable in Karate - karate

Currently I am using the following command to run my feature file:
mvn test -Dcucumber.options="--plugin html:target/cucumber-html --tags #dogs" -Dtest=TestParallel.java -Dkarate.env=Pets
But I wish to add another variable while calling running the command. Something like this:
mvn test -Dcucumber.options="--plugin html:target/cucumber-html --tags #dogs" -Dtest=TestParallel.java -Dkarate.env=Pets -Dname=Charlie
How can I do that?

You can pass extra dynamic parameters using a combination of Java system-properties and reading karate.properties
mvn test -Dtest=TestParallel.java -Dkarate.env=pets -Dmy.name=foo
And then in karate-config.js
var myName = karate.properties['my.name'];
Or even in any feature file:
* def myName = karate.properties['my.name']
Kindly do note that -Dcucumber.options="--plugin html:target/cucumber-html" does not have any effect in Karate and will be deprecated in the future.

Related

How to have log4j.properties read env variables

This should just be a quick question. I am wondering if this syntax would be correct.
Inside log4j.properties
log4j.rootLogger=${ROOT_LOGGER:INFO}, console
So what I'm trying to achieve is to have a ROOT_LOGGER env variable and if it's not present, fallback to INFO. I know this works in .yaml files, so just wondering if the same applies here.
Long time but Im going to put my found solution here.
we can add vars on properties like:
${sys:some.property:-default_value}
${env:ENV_NAME:-default_value}
build.gragle dependencies
dependencies {
implementation "org.apache.logging.log4j:log4j-api:2.14.1"
implementation "org.apache.logging.log4j:log4j-core:2.14.1"
}
log4j2.properties
appender.consoledev.type=Console
appender.consoledev.name=CONSOLEDEV
appender.consoledev.layout.type=PatternLayout
appender.consoledev.layout.pattern=%d{HH:mm:ss.sss} %5p %20logger{36} : %msg%n
loggers=logapp
logger.logapp.name=${sys:logging.package:-com.test}
logger.logapp.level=${sys:logging.level:-DEBUG}
logger.logapp.additivity=false
logger.logapp.appenderRef.consoledev.ref=CONSOLEDEV
running jar with args
java -jar -Dlogging.level=INFO -Dlogging.package=com.test.MainClass test.jar
java -jar -Dlogging.level=INFO -Dlogging.package=com.test test.jar
java -jar -Dlogging.level=DEBUG -Dlogging.package=root test.jar

Run Same Testcafe tests with different URLs per environment

I am working on a TestCafe proof of concept. I have a few tests working in one test environment. I need a way to run the same tests in up to 3 different test environments that have different URLs. Is there a best practice for this scenario?
A solution is to add custom options on the testcafe command-line like for example : --env=uat.
Use minimist to read all custom options that you have added to the TestCafe command-line and export a config object like this:
import * as minimist from 'minimist';
const args = minimist(process.argv.slice(2));
// get the options --env=xxx --user=yyy from the command line
export const config = {
env: args.env,
user: args.user,
};
Then import that config object wherever you need it in the test code.
see How do I work with configuration files and environment variables? for more details.
In v1.20.0 and later, TestCafe offers a way to specify the baseUrl in the test run setup:
CLI
Program API runner.run({baseUrl})
Config file
You can use this approach along with environment variables or custom command line arguments to determine what url should be assigned to the baseUrl option.
Alternatively, you can have a different configuration file for each test run setup and switch between these files using the --config-file option.

NoraUI - How to skip a scenario test?

I'm looking for a tag like "ignore" to skip a scenario test in NoraUI.
I tried this but it is not working :
#ignore
Scenario: 1 - Renvoi d’un rejet de mouvement Reflex
You not need add all run scenario tags in --tags of Maven command
sample:
-Dcucumber.options="--tags #hello,#bye,#Tag5,#tag10"
You can run all scenarios without some scenarios:
--tags ~#todo --tags ~#wip
full official notice here
Be careful, in NoraUi 3.x.x use io.cucumber => syntax change:
-Dcucumber.options="--tags '#hello or #bye or #Tag5 or #tag10'"

Play framework and SBT fail to override configuration with ENV variable

For some reason i fail to override a property in my configuration file when running tests with SBT.
Note that when I run the tests with IntelliJ and set the environment variable from there, the configuration file value is being overridden properly.
Here is what i am doing
application.conf:
mongodb.uri = "mongodb://mongodb:27017/"
mongodb.uri = ${?MONGO_URI}
In my SBT file I have:
fork in run := false
fork in test := false
And I run the tests like so:
sbt -DMONGO_URI=mongodb://localhost:27018/ clean test
But that doesn't work.
What am I doing wrong?
You can add a java option for test like this:
javaOptions in test += "-DMONGO_URI=mongodb://localhost:27018/"

PHPUnit --loader: What is a test suite loader for?

PHPUnit manual say:
If you point the PHPUnit command-line test runner to a directory it will look for *Test.php files.
see: http://www.phpunit.de/manual/3.6/en/organizing-tests.html#organizing-tests.filesystem
This is wrong!
When i call:
phpunit --config myconfig.xml --bootstrap mybootstrap.php tests
It takes all php files.
First idea was to use blacklist or whitelist in the config xml, but then i realised, that these lists are filters for subject under tests and filters test classes.
Second thought was to use testsuites within the config xml. But at the moment the test suites can be defined only, but not executed via command line (not jet implemented in PHPUnit, ticket is open for more than 1 year).
Next thought was to use a test suite loader, but i can not find a documentation on how to use them and if a tsl is what i think it is.
When i run:
phpunit --config myconfig.xml --bootstrap mybootstrap.php --loader My_Testsuite_Loader tests
PHPUnit takes all php file in "tests/" and executes them. The file "My/Testsuite/Loader.php" will be included. PHPUnit checks if the class My_Testsuite_Loader exists. All fine so far.
I used the "PHPUnit/Runner/StandardTestSuiteLoader.php" as template for "My/Testsuite/Loader.php". It contains the methods "load()" and "reload()". Both methods are never called by the PHPUnit Framework. Why not? I thought to have a own testsuiteloder will give me the oportunity to implement a test suite exclude schema.
Sample file system of my project:
<root>
|-src/MyProject/Package/Object.php
|-tests/MyProject/Package/Object/TestTemplate.php
|-tests/MyProject/Package/Object/GetFooTest.php
|-tests/MyProject/Package/Object/GetBarTest.php
|-tests/phpunit.xml
|-tests/bootstrap.php
|-tests/My/Testsuite/Loader.php
As you can see i use one file for all tests about a sut (method under test). All these *Test.php files inherits from TestTemplate (TestCase). In TestTemplate.php is a setup which initializes the object (Object.php) and stores it in a private member var.
How to use the test suite loader / for what is it meant to be?
(How to exclude test classes that do not fit to the pattern: "*Test.php"?)
You need to take out the 'tests' argument like so
phpunit --config myconfig.xml --bootstrap mybootstrap.php
Then in your myconfig.xml
<testsuites>
<testsuite name="AllTests">
<directory>.</directory>
</testsuite>
<testsuites>
<filter>
<blacklist>
<directory suffix=".xml">.</directory>
<file>MyProject/Package/Object/TestTemplate.php</file>
</blacklist>
</filter>