Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat[TE-17324] Addon for sending reply mails #52

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions reply_mails/pom.xml
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>
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;

@Email
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;
}
}
}
1 change: 1 addition & 0 deletions reply_mails/src/main/resources/testsigma-sdk.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testsigma-sdk.api.key=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJkZWYtZHNzZndlc2xkbGY0aTg4c2pkZmoiLCJ1bmlxdWVJZCI6IjE3IiwiZXh0ZXJuYWxUZW5hbnRJZCI6IjEifQ.lmcMsU7DUbHCc-9H28o7qIX3XCYixGYNaIKlxzi-jIznhcsqFI5jAkzwoBLiG6m7ByAgcrsT_pe-DW3cf2qhWA
navyana-srivalli marked this conversation as resolved.
Show resolved Hide resolved
Loading