Receive an Email and click a link?

What is the reason behind this scenario? You want to verify generated link is correct in term of its server address and generated activation token if any? Or extend further is when you click on this link the browser will redirect you to successful page?
Anyway in the first case :

  1. Clean-up the email inbox before this test scenario,any new email matching a pattern like ‘Welcome to my site…’ will be the correct activation email.
  2. Open this email and search for any text matching with the activation link. Make sure the server address is asserted first,and then assert generated activation token using regex comparison.
    You can store the search algorithm to be a variable and paste it directly to a browser

I believe if you really need to test this ,just make sure there is only one emailed-link in the email

Just an ideal to approach this test scenario.


Thanks, Blaze. That Quora thread was interesting.

Whatever you come up with, it would be nice if you could post a generic version (if possible) in the Tips & Tricks forum.

Take your time. I’m sure it’ll be worth it in the end

Addendum: Just saw Vinh’s approach arrive. Yes, that’s interesting too. Vinh’s main point seems to be, you’re not meant to be testing – that’s someone else’s job :wink:

1 Like


And this.

Testing an email service sounds like it should be out-of-scope of your responsibility to test the application itself. If you know the link that is injected into the email, this should suffice.

I’m not really understanding my error…any thoughts?

ohhh it’s maven stuff… not sure how to get this into Katalon…


do it your java stuff in e.g in JIDEA (maven project) and then create artifacts .jar file
import jar to Katalon (Drivers folder)
create Keyword where call java methods
in Katalon groovy class
//from .jar file
import com.package.java_class_name.*;

//create object
<package. object = new package.java_class_name();

//call method


Unfortunately there’s no dependency management tool integrated into the studio, so you would need to download a jar for each external library that you need. Follow this guide:

Looks like I might not even need maven for this I just get this error:

Groovy:No expression for the array constructor call at line: 

which is referring to this:

messages = unreadMessages.toArray(new Message[]{});

this is the only error in code when I’m trying to set this up but don’t understand what to do about it…

I’ve tried some rewrites but all give different errors.

SUCCESS! So a fellow manager and I spent 4 hours working on this and finally came up with the solution together. He doesn’t really do java and never seen Katalon till I showed it to him. So we put our heads together and hit the web and used this as a starting point:

Here is how I made it work in Katalon, with outlook and with returning a URL I can navigate to:

First I created a package and a class under keywords. I import the package and class into my test when I use it.

Here is the code I have in the class:

package emailVerification

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.mail.Folder;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

import org.jsoup.Jsoup as Jsoup;

 * from
 * Author(s): B_L
 * Created: 01/30/2019
 * Last Modified by: B_L
 * Last Modified: 01/30/2019
 * Purpose: Grab verify link from email
public class FetchEmailVarLink {

