0

I have gone through several related questions and solutions to solve my problem but none seem to solve mine. So here is my problem I have a properties file under enter image description here

and I need to read this properties file , here's my code

public class DBSPatientContext {
    public static final Logger logger = LoggerFactory.getLogger("TESTCONTEXT");
    public static final String DBS_PROPERTIES = "dbsautomationconfig.properties";

    static {
        try {
            TestContext.loadProperties(this.class.getClassLoader().getResourceAsStream(DBS_PROPERTIES));
        } catch (IOException var1) {
            logger.debug(var1.getMessage(), var1);
        }
    }

It's always returning null. Any help is appreciated

tim_yates
  • 167,322
  • 27
  • 342
  • 338
fOcusWow
  • 383
  • 1
  • 5
  • 14
  • I'd recommend reading this answer for a clear explanation of how to read files on the classpath: http://stackoverflow.com/a/1464366/992151 – cowls May 04 '16 at 20:43
  • Read through it I'm getting false as output through that approach – fOcusWow May 04 '16 at 21:05
  • What's the TestContext class? Also how are you running this? Is src/main/resources definitely on the classpath? – cowls May 04 '16 at 21:11
  • TestContext class is a library java class and the DBSPatientContext is a groovy class. TestContext is basically being used to extract the package name and activity name stored in the properties file and add it to the "adb command..." to open the app and run the test. But it's not able to read the properties file – fOcusWow May 04 '16 at 21:15

2 Answers2

1

Add a slash in front of the filename:

public static final String DBS_PROPERTIES = "/dbsautomationconfig.properties";
Jens
  • 67,715
  • 15
  • 98
  • 113
  • Or move the file into the same folder structure as your class within the resources folder – tim_yates May 04 '16 at 20:30
  • @fOcusWow then try: TestContext.loadProperties(this.class.getResourceAsStream(DBS_PROPERTIES)); and the slash at the beginning. – Jens May 04 '16 at 21:07
  • it didn't work man, one thing I forgot to mention is that the DBSPatientContext class is a groovy class and the TestContext class is java. I dont know how that makes a difference but you might have some insight on it – fOcusWow May 04 '16 at 21:10
  • You've got groovy in `src/main/java?`? – tim_yates May 05 '16 at 09:20
  • You can see in the screenshot DBSPatientContext is under src/main/java/...TestFrmwk – fOcusWow May 10 '16 at 16:23
0

Worked out fine later on. I think it was something random all together. Reloaded and rebuilt the project and it worked fine.

fOcusWow
  • 383
  • 1
  • 5
  • 14