我怎样才能将 Weblement 调用到另一个 class

How can I call the Weblement to the other class

public class LoginPagePages {
    @FindBy(how=How.XPATH,using="//div[@class='validation-summary-errors text-danger']/ul/li")
    WebElement incorrect_username;
}

如何将 WebElement incorrect_username; 传递给 class LoginPageTestCase,以便我可以将其文本放入 String errorsign 并将其用于我的断言

public class LoginPageTestCase {

    @Test(priority=1)
    public void IncorrectPassword() {

        String errorsign = I NEED TO CALL HERE THE "WebElement incorrect_username".getText();

        Assert.assertEquals(errorsign, "Username is incorrect");
        Add_Log.info("Login Failed");
    }

您可以在测试中创建 LoginPagePages 的实例并使用 getter 获取它

public class LoginPagePages {
    @FindBy(how=How.XPATH,using="//div[@class='validation-summary-errors text-danger']/ul/li")
    private WebElement incorrect_username;

    public WebElement getIncorrectUsername {
        return incorrect_username;
    }
}

public class LoginPageTestCase {

    @Test(priority=1)
    public void IncorrectPassword() {

        LoginPagePages loginPage = new LoginPagePages();
        String errorsign = loginPage.getIncorrectUsername().getText();

        Assert.assertEquals(errorsign, "Username is incorrect");
        Add_Log.info("Login Failed");
    }
}