	public static check(String host, String storeType, String user,
			String password) {
		try {
			String emailLink = ''
			//create properties field
			Properties properties = new Properties();

			properties.put("mail.imap.port", "993");
			properties.put("mail.imap.starttls.enable", "true");
			properties.setProperty("mail.imap.socketFactory.fallback", "false");
			Session emailSession = Session.getDefaultInstance(properties);

			//create the imap store object and connect with the pop server
			Store store = emailSession.getStore("imap");

			store.connect(host, user, password);

			//create the folder object and open it
			Folder emailFolder = store.getFolder("INBOX");;

			// retrieve the messages from the folder in an array and print it
			MimeMessage[] messages = emailFolder.getMessages();
			//System.out.println("messages.length---" + messages.length);
			int n=messages.length;

			//change n- to number of emails you want to dig through
			for (int i = n-5; i<n; i++) {
				MimeMessage message = messages[i];
				ArrayList<String> links = new ArrayList<String>();

				if(message.getSubject().contains("Verify your email for project") || message.getSubject().contains("Sign in to project")){
					//System.out.println("Subject: " + message.getSubject());
					MimeMultipart messageBody = message.getContent();

					String desc = messageBody.getBodyPart(1).getContent().toString();

					//System.out.println("Description: " + desc);
					Pattern linkPattern = Pattern.compile("href=\"(.*?)\"",  Pattern.CASE_INSENSITIVE|Pattern.DOTALL);
					Matcher pageMatcher = linkPattern.matcher(desc);
					System.out.println("Email:"+ i + " is not a wanted email");
				for(String temp:links){
						emailLink = temp;

			emailLink = Jsoup.parse((emailLink).toString()).text();
			return emailLink;

			//close the store and folder objects

		} catch (NoSuchProviderException e) {
		} catch (MessagingException e) {
		} catch (Exception e) {


	public static String getEmailLinkFromEmail(){
		String host = "";
		String mailStoreType = "imap";
		String username = "yourEmail";
		String password = "yourPassword";

		String emailLink = check(host, mailStoreType, username, password);
		return emailLink;


short example:

import emailVerification.FetchEmailVarLink

String emailLink = FetchEmailVarLink.getEmailLinkFromEmail()
WebUI.navigateToUrl(emailLink, FailureHandling.CONTINUE_ON_FAILURE)

Long example in a test case:

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 com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable

import miscMethods.MiscMethods
import filePath.FilePath

import areaValuesAndObjects.Page1
import areaValuesAndObjects.Page2
import areaValuesAndObjects.Login
import emailVerification.FetchEmailVarLink

 * Author: B_L
 * Last Modified: 01/30/2019
 * Last Modified By: B_L

String FilePath = FilePath.getScreenShotFilePath()
String screenShotPath = FilePath + '02_testfolder\\'


WebUI.openBrowser(MiscMethods.getCOP_URL(), FailureHandling.CONTINUE_ON_FAILURE)
WebUI.maximizeWindow(), FailureHandling.CONTINUE_ON_FAILURE)
WebUI.setText(Login.emailAddressInput, 'yourEmail', FailureHandling.CONTINUE_ON_FAILURE), FailureHandling.CONTINUE_ON_FAILURE)
WebUI.takeScreenshot(screenShotPath + '01 screenname.jpg', FailureHandling.OPTIONAL)

String emailLink = FetchEmailVarLink.getEmailLinkFromEmail()
WebUI.navigateToUrl(emailLink, FailureHandling.CONTINUE_ON_FAILURE)
WebUI.verifyElementPresent(Page2.thingLabel, 0, FailureHandling.CONTINUE_ON_FAILURE)
WebUI.verifyElementPresent(Page2.otherThingLabel, 0, FailureHandling.CONTINUE_ON_FAILURE)
WebUI.takeScreenshot(screenShotPath + '02 Navigating to link from email.jpg', FailureHandling.OPTIONAL)

I hope this is helpful for everyone this was a nightmare for me as I am not really a programmer. Self taught on java when I looked into Katalon. I tried to take out custom data so no secure data is shared but you still get use out of it.



I am new in katalon.I want to automated the scenario in Outlook in which i need to click on search box and enter the text.

Could you please me.

I am trying to fetch the xpath for search box but it is not working.


You can automate but not the Outlook executable (at least, not without using Winium).

However, I would refer you to the statement I made earlier in this thread:

Hey @Russ_Thomas

Thanks for replying.
Scenario which included following steps:
1.login to outlook.
2. click and enter the data on search text box.
3.Click on that filtered mail. on one button present on that email which opens the new window from the application.

Please let me know how can I automate these scenario.What should I do.


I am not able to understand this step. How we can filter email without giving any conditions ? I think you want to login into Outlook and then click on the Search text box, enter text to search ( that will display filtered data), then click on the filtered data and so on.

Hi @manpreet.mukkar

You are right.its my mistake.

Thanks for correcting it.
Could you please help me in that.


If you haven’t started automating this scenario yet then you can start recording this scenario using the recording functionality within the Katalon Studio, if you encounter any issue you can post it over here and someone would pick it up to help you automate it. Please follow this format

Hi Team, How can we handle the Xpath having Spaces   in Subject Line

As I need to verify the Notification mailers


The following code will do what you want:

TestObject tObj = new TestObject(text).addProperty("xpath", ConditionType.EQUALS,
		'//span[contains(.,"Ultimatrix") and contains(.,"Data") and contains(.,"Hub") and contains(.,":") and contains(.,"DHANYA(527014)") and contains(.,"have") and contains(.,"reject") and contains(.,"3") and contains(.,"row(s)") and contains(.,"from") and contains(.,"S1") and contains(.,"in") and contains(.,"DemoMailer2") and contains(.,"-") and contains(.,"2020") and contains(.,"FY") and contains(.,"Q4") and contains(.,"-") and contains(.,"Projection")]'
WebUI.verifyElementPresent(tObj, 10, FailureHandling.CONTINUE_ON_FAILURE)

I Tried this, but its too Lengthy and Time taken…Is thr any other way to create…I means where it handles " "

You should be able to write a Groovy function which

  1. as an input parameter, takes a string "Ultimatrix Data Hub : DHANYA(527014) have reject 3 row(s) from S1 in DemoMailer2 - 2020 FY Q4 - Projection"
  2. based on the given string, generates and return a XPath expression string '//span[contains(.,"Ultimatrix") and contains(.,"Data") and contains(.,"Hub") and contains(.,":") and contains(.,"DHANYA(527014)") and contains(.,"have") and contains(.,"reject") and contains(.,"3") and contains(.,"row(s)") and contains(.,"from") and contains(.,"S1") and contains(.,"in") and contains(.,"DemoMailer2") and contains(.,"-") and contains(.,"2020") and contains(.,"FY") and contains(.,"Q4") and contains(.,"-") and contains(.,"Projection")]'

It is just a string-to-string transformation. Please try to develop that Groovy code for yourself.