Writing to notepad based on environment



  • 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?

    IF URL = SYS
    THEN writeToNotepadSYS
    IF URL = UAT
    THEN writeToNotepadUAT
    ELSE writeToNotepadPPT  
    

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

    Thanks.



  • 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:

    <profiles>
        <profile>
            <id>dev</id>
            <properties>
                <myvariable>variableOnDev</myvariable>
            </properties>
        </profile>
        <profile>
            <id>prod</id>
            <properties>
                <myvariable>variableOnProd</myvariable>
            </properties>
        </profile>
    </profiles>
    

    The following code will be decoupled from the values themselves:

    public class MyClass {
        @Value("${myVariable}")
        private String myVariable;
    }
    

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



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2