Read and Write Gmail Messages


This is a companion discussion topic for the original entry at https://store.katalon.com/product/39#qa-content

Hello, Latest version 1.1.0 released with new custom keywords.

com.testwithhari.katalon.plugins.Gmail.getEmailsCount 
com.testwithhari.katalon.plugins.Gmail.sendEmail

Hi Hari

I’ve been using your plugin (Great!) and was wondering how to get hold of the latest message content. How is the data returned? If I try:

System.out.println(‘Content=’ + CustomKeywords.‘com.testwithhari.katalon.plugins.Gmail.readLatestEMailBodyContent’(‘Sample@gmail.com’, ‘Sample’,
‘Inbox’))

The following is returned:
Content=–000000000000133a4c05862ce8e5

Do you have any working example of use?

Many thanks - Great plugin

Hi Weebud, Thanks for your message.

As you described, "readLatestEMailBodyContent " keyword returning ‘hashcode’ for an email body content because you trying to read an email which has HTML content init. Currently, my plugin supports email content with ‘text/plain’ formate only. I’m shortly updating keywords to support all email content formats including ‘text/HTML’. You can expect a new version of the plugin shortly.

Regarding a sample project showing how to use all keywords, I will shortly share a GitHub repository with all sample details.

Meanwhile, if you come across any issues please let me know.

Thanks,

Hari

2 Likes

Hi Hari,
Thank you for the great plugin.
Using the keyword ‘.readLatestEmailBiodyContent’ I am able to successfully see the text within an email. However I have been unable to get a value within an email (a verification code). should i be able to get/store a specifc value within an email using this custom keyword?

Hi Rob2, Thanks for the message.

’readLatestEMailBodyContent’ method just read and returns the mail content in string format. Script developers should store the returned value in a variable and can read the portion of content using Java/Groovy String functions capabilities. For example, using 'String substring(int beginIndex, int endIndex)'

I hope this answer would help you to achieve your requirements. However, shortly I am going upload a youtube video which can show how to work with this plug-in and also a sample project in GitHub. Please watch this space. Thanks

2 Likes

Hey hari,

I have tried to use your plugin but not able to read latest email. Its reading random email. Also, I am getting hashcode for plain text emails. Could you please provide sample project for this plugin.

Regards
Suraj

Hi Hari,

Could you please check my issue. I got
> org.codehaus.groovy.runtime.InvokerInvocationException: javax.mail.MessagingException: Connection refused: connect;

  nested exception is:
	java.net.ConnectException: Connection refused: connect
	at com.testwithhari.katalon.plugins.Gmail.invokeMethod(Gmail.groovy)
	at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:49)

I had allowed less secure app to access Gmail, but still no result

hi,

you have to allow 3 part software to access gmail application by changing gmail settings
https://support.google.com/accounts/answer/6010255?hl=en

Any new info on the sample project in github or the youtube video? I can’t figure out how to use this plugin. Thanks!

hi,

what about organisation policy rules?

This is awesome plug in Hari! Can you please provide sample test case/video to start with this plug in thanks.

Regards, Mahesh (Wellington)

Hi,

Please find my code I am able to login and read the latest mail but its coming in hash format (in print), Please do let me know how do I use in string format or I can write the text/string in excel/csv. Excel code is not working for me,

Working code is here for gmail.

WebUI.openBrowser(’’)

WebUI.delay(5)

WebUI.maximizeWindow()

