Skip to content

Commit 090103e

Browse files
committed
More Implementaions added and code refactored
1 parent ea38ad1 commit 090103e

File tree

20 files changed

+439
-119
lines changed

20 files changed

+439
-119
lines changed

.DS_Store

8 KB
Binary file not shown.

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.settings
2+
.classpath
3+
.project
4+
target
5+
test-output
6+
z_others
7+
README.md

CucumberReports.zip

7.8 MB
Binary file not shown.

pom.xml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
<maven.compiler.source>8</maven.compiler.source>
99
<maven.compiler.target>8</maven.compiler.target>
1010
<!-- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> -->
11-
<cucumber.version>7.2.3</cucumber.version>
11+
<!-- <cucumber.version>7.2.3</cucumber.version> -->
12+
13+
<cucumber.version>7.2.0</cucumber.version>
1214
</properties>
1315

1416

@@ -93,6 +95,26 @@
9395
<version>2.13.1</version>
9496
</dependency>
9597

98+
<!-- https://mvnrepository.com/artifact/me.jvt.cucumber/reporting-plugin -->
99+
<dependency>
100+
<groupId>me.jvt.cucumber</groupId>
101+
<artifactId>reporting-plugin</artifactId>
102+
<version>${cucumber.version}</version>
103+
</dependency>
104+
105+
<!-- https://mvnrepository.com/artifact/org.zeroturnaround/zt-zip -->
106+
<dependency>
107+
<groupId>org.zeroturnaround</groupId>
108+
<artifactId>zt-zip</artifactId>
109+
<version>1.14</version>
110+
</dependency>
111+
112+
<!--https://mvnrepository.com/artifact/com.sun.mail/javax.mail/ -->
113+
<dependency>
114+
<groupId>com.sun.mail</groupId>
115+
<artifactId>javax.mail</artifactId>
116+
<version>1.6.2</version>
117+
</dependency>
96118

97119
</dependencies>
98120
</project>

