-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat[TE-17324] Addon for sending reply mails (#52)
* feat[TE-17324] Addon for sending reply mails * Resolved review changes * review changes
- Loading branch information
1 parent
1c560cf
commit 79673e7
Showing
3 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.testsigma.addons</groupId> | ||
<artifactId>reply_mails</artifactId> | ||
<version>1.0.0</version> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>11</maven.compiler.source> | ||
<maven.compiler.target>11</maven.compiler.target> | ||
<testsigma.sdk.version>1.2.8_cloud</testsigma.sdk.version> | ||
<junit.jupiter.version>5.8.0-M1</junit.jupiter.version> | ||
<testsigma.addon.maven.plugin>1.0.0</testsigma.addon.maven.plugin> | ||
<maven.source.plugin.version>3.2.1</maven.source.plugin.version> | ||
<lombok.version>1.18.20</lombok.version> | ||
|
||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.testsigma</groupId> | ||
<artifactId>testsigma-java-sdk</artifactId> | ||
<version>${testsigma.sdk.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>${lombok.version}</version> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<version>${junit.jupiter.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.testng</groupId> | ||
<artifactId>testng</artifactId> | ||
<version>6.14.3</version> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java --> | ||
<dependency> | ||
<groupId>org.seleniumhq.selenium</groupId> | ||
<artifactId>selenium-java</artifactId> | ||
<version>4.14.1</version> | ||
</dependency> | ||
<!-- https://mvnrepository.com/artifact/io.appium/java-client --> | ||
<dependency> | ||
<groupId>io.appium</groupId> | ||
<artifactId>java-client</artifactId> | ||
<version>9.0.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-annotations</artifactId> | ||
<version>2.13.0</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
<build> | ||
<finalName>reply_mails</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.2.4</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-source-plugin</artifactId> | ||
<version>${maven.source.plugin.version}</version> | ||
<executions> | ||
<execution> | ||
<id>attach-sources</id> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
74 changes: 74 additions & 0 deletions
74
reply_mails/src/main/java/com/testsigma/addons/web/SendReplyMails.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.testsigma.addons.web; | ||
|
||
import com.testsigma.sdk.ApplicationType; | ||
import com.testsigma.sdk.annotation.Mailbox; | ||
import com.testsigma.sdk.MailboxMessage; | ||
import com.testsigma.sdk.Result; | ||
import com.testsigma.sdk.WebAction; | ||
import com.testsigma.sdk.annotation.*; | ||
import lombok.Data; | ||
import org.openqa.selenium.NoSuchElementException; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
|
||
@Data | ||
@Action(actionText = "Reply to the mail with body that contains the subject in mail-name mail-box ", | ||
description = "Reply to the mail that matches the subject in the mail box", | ||
applicationType = ApplicationType.WEB) | ||
public class SendReplyMails extends WebAction { | ||
|
||
private static final String SUCCESS_MESSAGE = "Successfully replied to the mail."; | ||
private static final String MAIL_ERROR_MESSAGE = "Mail contains the given subject not found"; | ||
|
||
@TestData(reference = "body") | ||
private com.testsigma.sdk.TestData body; | ||
@TestData(reference = "subject") | ||
private com.testsigma.sdk.TestData subject; | ||
@TestData(reference = "mail-name") | ||
private com.testsigma.sdk.TestData mail; | ||
|
||
@Mailbox | ||
private com.testsigma.sdk.Mailbox mailbox; | ||
|
||
private com.testsigma.sdk.Email email; | ||
|
||
@Override | ||
protected Result execute() throws NoSuchElementException { | ||
mailbox.setEmail(mail.toString()); | ||
try { | ||
List<MailboxMessage> messageList = mailbox.getMessages(); | ||
MailboxMessage requiredMessage = null; | ||
for (MailboxMessage message : messageList) { | ||
if (message.getSubject().contains(subject.toString())) { | ||
requiredMessage = message; | ||
break; | ||
} | ||
} | ||
if(requiredMessage == null){ | ||
setErrorMessage(MAIL_ERROR_MESSAGE); | ||
return Result.FAILED; | ||
} | ||
String messageId = email.getMessageId(requiredMessage.getHeaders()); | ||
Map<String, String> headersList = new HashMap<>(); | ||
headersList.put("In-Reply-To", messageId); | ||
headersList.put("References", messageId); | ||
|
||
List<String> to = new ArrayList<>(); | ||
to.add(requiredMessage.getReceivedFrom()); | ||
email.setTo(to); | ||
email.setSubject("Re:" + subject.toString()); | ||
email.setBody(body.toString()); | ||
email.setHeader(headersList); | ||
email.send(); | ||
setSuccessMessage(SUCCESS_MESSAGE); | ||
return Result.SUCCESS; | ||
} catch (Exception e) { | ||
setErrorMessage(e.toString()); | ||
return Result.FAILED; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
testsigma-sdk.api.key=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJkZWYtZHNzZndlc2xkbGY0aTg4c2pkZmoiLCJ1bmlxdWVJZCI6IjE3IiwiZXh0ZXJuYWxUZW5hbnRJZCI6IjEifQ.lmcMsU7DUbHCc-9H28o7qIX3XCYixGYNaIKlxzi-jIznhcsqFI5jAkzwoBLiG6m7ByAgcrsT_pe-DW3cf2qhWA |