getData(Method method) {
31 |
32 | return TestDataReader.use(XlsxReader.class)
33 | .withTarget(TestData.class)
34 | //By default, it looks for files in src/test/resources directory
35 | .withSource(TEST_DATA_XLSX_FILE)
36 | .read()
37 | // .filter(testData -> testData.getTestCaseName().equalsIgnoreCase("titleValidationTest"));
38 |
39 | // Using Java reflection -> Getting method name and use it for filtering
40 | .filter(testData -> testData.getTestCaseName().equalsIgnoreCase(method.getName()));
41 | }
42 |
43 |
44 | //@DataProvider(name = "getInvalidLoginData")
45 | public static Object[][] REFERENCE_getInvalidLoginData() {
46 | return new Object[][]{
47 | //Username, Password, Expected Error Message
48 | {"Admin", "admin1234", "Invalid credentials"}
49 | };
50 | }
51 |
52 | //@DataProvider(name = "getValidLoginData")
53 | public static Object[][] REFERENCE_getValidLoginData() {
54 | return new Object[][]{
55 | //Username, Password, Expected Page Title
56 | {"Admin", "admin123", "OrangeHRM"}
57 | };
58 | }
59 |
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/com/learning/driver/Driver.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Rajat Verma
3 | * https://www.linkedin.com/in/rajat-v-3b0685128/
4 | * https://github.com/rajatt95
5 | * https://rajatt95.github.io/
6 | *
7 | * Course: Selenium - Java with Docker, Git and Jenkins (https://www.testingminibytes.com/courses/selenium-java-with-docker-git-and-jenkins/)
8 | * Tutor: Amuthan Sakthivel (https://www.testingminibytes.com/)
9 | */
10 |
11 | package com.learning.driver;
12 |
13 | import com.learning.config.ConfigFactory;
14 | import org.openqa.selenium.WebDriver;
15 |
16 | //final -> We do not want any class to extend this class
17 | public class Driver {
18 |
19 | //private -> We do not want anyone to create the object of this class
20 | private Driver() {
21 | }
22 |
23 | public static void initDriver() {//method should do only 1 thing
24 |
25 | String browser = ConfigFactory.getConfig().browser().trim();
26 | if (DriverManager.getDriver() == null) {
27 | WebDriver driver = DriverFactory.getDriver(browser);
28 |
29 | //threadLocal.set(driver);
30 | DriverManager.setDriver(driver);
31 |
32 | //driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
33 | //driver.manage().timeouts().implicitlyWait(config.timeout(), TimeUnit.SECONDS);
34 | // driver.manage().timeouts().implicitlyWait(ConfigFactory.getConfig().timeout(), TimeUnit.SECONDS);
35 | // threadLocal.get().manage().timeouts().implicitlyWait(ConfigFactory.getConfig().timeout(), TimeUnit.SECONDS);
36 | //DriverManager.getDriver().manage().timeouts().implicitlyWait(ConfigFactory.getConfig().timeout(), TimeUnit.SECONDS);
37 | DriverManager.getDriver().manage().window().maximize();
38 |
39 | //driver.get("https://opensource-demo.orangehrmlive.com/");
40 | // driver.get(config.url());
41 | //driver.get(ConfigFactory.getConfig().url());
42 | //threadLocal.get().get(ConfigFactory.getConfig().url());
43 | DriverManager.getDriver().get(ConfigFactory.getConfig().url());
44 |
45 | }
46 | }
47 |
48 | public static void quitDriver() {
49 |
50 | if (DriverManager.getDriver() != null) {
51 | //driver.quit();
52 | //threadLocal.get().quit();
53 | DriverManager.getDriver().quit();
54 | DriverManager.setDriver(null);
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/com/learning/driver/DriverFactoryLocal.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Rajat Verma
3 | * https://www.linkedin.com/in/rajat-v-3b0685128/
4 | * https://github.com/rajatt95
5 | * https://rajatt95.github.io/
6 | *
7 | * Course: Selenium - Java with Docker, Git and Jenkins (https://www.testingminibytes.com/courses/selenium-java-with-docker-git-and-jenkins/)
8 | * Tutor: Amuthan Sakthivel (https://www.testingminibytes.com/)
9 | */
10 |
11 | package com.learning.driver;
12 |
13 | import io.github.bonigarcia.wdm.WebDriverManager;
14 | import org.openqa.selenium.WebDriver;
15 | import org.openqa.selenium.chrome.ChromeDriver;
16 | import org.openqa.selenium.chrome.ChromeOptions;
17 | import org.openqa.selenium.edge.EdgeDriver;
18 | import org.openqa.selenium.firefox.FirefoxDriver;
19 | import org.openqa.selenium.opera.OperaDriver;
20 | import org.openqa.selenium.safari.SafariDriver;
21 |
22 | import static com.learning.constants.FrameworkConstants.*;
23 |
24 | //final -> We do not want any class to extend this class
25 | public final class DriverFactoryLocal {
26 |
27 | //private -> We do not want anyone to create the object of this class
28 | private DriverFactoryLocal() {
29 | }
30 |
31 | public static WebDriver setupForLocalRunMode(String browser) {
32 | WebDriver driver;
33 | if (browser.equalsIgnoreCase(CHROME)) {
34 | WebDriverManager.chromedriver().setup();
35 | driver = new ChromeDriver();
36 | }
37 | else if (browser.equalsIgnoreCase(CHROME_HEADLESS)) {
38 | ChromeOptions options = new ChromeOptions();
39 | options.addArguments(HEADLESS);
40 | WebDriverManager.chromedriver().setup();
41 | driver = new ChromeDriver(options);
42 | } else if (browser.equalsIgnoreCase(FIREFOX)) {
43 | WebDriverManager.firefoxdriver().setup();
44 | driver = new FirefoxDriver();
45 | } else if (browser.equalsIgnoreCase(EDGE)) {
46 | WebDriverManager.edgedriver().setup();
47 | driver = new EdgeDriver();
48 | } else if (browser.equalsIgnoreCase(OPERA)) {
49 | WebDriverManager.operadriver().setup();
50 | driver = new OperaDriver();
51 | } else if (browser.equalsIgnoreCase(SAFARI)) {
52 | driver = new SafariDriver();
53 | } else {
54 | WebDriverManager.chromedriver().setup();
55 | driver = new ChromeDriver();
56 | }
57 | return driver;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/learning/driver/DriverFactoryRemote.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Rajat Verma
3 | * https://www.linkedin.com/in/rajat-v-3b0685128/
4 | * https://github.com/rajatt95
5 | * https://rajatt95.github.io/
6 | *
7 | * Course: Selenium - Java with Docker, Git and Jenkins (https://www.testingminibytes.com/courses/selenium-java-with-docker-git-and-jenkins/)
8 | * Tutor: Amuthan Sakthivel (https://www.testingminibytes.com/)
9 | */
10 |
11 | package com.learning.driver;
12 |
13 | import java.net.MalformedURLException;
14 | import java.net.URL;
15 |
16 | import com.learning.exceptions.FrameworkException;
17 | import org.openqa.selenium.WebDriver;
18 | import org.openqa.selenium.remote.DesiredCapabilities;
19 | import org.openqa.selenium.remote.RemoteWebDriver;
20 |
21 | import com.learning.config.ConfigFactory;
22 |
23 | import static com.learning.constants.FrameworkConstants.*;
24 |
25 | //final -> We do not want any class to extend this class
26 | public final class DriverFactoryRemote {
27 |
28 | //private -> We do not want anyone to create the object of this class
29 | private DriverFactoryRemote() {
30 | }
31 |
32 |
33 | public static WebDriver setupForRemoteRunMode(String browser) {
34 | WebDriver driver = null;
35 | DesiredCapabilities capabilities = new DesiredCapabilities();
36 | if (browser.equalsIgnoreCase(CHROME)) {
37 | capabilities.setBrowserName(CHROME);
38 | } else if (browser.equalsIgnoreCase(FIREFOX)) {
39 | capabilities.setBrowserName(FIREFOX);
40 | } else if (browser.equalsIgnoreCase(EDGE)) {
41 | capabilities.setBrowserName(EDGE);
42 | }/*else if(browser.equalsIgnoreCase("opera")){
43 | driver = new OperaDriver();
44 | }else if(browser.equalsIgnoreCase("safari")){
45 | driver = new SafariDriver();
46 | }*/ else {
47 | capabilities.setBrowserName(CHROME);
48 | }
49 | /* try {
50 | driver = new RemoteWebDriver(new URL(ConfigFactory.getConfig().remoteUrl()),capabilities);
51 | } catch (MalformedURLException e) {
52 | e.printStackTrace();
53 | }*/
54 | try {
55 | driver = new RemoteWebDriver(new URL(ConfigFactory.getConfig().remoteUrl()), capabilities);
56 | } catch (MalformedURLException malformedURLException) {
57 | throw new FrameworkException("RemoteWebDriver you are trying to reach got MalformedURLException: It is not reachable", malformedURLException.fillInStackTrace());
58 | }
59 |
60 | return driver;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/com/learning/utils/ReportUtils.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Rajat Verma
3 | * https://www.linkedin.com/in/rajat-v-3b0685128/
4 | * https://github.com/rajatt95
5 | * https://rajatt95.github.io/
6 | *
7 | * Course: Selenium - Java with Docker, Git and Jenkins (https://www.testingminibytes.com/courses/selenium-java-with-docker-git-and-jenkins/)
8 | * Tutor: Amuthan Sakthivel (https://www.testingminibytes.com/)
9 | */
10 |
11 | package com.learning.utils;
12 |
13 | import com.learning.config.ConfigFactory;
14 | import com.learning.exceptions.FrameworkException;
15 | import com.learning.exceptions.InvalidPathForExtentReportFileException;
16 |
17 | import java.awt.*;
18 | import java.io.File;
19 | import java.io.FileNotFoundException;
20 | import java.io.IOException;
21 |
22 | import static com.learning.constants.FrameworkConstants.*;
23 |
24 |
25 | //final -> We do not want any class to extend this class
26 | public final class ReportUtils {
27 |
28 | //private -> We do not want anyone to create the object of this class
29 | // Private constructor to avoid external instantiation
30 | private ReportUtils() {
31 | }
32 |
33 | public static String createExtentReportPath() {
34 | if (ConfigFactory.getConfig().override_reports().trim().equalsIgnoreCase(NO)) {
35 | /**
36 | * Report name ->
37 | *
38 | * Windows_10_Tue_Oct_05_02_30_46_IST_2021_AutomationReport.html
39 | * Mac_OS_X_Tue_Feb_22_17_09_05_IST_2022_AutomationReport.html
40 | */
41 | return EXTENT_REPORT_FOLDER_PATH + OSInfoUtils.getOSInfo() + "_" + DateUtils.getCurrentDate() + "_"
42 | + EXTENT_REPORT_NAME;
43 |
44 | } else {
45 | return EXTENT_REPORT_FOLDER_PATH + EXTENT_REPORT_NAME;
46 | }
47 | }
48 |
49 | public static void openReports() {
50 | if (ConfigFactory.getConfig().open_reports_after_execution().trim().equalsIgnoreCase(YES)) {
51 | try {
52 | Desktop.getDesktop().browse(new File(getExtentReportFilePath()).toURI());
53 | } catch (FileNotFoundException fileNotFoundException) {
54 | throw new InvalidPathForExtentReportFileException("Extent Report file you are trying to reach is not found", fileNotFoundException.fillInStackTrace());
55 | } catch (IOException ioException) {
56 | throw new FrameworkException("Extent Report file you are trying to reach got IOException while reading the file", ioException.fillInStackTrace());
57 | }
58 |
59 |
60 | }
61 | }
62 | }
63 |
64 |
--------------------------------------------------------------------------------
/src/main/java/com/learning/pages/HomePage.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Rajat Verma
3 | * https://www.linkedin.com/in/rajat-v-3b0685128/
4 | * https://github.com/rajatt95
5 | * https://rajatt95.github.io/
6 | *
7 | * Course: Selenium - Java with Docker, Git and Jenkins (https://www.testingminibytes.com/courses/selenium-java-with-docker-git-and-jenkins/)
8 | * Tutor: Amuthan Sakthivel (https://www.testingminibytes.com/)
9 | */
10 |
11 | package com.learning.pages;
12 |
13 | import com.learning.enums.WaitType;
14 | import com.learning.pages.components.FooterMenuComponent;
15 |
16 | import static com.learning.utils.SeleniumUtils.*;
17 |
18 | import com.learning.pages.components.TopMenuComponent;
19 | import org.openqa.selenium.By;
20 |
21 |
22 | public class HomePage {
23 |
24 | //HomePage HAS-A TopMenu --> Composition
25 | //HomePage IS-A Page --> Inheritance
26 | private TopMenuComponent topMenuComponent;
27 | private FooterMenuComponent footerMenuComponent;
28 |
29 | public HomePage() {
30 | topMenuComponent = new TopMenuComponent();
31 | footerMenuComponent = new FooterMenuComponent();
32 | }
33 |
34 | private static final By WELCOME = By.id("welcome");
35 | private static final By LOGOUT = By.xpath("//a[normalize-space()='Logout']");
36 |
37 | private static final By DASHBOARD_MY_TIMESHEET = By.xpath("//span[normalize-space()='My Timesheet']");
38 | private static final By DASHBOARD_APPLY_LEAVE = By.xpath("//span[normalize-space()='Apply Leave']");
39 |
40 |
41 | public void clickOnAdmin() {
42 | topMenuComponent.clickAdmin();
43 | }
44 |
45 | public String getFooterText() {
46 | return footerMenuComponent.getFooterLable();
47 | }
48 |
49 |
50 | public String getHomePageTitle() {
51 | // return DriverManager.getDriver().getTitle();
52 | // return getPageTitle();
53 | // return SeleniumUtils.getPageTitle();
54 | return getPageTitle();
55 | }
56 |
57 | private HomePage clickOnWelcome() {
58 | click(WELCOME, WaitType.CLICKABLE);
59 | return this;
60 | }
61 |
62 | private LoginPage clickOnLogout() {
63 | click(LOGOUT, WaitType.CLICKABLE);
64 | return new LoginPage();
65 | }
66 |
67 | //Wrapper method for performing 2 operations
68 | public LoginPage logoutFromApplication() {
69 | // clickOnWelcome();
70 | // waitForGivenTime(2);
71 | // return clickOnLogout();
72 |
73 | //Method Chaining
74 | return clickOnWelcome()
75 | .clickOnLogout();
76 | }
77 |
78 | public HomePage clickOnMyTimeSheet() {
79 | click(DASHBOARD_MY_TIMESHEET, WaitType.CLICKABLE);
80 | return this;
81 | }
82 |
83 | public HomePage clickOnApplyLeave() {
84 | click(DASHBOARD_APPLY_LEAVE, WaitType.CLICKABLE);
85 | return this;
86 | }
87 |
88 | public String getPageURL() {
89 | return getWebPageURL();
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # TMB_SeleniumFramework2
2 | This project is designed and developed with the help of -
3 | 1. Selenium - Java with Docker, Git and Jenkins (https://www.testingminibytes.com/courses/selenium-java-with-docker-git-and-jenkins)
4 | 2. Learnings from Course - Github_TMB_Selenium - Java with Docker, Git and Jenkins
5 |
6 | ------------------------------------------------------------
7 | 
8 | 
9 | ------------------------------------------------------------
10 | 
11 | 
12 | ------------------------------------------------------------
13 | **ExtentReports V5**
14 | 1. User can apply the Filters -
15 | - Author - Rajat, Nishant, Gautam, Pankaj
16 | - Browser - Chrome, Edge, Safari, Firefox
17 | - TestType - Smoke, Sanity, Regression, BVT
18 |
19 | 2. Screenshots are attached in the ExtentReport as Base64 format.
20 | 
21 | 
22 |
23 | ------------------------------------------------------------
24 | **User has options for customization**
25 | 
26 | ------------------------------------------------------------
27 | **Email to User(s) using Java mail API**
28 | 
29 | ------------------------------------------------------------
30 | **Others implementations:**
31 | 1. Custom Enums, Exceptions, Annotations
32 | 2. Data Driven testing using .xlsx file (Reading values with the help of Data Supplier)
33 | -------------------------------
34 | 3. Icons addition in ExtentReport (Browser icon with every test case | Test status | Test Description -> Last -> Pass (Happy), Fail (Sad) | OS + Browser | Details in Dashboard page of ExtentReport (Rajat linkedIn and Github URL)
35 | ------------------------------
36 | 4. Zip the ExtentReports directory into Project path (you can send this Zip file as well as an Attachment in Email)
37 | 5. Automatically open the report after tests execution.
38 | ----------------------------------
39 | 6. Send EMail using Java mail API to User(s) with attachment(s).
40 | - https://mvnrepository.com/artifact/javax.mail/mail/1.4.7
41 | - https://www.tutorialspoint.com/java/java_sending_email.htm
42 | - Gmail -> Manage your Google account:
43 | 
44 | - Security -> Turn on : Less Secure App access:
45 | 
46 |
47 | ------------------------------------------------------------
48 | **How to run the Project from Local machine**
49 | 1. Pull the code into your machine and import in IDE (Eclipse/intelliJ).
50 | 2. Run Project as Mvn test
51 | It should start the execution -> Parallel Browser Testing.
52 | - **NOTE:** config.properties (./src/test/resources/config) is the configuration file.
53 | ------------------------------------------------------------
54 |
55 |
--------------------------------------------------------------------------------
/src/main/java/com/learning/java_Mail_API/EmailAttachmentsSender.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Rajat Verma
3 | * https://www.linkedin.com/in/rajat-v-3b0685128/
4 | * https://github.com/rajatt95
5 | * https://rajatt95.github.io/
6 | *
7 | * Course: Selenium - Java with Docker, Git and Jenkins (https://www.testingminibytes.com/courses/selenium-java-with-docker-git-and-jenkins/)
8 | * Tutor: Amuthan Sakthivel (https://www.testingminibytes.com/)
9 | */
10 |
11 | package com.learning.java_Mail_API;
12 |
13 | import java.io.IOException;
14 | import java.util.Date;
15 | import java.util.Properties;
16 |
17 | import javax.mail.Authenticator;
18 | import javax.mail.Message;
19 | import javax.mail.MessagingException;
20 | import javax.mail.Multipart;
21 | import javax.mail.PasswordAuthentication;
22 | import javax.mail.Session;
23 | import javax.mail.Transport;
24 | import javax.mail.internet.AddressException;
25 | import javax.mail.internet.InternetAddress;
26 | import javax.mail.internet.MimeBodyPart;
27 | import javax.mail.internet.MimeMessage;
28 | import javax.mail.internet.MimeMultipart;
29 |
30 | /**
31 | * https://www.codejava.net/java-ee/javamail/send-e-mail-with-attachment-in-java
32 | */
33 | public class EmailAttachmentsSender {
34 |
35 | /**
36 | * i) Send n no. of Attachments
37 | *
38 | * ii) Format set for TC count
39 | *
40 | * iii) Send mail to n no. of Users
41 | */
42 | public static void sendEmailWithAttachments(String host, String port, final String userName, final String password,
43 | String[] toAddress, String subject, String message, String... attachFiles)
44 | throws AddressException, MessagingException {
45 | // sets SMTP server properties
46 |
47 | Properties properties = new Properties();
48 | properties.put("mail.smtp.host", host);
49 | properties.put("mail.smtp.port", port);
50 | properties.put("mail.smtp.auth", "true");
51 | properties.put("mail.smtp.starttls.enable", "true");
52 | properties.put("mail.user", userName);
53 | properties.put("mail.password", password);
54 |
55 | // creates a new session with an authenticator
56 | Authenticator auth = new Authenticator() {
57 | public PasswordAuthentication getPasswordAuthentication() {
58 | return new PasswordAuthentication(userName, password);
59 | }
60 | };
61 | Session session = Session.getInstance(properties, auth);
62 |
63 | // creates a new e-mail message
64 | Message msg = new MimeMessage(session);
65 |
66 | msg.setFrom(new InternetAddress(userName));
67 |
68 | InternetAddress[] addressTo = new InternetAddress[toAddress.length];
69 | for (int i = 0; i < toAddress.length; i++)
70 | addressTo[i] = new InternetAddress(toAddress[i]);
71 | msg.setRecipients(Message.RecipientType.TO, addressTo);
72 |
73 | /*
74 | * InternetAddress[] toAddresses = { new InternetAddress(toAddress) };
75 | * msg.setRecipients(Message.RecipientType.TO, toAddresses);
76 | */
77 | msg.setSubject(subject);
78 | msg.setSentDate(new Date());
79 |
80 | // creates message part
81 | MimeBodyPart messageBodyPart = new MimeBodyPart();
82 | messageBodyPart.setContent(message, "text/html");
83 |
84 | // creates multi-part
85 | Multipart multipart = new MimeMultipart();
86 | multipart.addBodyPart(messageBodyPart);
87 |
88 | // adds attachments
89 | if (attachFiles != null && attachFiles.length > 0) {
90 | for (String filePath : attachFiles) {
91 | MimeBodyPart attachPart = new MimeBodyPart();
92 |
93 | try {
94 | attachPart.attachFile(filePath);
95 | } catch (IOException ex) {
96 | ex.printStackTrace();
97 | }
98 |
99 | multipart.addBodyPart(attachPart);
100 | }
101 | }
102 |
103 | // sets the multi-part as e-mail's content
104 | msg.setContent(multipart);
105 |
106 | // sends the e-mail
107 | Transport.send(msg);
108 | }
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/src/main/java/com/learning/pages/LoginPage.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Rajat Verma
3 | * https://www.linkedin.com/in/rajat-v-3b0685128/
4 | * https://github.com/rajatt95
5 | * https://rajatt95.github.io/
6 | *
7 | * Course: Selenium - Java with Docker, Git and Jenkins (https://www.testingminibytes.com/courses/selenium-java-with-docker-git-and-jenkins/)
8 | * Tutor: Amuthan Sakthivel (https://www.testingminibytes.com/)
9 | */
10 |
11 | package com.learning.pages;
12 |
13 | import static com.learning.utils.SeleniumUtils.*;
14 |
15 | import com.learning.enums.WaitType;
16 | import org.openqa.selenium.By;
17 | import org.openqa.selenium.WebElement;
18 |
19 | public class LoginPage {
20 |
21 | // By txtBoxUsername = By.id("txtUsername");
22 | // By txtBoxPassword = By.id("txtPassword");
23 | // By btnLogin = By.id("btnLogin");
24 |
25 | // private By txtBoxUsername = By.id("txtUsername");
26 | // private By txtBoxPassword = By.id("txtPassword");
27 | // private By btnLogin = By.id("btnLogin");
28 |
29 | // private final By txtBoxUsername = By.id("txtUsername"); //100 threads --> 100 times
30 | // private final By txtBoxPassword = By.id("txtPassword");
31 | // private final By btnLogin = By.id("btnLogin");
32 |
33 | //static --> Used for Memory management efficiency
34 | // private static final By txtBoxUsername = By.id("txtUsername"); //100 threads --> 1 txtBoxUsername
35 | // private static final By txtBoxPassword = By.id("txtPassword");
36 | // private static final By btnLogin = By.id("btnLogin");
37 |
38 | //Naming Convention for private static final fields/variables
39 | private static final By TXTBOX_USERNAME = By.id("txtUsername"); //100 threads --> 1 txtBoxUsername
40 | private static final String TXTBOX_USERNAME_TXT = "Username";
41 |
42 | private static final By TXTBOX_PASSWORD = By.id("txtPassword");
43 | private static final String TXTBOX_PASSWORD_TXT = "Password";
44 |
45 | private static final By BTN_LOGIN = By.id("btnLogin");
46 | private static final String BTN_LOGIN_TXT = "Login Button";
47 |
48 | private static final By MSG_ERROR = By.id("spanMessage");
49 | //private static final String MSG_ERROR_TXT = "Error Message";
50 |
51 |
52 |
53 | // public void setUsername(String username) {
54 | // DriverManager.getDriver().findElement(txtBoxUsername).sendKeys(username);
55 | // }
56 |
57 | // public LoginPage setUsername(String username) {
58 | private LoginPage setUsername(String username) {
59 | // DriverManager.getDriver().findElement(TXTBOX_USERNAME).sendKeys(username);
60 | // sendKeys(TXTBOX_USERNAME, username);
61 | // SeleniumUtils.sendKeys(TXTBOX_USERNAME, username);
62 | //sendKeys(TXTBOX_USERNAME, username);
63 | sendKeys(TXTBOX_USERNAME, username, TXTBOX_USERNAME_TXT);
64 |
65 | // return new LoginPage();
66 | return this;
67 | }
68 |
69 | public WebElement getTxtBoxUserame(){
70 | return getElement(TXTBOX_USERNAME);
71 | }
72 | public WebElement getTxtBoxPassword(){
73 | return getElement(TXTBOX_PASSWORD);
74 | }
75 | public WebElement getBtnLogin(){
76 | return getElement(BTN_LOGIN);
77 | }
78 |
79 | private LoginPage setPassword(String password) {
80 | //DriverManager.getDriver().findElement(TXTBOX_PASSWORD).sendKeys(password);
81 | //sendKeys(TXTBOX_PASSWORD, password);
82 | //SeleniumUtils.sendKeys(TXTBOX_PASSWORD, password);
83 | // sendKeys(TXTBOX_PASSWORD, password);
84 | sendKeys(TXTBOX_PASSWORD, password, TXTBOX_PASSWORD_TXT);
85 | return this;
86 | }
87 |
88 | private HomePage clickLogin() {
89 | //DriverManager.getDriver().findElement(BTN_LOGIN).click();
90 | // click(BTN_LOGIN);
91 | //SeleniumUtils. click(BTN_LOGIN);
92 | // click(BTN_LOGIN);
93 | //click(BTN_LOGIN, WaitType.CLICKABLE);
94 | //click(BTN_LOGIN, WaitType.CLICKABLE);
95 | click(BTN_LOGIN, WaitType.CLICKABLE, BTN_LOGIN_TXT);
96 | return new HomePage(); //Page Chaining
97 | }
98 |
99 | //Wrapper method for performing 3 operations
100 | public HomePage loginToApplication(String username, String password) {
101 | //Method Chaining
102 | return setUsername(username)
103 | .setPassword(password)
104 | .clickLogin();
105 | }
106 |
107 | public String getErrorMessage(){
108 | return getElementText(MSG_ERROR);
109 | }
110 |
111 |
112 | }
113 |
--------------------------------------------------------------------------------
/src/main/java/com/learning/reports/ExtentReport.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Rajat Verma
3 | * https://www.linkedin.com/in/rajat-v-3b0685128/
4 | * https://github.com/rajatt95
5 | * https://rajatt95.github.io/
6 | *
7 | * Course: Selenium - Java with Docker, Git and Jenkins (https://www.testingminibytes.com/courses/selenium-java-with-docker-git-and-jenkins/)
8 | * Tutor: Amuthan Sakthivel (https://www.testingminibytes.com/)
9 | */
10 |
11 | package com.learning.reports;
12 |
13 | import static com.learning.constants.FrameworkConstants.*;
14 |
15 | import java.util.Objects;
16 |
17 |
18 | import com.aventstack.extentreports.ExtentReports;
19 | import com.aventstack.extentreports.reporter.ExtentSparkReporter;
20 | import com.aventstack.extentreports.reporter.configuration.Theme;
21 | import com.learning.enums.AuthorType;
22 | import com.learning.enums.CategoryType;
23 | import com.learning.utils.BrowserInfoUtils;
24 | import com.learning.utils.IconUtils;
25 | import com.learning.utils.ReportUtils;
26 |
27 | //final -> We do not want any class to extend this class
28 | public final class ExtentReport {
29 |
30 | //private -> We do not want anyone to create the object of this class
31 | private ExtentReport() {
32 | }
33 |
34 | private static ExtentReports extent;
35 |
36 | public static void initReports() {
37 | if (Objects.isNull(extent)) {
38 | extent = new ExtentReports();
39 | ExtentSparkReporter spark = new ExtentSparkReporter(getExtentReportFilePath());
40 | /*
41 | * .viewConfigurer() .viewOrder() .as(new ViewName[] { ViewName.DASHBOARD,
42 | * ViewName.TEST, //ViewName.TAG, ViewName.CATEGORY, ViewName.AUTHOR,
43 | * ViewName.DEVICE, ViewName.EXCEPTION, ViewName.LOG }) .apply();
44 | */
45 |
46 | /*
47 | * You can even update the view of the ExtentRerport - What do you want to you
48 | * first, you can prioritize
49 | */
50 | /*
51 | * ExtentSparkReporter spark = new
52 | * ExtentSparkReporter(REPORTS_SPARK_CUSTOMISED_HTML).viewConfigurer().viewOrder
53 | * () .as(new ViewName[] { ViewName.DASHBOARD, ViewName.TEST, ViewName.CATEGORY
54 | * }).apply();
55 | */
56 | extent.attachReporter(spark);
57 |
58 | // spark.config().setEncoding("utf-8");
59 | spark.config().setTheme(Theme.STANDARD);
60 | spark.config().setDocumentTitle(PROJECT_NAME + " - ALL");
61 | spark.config().setReportName(PROJECT_NAME + " - ALL");
62 |
63 | extent.setSystemInfo("Organization", "Nagarro");
64 | extent.setSystemInfo("Employee",
65 | " Rajat Verma "
66 | + " " + ICON_SOCIAL_LINKEDIN + " " + ICON_SOCIAL_GITHUB);
67 | extent.setSystemInfo("Domain", "Engineering (IT - Software)" + " " + ICON_LAPTOP);
68 | extent.setSystemInfo("Skill", "Test Automation Engineer");
69 | }
70 | }
71 |
72 | public static void flushReports() {
73 | if (Objects.nonNull(extent)) {
74 | extent.flush();
75 | }
76 | ExtentManager.unload();
77 | ReportUtils.openReports();
78 | }
79 |
80 | public static void createTest(String testCaseName) {
81 | // ExtentManager.setExtentTest(extent.createTest(testCaseName));
82 | ExtentManager.setExtentTest(extent.createTest(IconUtils.getBrowserIcon() + " : " + testCaseName));
83 | }
84 |
85 | synchronized public static void addAuthors(AuthorType[] authors) {
86 | for (AuthorType author : authors) {
87 | ExtentManager.getExtentTest().assignAuthor(author.toString());
88 | }
89 | }
90 |
91 | // public static void addCategories(String[] categories) {
92 | synchronized public static void addCategories(CategoryType[] categories) {
93 | // for (String category : categories) {
94 | for (CategoryType category : categories) {
95 | ExtentManager.getExtentTest().assignCategory(category.toString());
96 | }
97 | }
98 |
99 | synchronized public static void addDevices() {
100 | ExtentManager.getExtentTest().assignDevice(BrowserInfoUtils.getBrowserInfo());
101 | // ExtentManager.getExtentTest()
102 | // .assignDevice(BrowserIconUtils.getBrowserIcon() + " : " + BrowserInfoUtils.getBrowserInfo());
103 | }
104 |
105 |
106 | }
107 |
--------------------------------------------------------------------------------
/src/main/java/com/learning/utils/EmailSendUtils.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Rajat Verma
3 | * https://www.linkedin.com/in/rajat-v-3b0685128/
4 | * https://github.com/rajatt95
5 | * https://rajatt95.github.io/
6 | *
7 | * Course: Selenium - Java with Docker, Git and Jenkins (https://www.testingminibytes.com/courses/selenium-java-with-docker-git-and-jenkins/)
8 | * Tutor: Amuthan Sakthivel (https://www.testingminibytes.com/)
9 | */
10 |
11 | package com.learning.utils;
12 |
13 | import static com.learning.constants.FrameworkConstants.PROJECT_NAME;
14 | import static com.learning.constants.FrameworkConstants.YES;
15 | import static com.learning.java_Mail_API.EmailConfig.*;
16 |
17 | import javax.mail.MessagingException;
18 |
19 | import com.learning.config.ConfigFactory;
20 | import com.learning.constants.FrameworkConstants;
21 | import com.learning.java_Mail_API.EmailAttachmentsSender;
22 |
23 | public class EmailSendUtils {
24 |
25 | /**
26 | * sendEmail_WithAttachmentsAndFormattedBodyText_ToManyUsersRajat
27 | */
28 | public static void sendEmail(int count_totalTCs, int count_passedTCs, int count_failedTCs, int count_skippedTCs) {
29 |
30 | if(ConfigFactory.getConfig().send_email_to_users().trim().equalsIgnoreCase(YES)){
31 | System.out.println("****************************************");
32 | System.out.println("Send Email - START");
33 | System.out.println("****************************************");
34 |
35 | // System.out.println("File name: " + FrameworkConstants.getExtentReportPath());
36 | System.out.println("File name: " + FrameworkConstants.getExtentReportFilePath());
37 |
38 |
39 | String messageBody = getTestCasesCountInFormat(count_totalTCs, count_passedTCs, count_failedTCs,
40 | count_skippedTCs);
41 | System.out.println(messageBody);
42 |
43 | /*
44 | * String attachmentFile_ExtentReport = Constants.REPORTS_Folder +
45 | * "All_Automation_Report_Fri_Sep_10_03_47_17_IST_2021.html";
46 | */
47 |
48 | // String attachmentFile_ExtentReport = FrameworkConstants.getExtentReportPath();
49 | String attachmentFile_ExtentReport = FrameworkConstants.getExtentReportFilePath();
50 |
51 |
52 | try {
53 | EmailAttachmentsSender.sendEmailWithAttachments(SERVER, PORT, FROM, PASSWORD, TO, SUBJECT, messageBody,
54 | attachmentFile_ExtentReport);
55 |
56 | System.out.println("****************************************");
57 | System.out.println("Email sent successfully.");
58 | System.out.println("Send Email - END");
59 | System.out.println("****************************************");
60 | } catch (MessagingException e) {
61 | e.printStackTrace();
62 | }
63 |
64 | }
65 |
66 | }
67 |
68 | private static String getTestCasesCountInFormat(int count_totalTCs, int count_passedTCs, int count_failedTCs,
69 | int count_skippedTCs) {
70 | System.out.println("count_totalTCs: " + count_totalTCs);
71 | System.out.println("count_passedTCs: " + count_passedTCs);
72 | System.out.println("count_failedTCs: " + count_failedTCs);
73 | System.out.println("count_skippedTCs: " + count_skippedTCs);
74 |
75 | return "\r\n" + "\r\n" + " \r\n" + "\r\n"
76 | + "
\r\n\r\n"
77 | + PROJECT_NAME + " |
\r\n\r\n\r\n"
78 | + " \r\n"
79 | + " | "
80 | + count_totalTCs + " | \r\n"
81 | + " | Total | \r\n" + " \r\n"
82 | + " \r\n" + " | \r\n" + " \r\n"
83 | + " \r\n" + " \r\n"
84 | + " | "
85 | + count_passedTCs + " | \r\n"
86 | + " | Passed | \r\n" + " \r\n"
87 | + " \r\n" + " | \r\n" + " \r\n"
88 | + " \r\n"
89 | + " | "
90 | + count_failedTCs + " | \r\n"
91 | + " | Failed | \r\n" + " \r\n"
92 | + " \r\n" + " \r\n" + " | \r\n"
93 | + " \r\n" + " \r\n"
94 | + " | "
95 | + count_skippedTCs + " | \r\n"
96 | + " | Skipped | \r\n" + " \r\n"
97 | + " \r\n" + " \r\n" + " | \r\n"
98 | + "
\r\n" + " \r\n" + " \r\n"
99 | + "
\r\n" + " \r\n" + " \r\n" + "";
100 | }
101 |
102 | }
103 |
--------------------------------------------------------------------------------
/src/test/java/com/learning/tests/LogoutTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Rajat Verma
3 | * https://www.linkedin.com/in/rajat-v-3b0685128/
4 | * https://github.com/rajatt95
5 | * https://rajatt95.github.io/
6 | *
7 | * Course: Selenium - Java with Docker, Git and Jenkins (https://www.testingminibytes.com/courses/selenium-java-with-docker-git-and-jenkins/)
8 | * Tutor: Amuthan Sakthivel (https://www.testingminibytes.com/)
9 | */
10 |
11 | package com.learning.tests;
12 |
13 | import com.learning.annotations.FrameworkAnnotation;
14 | import com.learning.driver.DriverManager;
15 | import com.learning.enums.AuthorType;
16 | import com.learning.enums.CategoryType;
17 | import com.learning.pages.HomePage;
18 | import com.learning.pages.LoginPage;
19 | import com.learning.testdata.TestData;
20 | import com.learning.utils.DataProviderUtils;
21 | import org.openqa.selenium.By;
22 | import org.testng.Assert;
23 | import org.testng.annotations.Test;
24 |
25 | public class LogoutTest extends BaseTest {
26 |
27 | @FrameworkAnnotation(author = {AuthorType.RAJAT, AuthorType.NISHANT},
28 | category = {CategoryType.BVT, CategoryType.SANITY, CategoryType.REGRESSION})
29 | @Test(groups = {"BVT","SANITY","REGRESSION"},description = "To check whether the User can logout from the application.",
30 | dataProvider = "getTestData", dataProviderClass = DataProviderUtils.class)
31 | public void logoutTest(TestData testData) {
32 |
33 | LoginPage loginPage = new LoginPage();
34 | HomePage homePage = loginPage.loginToApplication(testData.getUsername(), testData.getPassword());
35 | homePage.logoutFromApplication();
36 |
37 | Assert.assertTrue(loginPage.getTxtBoxUserame().isDisplayed(),
38 | "Assertion for TextBox Username presence");
39 | Assert.assertTrue(loginPage.getTxtBoxPassword().isDisplayed(),
40 | "Assertion for TextBox Password presence");
41 | Assert.assertTrue(loginPage.getBtnLogin().isDisplayed(),
42 | "Assertion for Button Login presence");
43 | }
44 |
45 |
46 | /**
47 | * --------------------------------------------------------------------- (2nd time)
48 | */
49 | // @FrameworkAnnotation(author = { AuthorType.RAJAT, AuthorType.NISHANT},
50 | // category = { CategoryType.BVT,CategoryType.REGRESSION })
51 | // @Test(description = "To check whether the User can not login with Invalid Credentials",
52 | // dataProvider = "getInvalidLoginData",dataProviderClass = DataProviderUtils.class)
53 | public void REFERENCE_errorInvalidCredentials(String username, String password, String expectedError) {
54 |
55 | LoginPage loginPage = new LoginPage();
56 | // loginPage.setUsername("Admin");
57 | // loginPage.setPassword("admin1234");
58 | // loginPage.setUsername(username);
59 | // loginPage.setPassword(password);
60 | // loginPage.clickLogin();
61 |
62 | // Method Chaining
63 | // loginPage
64 | // .setUsername(username)
65 | // .setPassword(password)
66 | // .clickLogin();
67 | loginPage.loginToApplication(username, password);
68 |
69 | String errorInvalidCreds = DriverManager.getDriver().findElement(By.id("spanMessage")).getText();
70 | Assert.assertEquals(errorInvalidCreds, expectedError,
71 | "Assertion for Invalid credentials Error message");
72 | }
73 |
74 |
75 | /**
76 | * --------------------------------------------------------------------- (1st time)
77 | */
78 |
79 | // @Test(description = "To check whether the User can not login with Invalid Credentials")
80 | public void REFERENCE__errorInvalidCredentials() {
81 | // driver.findElement(By.id("txtUsername")).sendKeys("Admin");
82 | // driver.findElement(By.id("txtPassword")).sendKeys("admin1234");
83 | // driver.findElement(By.id("btnLogin")).click();
84 | // holdScript(3);
85 |
86 | // Driver.threadLocal.get().findElement(By.id("txtUsername")).sendKeys("Admin");
87 | // Driver.threadLocal.get().findElement(By.id("txtPassword")).sendKeys("admin1234");
88 | // Driver.threadLocal.get().findElement(By.id("btnLogin")).click();
89 |
90 | // DriverManager.getDriver().findElement(By.id("txtUsername")).sendKeys("Admin");
91 | // DriverManager.getDriver().findElement(By.id("txtPassword")).sendKeys("admin1234");
92 | // DriverManager.getDriver().findElement(By.id("btnLogin")).click();
93 |
94 | // LoginPage loginPage =new LoginPage();
95 | // loginPage.setUsername("Admin");
96 | // loginPage.setPassword("admin1234");
97 | // loginPage.clickLogin();
98 |
99 | // String errorInvalidCreds = Driver.driver.findElement(By.id("spanMessage")).getText();
100 | // String errorInvalidCreds = Driver.threadLocal.get().findElement(By.id("spanMessage")).getText();
101 | String errorInvalidCreds = DriverManager.getDriver().findElement(By.id("spanMessage")).getText();
102 |
103 |
104 | // Assert.assertEquals(errorInvalidCreds, "Invalid credentials",
105 | // "Assertion for Invalid credentials Error message");
106 | Assert.assertEquals(errorInvalidCreds, "无效的凭证",
107 | "Assertion for Invalid credentials Error message");
108 |
109 |
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/src/test/java/com/learning/tests/LoginTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Rajat Verma
3 | * https://www.linkedin.com/in/rajat-v-3b0685128/
4 | * https://github.com/rajatt95
5 | * https://rajatt95.github.io/
6 | *
7 | * Course: Selenium - Java with Docker, Git and Jenkins (https://www.testingminibytes.com/courses/selenium-java-with-docker-git-and-jenkins/)
8 | * Tutor: Amuthan Sakthivel (https://www.testingminibytes.com/)
9 | */
10 |
11 | package com.learning.tests;
12 |
13 | import com.learning.annotations.FrameworkAnnotation;
14 | import com.learning.driver.DriverManager;
15 | import com.learning.enums.AuthorType;
16 | import com.learning.enums.CategoryType;
17 | import com.learning.pages.LoginPage;
18 | import com.learning.testdata.TestData;
19 | import com.learning.utils.DataProviderUtils;
20 | import com.learning.utils.VerificationUtils;
21 | import org.openqa.selenium.By;
22 | import org.testng.Assert;
23 | import org.testng.annotations.Test;
24 |
25 | import static com.learning.constants.FrameworkConstants.ASSERTION_FOR;
26 |
27 | public class LoginTest extends BaseTest {
28 |
29 | @FrameworkAnnotation(author = {AuthorType.RAJAT, AuthorType.NISHANT},
30 | category = {CategoryType.BVT, CategoryType.REGRESSION})
31 | @Test(groups = {"BVT","REGRESSION"},description = "To check whether the User can not login with Invalid Credentials",
32 | dataProvider = "getTestData", dataProviderClass = DataProviderUtils.class)
33 | public void errorInvalidCredentials(TestData testData) {
34 |
35 | LoginPage loginPage = new LoginPage();
36 | loginPage.loginToApplication(testData.getUsername(), testData.getPassword());
37 | String errorInvalidCreds = loginPage.getErrorMessage();
38 |
39 | // Assert.assertEquals(errorInvalidCreds, testData.getExpectedError(),
40 | // "Assertion for Invalid credentials Error message");
41 |
42 | VerificationUtils.validateResponse(errorInvalidCreds,testData.getExpectedError(),
43 | ASSERTION_FOR +" - Invalid credentials Error message ");
44 |
45 | }
46 |
47 |
48 | /**
49 | * --------------------------------------------------------------------- (2nd time)
50 | */
51 | // @FrameworkAnnotation(author = { AuthorType.RAJAT, AuthorType.NISHANT},
52 | // category = { CategoryType.BVT,CategoryType.REGRESSION })
53 | // @Test(description = "To check whether the User can not login with Invalid Credentials",
54 | // dataProvider = "getInvalidLoginData",dataProviderClass = DataProviderUtils.class)
55 | public void REFERENCE_errorInvalidCredentials(String username, String password, String expectedError) {
56 |
57 | LoginPage loginPage = new LoginPage();
58 | // loginPage.setUsername("Admin");
59 | // loginPage.setPassword("admin1234");
60 | // loginPage.setUsername(username);
61 | // loginPage.setPassword(password);
62 | // loginPage.clickLogin();
63 |
64 | // Method Chaining
65 | // loginPage
66 | // .setUsername(username)
67 | // .setPassword(password)
68 | // .clickLogin();
69 | loginPage.loginToApplication(username, password);
70 |
71 | String errorInvalidCreds = DriverManager.getDriver().findElement(By.id("spanMessage")).getText();
72 | Assert.assertEquals(errorInvalidCreds, expectedError,
73 | "Assertion for Invalid credentials Error message");
74 | }
75 |
76 |
77 | /**
78 | * --------------------------------------------------------------------- (1st time)
79 | */
80 |
81 | // @Test(description = "To check whether the User can not login with Invalid Credentials")
82 | public void REFERENCE__errorInvalidCredentials() {
83 | // driver.findElement(By.id("txtUsername")).sendKeys("Admin");
84 | // driver.findElement(By.id("txtPassword")).sendKeys("admin1234");
85 | // driver.findElement(By.id("btnLogin")).click();
86 | // holdScript(3);
87 |
88 | // Driver.threadLocal.get().findElement(By.id("txtUsername")).sendKeys("Admin");
89 | // Driver.threadLocal.get().findElement(By.id("txtPassword")).sendKeys("admin1234");
90 | // Driver.threadLocal.get().findElement(By.id("btnLogin")).click();
91 |
92 | // DriverManager.getDriver().findElement(By.id("txtUsername")).sendKeys("Admin");
93 | // DriverManager.getDriver().findElement(By.id("txtPassword")).sendKeys("admin1234");
94 | // DriverManager.getDriver().findElement(By.id("btnLogin")).click();
95 |
96 | // LoginPage loginPage =new LoginPage();
97 | // loginPage.setUsername("Admin");
98 | // loginPage.setPassword("admin1234");
99 | // loginPage.clickLogin();
100 |
101 | // String errorInvalidCreds = Driver.driver.findElement(By.id("spanMessage")).getText();
102 | // String errorInvalidCreds = Driver.threadLocal.get().findElement(By.id("spanMessage")).getText();
103 | String errorInvalidCreds = DriverManager.getDriver().findElement(By.id("spanMessage")).getText();
104 |
105 |
106 | // Assert.assertEquals(errorInvalidCreds, "Invalid credentials",
107 | // "Assertion for Invalid credentials Error message");
108 | Assert.assertEquals(errorInvalidCreds, "无效的凭证",
109 | "Assertion for Invalid credentials Error message");
110 |
111 |
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/src/main/java/com/learning/listeners/TestListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Rajat Verma
3 | * https://www.linkedin.com/in/rajat-v-3b0685128/
4 | * https://github.com/rajatt95
5 | * https://rajatt95.github.io/
6 | *
7 | * Course: Selenium - Java with Docker, Git and Jenkins (https://www.testingminibytes.com/courses/selenium-java-with-docker-git-and-jenkins/)
8 | * Tutor: Amuthan Sakthivel (https://www.testingminibytes.com/)
9 | */
10 |
11 | package com.learning.listeners;
12 |
13 |
14 | import java.util.Arrays;
15 |
16 | import com.learning.annotations.FrameworkAnnotation;
17 | import com.learning.config.ConfigFactory;
18 | import com.learning.reports.ExtentLogger;
19 | import com.learning.reports.ExtentReport;
20 | import com.learning.utils.BrowserOSInfoUtils;
21 | import com.learning.utils.EmailSendUtils;
22 | import com.learning.utils.IconUtils;
23 | import com.learning.utils.ZipUtils;
24 | import org.testng.ISuite;
25 | import org.testng.ISuiteListener;
26 | import org.testng.ITestListener;
27 | import org.testng.ITestResult;
28 |
29 | import com.aventstack.extentreports.markuputils.ExtentColor;
30 | import com.aventstack.extentreports.markuputils.Markup;
31 | import com.aventstack.extentreports.markuputils.MarkupHelper;
32 |
33 | import static com.learning.constants.FrameworkConstants.*;
34 |
35 | public class TestListener implements ITestListener, ISuiteListener {
36 |
37 | static int count_passedTCs;
38 | static int count_skippedTCs;
39 | static int count_failedTCs;
40 | static int count_totalTCs;
41 |
42 | @Override
43 | public void onStart(ISuite suite) {
44 | ExtentReport.initReports();
45 | }
46 |
47 | @Override
48 | public void onFinish(ISuite suite) {
49 | ExtentReport.flushReports();
50 | ZipUtils.zip();
51 | EmailSendUtils.sendEmail(count_totalTCs, count_passedTCs, count_failedTCs, count_skippedTCs);
52 | }
53 |
54 | @Override
55 | public void onTestStart(ITestResult result) {
56 |
57 | // System.out.println("onTestStart() ");
58 | count_totalTCs = count_totalTCs + 1;
59 | ExtentReport.createTest(result.getMethod().getMethodName());
60 | // ExtentReport.createTest(result.getMethod().getDescription());
61 |
62 | ExtentReport.addAuthors(result.getMethod().getConstructorOrMethod().getMethod()
63 | .getAnnotation(FrameworkAnnotation.class).author());
64 |
65 | ExtentReport.addCategories(result.getMethod().getConstructorOrMethod().getMethod()
66 | .getAnnotation(FrameworkAnnotation.class).category());
67 |
68 | ExtentReport.addDevices();
69 | // ExtentLogger.info("" +
70 | // BrowserOSInfoUtils.getOS_Browser_BrowserVersionInfo() + "");
71 | ExtentLogger.info(BOLD_START + IconUtils.getOSIcon() + " & " + IconUtils.getBrowserIcon() + " --------- "
72 | + BrowserOSInfoUtils.getOS_Browser_BrowserVersionInfo() + BOLD_END);
73 |
74 | // ExtentLogger.info(ICON_Navigate_Right + " Navigating to : " + BOLD_START +
75 | // ConfigFactory.getConfig().url() + BOLD_END);
76 |
77 | String url=ConfigFactory.getConfig().url();
78 | ExtentLogger.info(ICON_Navigate_Right + " Navigating to : " + url + "");
79 |
80 | }
81 |
82 | @Override
83 | public void onTestSuccess(ITestResult result) {
84 | count_passedTCs = count_passedTCs + 1;
85 | String logText = "" + result.getMethod().getMethodName() + " is passed." + " " + ICON_SMILEY_PASS;
86 | Markup markup_message = MarkupHelper.createLabel(logText, ExtentColor.GREEN);
87 | //ExtentLogger.pass(markup_message);
88 | ExtentLogger.pass(markup_message, true);
89 | }
90 |
91 | @Override
92 | public void onTestFailure(ITestResult result) {
93 | count_failedTCs = count_failedTCs + 1;
94 | ExtentLogger.fail(ICON_BUG + " " + "" + result.getThrowable().toString() + "");
95 | String exceptionMessage = Arrays.toString(result.getThrowable().getStackTrace());
96 | String message = " Exception occured, click to see details: "
97 | + ICON_SMILEY_FAIL + " " + "
" + exceptionMessage.replaceAll(",", "
")
98 | + " \n";
99 |
100 | ExtentLogger.fail(message);
101 |
102 | String logText = BOLD_START + result.getMethod().getMethodName() + " is failed." + BOLD_END + " " + ICON_SMILEY_FAIL;
103 | Markup markup_message = MarkupHelper.createLabel(logText, ExtentColor.RED);
104 | ExtentLogger.fail(markup_message, true);
105 |
106 | }
107 |
108 | @Override
109 | public void onTestSkipped(ITestResult result) {
110 |
111 | count_skippedTCs = count_skippedTCs + 1;
112 |
113 | ExtentLogger.skip(ICON_BUG + " " + "" + result.getThrowable().toString() + "");
114 | // ExtentLogger.skip("" + result.getThrowable().toString() + "");
115 | String logText = "" + result.getMethod().getMethodName() + " is skipped." + " " + ICON_SMILEY_FAIL;
116 | Markup markup_message = MarkupHelper.createLabel(logText, ExtentColor.YELLOW);
117 | ExtentLogger.skip(markup_message, true);
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/src/test/java/com/learning/tests/DashboardMyTimesheetTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Rajat Verma
3 | * https://www.linkedin.com/in/rajat-v-3b0685128/
4 | * https://github.com/rajatt95
5 | * https://rajatt95.github.io/
6 | *
7 | * Course: Selenium - Java with Docker, Git and Jenkins (https://www.testingminibytes.com/courses/selenium-java-with-docker-git-and-jenkins/)
8 | * Tutor: Amuthan Sakthivel (https://www.testingminibytes.com/)
9 | */
10 |
11 | package com.learning.tests;
12 |
13 | import com.learning.annotations.FrameworkAnnotation;
14 | import com.learning.driver.DriverManager;
15 | import com.learning.enums.AuthorType;
16 | import com.learning.enums.CategoryType;
17 | import com.learning.pages.HomePage;
18 | import com.learning.pages.LoginPage;
19 | import com.learning.testdata.TestData;
20 | import com.learning.utils.DataProviderUtils;
21 | import com.learning.utils.VerificationUtils;
22 | import org.openqa.selenium.By;
23 | import org.testng.Assert;
24 | import org.testng.annotations.Test;
25 |
26 | import static com.learning.constants.FrameworkConstants.ASSERTION_FOR;
27 |
28 | public class DashboardMyTimesheetTest extends BaseTest {
29 |
30 | @FrameworkAnnotation(author = { AuthorType.NISHANT},
31 | category = {CategoryType.SMOKE, CategoryType.REGRESSION})
32 | @Test(groups = {"SMOKE","REGRESSION"},description = "To check whether the User can not login with Invalid Credentials",
33 | dataProvider = "getTestData", dataProviderClass = DataProviderUtils.class)
34 | public void dashboardMyTimesheetTest(TestData testData) {
35 |
36 | LoginPage loginPage = new LoginPage();
37 | HomePage homePage = loginPage.loginToApplication(testData.getUsername(), testData.getPassword());
38 |
39 | homePage.clickOnMyTimeSheet();
40 |
41 | // Assert.assertTrue(homePage.getPageURL().contains(testData.getExpectedUrl()),
42 | // "Assertion for My TimeSheet URL");
43 | VerificationUtils.validateResponse(homePage.getPageURL().contains(testData.getExpectedUrl()),
44 | ASSERTION_FOR +" - My TimeSheet URL ");
45 | }
46 |
47 |
48 | /**
49 | * --------------------------------------------------------------------- (2nd time)
50 | */
51 | // @FrameworkAnnotation(author = { AuthorType.RAJAT, AuthorType.NISHANT},
52 | // category = { CategoryType.BVT,CategoryType.REGRESSION })
53 | // @Test(description = "To check whether the User can not login with Invalid Credentials",
54 | // dataProvider = "getInvalidLoginData",dataProviderClass = DataProviderUtils.class)
55 | public void REFERENCE_errorInvalidCredentials(String username, String password, String expectedError) {
56 |
57 | LoginPage loginPage = new LoginPage();
58 | // loginPage.setUsername("Admin");
59 | // loginPage.setPassword("admin1234");
60 | // loginPage.setUsername(username);
61 | // loginPage.setPassword(password);
62 | // loginPage.clickLogin();
63 |
64 | // Method Chaining
65 | // loginPage
66 | // .setUsername(username)
67 | // .setPassword(password)
68 | // .clickLogin();
69 | loginPage.loginToApplication(username, password);
70 |
71 | String errorInvalidCreds = DriverManager.getDriver().findElement(By.id("spanMessage")).getText();
72 | Assert.assertEquals(errorInvalidCreds, expectedError,
73 | "Assertion for Invalid credentials Error message");
74 | }
75 |
76 |
77 | /**
78 | * --------------------------------------------------------------------- (1st time)
79 | */
80 |
81 | // @Test(description = "To check whether the User can not login with Invalid Credentials")
82 | public void REFERENCE__errorInvalidCredentials() {
83 | // driver.findElement(By.id("txtUsername")).sendKeys("Admin");
84 | // driver.findElement(By.id("txtPassword")).sendKeys("admin1234");
85 | // driver.findElement(By.id("btnLogin")).click();
86 | // holdScript(3);
87 |
88 | // Driver.threadLocal.get().findElement(By.id("txtUsername")).sendKeys("Admin");
89 | // Driver.threadLocal.get().findElement(By.id("txtPassword")).sendKeys("admin1234");
90 | // Driver.threadLocal.get().findElement(By.id("btnLogin")).click();
91 |
92 | // DriverManager.getDriver().findElement(By.id("txtUsername")).sendKeys("Admin");
93 | // DriverManager.getDriver().findElement(By.id("txtPassword")).sendKeys("admin1234");
94 | // DriverManager.getDriver().findElement(By.id("btnLogin")).click();
95 |
96 | // LoginPage loginPage =new LoginPage();
97 | // loginPage.setUsername("Admin");
98 | // loginPage.setPassword("admin1234");
99 | // loginPage.clickLogin();
100 |
101 | // String errorInvalidCreds = Driver.driver.findElement(By.id("spanMessage")).getText();
102 | // String errorInvalidCreds = Driver.threadLocal.get().findElement(By.id("spanMessage")).getText();
103 | String errorInvalidCreds = DriverManager.getDriver().findElement(By.id("spanMessage")).getText();
104 |
105 |
106 | // Assert.assertEquals(errorInvalidCreds, "Invalid credentials",
107 | // "Assertion for Invalid credentials Error message");
108 | Assert.assertEquals(errorInvalidCreds, "无效的凭证",
109 | "Assertion for Invalid credentials Error message");
110 |
111 |
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/src/test/java/com/learning/tests/DashboardApplyLeaveTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Rajat Verma
3 | * https://www.linkedin.com/in/rajat-v-3b0685128/
4 | * https://github.com/rajatt95
5 | * https://rajatt95.github.io/
6 | *
7 | * Course: Selenium - Java with Docker, Git and Jenkins (https://www.testingminibytes.com/courses/selenium-java-with-docker-git-and-jenkins/)
8 | * Tutor: Amuthan Sakthivel (https://www.testingminibytes.com/)
9 | */
10 |
11 | package com.learning.tests;
12 |
13 | import com.learning.annotations.FrameworkAnnotation;
14 | import com.learning.driver.DriverManager;
15 | import com.learning.enums.AuthorType;
16 | import com.learning.enums.CategoryType;
17 | import com.learning.pages.HomePage;
18 | import com.learning.pages.LoginPage;
19 | import com.learning.testdata.TestData;
20 | import com.learning.utils.DataProviderUtils;
21 | import com.learning.utils.VerificationUtils;
22 | import org.openqa.selenium.By;
23 | import org.testng.Assert;
24 | import org.testng.annotations.Test;
25 |
26 | import static com.learning.constants.FrameworkConstants.ASSERTION_FOR;
27 |
28 | public class DashboardApplyLeaveTest extends BaseTest {
29 |
30 | @FrameworkAnnotation(author = { AuthorType.NISHANT},
31 | category = {CategoryType.SMOKE, CategoryType.REGRESSION})
32 | @Test(groups = {"SMOKE","REGRESSION"},description = "To check whether the User can not login with Invalid Credentials",
33 | dataProvider = "getTestData", dataProviderClass = DataProviderUtils.class)
34 | public void dashboardApplyLeaveTest(TestData testData) {
35 |
36 | LoginPage loginPage = new LoginPage();
37 | HomePage homePage = loginPage.loginToApplication(testData.getUsername(), testData.getPassword());
38 |
39 | homePage.clickOnApplyLeave();
40 |
41 | // Assert.assertTrue(homePage.getPageURL().contains(testData.getExpectedUrl()),
42 | // "Assertion for Apply Leave URL");
43 |
44 | VerificationUtils.validateResponse(homePage.getPageURL().contains(testData.getExpectedUrl()+"_FAIL"),
45 | ASSERTION_FOR +" - Apply Leave URL ");
46 | }
47 |
48 |
49 | /**
50 | * --------------------------------------------------------------------- (2nd time)
51 | */
52 | // @FrameworkAnnotation(author = { AuthorType.RAJAT, AuthorType.NISHANT},
53 | // category = { CategoryType.BVT,CategoryType.REGRESSION })
54 | // @Test(description = "To check whether the User can not login with Invalid Credentials",
55 | // dataProvider = "getInvalidLoginData",dataProviderClass = DataProviderUtils.class)
56 | public void REFERENCE_errorInvalidCredentials(String username, String password, String expectedError) {
57 |
58 | LoginPage loginPage = new LoginPage();
59 | // loginPage.setUsername("Admin");
60 | // loginPage.setPassword("admin1234");
61 | // loginPage.setUsername(username);
62 | // loginPage.setPassword(password);
63 | // loginPage.clickLogin();
64 |
65 | // Method Chaining
66 | // loginPage
67 | // .setUsername(username)
68 | // .setPassword(password)
69 | // .clickLogin();
70 | loginPage.loginToApplication(username, password);
71 |
72 | String errorInvalidCreds = DriverManager.getDriver().findElement(By.id("spanMessage")).getText();
73 | Assert.assertEquals(errorInvalidCreds, expectedError,
74 | "Assertion for Invalid credentials Error message");
75 | }
76 |
77 |
78 | /**
79 | * --------------------------------------------------------------------- (1st time)
80 | */
81 |
82 | // @Test(description = "To check whether the User can not login with Invalid Credentials")
83 | public void REFERENCE__errorInvalidCredentials() {
84 | // driver.findElement(By.id("txtUsername")).sendKeys("Admin");
85 | // driver.findElement(By.id("txtPassword")).sendKeys("admin1234");
86 | // driver.findElement(By.id("btnLogin")).click();
87 | // holdScript(3);
88 |
89 | // Driver.threadLocal.get().findElement(By.id("txtUsername")).sendKeys("Admin");
90 | // Driver.threadLocal.get().findElement(By.id("txtPassword")).sendKeys("admin1234");
91 | // Driver.threadLocal.get().findElement(By.id("btnLogin")).click();
92 |
93 | // DriverManager.getDriver().findElement(By.id("txtUsername")).sendKeys("Admin");
94 | // DriverManager.getDriver().findElement(By.id("txtPassword")).sendKeys("admin1234");
95 | // DriverManager.getDriver().findElement(By.id("btnLogin")).click();
96 |
97 | // LoginPage loginPage =new LoginPage();
98 | // loginPage.setUsername("Admin");
99 | // loginPage.setPassword("admin1234");
100 | // loginPage.clickLogin();
101 |
102 | // String errorInvalidCreds = Driver.driver.findElement(By.id("spanMessage")).getText();
103 | // String errorInvalidCreds = Driver.threadLocal.get().findElement(By.id("spanMessage")).getText();
104 | String errorInvalidCreds = DriverManager.getDriver().findElement(By.id("spanMessage")).getText();
105 |
106 |
107 | // Assert.assertEquals(errorInvalidCreds, "Invalid credentials",
108 | // "Assertion for Invalid credentials Error message");
109 | Assert.assertEquals(errorInvalidCreds, "无效的凭证",
110 | "Assertion for Invalid credentials Error message");
111 |
112 |
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/src/test/java/com/learning/tests/HomePageTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Rajat Verma
3 | * https://www.linkedin.com/in/rajat-v-3b0685128/
4 | * https://github.com/rajatt95
5 | * https://rajatt95.github.io/
6 | *
7 | * Course: Selenium - Java with Docker, Git and Jenkins (https://www.testingminibytes.com/courses/selenium-java-with-docker-git-and-jenkins/)
8 | * Tutor: Amuthan Sakthivel (https://www.testingminibytes.com/)
9 | */
10 |
11 | package com.learning.tests;
12 |
13 | import com.learning.annotations.FrameworkAnnotation;
14 | import com.learning.driver.DriverManager;
15 | import com.learning.enums.AuthorType;
16 | import com.learning.enums.CategoryType;
17 | import com.learning.pages.HomePage;
18 | import com.learning.pages.LoginPage;
19 | import com.learning.testdata.TestData;
20 | import com.learning.utils.DataProviderUtils;
21 | import com.learning.utils.VerificationUtils;
22 | import org.testng.Assert;
23 | import org.testng.annotations.Test;
24 |
25 | import static com.learning.constants.FrameworkConstants.ASSERTION_FOR;
26 |
27 | public class HomePageTest extends BaseTest {
28 |
29 | @FrameworkAnnotation(author = { AuthorType.GAUTAM, AuthorType.PANKAJ},
30 | category = { CategoryType.SANITY, CategoryType.SMOKE,CategoryType.REGRESSION })
31 | @Test(groups = {"SANITY","SMOKE","REGRESSION"},description = "To check whether the User can login and title is displayed correctly",
32 | dataProvider = "getTestData",dataProviderClass = DataProviderUtils.class)
33 | public void titleValidationTest(TestData testData) {
34 |
35 | LoginPage loginPage = new LoginPage();
36 | HomePage homePage = loginPage
37 | .loginToApplication(testData.getUsername(), testData.getPassword());
38 |
39 | // Assert.assertEquals(homePage.getHomePageTitle(), testData.getExpectedTitle(),
40 | // "Assertion for Page Title after successful Login");
41 |
42 | VerificationUtils.validateResponse(homePage.getHomePageTitle(), testData.getExpectedTitle(),
43 | ASSERTION_FOR +" - Page Title after successful Login ");
44 |
45 | }
46 |
47 |
48 |
49 | /**
50 | * --------------------------------------------------------------------- (2nd time)
51 | * */
52 | // @FrameworkAnnotation(author = { AuthorType.GAUTAM, AuthorType.PANKAJ},
53 | // category = { CategoryType.SANITY, CategoryType.SMOKE,CategoryType.REGRESSION })
54 | // @Test(description = "To check whether the User can login and title is displayed correctly",
55 | // dataProvider = "getValidLoginData", dataProviderClass = DataProviderUtils.class)
56 | public void REFERENCE_titleValidationTest(String username, String password, String expectedTitle) {
57 |
58 | LoginPage loginPage = new LoginPage();
59 | // loginPage.setUsername("Admin");
60 | // loginPage.setPassword("admin1234");
61 | // loginPage.setUsername(username);
62 | // loginPage.setPassword(password);
63 | // loginPage.clickLogin();
64 |
65 | // Method Chaining
66 | // loginPage
67 | // .setUsername(username)
68 | // .setPassword(password)
69 | // .clickLogin();
70 | HomePage homePage = loginPage
71 | .loginToApplication(username, password);
72 |
73 | // Assert.assertEquals(DriverManager.getDriver().getTitle(), "OrangeHRM", "Assertion for Page Title after successful Login");
74 | Assert.assertEquals(homePage.getHomePageTitle(), expectedTitle,
75 | "Assertion for Page Title after successful Login");
76 |
77 | }
78 |
79 |
80 | /**
81 | * --------------------------------------------------------------------- (1st time)
82 | * */
83 | // @Test(description = "To check whether the User can login and title is displayed correctly")
84 | public void REFERENCE_errorInvalidCredentials() {
85 | // driver.findElement(By.id("txtUsername")).sendKeys("Admin");
86 | // driver.findElement(By.id("txtPassword")).sendKeys("admin1234");
87 | // driver.findElement(By.id("btnLogin")).click();
88 | // holdScript(3);
89 | // Driver.driver.findElement(By.id("txtUsername")).sendKeys("Admin");
90 | // Driver.driver.findElement(By.id("txtPassword")).sendKeys("admin1234");
91 | // Driver.driver.findElement(By.id("btnLogin")).click();
92 |
93 | // Driver.threadLocal.get().findElement(By.id("txtUsername")).sendKeys("Admin");
94 | // Driver.threadLocal.get().findElement(By.id("txtPassword")).sendKeys("admin1234");
95 | // Driver.threadLocal.get().findElement(By.id("btnLogin")).click();
96 |
97 | // DriverManager.getDriver().findElement(By.id("txtUsername")).sendKeys("Admin");
98 | // DriverManager.getDriver().findElement(By.id("txtPassword")).sendKeys("admin1234");
99 | // DriverManager.getDriver().findElement(By.id("btnLogin")).click();
100 |
101 | // LoginPage loginPage =new LoginPage();
102 | // loginPage.setUsername("Admin");
103 | // loginPage.setPassword("admin1234");
104 | // loginPage.clickLogin();
105 |
106 | // Assert.assertEquals( Driver.driver.getTitle(), "OrangeHRM", "Assertion for Page Title");
107 | // Assert.assertEquals( Driver.threadLocal.get().getTitle(), "OrangeHRM", "Assertion for Page Title");
108 | Assert.assertEquals(DriverManager.getDriver().getTitle(), "OrangeHRM", "Assertion for Page Title");
109 |
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.example
8 | TMB_SeleniumFramework2
9 | 1.0-SNAPSHOT
10 |
11 |
12 | 8
13 | 8
14 |
16 | testng
17 | 2
18 |
19 |
20 |
21 |
22 |
23 | org.apache.maven.plugins
24 | maven-compiler-plugin
25 | 3.8.1
26 |
27 | 8
28 | 8
29 |
30 |
31 |
32 | org.apache.maven.plugins
33 | maven-surefire-plugin
34 | 3.0.0-M5
35 |
36 | ${browserInstances}
37 |
38 |
39 |
40 |
41 |
42 | src/test/resources/runners/${suiteFile}.xml
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | org.seleniumhq.selenium
57 | selenium-java
58 | 3.141.59
59 |
60 |
61 |
62 |
63 | org.testng
64 | testng
65 | 7.3.0
66 |
67 |
68 |
69 |
70 |
71 | io.github.bonigarcia
72 | webdrivermanager
73 | 5.0.3
74 |
75 |
76 |
77 |
78 | com.aventstack
79 | extentreports
80 | 5.0.9
81 |
82 |
83 |
84 |
85 | org.apache.poi
86 | poi
87 | 5.1.0
88 |
89 |
90 |
91 |
92 | org.apache.poi
93 | poi-ooxml
94 | 5.1.0
95 |
96 |
97 |
98 |
99 | org.aeonbits.owner
100 | owner
101 | 1.0.12
102 |
103 |
104 |
105 |
106 | com.github.javafaker
107 | javafaker
108 | 1.0.2
109 |
110 |
111 |
112 |
113 | io.github.sskorol
114 | test-data-supplier
115 | 1.9.7
116 |
117 |
118 |
119 |
120 | com.sun.mail
121 | javax.mail
122 | 1.6.2
123 |
124 |
125 |
126 |
127 | org.zeroturnaround
128 | zt-zip
129 | 1.14
130 |
131 |
132 |
133 |
134 |
135 |
--------------------------------------------------------------------------------
/src/main/java/com/learning/reports/ExtentLogger.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Rajat Verma
3 | * https://www.linkedin.com/in/rajat-v-3b0685128/
4 | * https://github.com/rajatt95
5 | * https://rajatt95.github.io/
6 | *
7 | * Course: Selenium - Java with Docker, Git and Jenkins (https://www.testingminibytes.com/courses/selenium-java-with-docker-git-and-jenkins/)
8 | * Tutor: Amuthan Sakthivel (https://www.testingminibytes.com/)
9 | */
10 |
11 | package com.learning.reports;
12 |
13 | import com.aventstack.extentreports.MediaEntityBuilder;
14 | import com.aventstack.extentreports.markuputils.Markup;
15 | import com.learning.config.ConfigFactory;
16 | import com.learning.utils.ScreenshotUtils;
17 |
18 | import static com.learning.constants.FrameworkConstants.*;
19 |
20 | //final -> We do not want any class to extend this class
21 | public final class ExtentLogger {
22 |
23 | //private -> We do not want anyone to create the object of this class
24 | private ExtentLogger() {
25 | }
26 |
27 | public static void pass(String message) {
28 | ExtentManager.getExtentTest().pass(message);
29 | }
30 |
31 | public static void pass(Markup message) {
32 | ExtentManager.getExtentTest().pass(message);
33 | }
34 |
35 | public static void fail(String message) {
36 | ExtentManager.getExtentTest().fail(message);
37 | }
38 |
39 | public static void fail(Markup message) {
40 | ExtentManager.getExtentTest().fail(message);
41 | }
42 |
43 | public static void skip(String message) {
44 | ExtentManager.getExtentTest().skip(message);
45 | }
46 |
47 | public static void skip(Markup message) {
48 | ExtentManager.getExtentTest().skip(message);
49 | }
50 |
51 | public static void info(Markup message) {
52 | ExtentManager.getExtentTest().info(message);
53 | }
54 |
55 | public static void info(String message) {
56 | ExtentManager.getExtentTest().info(message);
57 | }
58 |
59 | public static void captureScreenshot() {
60 | ExtentManager.getExtentTest().info("Capturing Screenshot",
61 | MediaEntityBuilder.createScreenCaptureFromBase64String(ScreenshotUtils.getBase64Image()).build());
62 | }
63 |
64 | public static void pass(String message, boolean isScreeshotNeeded) {
65 | if (ConfigFactory.getConfig().passed_steps_screenshot().trim().equalsIgnoreCase(YES) && isScreeshotNeeded) {
66 | ExtentManager.getExtentTest().pass(message,
67 | MediaEntityBuilder.createScreenCaptureFromBase64String(ScreenshotUtils.getBase64Image()).build());
68 | } else {
69 | pass(message);
70 | }
71 | }
72 |
73 | public static void pass(Markup message, boolean isScreeshotNeeded) {
74 | if (ConfigFactory.getConfig().passed_steps_screenshot().trim().equalsIgnoreCase(YES) && isScreeshotNeeded) {
75 | /* System.out.println("----------------");
76 | System.out.println("ConfigFactory.getConfig().passed_steps_screenshot() = " + ConfigFactory.getConfig().passed_steps_screenshot());
77 | System.out.println("ConfigFactory.getConfig().passed_steps_screenshot().trim().equalsIgnoreCase(YES) = " + ConfigFactory.getConfig().passed_steps_screenshot().trim().equalsIgnoreCase(YES));
78 | System.out.println("isScreeshotNeeded = " + isScreeshotNeeded);
79 | */
80 | ExtentManager.getExtentTest().pass(
81 | MediaEntityBuilder.createScreenCaptureFromBase64String(ScreenshotUtils.getBase64Image()).build());
82 | ExtentManager.getExtentTest().pass(message);
83 | } else {
84 | pass(message);
85 | }
86 | }
87 |
88 | public static void fail(String message, boolean isScreeshotNeeded) {
89 | if (ConfigFactory.getConfig().failed_steps_screenshot().trim().equalsIgnoreCase(YES) && isScreeshotNeeded) {
90 | ExtentManager.getExtentTest().fail(message,
91 | MediaEntityBuilder.createScreenCaptureFromBase64String(ScreenshotUtils.getBase64Image()).build());
92 | } else {
93 | fail(message);
94 | }
95 | }
96 |
97 | public static void fail(Markup message, boolean isScreeshotNeeded) {
98 | if (ConfigFactory.getConfig().failed_steps_screenshot().trim().equalsIgnoreCase(YES) && isScreeshotNeeded) {
99 | ExtentManager.getExtentTest().fail(
100 | MediaEntityBuilder.createScreenCaptureFromBase64String(ScreenshotUtils.getBase64Image()).build());
101 | ExtentManager.getExtentTest().fail(message);
102 | } else {
103 | fail(message);
104 | }
105 | }
106 |
107 | public static void skip(String message, boolean isScreeshotNeeded) {
108 | if (ConfigFactory.getConfig().skipped_steps_screenshot().trim().equalsIgnoreCase(YES) && isScreeshotNeeded) {
109 | ExtentManager.getExtentTest().skip(message,
110 | MediaEntityBuilder.createScreenCaptureFromBase64String(ScreenshotUtils.getBase64Image()).build());
111 | } else {
112 | skip(message);
113 | }
114 | }
115 |
116 | public static void skip(Markup message, boolean isScreeshotNeeded) {
117 | if (ConfigFactory.getConfig().skipped_steps_screenshot().trim().equalsIgnoreCase(YES) && isScreeshotNeeded) {
118 | ExtentManager.getExtentTest().skip(
119 | MediaEntityBuilder.createScreenCaptureFromBase64String(ScreenshotUtils.getBase64Image()).build());
120 | ExtentManager.getExtentTest().skip(message);
121 | } else {
122 | skip(message);
123 | }
124 | }
125 |
126 | }
127 |
--------------------------------------------------------------------------------
/src/main/java/com/learning/constants/FrameworkConstants.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Rajat Verma
3 | * https://www.linkedin.com/in/rajat-v-3b0685128/
4 | * https://github.com/rajatt95
5 | * https://rajatt95.github.io/
6 | *
7 | * Course: Selenium - Java with Docker, Git and Jenkins (https://www.testingminibytes.com/courses/selenium-java-with-docker-git-and-jenkins/)
8 | * Tutor: Amuthan Sakthivel (https://www.testingminibytes.com/)
9 | */
10 |
11 | package com.learning.constants;
12 |
13 | import com.learning.utils.ReportUtils;
14 |
15 | //final -> We do not want any class to extend this class
16 | public class FrameworkConstants {
17 |
18 | //private -> We do not want anyone to create the object of this class
19 | private FrameworkConstants() {
20 | }
21 |
22 | public static final String ASSERTION_FOR_RESPONSE_STATUS_CODE = "Assertion for Response Status Code";
23 | public static final String ASSERTION_FOR_RESPONSE_HEADER = "Assertion for Response Headers";
24 | public static final String ASSERTION_FOR_RESPONSE_CUSTOM_FIELD = "Assertion for Response Custom Field";
25 | public static final String ASSERTION_FOR = "Assertion for ";
26 |
27 | public static final long WAIT = 5;
28 |
29 | public static final String PROJECT_PATH = System.getProperty("user.dir");
30 |
31 | public static final String CHROME = "chrome";
32 | public static final String CHROME_HEADLESS = "chrome_headless";
33 | public static final String HEADLESS = "headless";
34 |
35 | public static final String FIREFOX = "firefox";
36 | public static final String EDGE = "edge";
37 | public static final String OPERA = "opera";
38 | public static final String SAFARI = "safari";
39 |
40 | public static final String LOCAL = "local";
41 | public static final String REMOTE = "remote";
42 |
43 |
44 |
45 |
46 | /*ExtentReports - START*/
47 |
48 | // private static final String REPORT_PATH = PROJECT_PATH + "/ExtentReport.html";
49 | // public static final String REPORT_LOCATION = PROJECT_PATH + "/ExtentReports/";
50 |
51 | // private static final String REPORT_PATH = getExtentReportFilePath();
52 | // public static final String REPORT_LOCATION = PROJECT_PATH + "/ExtentReports/";
53 | // private static String extentReportFilePath = "";
54 | // private static final String EXTENT_REPORT_NAME = "AutomationReport.html";
55 |
56 | public static final String EXTENT_REPORT_FOLDER_PATH = PROJECT_PATH + "/ExtentReports/";
57 | public static final String EXTENT_REPORT_NAME = "AutomationReport.html";
58 | private static String extentReportFilePath = "";
59 |
60 | /**
61 | * Zip file of Extent Reports
62 | */
63 | public static final String Zipped_ExtentReports_Folder_Name = "ExtentReports.zip";
64 |
65 | /*ExtentReports - END*/
66 |
67 | public static final String TEST_DATA_XLSX_FILE = "testdata/testData.xlsx";
68 |
69 | public static final String PROJECT_NAME = "Automation Test Suite Report - Selenium Framework - TMB 2";
70 | public static final String YES = "YES";
71 | public static final String NO = "NO";
72 |
73 | public static final String BOLD_START = "";
74 | public static final String BOLD_END = "";
75 |
76 | /* ICONS - START */
77 |
78 | public static final String ICON_SMILEY_PASS = "";
79 | public static final String ICON_SMILEY_SKIP = "";
80 | public static final String ICON_SMILEY_FAIL = "";
81 |
82 | public static final String ICON_OS_WINDOWS = "";
83 | public static final String ICON_OS_MAC = "";
84 | public static final String ICON_OS_LINUX = "";
85 |
86 | // public static final String ICON_BROWSER_OPERA = "";
87 | // public static final String ICON_BROWSER_EDGE = "";
88 | // public static final String ICON_BROWSER_CHROME = "";
89 | // public static final String ICON_BROWSER_FIREFOX = "";
90 | // public static final String ICON_BROWSER_SAFARI = "";
91 |
92 | public static final String ICON_Navigate_Right = "";
93 | public static final String ICON_LAPTOP = "";
94 | public static final String ICON_BUG = "";
95 | /* style="text-align:center;" */
96 |
97 | public static final String ICON_SOCIAL_GITHUB_PAGE_URL = "https://rajatt95.github.io/";
98 | public static final String ICON_SOCIAL_LINKEDIN_URL = "https://www.linkedin.com/in/rajat-v-3b0685128/";
99 | public static final String ICON_SOCIAL_GITHUB_URL = "https://github.com/rajatt95";
100 | public static final String ICON_SOCIAL_LINKEDIN = "";
102 | public static final String ICON_SOCIAL_GITHUB = "";
104 |
105 | // public static final String ICON_SOCIAL_LINKEDIN = "";
106 | // public static final String ICON_SOCIAL_GITHUB = "";
107 | // public static final String ICON_SOCIAL_LINKEDIN_VALUE = "LinkedIn";
108 | // public static final String ICON_SOCIAL_GITHUB_VALUE = "https://github.com/rajatt95";
109 |
110 | public static final String ICON_CAMERA = "";
111 |
112 | public static final String ICON_BROWSER_EDGE = "edge";
113 | public static final String ICON_BROWSER_PREFIX = "";
115 | /* ICONS - END */
116 |
117 | public static String getExtentReportFilePath() {
118 | if (extentReportFilePath.isEmpty()) {
119 | extentReportFilePath = ReportUtils.createExtentReportPath();
120 | }
121 | return extentReportFilePath;
122 | }
123 |
124 | }
125 |
--------------------------------------------------------------------------------
/src/main/java/com/learning/utils/SeleniumUtils.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Rajat Verma
3 | * https://www.linkedin.com/in/rajat-v-3b0685128/
4 | * https://github.com/rajatt95
5 | * https://rajatt95.github.io/
6 | *
7 | * Course: Selenium - Java with Docker, Git and Jenkins (https://www.testingminibytes.com/courses/selenium-java-with-docker-git-and-jenkins/)
8 | * Tutor: Amuthan Sakthivel (https://www.testingminibytes.com/)
9 | */
10 |
11 | package com.learning.utils;
12 |
13 | import com.google.common.util.concurrent.Uninterruptibles;
14 | import com.learning.config.ConfigFactory;
15 | import com.learning.driver.DriverManager;
16 | import com.learning.enums.WaitType;
17 | import com.learning.reports.ExtentLogger;
18 | import org.openqa.selenium.By;
19 | import org.openqa.selenium.WebElement;
20 | import org.openqa.selenium.support.ui.ExpectedConditions;
21 | import org.openqa.selenium.support.ui.WebDriverWait;
22 |
23 | import java.util.concurrent.TimeUnit;
24 |
25 | import static com.learning.constants.FrameworkConstants.*;
26 |
27 | public class SeleniumUtils {
28 |
29 | private static WebElement waitUntilPresenceOfElementLocated(By by) {
30 | WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), ConfigFactory.getConfig().timeout());
31 | return wait.until(ExpectedConditions.presenceOfElementLocated(by));
32 | }
33 |
34 | private static WebElement waitUntilElementToBeClickable(By by) {
35 | WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), ConfigFactory.getConfig().timeout());
36 | return wait.until(ExpectedConditions.elementToBeClickable(by));
37 | }
38 |
39 | private static WebElement waitUntilElementToBeVisible(By by) {
40 | WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), ConfigFactory.getConfig().timeout());
41 | return wait.until(ExpectedConditions.visibilityOfElementLocated(by));
42 | }
43 |
44 | public static void sendKeys(By by, String value) {
45 | // WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), ConfigFactory.getConfig().timeout());
46 | // wait.until(ExpectedConditions.presenceOfElementLocated(by));
47 | // return DriverManager.getDriver().findElement(by).getText();
48 | WebElement element = waitUntilPresenceOfElementLocated(by);
49 | element.sendKeys(value);
50 | // ExtentLogger.pass("Value: " + value + " is successfully passed in textBox: " + element.getText());
51 | ExtentLogger.pass("Value: " + value + " is successfully passed in textBox: " + element.getText(), true);
52 | }
53 |
54 | public static void sendKeys(By by, String value, String elementName) {
55 | // WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), ConfigFactory.getConfig().timeout());
56 | // wait.until(ExpectedConditions.presenceOfElementLocated(by));
57 | // return DriverManager.getDriver().findElement(by).getText();
58 | WebElement element = waitUntilPresenceOfElementLocated(by);
59 | element.sendKeys(value);
60 | // ExtentLogger.pass("Value " + BOLD_START + value + BOLD_END + " is successfully passed in "
61 | // + BOLD_START + elementName + BOLD_END + " textbox.");
62 | ExtentLogger.pass("Value " + BOLD_START + value + BOLD_END + " is successfully passed in "
63 | + BOLD_START + elementName + BOLD_END + " textbox.", true);
64 | }
65 |
66 |
67 | public static void click(By by) {
68 | // WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), ConfigFactory.getConfig().timeout());
69 | // wait.until(ExpectedConditions.elementToBeClickable(by));
70 | // DriverManager.getDriver().findElement(by).click();
71 | WebElement element = waitUntilElementToBeClickable(by);
72 | element.click();
73 | // ExtentLogger.pass("Element: " + element.getText() + " is clicked successfully.");
74 | //ExtentLogger.pass(element.getText() + " is clicked successfully.", true);
75 | ExtentLogger.pass("Clicking on: " + BOLD_START + element.getText() + BOLD_END, true);
76 |
77 | }
78 |
79 | public static void click(By by, WaitType waitType) {
80 | WebElement element = getElementAfterWait(by, waitType);
81 | // ExtentLogger.pass("Element: " + BOLD_START + element.getText() + BOLD_END + " is clicked successfully");
82 | // ExtentLogger.pass(BOLD_START + element.getText() + BOLD_END + " is clicked successfully", true);
83 | ExtentLogger.pass("Clicking on: " + BOLD_START + element.getText() + BOLD_END, true);
84 | element.click();
85 |
86 | }
87 |
88 | private static WebElement getElementAfterWait(By by, WaitType waitType) {
89 | //waitUntilElementToBeClickable(by).click();
90 | WebElement element = null;
91 | if (waitType == WaitType.PRESENCE) {
92 | element = waitUntilPresenceOfElementLocated(by);
93 | } else if (waitType == WaitType.CLICKABLE) {
94 | element = waitUntilElementToBeClickable(by);
95 | } else if (waitType == WaitType.VISIBLE) {
96 | element = waitUntilElementToBeVisible(by);
97 | }
98 | return element;
99 | }
100 |
101 | public static void click(By by, WaitType waitType, String elementName) {
102 | WebElement element = getElementAfterWait(by, waitType);
103 | // ExtentLogger.pass("Element: " + BOLD_START + elementName + BOLD_END + " is clicked successfully.");
104 | //ExtentLogger.pass(BOLD_START + elementName + BOLD_END + " is clicked successfully.", true);
105 | ExtentLogger.pass("Clicking on: " + BOLD_START + elementName + BOLD_END, true);
106 | element.click();
107 |
108 | }
109 |
110 |
111 | public static String getElementText(By by) {
112 | // WebDriverWait wait = new WebDriverWait(DriverManager.getDriver(), ConfigFactory.getConfig().timeout());
113 | // wait.until(ExpectedConditions.presenceOfElementLocated(by));
114 | // return DriverManager.getDriver().findElement(by).getText();
115 | WebElement element = waitUntilPresenceOfElementLocated(by);
116 | ExtentLogger.info("Element Text: " + BOLD_START + element.getText() + BOLD_END);
117 | return element.getText();
118 | }
119 |
120 | public static String getPageTitle() {
121 | String title = DriverManager.getDriver().getTitle();
122 | ExtentLogger.info("Page title: " + BOLD_START + title + BOLD_END);
123 | return title;
124 | }
125 |
126 |
127 | public static WebElement getElement(By by) {
128 | return waitUntilElementToBeVisible(by);
129 | }
130 |
131 | public static void captureScreenshot() {
132 | ExtentLogger.captureScreenshot();
133 | }
134 |
135 | public static void waitForSomeTime() {
136 | Uninterruptibles.sleepUninterruptibly(WAIT, TimeUnit.SECONDS);
137 | }
138 |
139 | public static void waitForGivenTime(long time) {
140 | Uninterruptibles.sleepUninterruptibly(time, TimeUnit.SECONDS);
141 | }
142 |
143 | public static String getWebPageURL() {
144 | String url = DriverManager.getDriver().getCurrentUrl();
145 | //ExtentLogger.info("Page URL: " + BOLD_START + url + BOLD_END);
146 | ExtentLogger.info("Page URL: " + "" + url + "");
147 |
148 | return url;
149 | }
150 |
151 | }
152 |
--------------------------------------------------------------------------------
/ExtentReports/Mac_OS_X_Tue_Feb_22_18_21_15_IST_2022_AutomationReport.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Automation Test Suite Report - Selenium Framework - TMB 2 - ALL
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
73 |
74 |
402 |
719 |
720 |
721 |
722 |
Started
723 |
Feb 22, 2022 06:21:15 PM
724 |
725 |
726 |
727 |
728 |
Ended
729 |
Feb 22, 2022 06:21:38 PM
730 |
731 |
732 |
733 |
734 |
Tests Passed
735 |
3
736 |
737 |
738 |
739 |
740 |
Tests Failed
741 |
0
742 |
743 |
744 |
745 |
790 |
797 |
802 |
803 |
804 |
805 |
806 |
807 | | Name | Passed | Failed | Skipped | Others | Passed % |
808 |
809 |
810 | | NISHANT |
811 | 3 |
812 | 0 |
813 | 0 |
814 | 0 |
815 | 100% |
816 |
817 |
818 | | RAJAT |
819 | 3 |
820 | 0 |
821 | 0 |
822 | 0 |
823 | 100% |
824 |
825 |
826 |
827 |
828 |
829 |
830 |
831 |
832 |
833 | | Name | Passed | Failed | Skipped | Others | Passed % |
834 |
835 | | BVT |
836 | 3 |
837 | 0 |
838 | 0 |
839 | 0 |
840 | 100% |
841 |
842 |
843 | | REGRESSION |
844 | 3 |
845 | 0 |
846 | 0 |
847 | 0 |
848 | 100% |
849 |
850 |
851 | | SANITY |
852 | 1 |
853 | 0 |
854 | 0 |
855 | 0 |
856 | 100% |
857 |
858 |
859 |
860 |
861 |
862 |
863 |
864 |
865 |
866 | | Name | Passed | Failed | Skipped | Others | Passed % |
867 |
868 |
869 | | CHROME |
870 | 3 |
871 | 0 |
872 | 0 |
873 | 0 |
874 | 100% |
875 |
876 |
877 |
878 |
879 |
880 |
881 |
882 |
883 |
884 | | Name | Value |
885 |
886 |
887 | | Organization |
888 | Nagarro |
889 |
890 |
891 | | Employee |
892 | Rajat Verma |
893 |
894 |
895 | | Domain |
896 | Engineering (IT - Software) |
897 |
898 |
899 | | Skill |
900 | Test Automation Engineer |
901 |
902 |
903 |
904 |
905 |
906 |
907 |
908 |
935 |
936 |
937 |
938 |
939 |
940 |
--------------------------------------------------------------------------------