src/test/java/awesomecucumber/constants/FrameworkConstants.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@ public class FrameworkConstants {
55
// public static final String STORE = "/store";
66
public static final int EXPLICIT_WAIT = 10;
77

8+
public static final String YES = "yes";
9+
public static final String NO = "no";
10+
11+
public static final String PROJECT_NAME = "Automation Test Suite Report - Master Selenium Framework - BDD Cucumber";
12+
813
/* PARAMETERS TO BE USED FROM MAVEN COMMAND LINE */
914
public static final String PARAMETER_ENV = "env";
1015
public static final String PARAMETER_BROWSER = "browser";
1116

12-
13-
/*SUPPORTED BROWSERS*/
17+
/* SUPPORTED BROWSERS */
1418
public static final String BROWSER_CHROME = "chrome";
1519
public static final String BROWSER_FIREFOX = "firefox";
1620
public static final String BROWSER_SAFARI = "safari";
1721
public static final String BROWSER_EDGE = "edge";
1822
public static final String BROWSER_OPERA = "opera";
19-
23+
2024
public static final String ATTRIBUTE_VALUE = "value";
2125

2226
/* ENVIRONMENT CONFIGURATION FILES */
@@ -26,4 +30,9 @@ public class FrameworkConstants {
2630
public static final String ENV_CONFIG_STG = "stg_config.properties";
2731
public static final String ENV_CONFIG_PROD = "prod_config.properties";
2832

33+
/* CUCUMBER REPORTS */
34+
public static final String REPORTS_CUCUMBER_LOCATION = "./target/cucumber/";
35+
public static final String REPORTS_CUCUMBER_LOCAL = REPORTS_CUCUMBER_LOCATION + "cucumber.html";
36+
public static final String REPORTS_ZIPPED_FILE_NAME = "CucumberReports.zip";
37+
2938
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package awesomecucumber.enums;
2+
3+
public enum WaitStrategy {
4+
CLICKABLE, PRESENCE, VISIBLE, NONE
5+
6+
}

src/test/java/awesomecucumber/hooks/MyHooks.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package awesomecucumber.hooks;
22

3-
import static awesomecucumber.constants.FrameworkConstants.BROWSER_EDGE;
3+
import static awesomecucumber.constants.FrameworkConstants.BROWSER_CHROME;
44
import static awesomecucumber.constants.FrameworkConstants.PARAMETER_BROWSER;
55

6+
import org.openqa.selenium.OutputType;
7+
import org.openqa.selenium.TakesScreenshot;
68
import org.openqa.selenium.WebDriver;
79

810
import awesomecucumber.context.TestContext;
911
import awesomecucumber.factory.DriverFactory;
12+
import awesomecucumber.utils.ZipUtils;
1013
import io.cucumber.java.After;
14+
import io.cucumber.java.AfterAll;
1115
import io.cucumber.java.Before;
1216
import io.cucumber.java.Scenario;
1317

@@ -25,7 +29,7 @@ public MyHooks(TestContext context) {
2529

2630
@Before
2731
public void before(Scenario scenario) {
28-
32+
2933
System.out.println(
3034
"BEFORE: THREAD ID : " + Thread.currentThread().getId() + "," + "SCENARIO NAME: " + scenario.getName());
3135

@@ -37,7 +41,7 @@ public void before(Scenario scenario) {
3741
* Setting Edge browser as default
3842
*/
3943
// driver = DriverFactory.initializeDriver(System.getProperty("browser", "edge"));
40-
driver = DriverFactory.initializeDriver(System.getProperty(PARAMETER_BROWSER, BROWSER_EDGE));
44+
driver = DriverFactory.initializeDriver(System.getProperty(PARAMETER_BROWSER, BROWSER_CHROME));
4145

4246
context.driver = driver;
4347
}
@@ -46,6 +50,20 @@ public void before(Scenario scenario) {
4650
public void after(Scenario scenario) {
4751
System.out.println(
4852
"AFTER: THREAD ID : " + Thread.currentThread().getId() + "," + "SCENARIO NAME: " + scenario.getName());
53+
54+
/* This is for attaching the screenshot in Cucumber report */
55+
if (scenario.isFailed()) {
56+
byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
57+
scenario.attach(screenshot, "image/png", scenario.getName());
58+
}
59+
4960
driver.quit();
5061
}
62+
63+
@AfterAll
64+
public static void afterAll() {
65+
ZipUtils.zip();
66+
// EmailSendUtils.sendEmail();
67+
}
68+
5169
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package awesomecucumber.java_Mail_API;
2+
3+
import java.io.IOException;
4+
import java.util.Date;
5+
import java.util.Properties;
6+
7+
import javax.mail.Authenticator;
8+
import javax.mail.Message;
9+
import javax.mail.MessagingException;
10+
import javax.mail.Multipart;
11+
import javax.mail.PasswordAuthentication;
12+
import javax.mail.Session;
13+
import javax.mail.Transport;
14+
import javax.mail.internet.AddressException;
15+
import javax.mail.internet.InternetAddress;
16+
import javax.mail.internet.MimeBodyPart;
17+
import javax.mail.internet.MimeMessage;
18+
import javax.mail.internet.MimeMultipart;
19+
20+
/**
21+
* https://www.codejava.net/java-ee/javamail/send-e-mail-with-attachment-in-java
22+
*/
23+
public class EmailAttachmentsSender {
24+
25+
/**
26+
* i) Send n no. of Attachments
27+
*
28+
* ii) Format set for TC count
29+
*
30+
* iii) Send mail to n no. of Users
31+
*
32+
*/
33+
public static void sendEmailWithAttachments(String host, String port, final String userName, final String password,
34+
String[] toAddress, String subject, String message, String... attachFiles)
35+
throws AddressException, MessagingException {
36+
// sets SMTP server properties
37+
38+
Properties properties = new Properties();
39+
properties.put("mail.smtp.host", host);
40+
properties.put("mail.smtp.port", port);
41+
properties.put("mail.smtp.auth", "true");
42+
properties.put("mail.smtp.starttls.enable", "true");
43+
properties.put("mail.user", userName);
44+
properties.put("mail.password", password);
45+
46+
// creates a new session with an authenticator
47+
Authenticator auth = new Authenticator() {
48+
public PasswordAuthentication getPasswordAuthentication() {
49+
return new PasswordAuthentication(userName, password);
50+
}
51+
};
52+
Session session = Session.getInstance(properties, auth);
53+
54+
// creates a new e-mail message
55+
Message msg = new MimeMessage(session);
56+
57+
msg.setFrom(new InternetAddress(userName));
58+
59+
InternetAddress[] addressTo = new InternetAddress[toAddress.length];
60+
for (int i = 0; i < toAddress.length; i++)
61+
addressTo[i] = new InternetAddress(toAddress[i]);
62+
msg.setRecipients(Message.RecipientType.TO, addressTo);
63+
64+
/*
65+
* InternetAddress[] toAddresses = { new InternetAddress(toAddress) };
66+
* msg.setRecipients(Message.RecipientType.TO, toAddresses);
67+
*/ msg.setSubject(subject);
68+
msg.setSentDate(new Date());
69+
70+
// creates message part
71+
MimeBodyPart messageBodyPart = new MimeBodyPart();
72+
messageBodyPart.setContent(message, "text/html");
73+
74+
// creates multi-part
75+
Multipart multipart = new MimeMultipart();
76+
multipart.addBodyPart(messageBodyPart);
77+
78+
// adds attachments
79+
if (attachFiles != null && attachFiles.length > 0) {
80+
for (String filePath : attachFiles) {
81+
MimeBodyPart attachPart = new MimeBodyPart();
82+
83+
try {
84+
attachPart.attachFile(filePath);
85+
} catch (IOException ex) {
86+
ex.printStackTrace();
87+
}
88+
89+
multipart.addBodyPart(attachPart);
90+
}
91+
}
92+
93+
// sets the multi-part as e-mail's content
94+
msg.setContent(multipart);
95+
96+
// sends the e-mail
97+
Transport.send(msg);
98+
99+
}
100+
101+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package awesomecucumber.java_Mail_API;
2+
3+
import static awesomecucumber.constants.FrameworkConstants.PROJECT_NAME;
4+
5+
/**
6+
* Data for Sending EMail after execution
7+
*/
8+
public class EmailConfig {
9+
10+
public static final String SERVER = "smtp.gmail.com";
11+
public static final String PORT = "587";
12+
13+
public static final String FROM = "*****@gmail.com";
14+
public static final String PASSWORD = "******8";
15+
16+
/* "**********@gmail.com", */
17+
public static final String[] TO = { "****@gmail.com" };
18+
public static final String SUBJECT = PROJECT_NAME;
19+
}

src/test/java/awesomecucumber/pages/BasePage.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
import awesomecucumber.utils.ConfigLoader;
44
import org.openqa.selenium.By;
5+
import org.openqa.selenium.JavascriptExecutor;
56
import org.openqa.selenium.WebDriver;
67
import org.openqa.selenium.WebElement;
78
import org.openqa.selenium.support.PageFactory;
89
import org.openqa.selenium.support.ui.ExpectedConditions;
910
import org.openqa.selenium.support.ui.WebDriverWait;
1011

12+
import static awesomecucumber.constants.FrameworkConstants.ATTRIBUTE_VALUE;
1113
import static awesomecucumber.constants.FrameworkConstants.EXPLICIT_WAIT;
1214

1315
import java.time.Duration;
@@ -38,4 +40,46 @@ public void waitForOverlaysToDisappear(By overlay) {
3840
}
3941
}
4042

43+
public void clearAndSendKeys(WebElement element, String value) {
44+
element = waitForElementVisibility(element);
45+
element.clear();
46+
element.sendKeys(value);
47+
}
48+
49+
public void click(WebElement element) {
50+
waitForElementToBeClickable(element).click();
51+
}
52+
53+
public void click(By by) {
54+
waitForElementToBeClickable(by).click();
55+
}
56+
57+
public WebElement waitForElementVisibility(WebElement element) {
58+
return wait.until(ExpectedConditions.visibilityOf(element));
59+
}
60+
61+
public WebElement waitForElementToBeClickable(WebElement element) {
62+
return wait.until(ExpectedConditions.elementToBeClickable(element));
63+
}
64+
65+
public WebElement waitForElementToBeClickable(By by) {
66+
return wait.until(ExpectedConditions.elementToBeClickable(by));
67+
}
68+
69+
public void scrollToElement(WebElement element) {
70+
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
71+
}
72+
73+
public String getElementText(WebElement element) {
74+
return waitForElementVisibility(element).getText();
75+
}
76+
77+
public String getElementElementAttribute_Value(WebElement element) {
78+
return waitForElementVisibility(element).getAttribute(ATTRIBUTE_VALUE);
79+
}
80+
81+
public String getElementElementCustomAttribute(WebElement element, String customAttribute) {
82+
return waitForElementVisibility(element).getAttribute(customAttribute);
83+
}
84+
4185
}

0 commit comments

Comments
 (0)