Does anyone know of a way that I can write to my notepad file, but depending on the environment it is running on, what notepad file to write to?

So for example, I've automated an account setup, as it completes it writes to a notepad with the location held in the constants class. I'm looking to know if I set up multiple locations in the constants class, can I switch which location the file is stored in based on the environment that the tests are currently being ran in?

THEN writeToNotepadSYS
THEN writeToNotepadUAT
ELSE writeToNotepadPPT  

Some bad psuedocode that I hope will help clear up my issue.


  • 2
    use driver.getCurrentUrl() to get the url and pass the url to function – PDHide Feb 12 at 9:46
  • Do you think the best approach is to get the value from the App.Debug.Config? That's the config that will be running when the selenium tests have kicked off. Is this function standalone? – automationlife Feb 12 at 10:18
  • thanks for your help by the way, I can't seem to reply directly to you, so I'm not even sure if that, or this comment will even get to you. – automationlife Feb 12 at 10:19
  • I am not sure how your project looks like , how you deploy it, if using CI/CD there will eb variables that let you know the enviroment to which deployment happens . Use thos variable and pass it as command line argument – PDHide Feb 12 at 10:21
  • perfect, thank you! – automationlife Feb 12 at 10:31

In general, what you are looking for is called Dependency Injection:

You want to decouple your code from the data it uses, moving the responsibility of sending this data to the callers of your code.

There are innumerable ways of applying it. Below is an example of setting a variable to a prod or dev environments:

If you setup a configuration XML file like the following:


The following code will be decoupled from the values themselves:

public class MyClass {
    private String myVariable;

To pick which profile you want to run, you run it with -Dspring.profiles.active=dev or -Dspring.profiles.active=prod

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.