Hey guys, I have been working on expanding some code coverage, and created some testing logic for a fall back.
Example:
Zip code entered into site searching for medical plans, no plans can be found for specific zip code so a new page loads indicating that.
I have one test case that tests End to End on successful zip codes, and I have a few bad zip codes to check error handling in order to make sure the error page loads.
I have another Test case (FallBack) for testing the error page, I created some logic if a specific test step fails and the error page loads to call a different test case.
I have the test case/test suite working really well, only issue I recently discovered is when the “Fallback” test case runs from a zip code that should have passed I don’t have any sort of notification from the failure. Recently we had an outage, and the test suite said everything was solid, because in practice it was… One failed fallback ran, and verified that the error page loads.
So my solution is I want to implement a custom keyword to send an email when the fallback execution starts.
I have written the java class, and created the custom keyword, I need to test it to make sure it works, but I am unsure how to trigger/call the custom keyword. So that the email is sent when a test class starts, I am not sure on the scripting syntax since it won’t be tied to an element but to a Test Case.
CustomKeywords.'emails.email_Send(NO_IDEA_WHAT_TO_PUT_HERE)
Am I bonkers? This seems like it shouldn’t be very difficult.
Can someone point me in the right direction.
Example of custom Keyword
package emails import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase import static com.kms.katalon.core.testdata.TestDataFactory.findTestData import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject import static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject import com.kms.katalon.core.annotation.Keyword import com.kms.katalon.core.checkpoint.Checkpoint import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile import com.kms.katalon.core.model.FailureHandling import com.kms.katalon.core.testcase.TestCase import com.kms.katalon.core.testdata.TestData import com.kms.katalon.core.testobject.TestObject import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI import com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows import internal.GlobalVariable import java.util.*; import javax.mail.*; import javax.mail.internet.*; import javax.activation.*; public class SendEmail { @Keyword public static void main(String[] args) { String host="smtp.office365.com"; final String user="FROM_EMAIL_ADDRESS_HERE"; //change accordingly final String password="FROM_EMAIL_PASSWORD_HERE"; //change accordingly String to="TO_EMAIL_ADDRESS_HERE"; //change accordingly //Get the session object Properties props = new Properties(); props.put("mail.smtp.host",host); props.put("mail.smtp.auth", "true"); Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(user,password); } }); //Compose the message try { MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(user)); message.addRecipient(Message.RecipientType.TO,new InternetAddress(to)); message.setSubject("Test"); message.setText("This is simple program of sending email using JavaMail API"); //send the message Transport.send(message); System.out.println("message sent successfully..."); } catch (MessagingException e) {e.printStackTrace();} } }