WebUI.navigateToUrl(‘https://accounts.google.com/signin/v2/identifier?service=mail&passive=true&rm=false&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin’)

WebUI.delay(2)

WebUI.setText(findTestObject(‘BrowserTest/input_Continue’), ‘xxxxx’)

WebUI.click(findTestObject(‘BrowserTest/Temp/New Folder/span_Next_1’))

WebUI.delay(3)

WebUI.setEncryptedText(findTestObject(‘BrowserTest/input_password’), ‘xxxx’)

WebUI.delay(5)

WebUI.click(findTestObject(‘BrowserTest/Temp/New Folder/span_Next_2’))

WebUI.delay(20)

not_run: WebUI.click(findTestObject(‘BrowserTest/Temp/New Folder/a_Sent’))

WebUI.delay(3)

not_run: WebUI.click(findTestObject(‘BrowserTest/Temp/New Folder/a_Inbox’))

WebUI.delay(3)

CustomKeywords.‘com.testwithhari.katalon.plugins.Gmail.getEmailsCount’(‘xxxx@gmail.com’, ‘xxxxx’, ‘Inbox’)

text = CustomKeywords.‘com.testwithhari.katalon.plugins.Gmail.readLatestEMailBodyContent’(‘xxxxx’, ‘xxxx’,
‘Inbox’)

System.out.println(text)

Hi satish1607,

Thanks for your message.
I have just updated the plugin with few bug fixes. Get latest version 1.2.0. And also the sample project is here https://github.com/hariprasadms/Katalon-Gmail-Plugin-Sample-Project to refer to keywords usage.

Let me know if need more help.

Thanks,

Hari

Hi Mahesh,

Thanks for your message.

I have just updated the plugin with few bug fixes. Get latest version 1.2.0. And also the sample project is here https://github.com/hariprasadms/Katalon-Gmail-Plugin-Sample-Project to refer to keywords usage.

Thanks,

Hari

1 Like

Hi Brian_batt,

Thanks for your message.

I have just updated the plugin with few bug fixes. Get latest version 1.2.0. And also the sample project is here https://github.com/hariprasadms/Katalon-Gmail-Plugin-Sample-Project to refer to keywords usage.

Thanks,

Hari

My issue with

Connection refused: connect

solved. How? Check your antivirus application, it can blocks Katalon Studio application. Just disable antivirus

Thank you!

When I try to run your sample for reading the latest email, I’m getting this error:


Elapsed time: 4.274s

com.testwithhari.katalon.plugins.Gmail.invokeMethod:0

Test Cases/try read latest email in mailbox FAILED.
Reason:
org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: java.lang.Boolean.call() is applicable for argument types: (com.testwithhari.katalon.plugins.Gmail$_writePart_closure1) values: [com.testwithhari.katalon.plugins.Gmail$_writePart_closure1@2a65bb85]
Possible solutions: wait(), any(), wait(long), each(groovy.lang.Closure), any(groovy.lang.Closure), and(java.lang.Boolean)
	at com.testwithhari.katalon.plugins.Gmail.invokeMethod(Gmail.groovy)
	at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:49)
	at try read latest email in mailbox.run(try read latest email in mailbox:16)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:336)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:327)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:306)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:298)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:232)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
	at TempTestCase1557173074877.run(TempTestCase1557173074877.groovy:21)
