Bazel unable to read .properties file.

221 views
Skip to first unread message

Kehinde Adeoya

unread,
Sep 22, 2023, 10:28:15 AM9/22/23
to bazel-discuss
I have tried all suggested ways in the Bazel book/documentation online, and all other forum resources to configure it to work with loading .properties file but none has worked so far.  It  is a simple config.properties file. When I run the BUILD file , it returns file not found exception. 

load("@rules_java//java:defs.bzl", "java_test")

java_test(
name = "testng_integration",
args=["/Users/user/Documents/project/Bench/MultiLangTestFramework/WebPOM/src/test/resources/testrunners/testng_regressions.xml"],
data=["testng_regressions.xml",
"//WebPOM/src/test/resources/config:config_properties"],
resources = ["//WebPOM/src/test/resources/config:config_properties"],
main_class="org.testng.TestNG",
runtime_deps = [
"//WebPOM/src/main/java/com/qa/opencart/listeners:extent_report_listener",
"//WebPOM/src/test/java/com/qa/opencart/tests:login_steps",
"//WebPOM/src/test/java/com/qa/opencart/base:base_test",
"@maven//:org_apache_logging_log4j_log4j_slf4j_impl",
],
use_testrunner=False,
visibility = ["//visibility:public"],
)


All help would be appreciated. 
Error
bazel test --tool_tag=ijwb:IDEA:community --curses=no --color=yes --progress_in_terminal_title=no --build_event_binary_file=/var/folders/78/k56g5_1s17nb2ybq7_2f_gl00000gp/T/intellij-bep-a9e37988-9507-4ed0-9cec-3280dc8d675f --nobuild_event_binary_file_path_conversion -- //WebPOM/src/test/resources/testrunners:testng_integration
Testing started at 14:55 ...
Loading:
Loading:
Loading: 0 packages loaded
Analyzing: target //WebPOM/src/test/resources/testrunners:testng_integration (0 packages loaded, 0 targets configured)
INFO: Analyzed target //WebPOM/src/test/resources/testrunners:testng_integration (1 packages loaded, 4 targets configured).
INFO: Found 1 test target...
[0 / 6] [Prepa] BazelWorkspaceStatusAction stable-status.txt
[6 / 7] Testing //WebPOM/src/test/resources/testrunners:testng_integration; 1s darwin-sandbox
Target //WebPOM/src/test/resources/testrunners:testng_integration up-to-date:
bazel-bin/WebPOM/src/test/resources/testrunners/testng_integration.jar
bazel-bin/WebPOM/src/test/resources/testrunners/testng_integration
INFO: Elapsed time: 1.582s, Critical Path: 1.39s
INFO: 5 processes: 1 internal, 3 darwin-sandbox, 1 worker.
INFO: Build completed successfully, 5 total actions
//WebPOM/src/test/resources/testrunners:testng_integration PASSED in 1.1s

Executed 1 out of 1 test: 1 test passes.
There were tests whose specified size is too big. Use the --test_verbose_timeout_warnings command line option to see which ones these are.
INFO: Build completed successfully, 5 total actions
INFO: Build Event Protocol files produced successfully.

Generated test.log (if the file is not UTF-8, then this may be unreadable):
exec ${PAGER:-/usr/bin/less} "$0" || exit 1
Executing tests from //WebPOM/src/test/resources/testrunners:testng_integration
-----------------------------------------------------------------------------
...
... TestNG 7.8.0 by Cédric Beust (cedric@beust.com)
...

