-
-
Notifications
You must be signed in to change notification settings - Fork 374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System env property as placeholder token in the test steps #248
Comments
@authorjapps I started working on this issue, got it working but want to run the solution by everyone to see what they think. In github_host.properties I added the value as an environment variable: Test class refers to the properties file: Inside the property section, it replaces all properties that meet the regex Haven't tested it loads but it does work, wanted to see others thoughts before progressing. |
@jneate thanks mate 👍 . For everyone's benefit(and to make it easy to understand) I am putting the below comments. Reading properties from the What Jame's solution will do is- e.g. (one of its application could be) config propertiesdb_port=${MONGO_DB_PORT} Then the developer/tester can run the test(s) against different ports(27018, 27019 etc) or different hosts(dev, sit, uat/preprod etc) or typically in Jenkins pipeline by maven runtime args via
or
or
or
Hello @ashishMal, can you review n comment here please ? Folkd for your review please- @santhoshTpixler @BeTheCodeWithYou @officiallysameer |
Thanks @jneate for the solution and @authorjapps for the explanation. Let me check and come back to this. |
@authorjapps @ashishMal - Just one slight clarification to my earlier comment, I'd originally coded it so that you could access environment variables by referencing them inside the properties file. Example: If you want to pass the variables via the -D flag then I just need to change the code from Hope this helps. |
Right now we can override the properties file with It is possible to use either propery file or System properties which can be choosen at run-time. @ashishMal Will this solution be useful for you? |
@santhoshTpixler I thought @ashishMal still wanted to use the property files but pass values to the property file via -D because I assume there will be property values in the config that remain consistent regardless of the target environment and the command could become quite lengthy dependent on the number of properties. |
@jneate Looks like the requirement is to use both the property file and System properties.
Property files are used to solve the quoted issue. We use multiple properties file with environment name prefixed to keep it simple and maintainable. I haven't seen where the environment variables change quite often. Let's say there is a need to override couple of properties frequently, then a @ashishMal can you comment on this? |
Yeah I agree @santhoshTpixler that it looks a bit overkill, I thought at first it was to retrieve environment variables as opposed to properties. Maybe we just need to update the documentation providing more examples but let's wait and see. |
@ashishMal , Picking/Configuring/Running Env specific properties - Maven/Gradle |
@ashishMal any update on this? |
Hi @authorjapps/ @jneate Although it is working but I was looking for some other approach like reading system properties directly in the test json files. @authorjapps I cannot use the approach of environment specific files as I have some system properties which I want to read at the time of executing it. But thanks calling a class before all the test cases and replacing the property value will do. |
@ashishMal, Thanks for further details! Let me reiterate it below- 1Actually you are looking for
and the
Fair enough until this point. We will sort that out for you soon! 2and you really don't need is -- to resolve this from a
In this case, Now the Q is -
We know you are already unblocked(that's fine), but we can have this as |
@authorjapps Can we have a place holder like ${SYSTEM.PROP:host} which will be resolved to |
Yes exactly, this is something I am looking for. |
@ashishMal - Thanks for the clarification, I'll update and come back |
Hi @jneate /@authorjapps/ @santhoshTpixler Any update/workaround to the problem above? |
@ashishMal , sorry mate, we were a little busy with other issues/PRs. @jneate , just checking, if you could pick this and amend the PR please(sometimes this week? )? |
@ashishMal @authorjapps - Hoping to pick this up tonight, sorry about the delay work has been really busy. |
@authorjapps @santhoshTpixler - PR raised to address |
@ashishMal mate, we are trying to fit this into the release Thanks for your patience! |
Release done mate @ashishMal. stackoverflow link- https://stackoverflow.com/questions/56252109/zerocode-set-system-property-in-host-configuration-file Maven dependency: <dependency>
<groupId>org.jsmart</groupId>
<artifactId>zerocode-tdd</artifactId>
<version>1.3.9</version>
</dependency> |
Thanks @authorjapps |
@ashishMal requested a feature via StackOverFlow n Gitter.
Background
I need to load the system properties in one class like host etc. and once they are loaded, It can be used in all the further test cases/scenarios like normal properties as ${propetyName}.
Check this stackoverflow link- https://stackoverflow.com/questions/56252109/zerocode-set-system-property-in-host-configuration-file
From SOF
Configuration:
zerocode-tdd.1.3.2
${host}
At runtime, system property set with -D java option. All is well.
Problem / What I Need:
At unit test time, system property not set, and host not resolved.
App uses Junit and Zerocode, would like to simply configure Zerocode to set the system property.
Example:
host.properties
More Info:
Requirement is for configuration only. Can't introduce new Java code, or entries into IDE.
Any help out there? Any ideas are appreciated.
More Details
@siddhagalaxy wrote-
This sounds similar to your question, but defined in the config file instead of system-env.
Can you check this answer - https://stackoverflow.com/questions/54716763/reading-extra-properties-or-host-addresses-inside-the-json-test-case/55077950#55077950
Solution
User is looking for host to be supplied as system-env? so that he can execute the test for different hosts in runtime ?
e.g.
-Dhost=https://dev1.local.uk
or
-Dhost=https://sit1.local.uk
Workaround
He has worked it out correctly, which is great! 👍 (which unblocks you)
We will make it more straight forward soonish...
(Checking with other committers for the best approach... Probably you can pick this ticket and contribute. This shd be a minor code change only)
History
@ashishMal replied in SOF-
Found a solution, but not sure if this is the correct way to do so.
Step 1: Create a config file and load system properties.
Config.java
Step 2: Add a step (before other steps) to use the loaded properties in the .json file.
test.json
Step 3: Use loaded property in step config
test.json
That's it, although it is working but I am looking for better approach.
Some possible options I am trying are:
Again any help/ideas are appreciated.
The text was updated successfully, but these errors were encountered: