Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 16, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 16, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 16, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 16, 2025

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025

      Minecraft licensing robbed us of this controversial NFL schedule release video

      May 16, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      The power of generators

      May 16, 2025
      Recent

      The power of generators

      May 16, 2025

      Simplify Factory Associations with Laravel’s UseFactory Attribute

      May 16, 2025

      This Week in Laravel: React Native, PhpStorm Junie, and more

      May 16, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025
      Recent

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»How to load Config.properties file in Cucumber TestRunner.java file?

    How to load Config.properties file in Cucumber TestRunner.java file?

    June 24, 2024

    To run my Selenium/Cucumber java project, I need to pass some VM arguments, variables, properties path etc… now easiest way is to pass it in Eclipse run configuration under “VM arguments” tab. I need to give path of Log4j2.xml, sqlJdbc driver, any UserID etc.

    Now, if i put all this in a properties file and then run the “TestRunner’, then how can i make sure properties are loaded before the Features run. I get NullPointerException.

    Can i put this in a static block? THis way will it get initialized before any TestNG feature runs?

    @CucumberOptions(glue = { “stepDefinitions” }, features = {
    “src/test/resources/features/CreateUserProfile.feature” }, plugin = { “pretty”,
    “json:test-output/JsonReport.json”, “html:test-output/HTMLReport.html”,
    “com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:”, })

    public class TestRunner {
    public TestNGCucumberRunner testNGCucumberRunner;

    @BeforeClass(alwaysRun = true)
    public void setUpClass() {
    if (testNGCucumberRunner == null) {
    testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
    }
    }

    @Test(groups = “cucumber scenarios”, description = “Runs Cucumber Scenarios”, dataProvider = “scenarios”)
    public void scenario(PickleWrapper pickleEvent, FeatureWrapper cucumberFeature) throws Throwable {
    testNGCucumberRunner.runScenario(pickleEvent.getPickle());
    }

    @DataProvider
    public Object[][] scenarios() {
    if (testNGCucumberRunner == null) {
    testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
    }
    return testNGCucumberRunner.provideScenarios();
    }

    @AfterClass(alwaysRun = true)
    public void tearDownClass() {
    testNGCucumberRunner.finish();

    }

    static {
    SimpleDateFormat dateFormat = new SimpleDateFormat(“yyyy-MM-dd”);
    System.setProperty(“current.date”, dateFormat.format(new Date()));
    String propertyFilePath = “C:\EclipseWorkspace\Automation\src\main\resources\config.properties”;
    BufferedReader reader;
    try {
    reader = new BufferedReader(new FileReader(propertyFilePath));
    Properties properties = new Properties();
    try {
    properties.load(reader);
    reader.close();
    } catch (IOException e) {
    e.printStackTrace();
    }
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    throw new RuntimeException(“Config.properties not found at ” + propertyFilePath);
    }

    }

    }

    UPDATE:

    I get this error …i have loaded the properties file in the TestRunner.java file, also loaded in the BaseTest.java class where driver is initialized. Still i get this error. Please help. I don’t want to use eclipse VM arguments and want my properties to be loaded from the script only.

    java.lang.NullPointerException: Cannot invoke “String.equalsIgnoreCase(String)” because the return value of “java.lang.System.getProperty(String)” is null

    Source: Read More

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleCodeSOD: Sdrawkcab Error Handling
    Next Article Convolutional Kolmogorov-Arnold Networks (Convolutional KANs): An Innovative Alternative to the Standard Convolutional Neural Networks (CNNs)

    Related Posts

    Machine Learning

    Salesforce AI Releases BLIP3-o: A Fully Open-Source Unified Multimodal Model Built with CLIP Embeddings and Flow Matching for Image Understanding and Generation

    May 16, 2025
    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 16, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    BMW Data Breach Exposes 14,000 Hong Kong Customers’ Personal Information

    Development

    Closing Deals Faster: The Future of Sales with AI & Personalization

    Development

    Map Eloquent Attributes into an Object Using the Collection Cast in Laravel 12.10

    Development

    Josh Krueger of Project Hosts, Inc. Appointed to Federal Secure Cloud Advisory Committee

    Development

    Highlights

    Specialized Solutions: Leveraging SDKs for Enhanced Development

    May 1, 2024

    In my 25+ years of experience, I have seen firsthand that component technology can offer…

    Use Amazon ElastiCache as a cache for Amazon Keyspaces (for Apache Cassandra)

    November 12, 2024

    Monster Hunter Wilds open beta test is live with over 225,000 concurrent Steam players in less than 24 hours

    February 7, 2025

    CVE-2025-40618 – Bookgy SQL Injection Vulnerability

    April 29, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.