Test Suite started!
java.io.FileNotFoundException: ./src/test/resources/config/config.properties (No such file or directory)
at java.base/java.io.FileInputStream.open0(Native Method)
at java.base/java.io.FileInputStream.open(FileInputStream.java:219)
at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
at java.base/java.io.FileInputStream.<init>(FileInputStream.java:112)
at com.qa.opencart.factory.PlaywrightFactory.init_prop(PlaywrightFactory.java:91)
at com.qa.opencart.base.BaseTest.setup(BaseTest.java:28)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139)
at org.testng.internal.invokers.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:69)
at org.testng.internal.invokers.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:390)
at org.testng.internal.invokers.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:325)
at org.testng.TestRunner.invokeTestConfigurations(TestRunner.java:663)
at org.testng.TestRunner.beforeRun(TestRunner.java:652)
at org.testng.TestRunner.run(TestRunner.java:614)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:443)
at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:481)
at org.testng.internal.thread.ThreadUtil.lambda$execute$0(ThreadUtil.java:58)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
homePageTitleTest started!
homePageTitleTest skipped!
homePageTitleTest failed!
===== Invoked methods
=====
Test Suite is ending!
FAILED CONFIGURATION: @BeforeTest com.qa.opencart.base.BaseTest.setup("chrome")
java.lang.NullPointerException
at com.qa.opencart.base.BaseTest.setup(BaseTest.java:31)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139)
at org.testng.internal.invokers.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:69)
at org.testng.internal.invokers.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:390)
at org.testng.internal.invokers.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:325)
at org.testng.TestRunner.invokeTestConfigurations(TestRunner.java:663)
at org.testng.TestRunner.beforeRun(TestRunner.java:652)
at org.testng.TestRunner.run(TestRunner.java:614)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:443)
at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:481)
at org.testng.internal.thread.ThreadUtil.lambda$execute$0(ThreadUtil.java:58)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)

SKIPPED CONFIGURATION: @AfterTest com.qa.opencart.base.BaseTest.tearDown
SKIPPED: com.qa.opencart.tests.HomePageTest.homePageTitleTest
java.lang.NullPointerException
at com.qa.opencart.base.BaseTest.setup(BaseTest.java:31)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139)
at org.testng.internal.invokers.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:69)
at org.testng.internal.invokers.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:390)
at org.testng.internal.invokers.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:325)
at org.testng.TestRunner.invokeTestConfigurations(TestRunner.java:663)
at org.testng.TestRunner.beforeRun(TestRunner.java:652)
at org.testng.TestRunner.run(TestRunner.java:614)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:443)
at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:481)
at org.testng.internal.thread.ThreadUtil.lambda$execute$0(ThreadUtil.java:58)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)


===============================================
Open Cart Home Page Test_chrome
Tests run: 3, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
===============================================


===============================================
Open Cart Test Regression PW Suite
Total tests run: 0, Passes: 0, Failures: 0, Skips: 0
===============================================

This is the project structure




David Turner

unread,
Sep 22, 2023, 12:09:23 PM9/22/23
to Kehinde Adeoya, bazel-discuss
Your Java exception shows that the program tries to find "./src/test/resources/config/config.properties" in the current directory, which happens to be a sandbox populated by `bazel test` based on the content of `runtime_deps`.

This attribute does not list this file, which appears in `resources` instead. I believe the latter is only used to ensure the file is embedded in the .jar file instead.
Maybe adding the file to `runtime_deps` will solve it, or find a way for your test program to read it from its own resource pool instead?

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/60215a42-b09c-4a4f-8eec-1b6b7015cfben%40googlegroups.com.

Kehinde Adeoya

unread,
Sep 25, 2023, 4:37:01 AM9/25/23
to bazel-discuss
Thanks for the answer. I have tried all possible suggestions in the books/forums to no avail, including the one you suggested now. 

Gunnar Wagenknecht

unread,
Sep 25, 2023, 6:33:36 AM9/25/23
to Kehinde Adeoya, bazel-discuss
Resources from the class path should be loaded with with the ClassLoader.getResourceAsStream method. You need to inspect the jar file at which location Bazel puts it. There is some default stripping implement. You can override it with resource_strip_prefix.

Data files can be accessed from the file system. Did you try the data attribute?

-Gunnar


-- 
Gunnar Wagenknecht
gun...@wagenknecht.org, http://guw.io/



Kehinde Adeoya

unread,
Sep 25, 2023, 7:12:29 AM9/25/23
to bazel-discuss
I have attached the whole project. I really need help in this case. It's been over a week I have been on to run this simple PoC. How do I inpsect "the jar file at which location Bazel puts it"? I'm a newbie to Bazel.

Reply all
Reply to author
Forward
0 new messages