I have a class with the name CommonSteps.java which contains the following method:
@Then("^the following error is displayed: \"([^\"]*)\"$")
public void the_error_is_displayed(String message) throws Exception {
// although using the login page to retrieve - these will return if visible from any page!
message = errorHelper.generateErrorMessage(message);
assertThat(runtimeState.loginPage.getErrors(), hasItem(containsString(message)));
}
I would like to call this method into another class in an assertion. I have written the following code so far :
@Then("^an upload invoice error message is displayed$")
public void an_upload_invoice_error_message_is_displayed() throws Throwable {
List<Map<String, Object>> invoiceDocuments = dbHelperInvoices.getInvoiceDocumentsFilePath(testData.getInt("orderRef"));
if (invoiceDocuments.get(0).get("jobSheetFilePath") == null && invoiceDocuments.get(0).get("invoiceFilePath") != null) {
assertTrue("Unexpected error message displayed", commonSteps.the_error_is_displayed(message));
My question is what should i use in the place of message variable ? Or what do I need to add to get message variable to work ? As this code is throwing an error. Hope this is enough information. I am new to coding so apologies if this is a daft question.
EDIT: My previous code for this was
public void an_upload_invoice_error_message_is_displayed() throws Throwable {
List<Map<String, Object>> invoiceDocuments = dbHelperInvoices.getInvoiceDocumentsFilePath(testData.getInt("orderRef"));
if (invoiceDocuments.get(0).get("jobSheetFilePath") == null && invoiceDocuments.get(0).get("invoiceFilePath") != null) {
assertTrue("Unexpected error message displayed", runtimeState.uploadInvoiceDocumentPage.isUploadJobSheetErrorDisplayed());
outputHelper.takeScreenshot();
} else if (invoiceDocuments.get(0).get("invoiceFilePath") == null && invoiceDocuments.get(0).get("jobSheetFilePath") != null) {
assertTrue("Unexpected error message displayed", runtimeState.uploadInvoiceDocumentPage.isUploadInvoiceErrorDisplayed());
outputHelper.takeScreenshot();
} else if (invoiceDocuments.get(0).get("invoiceFilePath") == null && invoiceDocuments.get(0).get("jobSheetFilePath") == null){
assertTrue("Unexpected error message displayed", runtimeState.uploadInvoiceDocumentsPage.isUploadInvoiceErrorDisplayed());
assertTrue("Unexpected error message displayed", runtimeState.uploadInvoiceDocumentsPage.isUploadJobsheetErrorDisplayed());
outputHelper.takeScreenshot();
}
}
However, I was told to change the code to call the method from CommonSteps.java above