Caused by: groovy.lang.MissingMethodException: No signature of method: java.lang.Boolean.call() is applicable for argument types: (com.testwithhari.katalon.plugins.Gmail$_writePart_closure1) values: [com.testwithhari.katalon.plugins.Gmail$_writePart_closure1@2a65bb85]
Possible solutions: wait(), any(), wait(long), each(groovy.lang.Closure), any(groovy.lang.Closure), and(java.lang.Boolean)
	at com.testwithhari.katalon.plugins.Gmail.writePart(Gmail.groovy:262)
	at com.testwithhari.katalon.plugins.Gmail.readLatestEMailBodyContent(Gmail.groovy:67)
	at com.testwithhari.katalon.plugins.Gmail.invokeMethod(Gmail.groovy)
	at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:49)
	at Script1556925375410.run(Script1556925375410.groovy:16)
	... 11 more```

Any ideas?

Hi Bruab_Batt,

Thanks for sharing error details.
I suggest try this with a new project along with plugin updated for latest version.

I suggest do not try to run sample project directly. This error because sample project does not have link with gmail plugin added.

Let me know if you have still issues.

Regards,

Hari

Thanks Hari For sharing the new Gmail Project,

Could you please let me know how to install it when I tried from store its not showing install button.

Mean time I am also getting the below error.

2019-05-07 10:44:32.631 DEBUG testcase.temp - 17: com.testwithhari.katalon.plugins.Gmail.readLatestEMailBodyContent("xxx@gmail.com", “xxxxxx”, “Inbox”)
2019-05-07 10:44:35.081 INFO com.kms.katalon.core.util.KeywordUtil - ***********************************************************
2019-05-07 10:44:35.120 INFO com.kms.katalon.core.util.KeywordUtil - This is the message envelope
2019-05-07 10:44:35.122 INFO com.kms.katalon.core.util.KeywordUtil - ---------------------------
2019-05-07 10:44:35.333 INFO com.kms.katalon.core.util.KeywordUtil - FROM: noreply@smartcontrols.bt.com

2019-05-07 10:44:35.429 ERROR k.k.c.m.CustomKeywordDelegatingMetaClass - :x: groovy.lang.MissingMethodException: No signature of method: java.lang.Boolean.call() is applicable for argument types: (com.testwithhari.katalon.plugins.Gmail$_writePart_closure1) values: [com.testwithhari.katalon.plugins.Gmail$_writePart_closure1@61874b9d]
Possible solutions: wait(), any(), wait(long), and(java.lang.Boolean), each(groovy.lang.Closure), any(groovy.lang.Closure)
2019-05-07 10:44:35.464 ERROR c.k.katalon.core.main.TestCaseExecutor - :x: com.testwithhari.katalon.plugins.Gmail.readLatestEMailBodyContent("xxx@gmail.com", “xxxx”, “Inbox”) FAILED.
Reason:
org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: java.lang.Boolean.call() is applicable for argument types: (com.testwithhari.katalon.plugins.Gmail$_writePart_closure1) values: [com.testwithhari.katalon.plugins.Gmail$_writePart_closure1@61874b9d]
Possible solutions: wait(), any(), wait(long), and(java.lang.Boolean), each(groovy.lang.Closure), any(groovy.lang.Closure)
at com.testwithhari.katalon.plugins.Gmail.invokeMethod(Gmail.groovy)
at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:49)
at temp.run(temp:48)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:331)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:322)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:301)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:293)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:227)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1557222237121.run(TempTestCase1557222237121.groovy:21)
Caused by: groovy.lang.MissingMethodException: No signature of method: java.lang.Boolean.call() is applicable for argument types: (com.testwithhari.katalon.plugins.Gmail$_writePart_closure1) values: [com.testwithhari.katalon.plugins.Gmail$_writePart_closure1@61874b9d]
Possible solutions: wait(), any(), wait(long), and(java.lang.Boolean), each(groovy.lang.Closure), any(groovy.lang.Closure)
at com.testwithhari.katalon.plugins.Gmail.writePart(Gmail.groovy:262)
at com.testwithhari.katalon.plugins.Gmail.readLatestEMailBodyContent(Gmail.groovy:67)
at com.testwithhari.katalon.plugins.Gmail.invokeMethod(Gmail.groovy)
at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:49)
at Script1556621018263.run(Script1556621018263.groovy:48)
… 11 more

2019-05-07 10:44:35.474 ERROR c.k.katalon.core.main.TestCaseExecutor - :x: Test Cases/BrowserTest/temp FAILED.
Reason:
org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: java.lang.Boolean.call() is applicable for argument types: (com.testwithhari.katalon.plugins.Gmail$_writePart_closure1) values: [com.testwithhari.katalon.plugins.Gmail$_writePart_closure1@61874b9d]
Possible solutions: wait(), any(), wait(long), and(java.lang.Boolean), each(groovy.lang.Closure), any(groovy.lang.Closure)
at com.testwithhari.katalon.plugins.Gmail.invokeMethod(Gmail.groovy)
at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:49)
at temp.run(temp:48)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:331)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:322)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:301)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:293)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:227)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1557222237121.run(TempTestCase1557222237121.groovy:21)
Caused by: groovy.lang.MissingMethodException: No signature of method: java.lang.Boolean.call() is applicable for argument types: (com.testwithhari.katalon.plugins.Gmail$_writePart_closure1) values: [com.testwithhari.katalon.plugins.Gmail$_writePart_closure1@61874b9d]
Possible solutions: wait(), any(), wait(long), and(java.lang.Boolean), each(groovy.lang.Closure), any(groovy.lang.Closure)
at com.testwithhari.katalon.plugins.Gmail.writePart(Gmail.groovy:262)
at com.testwithhari.katalon.plugins.Gmail.readLatestEMailBodyContent(Gmail.groovy:67)
at com.testwithhari.katalon.plugins.Gmail.invokeMethod(Gmail.groovy)
at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:49)
at Script1556621018263.run(Script1556621018263.groovy:48)
… 11 more

2019-05-07 10:44:35.499 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/BrowserTest/temp