Skip to content

Execute tests from a relative path of a scenario file from the PWD(Present Working Directory) #723

Open

Description

@authorjapps

Currently the Zerocode runner can execute a test from the Classpath. That's fine and we will retain this as this is given default to us.
See example:
https://github.com/authorjapps/zerocode/blob/master/http-testing-examples/src/test/java/org/jsmart/zerocode/testhelp/tests/helloworld/JustHelloWorldTest.java

@TargetEnv("github_host.properties")
@RunWith(ZeroCodeUnitRunner.class)
public class JustHelloWorldTest {

    @Test
    @Scenario("helloworld/hello_world_status_ok_assertions.json") <---------- picks from Classapth
    public void testGet() throws Exception {
    }

}

AC1:

But, we need a mechanism to make it flexible to run even if

  • relative path is provided to the scenario file

Example 1:

    $pwd
    /home/authorj/code/zerocode
    $

    then, I should be able to run using below:
    @Test
    //  should pick from relative-apth from PWD //
    @Scenario("./http-testing-examples/src/test/resources/helloworld/hello_world_status_ok_assertions.json")
    public void testGet() throws Exception {
    }

   // in the above PWD =  /home/authorj/code/zerocode, which is represented by "."

Example 2:

    $pwd
    /home/authorj/code/zerocode/http-testing-examples/src
    $

    then, I should be able to run using below:
    @Test
    //  should pick from relative-apth from PWD //
    @Scenario("./test/resources/helloworld/hello_world_status_ok_assertions.json")
    public void testGet() throws Exception {
    }

   // in the above PWD =  /home/authorj/code/zerocode/http-testing-examples/src, which is represented by "."

Linked Issue #722

AC = Acceptance Criteria

Activity

  1. pratyushkumar211 commented on Aug 23, 2025

    @pratyushkumar211

    Hello, I am a first time contributor and interested in making a change to resolve this issue. Can I take this up? Thanks

  2. authorjapps commented on Aug 24, 2025

    @authorjapps
    OwnerAuthor

    Hello, I am a first time contributor and interested in making a change to resolve this issue. Can I take this up? Thanks

    @pratyushkumar211 , Yes please go ahead. Thanks for your interest.

    When you're ready or just before you implement the solution, can you put a summary of what approach or solution you would be implementing?
    This will make everyone to be in sync for PR reviews.

  3. pratyushkumar211 commented on Aug 24, 2025

    @pratyushkumar211

    Thanks @authorjapps !

    I was thinking that the Scenario path gets resolved in the function public static String readJsonAsString(String scenarioFile) in this file: https://github.com/authorjapps/zerocode/blob/master/core/src/main/java/org/jsmart/zerocode/core/utils/SmartUtils.java

    So I can modify the readJsonAsString function with the following additions in the try statement.

      String pwd = System.getProperty("user.dir");
      if (scenarioFile.startsWith("./") || scenarioFile.startsWith("../")) {  
         // Relative path: Resolve from PWD
         scenarioFile = Paths.get(pwd, scenarioFile.substring(2)).normalize().toString(); // Adjust for ../
      }
    

    Could you let me know if this makes sense?
    And are you aware of any other files / function where a change needs to be made to resolve this issue?

  4. nirmalchandra commented on Aug 30, 2025

    @nirmalchandra
    Collaborator

    Thanks @authorjapps !

    I was thinking that the Scenario path gets resolved in the function public static String readJsonAsString(String scenarioFile) in this file: https://github.com/authorjapps/zerocode/blob/master/core/src/main/java/org/jsmart/zerocode/core/utils/SmartUtils.java

    So I can modify the readJsonAsString function with the following additions in the try statement.

      String pwd = System.getProperty("user.dir");
      if (scenarioFile.startsWith("./") || scenarioFile.startsWith("../")) {  
         // Relative path: Resolve from PWD
         scenarioFile = Paths.get(pwd, scenarioFile.substring(2)).normalize().toString(); // Adjust for ../
      }
    

    Could you let me know if this makes sense? And are you aware of any other files / function where a change needs to be made to resolve this issue?

    Hello @pratyushkumar211 , Thanks for asking. Looks good to me.
    But, can you also have a look this has not already implemented like the other ticket for full abs path?

    If not, then your solution approach should work I think.

    • Another query, will this "user.dir" work for Windows OS? worth checking
    • Is there no other way to work out the PWD for all OS in general ?

    Anyway give it a go, and go ahead with the PR.

  5. pratyushkumar211 commented on Sep 6, 2025

    @pratyushkumar211

    Thanks @nirmalchandra. I double checked and did not found this relative path feature implemented already like the abs path, and the String pwd = System.getProperty("user.dir"); command should work for all OS in general as well.

    I have submitted the following PR #727 to resolve this. I will look forward to hearing feedback on my proposed changes and getting the updates incorporated in the main repo. Thanks.

  6. nirmalchandra commented on Sep 6, 2025

    @nirmalchandra
    Collaborator

    Thanks @nirmalchandra. I double checked and did not found this relative path feature implemented already like the abs path, and the String pwd = System.getProperty("user.dir"); command should work for all OS in general as well.

    I have submitted the following PR #727 to resolve this. I will look forward to hearing feedback on my proposed changes and getting the updates incorporated in the main repo. Thanks.

    Thanks @pratyushkumar211 ,
    Can you check the PR comments and fix them?

  7. pratyushkumar211 commented on Sep 6, 2025

    @pratyushkumar211

    Thanks @nirmalchandra. However, I don't see any comments in my PR (#727) and it only says "Review Required" or "1 workflow awaiting approval" like in the screenshot below. Could you let me know how could I check whether those builds are successful or not?

    Thank you

    Image
  8. nirmalchandra commented on Sep 6, 2025

    @nirmalchandra
    Collaborator

    Here is the screenshot of the comment. Let me check why GitHub is not showing you

    Image
  9. Yaksha50 commented on Oct 21, 2026

    @Yaksha50

    Hello, I am begginer in open source contribution and I would like to contribute in this issue. Can I take up this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions