Webdriver wait variable null only when running testng.xml file but works fine when the Alltest class is run individually

Im just learning testng and am having trouble executing groups. When I run the Alltests class individually I have no issues and it completes the tests successfully. But when I try to run it through the testng.xml file I get the following error.

java.lang.NullPointerException: Cannot invoke "org.openqa.selenium.support.ui.WebDriverWait.until(java.util.function.Function)" because "this.wait" is null

Ive tried a few things to see if I could identify the issue but was unsuccessful. I tried a print statement in the setup method to see if it even went through that part but it didnt print. So it doesnt even go through the baseclass?

I also tried a few alternative tests to see if there were any issues with testng. I ran a few print statements in a set up and extended class and it worked. But when I tried it with groups i got a similar error. So i think there might be an issue with how ive done the groups?

Please check my code and let me know if I have made any mistakes.

My BaseClass

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.*;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.By;
import java.time.Duration;


public class BaseClass {

    protected WebDriver driver;
    protected WebDriverWait wait;

    Duration timeout = Duration.ofSeconds(50);

    @BeforeMethod
    public void setup() {

        WebDriverManager.chromedriver().setup();
        driver = new ChromeDriver();

        wait = new WebDriverWait(driver, timeout);

        driver.get("http://localhost/Work%20management%20system/");
        System.out.println("Driver and wait initialized.");
    }

    @AfterMethod
    public void tearDown() {
        if (driver != null) {
            driver.quit();
        }
    }


}

My Alltests class

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.testng.Assert;
import org.testng.annotations.Test;



public class Alltests extends BaseClass{

private void loginProcess(String username, String password){

    WebElement login = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("/html/body/div/center[2]/a")));
    login.click();

    WebElement usernamefield = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("/html/body/div/form/input[1]")));
    usernamefield.sendKeys(username);

    WebElement passwordfield = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("/html/body/div/form/input[2]")));
    passwordfield.sendKeys(password);

    WebElement submit = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("/html/body/div/form/button")));
    submit.click();

}

@Test(groups = {"loginTests"})
public void shouldfail(){

    loginProcess("[email protected]", "doughnuts");


    boolean isErrorMessagePresent = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/div/div"))).isDisplayed();

    boolean isAnnouncementAbsent = driver.findElements(By.xpath("/html/body/div/div[3]/div")).isEmpty();

    Assert.assertTrue(isErrorMessagePresent, "Error message should be present");

    Assert.assertTrue(isAnnouncementAbsent, "Announcement button should be absent");

    if (isErrorMessagePresent && isAnnouncementAbsent){

        System.out.print("Test case passed access denied");
    }

}



@Test(groups = {"loginTests"})
public void shouldAlsoFail(){

    loginProcess("[email protected]", "danny1234");


    boolean isErrorMessagePresent = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/div/div"))).isDisplayed();

    boolean isAnnouncementAbsent = driver.findElements(By.xpath("/html/body/div/div[3]/div")).isEmpty();

    Assert.assertTrue(isErrorMessagePresent, "Error message should be present");

    Assert.assertTrue(isAnnouncementAbsent, "Logout button should be absent");

    if (isErrorMessagePresent && isAnnouncementAbsent){

        System.out.print("Test case passed, access denied");
    }
}



@Test(groups = {"loginTests"})
public void willFail(){

    loginProcess("[email protected]", "danny128934");


    boolean isErrorMessagePresent = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/div/div"))).isDisplayed();

    boolean isAnnouncementAbsent = driver.findElements(By.xpath("/html/body/div/div[3]/div")).isEmpty();

    Assert.assertTrue(isErrorMessagePresent, "Error message should be present");

    Assert.assertTrue(isAnnouncementAbsent, "Announcement button should be absent");

    if (isErrorMessagePresent && isAnnouncementAbsent){

        System.out.print("Test case passed access denied");
    }

}



@Test(groups = {"loginTests"})
public void accessAllowed(){

    loginProcess("[email protected]", "danny1234");


    boolean isAnnouncementPresent = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/div/div[3]/div"))).isDisplayed();

    Assert.assertTrue(isAnnouncementPresent, "Announcements should be present");

    if (isAnnouncementPresent){

        System.out.print("Test case passed access is granted");
    }


}

}

My tesng.xml file

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite">
    <test name="Test Group">
        <groups>
            <run>
                <include name="loginTests"/>

            </run>
        </groups>
        <classes>
            <class name="Alltests"/>
        </classes>
    </test>
</suite>

and my pom file

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>LoginTests</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version> 4.21.0 </version>
        </dependency>

        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.10.2</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>5.9.1</version>
        </dependency>


    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>17</source>
                    <target>17</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.3.1</version>
                <configuration>
                    <suiteXmlFiles>
                            <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>


            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>versions-maven-plugin</artifactId>
                <version>2.8.1</version>
            </plugin>

        </plugins>
    </build>

</project>

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật