├── .classpath ├── .gitignore ├── .project ├── .settings ├── org.eclipse.core.resources.prefs ├── org.eclipse.jdt.core.prefs ├── org.eclipse.jdt.ui.prefs └── org.eclipse.m2e.core.prefs ├── README.md ├── _config.yml ├── debug.log ├── pom.xml ├── src ├── main │ ├── java │ │ └── com │ │ │ └── test │ │ │ ├── constants │ │ │ ├── CommonProperties.java │ │ │ └── SystemVariables.java │ │ │ ├── framework │ │ │ ├── BaseClass.java │ │ │ ├── ExcelDataProviderMap.java │ │ │ ├── ExcelResultUpdate.java │ │ │ └── UtilityClass.java │ │ │ ├── listeners │ │ │ ├── AnnotationTransformer.java │ │ │ ├── FailureRetryListener.java │ │ │ ├── TestNGListener.java │ │ │ ├── TestSuiteListener.java │ │ │ └── WebDriverListener.java │ │ │ └── pageobjects │ │ │ ├── GoogleHomePage.java │ │ │ ├── RahulShettyAcademy.java │ │ │ └── RahulShettyPractice.java │ └── resources │ │ ├── configuration.properties │ │ └── log4j2.xml └── test │ ├── java │ └── com │ │ └── test │ │ ├── api │ │ └── GooglePlaceUpdateQA.java │ │ └── gui │ │ ├── PassFailTest.java │ │ └── SeleniumPractice.java │ └── resources │ └── TestData.xlsx └── testng.xml /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | test-output/ -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | AutoFrameWork 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding//src/test/resources=UTF-8 6 | encoding/=UTF-8 7 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.8 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 12 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 13 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 14 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning 15 | org.eclipse.jdt.core.compiler.release=disabled 16 | org.eclipse.jdt.core.compiler.source=1.8 17 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.ui.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.ui.text.custom_code_templates= 3 | -------------------------------------------------------------------------------- /.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Selenium TDD Framework 2 | 3 | A framework that incorporates key features of Selenium and TestNG which can be used to create web-based automation scripts. 4 | 5 | **Key Features** 6 | 7 | * Supports method wise Parallel test execution 8 | * Screenshots can be taken for Pass/Fail steps 9 | * WebDriver manager based browser initiation 10 | * Platform independent 11 | * Integration with Extent Reports and Excel result updates 12 | * Automatic failure reruns 13 | * Integrated with sonarQube and java code coverage plugin for vulnerability analysis 14 | 15 | Note : Utility class is a work in progress 16 | 17 | # Table of contents 18 | * [Installation](#installation) 19 | * [Test Framework Design](#test-framework-design) 20 | * [Test Folder Structure](#test-folder-structure) 21 | * [Running the tests](#running-the-tests) 22 | * [Creating new tests](#creating-new-tests) 23 | * [Generating sonar and jacoco reports](#generating-sonar-and-jacoco-reports) 24 | * [Built With](#built-with) 25 | * [Contributing](#contributing) 26 | * [License](#license) 27 | * [Acknowledgments](#acknowledgments) 28 | * [References](#references) 29 | 30 | # Test Framework Design 31 | ![image](https://user-images.githubusercontent.com/11471191/85928673-6e349380-b8cc-11ea-88dd-7d78423259f8.png) 32 | 33 | # Test Folder Structure 34 | ![image](https://user-images.githubusercontent.com/11471191/85921106-424aeb00-b897-11ea-86a2-c1d31a0e5b24.png) 35 | 36 | # Installation 37 | 38 | Clone the repo from GitHub using below command 39 | ```git 40 | git clone https://github.com/naveenchr/AutoFrameWork.git 41 | ``` 42 | Clean and compile the maven project using below commands 43 | 44 | ```maven 45 | mvn clean 46 | mvn compile 47 | ``` 48 | 49 | # Running the tests 50 | 51 | Start test execution from either command prompt or Jenkins 52 | 53 | **From Command Prompt** 54 | 55 | ```maven 56 | mvn clean test -DtestngXML=testng.xml -P Profile_1 57 | 58 | ``` 59 | Run with groups tag 60 | 61 | ```maven 62 | mvn clean test -DtestngXML=testng.xml -Dgroups="Smoke Test" -P Profile_1 63 | ``` 64 | 65 | Manual failed run addition to automatic rerun 66 | ```maven 67 | mvn test -P Profile_2 68 | ``` 69 | 70 | **From Jenkins** 71 | 72 | ```maven 73 | mvn clean test -DparallelRun=$parallelMode -DthreadCount=$threadCount -DdataProviderThread=$dataProviderThread -DbrowserType=$browserType -DheadlessMode=$headlessMode -DtestngXML=$testngXML -Dgroups="Smoke Test" -P Profile_1 74 | 75 | ``` 76 | 77 | **Report Location** 78 | 79 | test-output/ExtentReport.html 80 | 81 | **Sample Report** 82 | 83 | ![image](https://user-images.githubusercontent.com/11471191/85928271-5c052600-b8c9-11ea-8b26-84ebd6079002.png) 84 | 85 | 86 | # Creating new tests 87 | 88 | ## Test Class File 89 | 90 | ```java 91 | package com.test.gui; 92 | 93 | import java.util.HashMap; 94 | import org.apache.logging.log4j.LogManager; 95 | import org.apache.logging.log4j.Logger; 96 | import org.testng.annotations.Test; 97 | import com.test.framework.BaseClass; 98 | import com.test.pageobjects.GoogleHomePage; 99 | 100 | public class PassFailTest { 101 | 102 | private static final Logger logger = LogManager.getLogger(PassFailTest.class); 103 | 104 | @Test 105 | public void googleTest_TC001(HashMap dataHashMap) { 106 | 107 | try { 108 | GoogleHomePage googleHomePage = new GoogleHomePage(dataHashMap); 109 | googleHomePage.searchTextBox(); 110 | } catch (Exception e) { 111 | BaseClass.getBaseObj().testFailureException(e); 112 | } 113 | } 114 | ``` 115 | ## Page Object File 116 | 117 | ```Java 118 | package com.test.pageobjects; 119 | 120 | import java.util.Map; 121 | import org.openqa.selenium.By; 122 | import com.test.framework.UtilityClass; 123 | 124 | public class GoogleHomePage extends UtilityClass { 125 | 126 | private Map map; 127 | 128 | public GoogleHomePage(Map map) { 129 | this.map = map; 130 | } 131 | 132 | By searchTextBox = By.cssSelector("[type='text']"); 133 | 134 | public void searchTextBox() { 135 | textField(searchTextBox, map.get("From Location")); 136 | } 137 | } 138 | ``` 139 | 140 | ## Excel File 141 | ![image](https://user-images.githubusercontent.com/11471191/85922565-079a8000-b8a2-11ea-89d9-31f2f3c365a6.png) 142 | 143 | # Generating sonar and jacoco reports 144 | 145 | * Add sonar server URL in POM file 146 | ```XML 147 | http://localhost:9000 148 | ``` 149 | * Execute the below maven command after the test run 150 | ```maven 151 | mvn sonar:sonar 152 | ``` 153 | 154 | # Built With 155 | 156 | * Selenium WebDriver 157 | * TestNG 158 | * Maven 159 | * Git 160 | * log4j 161 | * ExtentReport 162 | 163 | # Contributing 164 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. 165 | 166 | Please make sure to update the tests as appropriate. 167 | 168 | # License 169 | [MIT](https://choosealicense.com/licenses/mit/) 170 | 171 | # Acknowledgments 172 | 173 | * [Pooja Doshi](https://github.com/poojadoshi7) 174 | * [Vishnu M V](https://github.com/mvvishnu7) 175 | 176 | # References 177 | 178 | * Selenium WebDriver with Java -Basics to Advanced+Frameworks 179 | [udemy](https://www.udemy.com/course/selenium-real-time-examplesinterview-questions) 180 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /debug.log: -------------------------------------------------------------------------------- 1 | [0621/200549.635:ERROR:prune_crash_reports.cc(35)] PruneCrashReportDatabase: Failed to get pending reports 2 | [0621/200550.018:ERROR:prune_crash_reports.cc(35)] PruneCrashReportDatabase: Failed to get pending reports 3 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | com.cisco.framework 7 | AutoFrameWork 8 | 0.0.1-SNAPSHOT 9 | 10 | AutoFrameWork 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 1.8 16 | 1.8 17 | 18 | http://localhost:9000 19 | 20 | 21 | 22 | 23 | 24 | 25 | Profile_1 26 | 27 | 28 | 29 | org.apache.maven.plugins 30 | maven-surefire-plugin 31 | 3.0.0-M4 32 | 33 | 34 | ${testngXML} 35 | 36 | ${groups} 37 | true 38 | 39 | 40 | 41 | 42 | 43 | 44 | Profile_2 45 | 46 | 47 | 48 | org.apache.maven.plugins 49 | maven-surefire-plugin 50 | 3.0.0-M4 51 | 52 | 53 | ${project.basedir}/test-output/testng-failed.xml 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | org.jacoco 66 | jacoco-maven-plugin 67 | 0.8.3 68 | 69 | 70 | coverage-initialize 71 | 72 | prepare-agent 73 | 74 | 75 | 76 | coverage-report 77 | test 78 | 79 | report 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | org.seleniumhq.selenium 95 | selenium-java 96 | 3.141.59 97 | 98 | 99 | 100 | 101 | org.testng 102 | testng 103 | 7.1.0 104 | 105 | 106 | 107 | 108 | org.apache.maven.plugins 109 | maven-surefire-plugin 110 | 3.0.0-M4 111 | 112 | 113 | 114 | 115 | org.apache.logging.log4j 116 | log4j-api 117 | 2.17.1 118 | 119 | 120 | org.apache.logging.log4j 121 | log4j-core 122 | 2.17.1 123 | 124 | 125 | 126 | 127 | org.apache.poi 128 | poi 129 | 4.1.2 130 | 131 | 132 | 133 | 134 | org.apache.poi 135 | poi-ooxml 136 | 4.1.2 137 | 138 | 139 | 140 | 141 | 142 | com.aventstack 143 | extentreports 144 | 4.1.5 145 | 146 | 147 | 148 | 149 | org.sonarsource.scanner.maven 150 | sonar-maven-plugin 151 | 3.7.0.1746 152 | 153 | 154 | 155 | 156 | org.jacoco 157 | jacoco-maven-plugin 158 | 0.8.5 159 | 160 | 161 | 162 | 163 | 164 | io.github.bonigarcia 165 | webdrivermanager 166 | 4.0.0 167 | 168 | 169 | 170 | 171 | io.rest-assured 172 | rest-assured 173 | 4.3.0 174 | test 175 | 176 | 177 | 178 | 179 | 180 | 181 | -------------------------------------------------------------------------------- /src/main/java/com/test/constants/CommonProperties.java: -------------------------------------------------------------------------------- 1 | package com.test.constants; 2 | 3 | import java.io.FileInputStream; 4 | import java.util.Properties; 5 | 6 | import org.apache.logging.log4j.LogManager; 7 | import org.apache.logging.log4j.Logger; 8 | import org.testng.xml.XmlSuite.ParallelMode; 9 | 10 | import io.github.bonigarcia.wdm.config.DriverManagerType; 11 | 12 | /************************************************************************************************************************ 13 | * @Date : Jun 20, 2020 14 | * @Author : nachrist 15 | * @Description : Class to fetch data from properties file and from Jenkins and 16 | * pass to getter methods 17 | * @Version : 1.0 18 | ************************************************************************************************************************/ 19 | public class CommonProperties { 20 | 21 | public enum PropertyEnum { 22 | 23 | BROWSER_TYPE("browserType"), PARALLEL_RUN("parallelRun"), THREAD_COUNT("threadCount"), 24 | DATAPROVIDER_THREAD("dataproviderThread"), HEADLESS_MODE("headlessMode"), 25 | TAKE_SCREENSHOTS("takePassScreenshot"), PRACTICE_URL("practiceUrl"), GOOGLE_URL("googleUrl"), 26 | FAIL_TEST_URL("failTestUrl"); 27 | 28 | private String property; 29 | 30 | PropertyEnum(String systemProperty) { 31 | if (System.getProperty(systemProperty) != null) { 32 | this.property = System.getProperty(systemProperty); 33 | } else { 34 | this.property = properties.getProperty(systemProperty); 35 | } 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return property; 41 | } 42 | 43 | public Integer toInteger() { 44 | return Integer.valueOf(property); 45 | } 46 | 47 | public Boolean toBoolean() { 48 | return Boolean.valueOf(property); 49 | } 50 | 51 | } 52 | 53 | private static final Logger logger = LogManager.getLogger(CommonProperties.class); 54 | 55 | private static Properties properties; 56 | 57 | public static void loadProperties() { 58 | 59 | logger.debug("Data read from properties File"); 60 | 61 | try (FileInputStream file = new FileInputStream(SystemVariables.MAIN_RESOURCES + "configuration.properties");) { 62 | 63 | properties = new Properties(); 64 | properties.load(file); 65 | logger.debug("Data loaded to properties object"); 66 | } catch (Exception e) { 67 | logger.debug("Error in fetching common properties :{}", e); 68 | } 69 | 70 | } 71 | 72 | public static DriverManagerType getBrowserType() { 73 | return DriverManagerType.valueOf(PropertyEnum.BROWSER_TYPE.toString().toUpperCase()); 74 | } 75 | 76 | public static ParallelMode getParallelRun() { 77 | 78 | if (PropertyEnum.PARALLEL_RUN.toString().equalsIgnoreCase(ParallelMode.METHODS.name())) { 79 | return ParallelMode.METHODS; 80 | } else if (PropertyEnum.PARALLEL_RUN.toString().equalsIgnoreCase(ParallelMode.CLASSES.name())) { 81 | return ParallelMode.CLASSES; 82 | } else { 83 | return ParallelMode.NONE; 84 | } 85 | } 86 | 87 | public static Integer getThreadCount() { 88 | return PropertyEnum.THREAD_COUNT.toInteger(); 89 | } 90 | 91 | public static Integer getDataproviderThread() { 92 | return PropertyEnum.DATAPROVIDER_THREAD.toInteger(); 93 | } 94 | 95 | public static Boolean getHeadlessMode() { 96 | return PropertyEnum.HEADLESS_MODE.toBoolean(); 97 | } 98 | 99 | public static String getPracticeUrl() { 100 | return PropertyEnum.PRACTICE_URL.toString(); 101 | } 102 | 103 | public static Boolean getScreenshotFlag() { 104 | return PropertyEnum.TAKE_SCREENSHOTS.toBoolean(); 105 | } 106 | 107 | public static String getGoogleUrl() { 108 | return PropertyEnum.GOOGLE_URL.toString(); 109 | } 110 | 111 | public static String getFailTestUrl() { 112 | return PropertyEnum.FAIL_TEST_URL.toString(); 113 | } 114 | 115 | } 116 | -------------------------------------------------------------------------------- /src/main/java/com/test/constants/SystemVariables.java: -------------------------------------------------------------------------------- 1 | package com.test.constants; 2 | 3 | import java.io.File; 4 | 5 | /************************************************************************************************************************ 6 | * @Date : Jun 1, 2020 7 | * @Author : nachrist 8 | * @Description : Enum class for saving directory variables 9 | * @Version : 1.0 10 | ************************************************************************************************************************/ 11 | public enum SystemVariables { 12 | 13 | USER_DIR("user.dir"), 14 | MAIN_RESOURCES(SystemVariables.USER_DIR, "src" + File.separator + "main" + File.separator + "resources"), 15 | TEST_RESOURCES(SystemVariables.USER_DIR, "src" + File.separator + "test" + File.separator + "resources"), 16 | OUTPUT_FOLDER(SystemVariables.USER_DIR, "test-output"), USER_NAME("user.name"), OS_ARCH("os.arch"), 17 | OS_NAME("os.name"), OS_VERSION("os.version"); 18 | 19 | String systemProperty; 20 | 21 | SystemVariables(String systemProperty) { 22 | this.systemProperty = System.getProperty(systemProperty); 23 | } 24 | 25 | SystemVariables(SystemVariables systemProperty, String dir) { 26 | this.systemProperty = systemProperty + File.separator + dir + File.separator; 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return systemProperty; 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/test/framework/BaseClass.java: -------------------------------------------------------------------------------- 1 | package com.test.framework; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.util.ArrayList; 6 | import java.util.HashMap; 7 | import java.util.LinkedHashMap; 8 | import java.util.List; 9 | import java.util.concurrent.ConcurrentHashMap; 10 | 11 | import org.apache.commons.io.FileUtils; 12 | import org.apache.logging.log4j.LogManager; 13 | import org.apache.logging.log4j.Logger; 14 | import org.openqa.selenium.By; 15 | import org.openqa.selenium.OutputType; 16 | import org.openqa.selenium.TakesScreenshot; 17 | import org.openqa.selenium.WebDriver; 18 | import org.openqa.selenium.chrome.ChromeDriver; 19 | import org.openqa.selenium.chrome.ChromeOptions; 20 | import org.openqa.selenium.firefox.FirefoxDriver; 21 | import org.openqa.selenium.support.events.EventFiringWebDriver; 22 | import org.openqa.selenium.support.ui.ExpectedConditions; 23 | import org.openqa.selenium.support.ui.WebDriverWait; 24 | import org.testng.Assert; 25 | import org.testng.ITestResult; 26 | import org.testng.Reporter; 27 | import org.testng.internal.TestResult; 28 | 29 | import com.aventstack.extentreports.ExtentReports; 30 | import com.aventstack.extentreports.ExtentTest; 31 | import com.aventstack.extentreports.Status; 32 | import com.aventstack.extentreports.reporter.ExtentSparkReporter; 33 | import com.aventstack.extentreports.reporter.configuration.Theme; 34 | import com.test.constants.CommonProperties; 35 | import com.test.constants.SystemVariables; 36 | import com.test.listeners.WebDriverListener; 37 | 38 | import io.github.bonigarcia.wdm.WebDriverManager; 39 | import io.github.bonigarcia.wdm.config.DriverManagerType; 40 | 41 | /************************************************************************************************************************ 42 | * @Date : Mar 28, 2020 43 | * @Author : nachrist 44 | * @Description : Base class to keep all common methods 45 | * @Version : 2.0 46 | ************************************************************************************************************************/ 47 | public class BaseClass { 48 | 49 | private static final Logger logger = LogManager.getLogger(BaseClass.class); 50 | 51 | protected static HashMap dataMap = new LinkedHashMap<>(); 52 | protected static LinkedHashMap> linkedMap = new LinkedHashMap<>(); 53 | protected static ConcurrentHashMap>> nestedMap = new ConcurrentHashMap<>(); 54 | 55 | protected static ConcurrentHashMap> executionStatusMap = new ConcurrentHashMap<>(); 56 | private static final ThreadLocal baseClassObj = new ThreadLocal<>(); 57 | 58 | private static ExtentReports extentReports; 59 | private static final int EXPLICIT_TIMEOUT_SECONDS = 3; 60 | 61 | private WebDriver driver; 62 | private String methodName; 63 | private ExtentTest extentTest; 64 | private Double testSetNum; 65 | 66 | /************************************************************************************************************************ 67 | * @Date : Apr 25, 2020 68 | * @Author : nachrist 69 | * @Description : Method to fetch url for test either from properties file or excel 70 | * @Method : getUrl 71 | * @Version : 1.0 72 | * @ReturnType : void / 73 | ***********************************************************************************************************************/ 74 | public void fetchUrl() { 75 | 76 | try { 77 | String method = methodName; 78 | logger.debug("Method Name :{}", method); 79 | 80 | if (method.toUpperCase().contains("SELENIUM")) { 81 | method = CommonProperties.getPracticeUrl(); 82 | } else if (method.toUpperCase().contains("GOOGLE")) { 83 | method = CommonProperties.getGoogleUrl(); 84 | } else if (method.toUpperCase().contains("FAIL")) { 85 | method = CommonProperties.getFailTestUrl(); 86 | } else { 87 | method = nestedMap.get(method).get(1.0).get("URL"); 88 | } 89 | 90 | logger.debug("Test Url : {}", method); 91 | 92 | driver.manage().deleteAllCookies(); 93 | driver.manage().window().maximize(); 94 | driver.get(method); 95 | } catch ( 96 | 97 | Exception e) { 98 | testFailureException(e); 99 | } 100 | 101 | } 102 | 103 | /************************************************************************************************************************ 104 | * @Date : Mar 28, 2020 105 | * @Author : nachrist 106 | * @Description : Method to open browser instance based on common properties 107 | * @Method : browserSelection 108 | * @Version : 1.0 109 | * @return 110 | * @throws IOException 111 | * @ReturnType : WebDriver / 112 | ***********************************************************************************************************************/ 113 | public void browserSelection() { 114 | 115 | DriverManagerType browserType; 116 | boolean headlessMode; 117 | 118 | try { 119 | 120 | browserType = CommonProperties.getBrowserType(); 121 | logger.debug("Browser Name :{} ", browserType); 122 | 123 | WebDriverManager.chromedriver().setup(); 124 | ChromeOptions options = new ChromeOptions(); 125 | 126 | headlessMode = CommonProperties.getHeadlessMode(); 127 | logger.debug("Headless Mode :{} ", headlessMode); 128 | options.setHeadless(headlessMode); 129 | 130 | WebDriverManager.getInstance(browserType).setup(); 131 | 132 | if (browserType.equals(DriverManagerType.CHROME)) { 133 | driver = new ChromeDriver(options); 134 | logger.info("Chrome instance started"); 135 | } else if (browserType.equals(DriverManagerType.FIREFOX)) { 136 | driver = new FirefoxDriver(); 137 | logger.info("Firefox instance started"); 138 | } else { 139 | driver = new ChromeDriver(); 140 | logger.info("Default browser chrome instance started"); 141 | } 142 | 143 | if (CommonProperties.getScreenshotFlag().equals(true)) { 144 | EventFiringWebDriver eventDriver = new EventFiringWebDriver(driver); 145 | WebDriverListener webDriverListener = new WebDriverListener(); 146 | eventDriver.register(webDriverListener); 147 | driver = eventDriver; 148 | } 149 | logger.debug("Take screenshots for all Steps :{} ", CommonProperties.getScreenshotFlag()); 150 | 151 | } catch (Exception e) { 152 | testFailureException(e); 153 | } 154 | 155 | } 156 | 157 | /************************************************************************************************************************ 158 | * @Date : Mar 28, 2020 159 | * @Author : nachrist 160 | * @Description : Tear down method and updates to be executed after each test 161 | * suite 162 | * @Method : saveTestRunDetails 163 | * @Version : 2.0 164 | * @ReturnType : void / 165 | ***********************************************************************************************************************/ 166 | public void saveTestRunDetails(ITestResult result) { 167 | 168 | String testCaseID; 169 | Double testSetNumber; 170 | long tcStartTime; 171 | long tcEndTime; 172 | boolean executionStatus; 173 | 174 | tcStartTime = result.getStartMillis(); 175 | logger.debug("Test Start Time :{} ", tcStartTime); 176 | 177 | testCaseID = result.getMethod().getMethodName(); 178 | logger.debug("Method Name :{} ", testCaseID); 179 | 180 | testSetNumber = ((TestResult) result).getParameterIndex() + 1.0; 181 | logger.debug("Test Set ID :{} ", testSetNumber); 182 | 183 | tcEndTime = result.getEndMillis(); 184 | logger.debug("Test End Time :{} ", tcEndTime); 185 | 186 | executionStatus = result.isSuccess(); 187 | logger.debug("Test Execution Passed :{} ", executionStatus); 188 | 189 | StringBuilder bld = new StringBuilder(); 190 | bld.append(testCaseID); 191 | bld.append("_"); 192 | bld.append(testSetNumber); 193 | 194 | testCaseID = bld.toString(); 195 | 196 | logger.debug(testCaseID); 197 | 198 | List testRunInfo = new ArrayList<>(); 199 | testRunInfo.add(tcStartTime); 200 | testRunInfo.add(tcEndTime); 201 | if (executionStatus) { 202 | testRunInfo.add(1L); 203 | } else { 204 | testRunInfo.add(0L); 205 | } 206 | 207 | logger.debug("testRunInfo :{} ", testRunInfo); 208 | 209 | logger.debug("testCaseID_testSetNum :{} ", testCaseID); 210 | executionStatusMap.put(testCaseID, testRunInfo); 211 | logger.debug("Execution Status Map :{}", executionStatusMap); 212 | 213 | logger.info("Saved test Start Time :{} ", tcStartTime); 214 | logger.info("End Time :{} ", tcEndTime); 215 | 216 | } 217 | 218 | /************************************************************************************************************************ 219 | * @Date : Mar 28, 2020 220 | * @Author : nachrist 221 | * @Description : Method to close any open browsers 222 | * @Method : closeBrowsers 223 | * @Version : 1.0 224 | * @ReturnType : void / 225 | ***********************************************************************************************************************/ 226 | public void closeBrowsers() { 227 | 228 | if (driver != null) { 229 | driver.quit(); 230 | logger.info("All browser instances are closed"); 231 | } else { 232 | logger.debug("No browser instances are open"); 233 | } 234 | 235 | } 236 | 237 | /************************************************************************************************************************ 238 | * @Date : Mar 28, 2020 239 | * @Author : nachrist 240 | * @Description : 241 | * @Method : testFailureException 242 | * @Version : 1.0 243 | * @param e 244 | * @param methodName 245 | * @ReturnType : void / 246 | ***********************************************************************************************************************/ 247 | public void testFailureException(Exception e) { 248 | 249 | logger.error("Error Log :{} ", e); 250 | 251 | takeScreenshot(); 252 | closeBrowsers(); 253 | extentTest.log(Status.FAIL, e); 254 | Assert.assertTrue(false); 255 | } 256 | 257 | /************************************************************************************************************************ 258 | * @Date : Apr 26, 2020 259 | * @Author : nachrist 260 | * @Description : Method to wait for an element till its visible 261 | * @Method : waitForElement 262 | * @Version : 1.0 263 | * @param driver 264 | * @param by 265 | * @param EXPLICIT_TIMEOUT_SECONDS 266 | * @ReturnType : void / 267 | ***********************************************************************************************************************/ 268 | public void explicitWait(By by) { 269 | 270 | WebDriverWait wait = new WebDriverWait(driver, EXPLICIT_TIMEOUT_SECONDS); 271 | wait.until(ExpectedConditions.visibilityOfElementLocated((by))); 272 | 273 | } 274 | 275 | /************************************************************************************************************************ 276 | * @param result 277 | * @throws IOException 278 | * @Date : Mar 28, 2020 279 | * @Author : nachrist 280 | * @Description : Method to take screenshot during failures 281 | * @Method : takeFailureScreenshot 282 | * @Version : 1.0 283 | * @ReturnType : void / 284 | ***********************************************************************************************************************/ 285 | public void takeScreenshot() { 286 | 287 | String screenshotName; 288 | String screenshotPath; 289 | 290 | screenshotName = methodName + "_" + System.currentTimeMillis() + ".jpg"; 291 | 292 | try { 293 | 294 | TakesScreenshot takeScreenshot = (TakesScreenshot) driver; 295 | File srcFile = takeScreenshot.getScreenshotAs(OutputType.FILE); 296 | logger.debug("Taken Screenshot for Step"); 297 | 298 | File tgtFile = new File(SystemVariables.OUTPUT_FOLDER + "Screenshots" + File.separator, screenshotName); 299 | FileUtils.copyFile(srcFile, tgtFile); 300 | logger.debug("Saved screenshot to results with Name :{} ", screenshotName); 301 | 302 | Reporter.log("

"); 303 | 304 | screenshotPath = SystemVariables.OUTPUT_FOLDER + "Screenshots" + File.separator + screenshotName; 305 | logger.debug("Screenshot Path :{} ", screenshotPath); 306 | 307 | getExtentTest().addScreenCaptureFromPath(screenshotPath); 308 | 309 | } catch (Exception e) { 310 | logger.error("Error in Capturing Screenshot for :{} ", driver.getTitle()); 311 | } 312 | 313 | } 314 | 315 | /************************************************************************************************************************ 316 | * @Date : Jun 20, 2020 317 | * @Author : nachrist 318 | * @Description : Configuration setups for extent report 319 | * @Method : configureExtentReports 320 | * @Version : 1.0 321 | * @ReturnType : void / 322 | ***********************************************************************************************************************/ 323 | public static void configureExtentReports() { 324 | 325 | try { 326 | String outputDirectory = SystemVariables.OUTPUT_FOLDER + "ExtentReport.html"; 327 | 328 | ExtentSparkReporter extentSparkReporter = new ExtentSparkReporter(outputDirectory); 329 | extentSparkReporter.config().setReportName("Extend Report Test"); 330 | extentSparkReporter.config().setDocumentTitle("Test Execution"); 331 | extentSparkReporter.config().enableOfflineMode(false); 332 | extentSparkReporter.config().setTheme(Theme.DARK); 333 | 334 | extentReports = new ExtentReports(); 335 | extentReports.attachReporter(extentSparkReporter); 336 | extentReports.setSystemInfo(SystemVariables.USER_NAME.name(), SystemVariables.USER_NAME.toString()); 337 | extentReports.setSystemInfo(CommonProperties.PropertyEnum.BROWSER_TYPE.name(), 338 | CommonProperties.getBrowserType().toString()); 339 | extentReports.setSystemInfo(SystemVariables.OS_VERSION.name(), SystemVariables.OS_VERSION.toString()); 340 | extentReports.setSystemInfo(SystemVariables.OS_NAME.name(), SystemVariables.OS_NAME.toString()); 341 | 342 | } catch (Exception e) { 343 | logger.error("Error in configuring extent report settings :{} ", e); 344 | } 345 | } 346 | 347 | /************************************************************************************************************************ 348 | * @Date : Jun 27, 2020 349 | * @Author : nachrist 350 | * @Description : Getter setter methods to set driver , test , report , method objects 351 | * @Method : GettersSetters 352 | * @Version : 1.0 353 | * @param method 354 | * @ReturnType : void 355 | /***********************************************************************************************************************/ 356 | 357 | public void setMethodName(String method) { 358 | this.methodName = method; 359 | } 360 | 361 | public void setTestSetNum(Double testSetNum) { 362 | this.testSetNum = testSetNum; 363 | } 364 | 365 | public ExtentTest getExtentTest() { 366 | return extentTest; 367 | } 368 | 369 | public void setExtentTest() { 370 | this.extentTest = extentReports.createTest(methodName + "_" + testSetNum); 371 | } 372 | 373 | public static ExtentReports getExtentReports() { 374 | return extentReports; 375 | } 376 | 377 | public WebDriver getDriver() { 378 | return driver; 379 | } 380 | 381 | public static void setBaseObj(BaseClass baseObj) { 382 | baseClassObj.set(baseObj); 383 | } 384 | 385 | public static BaseClass getBaseObj() { 386 | return baseClassObj.get(); 387 | } 388 | 389 | public static void removeBaseObj() { 390 | baseClassObj.remove(); 391 | } 392 | 393 | } 394 | -------------------------------------------------------------------------------- /src/main/java/com/test/framework/ExcelDataProviderMap.java: -------------------------------------------------------------------------------- 1 | package com.test.framework; 2 | 3 | import java.io.FileInputStream; 4 | import java.io.FileNotFoundException; 5 | import java.io.IOException; 6 | import java.lang.reflect.Method; 7 | import java.util.HashMap; 8 | import java.util.Iterator; 9 | import java.util.LinkedHashMap; 10 | import java.util.Map; 11 | 12 | import org.apache.logging.log4j.LogManager; 13 | import org.apache.logging.log4j.Logger; 14 | import org.apache.poi.ss.usermodel.CellType; 15 | import org.apache.poi.ss.usermodel.Row; 16 | import org.apache.poi.ss.usermodel.Row.MissingCellPolicy; 17 | import org.apache.poi.ss.usermodel.Sheet; 18 | import org.apache.poi.ss.util.NumberToTextConverter; 19 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 20 | import org.testng.annotations.DataProvider; 21 | 22 | import com.test.constants.SystemVariables; 23 | 24 | /************************************************************************************************************************ 25 | * @Date : Apr 2, 2020 26 | * @Author : nachrist 27 | * @Description : Class for extracting data from excel and passing to method as 28 | * data provider using Maps 29 | * @Version : 1.0 30 | ************************************************************************************************************************/ 31 | 32 | public class ExcelDataProviderMap extends BaseClass { 33 | 34 | private static final Logger logger = LogManager.getLogger(ExcelDataProviderMap.class); 35 | 36 | private static String prevTestID = null; 37 | private static double prevTestSet = 0.0; 38 | 39 | /************************************************************************************************************************ 40 | * @throws IOException 41 | * @Date : Apr 4, 2020 42 | * @Author : nachrist 43 | * @Description : Method to fetch data from excel to single LinkedHashMap object 44 | * @Method : excelDataProviderClass 45 | * @Version : 1.0 46 | * @ReturnType : void / 47 | ***********************************************************************************************************************/ 48 | 49 | public static void fetchExcelDataProviderMap(String suiteName) throws IOException { 50 | 51 | try ( 52 | 53 | FileInputStream fileIn = new FileInputStream(SystemVariables.TEST_RESOURCES + "TestData.xlsx"); 54 | 55 | XSSFWorkbook workBook = new XSSFWorkbook(fileIn);) { 56 | 57 | logger.info("Data Load From Excel Started"); 58 | 59 | workBook.setMissingCellPolicy(MissingCellPolicy.CREATE_NULL_AS_BLANK); 60 | 61 | for (Sheet sheet : workBook) { 62 | 63 | logger.debug("Sheet Name :{}", sheet.getSheetName()); 64 | logger.debug("Sheet Name :{}", suiteName); 65 | 66 | if (suiteName.contains(sheet.getSheetName())) { 67 | 68 | loadSheetData(sheet); 69 | 70 | } 71 | 72 | } 73 | 74 | linkedMap.put(prevTestSet, dataMap); 75 | logger.debug("Linked Map Update Last:{} ", linkedMap); 76 | nestedMap.put(prevTestID, linkedMap); 77 | logger.debug("Previous Test ID :{} ", prevTestID); 78 | logger.debug("LinkedMap :{} ", linkedMap); 79 | logger.debug("Nested Map :{} ", nestedMap); 80 | 81 | logger.info("Data Load From Excel Completed"); 82 | } 83 | 84 | catch (FileNotFoundException e) { 85 | logger.error("File not found :{}", e); 86 | } catch (Exception e) { 87 | logger.error("Data Load Error :{}", e); 88 | 89 | } 90 | } 91 | 92 | /************************************************************************************************************************ 93 | * @Date : Apr 24, 2020 94 | * @Author : nachrist 95 | * @Description : To load all sheet data 96 | * @Method : loadSheetData 97 | * @Version : 1.0 98 | * @ReturnType : void / 99 | ***********************************************************************************************************************/ 100 | public static void loadSheetData(Sheet sheet) { 101 | 102 | double testSet; 103 | String testID = null; 104 | String attribute = null; 105 | String value = null; 106 | 107 | Iterator rows = sheet.rowIterator(); 108 | 109 | rows.next(); 110 | 111 | while (rows.hasNext()) { 112 | 113 | Row row = rows.next(); 114 | testID = row.getCell(0).getStringCellValue(); 115 | testSet = row.getCell(1).getNumericCellValue(); 116 | attribute = row.getCell(2).getStringCellValue(); 117 | 118 | if (row.getCell(3).getCellType() == CellType.STRING) { 119 | value = row.getCell(3).getStringCellValue(); 120 | } else if (row.getCell(3).getCellType() == CellType.NUMERIC) { 121 | value = NumberToTextConverter.toText(row.getCell(3).getNumericCellValue()); 122 | } 123 | 124 | logger.debug("Test ID in Data Sheet :{} ", testID); 125 | logger.debug("Test Set No. :{} ", testSet); 126 | logger.debug("Test Attribute :{} ", attribute); 127 | 128 | logger.debug("Previous Test ID :{}", prevTestID); 129 | if ((prevTestID == null || testID.equals(prevTestID))) { 130 | prevTestID = testID; 131 | logger.debug("Previous Test Set :{} ", prevTestSet); 132 | 133 | if (prevTestSet == 0.0 || testSet == prevTestSet) { 134 | dataMap.put(attribute, value); 135 | logger.debug("List :{}", dataMap); 136 | 137 | prevTestSet = testSet; 138 | 139 | } else if (testSet != prevTestSet) { 140 | 141 | linkedMap.put(prevTestSet, dataMap); 142 | logger.debug("Linked Map :{}", linkedMap); 143 | 144 | prevTestSet = testSet; 145 | dataMap = new LinkedHashMap(); 146 | dataMap.put(attribute, value); 147 | logger.debug("List :{} ", dataMap); 148 | 149 | } 150 | logger.debug("Previous TestSet :{}", prevTestSet); 151 | 152 | } else if (!testID.equals(prevTestID) && testSet != 0.0) { 153 | 154 | linkedMap.put(prevTestSet, dataMap); 155 | logger.debug("Linked Map in Else If:{} ", linkedMap); 156 | 157 | linkedMap.remove(0.0); 158 | 159 | nestedMap.put(prevTestID, linkedMap); 160 | logger.debug("Previous Test ID :{}", prevTestID); 161 | logger.debug(" LinkedMap :{} ", linkedMap); 162 | logger.debug("Nested Map :{} ", nestedMap); 163 | 164 | prevTestID = testID; 165 | prevTestSet = testSet; 166 | 167 | dataMap = new HashMap(); 168 | linkedMap = new LinkedHashMap>(); 169 | dataMap.put(attribute, value); 170 | logger.debug("List :{} ", dataMap); 171 | 172 | } 173 | logger.debug("Previous Test ID :{} ", prevTestID); 174 | 175 | } 176 | 177 | } 178 | 179 | /************************************************************************************************************************ 180 | * @Date : Apr 4, 2020 181 | * @Author : nachrist 182 | * @Description : Data provider method which uses the data hash map to iterate 183 | * through the data sets 184 | * @Method : dataProviderMethod 185 | * @Version : 1.0 186 | * @param m 187 | * @return 188 | * @throws IOException 189 | * @ReturnType : Object[][] / 190 | ***********************************************************************************************************************/ 191 | @DataProvider(name = "Excel Map Provider", parallel = true) 192 | public Object[][] dataProviderMethod(Method m) { 193 | 194 | int testSetNum; 195 | int j = 0; 196 | String methodName = null; 197 | Object[][] testData = null; 198 | LinkedHashMap> testDataMap; 199 | 200 | try { 201 | 202 | methodName = m.getName(); 203 | logger.debug("Method Name :{} ", methodName); 204 | testDataMap = nestedMap.get(methodName); 205 | logger.debug("Test Data Map :{}", testDataMap); 206 | 207 | testSetNum = testDataMap.size(); 208 | logger.debug("Test Set Count :{} ", testSetNum); 209 | 210 | testData = new Object[testSetNum][1]; 211 | 212 | for (Map.Entry> entry : testDataMap.entrySet()) { 213 | 214 | logger.debug("Test Set Num :{} ", entry.getKey()); 215 | testData[j][0] = testDataMap.get(entry.getKey()); 216 | logger.debug("Test Parameter :{} ", testDataMap.get(entry.getKey())); 217 | 218 | j++; 219 | 220 | } 221 | 222 | } catch (Exception e) { 223 | testFailureException(e); 224 | } 225 | return testData; 226 | 227 | } 228 | } 229 | -------------------------------------------------------------------------------- /src/main/java/com/test/framework/ExcelResultUpdate.java: -------------------------------------------------------------------------------- 1 | package com.test.framework; 2 | 3 | import java.io.FileInputStream; 4 | import java.io.FileOutputStream; 5 | import java.io.IOException; 6 | import java.text.DateFormat; 7 | import java.text.SimpleDateFormat; 8 | import java.util.Date; 9 | import java.util.Iterator; 10 | 11 | import org.apache.logging.log4j.LogManager; 12 | import org.apache.logging.log4j.Logger; 13 | import org.apache.poi.ss.usermodel.Cell; 14 | import org.apache.poi.ss.usermodel.Row; 15 | import org.apache.poi.ss.usermodel.Row.MissingCellPolicy; 16 | import org.apache.poi.ss.usermodel.Sheet; 17 | import org.apache.poi.xssf.usermodel.XSSFWorkbook; 18 | 19 | import com.test.constants.SystemVariables; 20 | 21 | public class ExcelResultUpdate extends BaseClass { 22 | 23 | private static final Logger logger = LogManager.getLogger(ExcelResultUpdate.class); 24 | 25 | /************************************************************************************************************************ 26 | * @Date : Apr 24, 2020 27 | * @Author : nachrist 28 | * @Description : Method to update test result to excel 29 | * @Method : excelDataUpdate 30 | * @Version : 1.0 31 | * @throws IOException 32 | * @ReturnType : void / 33 | ***********************************************************************************************************************/ 34 | public static void excelDataUpdate(String suiteName) throws IOException { 35 | 36 | try ( 37 | 38 | FileInputStream fileIn = new FileInputStream(SystemVariables.TEST_RESOURCES + "TestData.xlsx"); 39 | 40 | XSSFWorkbook workBook = new XSSFWorkbook(fileIn); 41 | 42 | FileOutputStream fileOut = new FileOutputStream(SystemVariables.TEST_RESOURCES + "TestData.xlsx"); 43 | 44 | ) { 45 | 46 | workBook.setMissingCellPolicy(MissingCellPolicy.CREATE_NULL_AS_BLANK); 47 | 48 | for (Sheet sheet : workBook) { 49 | 50 | logger.debug("Sheet Name :{}", sheet.getSheetName()); 51 | 52 | if (suiteName.contains(sheet.getSheetName())) { 53 | updateSheetData(sheet); 54 | } 55 | 56 | } 57 | 58 | workBook.write(fileOut); 59 | logger.debug("Updated to Work Book"); 60 | 61 | } catch (Exception e) { 62 | logger.error("Excel Data Update Error :{}", e); 63 | } 64 | 65 | } 66 | 67 | /************************************************************************************************************************ 68 | * @Date : Apr 24, 2020 69 | * @Author : nachrist 70 | * @Description : Method to update sheet data 71 | * @Method : updateSheetData 72 | * @Version : 1.0 73 | * @param sheet 74 | * @ReturnType : void / 75 | ***********************************************************************************************************************/ 76 | public static void updateSheetData(Sheet sheet) { 77 | 78 | String testCaseID = null; 79 | double testRunStatus; 80 | double testSetID; 81 | long tcStartTime; 82 | long tcEndTime; 83 | 84 | Cell cell; 85 | 86 | DateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy HH:mm:ss"); 87 | 88 | Iterator rows = sheet.rowIterator(); 89 | 90 | rows.next(); 91 | 92 | while (rows.hasNext()) { 93 | 94 | Row row = rows.next(); 95 | 96 | testCaseID = row.getCell(0).getStringCellValue(); 97 | logger.debug("Test Case ID :{} ", testCaseID); 98 | 99 | testSetID = row.getCell(1).getNumericCellValue(); 100 | if (testSetID == 0.0) { 101 | testSetID = 1.0; 102 | } 103 | logger.debug("Test Set ID :{} ", testSetID); 104 | 105 | StringBuilder bld = new StringBuilder(); 106 | bld.append(testCaseID); 107 | bld.append("_"); 108 | bld.append(testSetID); 109 | 110 | testCaseID = bld.toString(); 111 | 112 | if (executionStatusMap.get(testCaseID) != null) { 113 | 114 | tcStartTime = executionStatusMap.get(testCaseID).get(0); 115 | logger.debug("Test Start Time :{} ", tcStartTime); 116 | cell = row.getCell(5); 117 | cell.setCellValue(dateFormat.format((new Date(tcStartTime)))); 118 | logger.debug("Test Start Time Updated as :{} ", tcStartTime); 119 | 120 | tcEndTime = executionStatusMap.get(testCaseID).get(1); 121 | logger.debug("Test End Time :{} ", tcEndTime); 122 | cell = row.getCell(6); 123 | cell.setCellValue(dateFormat.format((new Date(tcEndTime)))); 124 | logger.debug("Test End Time Updated as :{} ", tcEndTime); 125 | 126 | testRunStatus = executionStatusMap.get(testCaseID).get(2); 127 | logger.debug("Test run Status :{} ", testRunStatus); 128 | cell = row.getCell(7); 129 | if (testRunStatus == 1.0) { 130 | cell.setCellValue("PASSED"); 131 | } else { 132 | cell.setCellValue("FAILED"); 133 | } 134 | logger.debug("Test Run Status Updated as :{} ", testRunStatus); 135 | } 136 | } 137 | 138 | } 139 | 140 | } 141 | -------------------------------------------------------------------------------- /src/main/java/com/test/framework/UtilityClass.java: -------------------------------------------------------------------------------- 1 | package com.test.framework; 2 | 3 | import org.apache.logging.log4j.LogManager; 4 | import org.apache.logging.log4j.Logger; 5 | import org.openqa.selenium.By; 6 | import org.openqa.selenium.Keys; 7 | import org.openqa.selenium.WebDriver; 8 | import org.openqa.selenium.WebElement; 9 | 10 | /************************************************************************************************************************ 11 | * @Date : Jun 21, 2020 12 | * @Author : nachrist 13 | * @Description : Class to maintain utility functions used for POM 14 | * @Version : 1.0 15 | ************************************************************************************************************************/ 16 | public class UtilityClass { 17 | 18 | private WebDriver driver; 19 | private BaseClass baseLocalObj; 20 | 21 | private static final Logger logger = LogManager.getLogger(UtilityClass.class); 22 | 23 | /************************************************************************************************************************ 24 | * @Date : Mar 28, 2020 25 | * @Author : nachrist 26 | * @Description : Method to click on given Link 27 | * @Method : clickLink 28 | * @Version : 1.0 29 | * @param driver 30 | * @param by 31 | * @param buttonName 32 | * @param EXPLICIT_TIMEOUT_SECONDS 33 | * @ReturnType : void / 34 | ***********************************************************************************************************************/ 35 | public void clickLink(By by) { 36 | 37 | baseLocalObj = BaseClass.getBaseObj(); 38 | 39 | try { 40 | driver = baseLocalObj.getDriver(); 41 | 42 | baseLocalObj.explicitWait(by); 43 | 44 | driver.findElement(by).click(); 45 | logger.debug("Page Title :{}", driver.getTitle()); 46 | } catch (Exception e) { 47 | baseLocalObj.testFailureException(e); 48 | } 49 | 50 | } 51 | 52 | /************************************************************************************************************************ 53 | * @Date : Apr 4, 2020 54 | * @Author : nachrist 55 | * @Description : Method to enter text to a text field 56 | * @Method : textField 57 | * @Version : 1.0 58 | * @param driver 59 | * @param by 60 | * @param buttonName 61 | * @param sendKeys 62 | * @param EXPLICIT_TIMEOUT_SECONDS 63 | * @ReturnType : void / 64 | ***********************************************************************************************************************/ 65 | public void textField(By by, String sendKeys) { 66 | 67 | try { 68 | baseLocalObj = BaseClass.getBaseObj(); 69 | driver = baseLocalObj.getDriver(); 70 | 71 | baseLocalObj.explicitWait(by); 72 | 73 | driver.findElement(by).sendKeys(sendKeys); 74 | logger.debug("Page Title :{} ", driver.getTitle()); 75 | logger.debug("Inserted Text :{} ", driver.findElement(by).getAttribute("value")); 76 | } catch (Exception e) { 77 | baseLocalObj.testFailureException(e); 78 | } 79 | 80 | } 81 | 82 | /************************************************************************************************************************ 83 | * @Date : Apr 26, 2020 84 | * @Author : nachrist 85 | * @Description : Method to select from suggestive dropdown 86 | * @Method : suggestiveDropdDown 87 | * @Version : 1.0 88 | * @param by 89 | * @param sendKeys 90 | * @param fieldName 91 | * @param selection 92 | * @param EXPLICIT_TIMEOUT_SECONDS 93 | * @throws InterruptedException 94 | * @ReturnType : void / 95 | ***********************************************************************************************************************/ 96 | 97 | public void suggestiveDropdDown(By by, String sendKeys, String selection) throws InterruptedException { 98 | 99 | baseLocalObj = BaseClass.getBaseObj(); 100 | 101 | try { 102 | driver = baseLocalObj.getDriver(); 103 | 104 | int selectionNum = Integer.parseInt(selection); 105 | WebElement element = driver.findElement(by); 106 | 107 | baseLocalObj.explicitWait(by); 108 | 109 | element.clear(); 110 | element.sendKeys(sendKeys); 111 | logger.debug("Entered text :{} ", sendKeys); 112 | 113 | if (selectionNum > 1) { 114 | for (int i = 0; i < selectionNum; i++) { 115 | Thread.sleep(500); 116 | element.sendKeys(Keys.ARROW_DOWN); 117 | } 118 | } 119 | 120 | Thread.sleep(500); 121 | element.sendKeys(Keys.ENTER); 122 | logger.info("Selected Value :{}", element.getAttribute("value")); 123 | } catch (Exception e) { 124 | baseLocalObj.testFailureException(e); 125 | } 126 | 127 | } 128 | 129 | } 130 | -------------------------------------------------------------------------------- /src/main/java/com/test/listeners/AnnotationTransformer.java: -------------------------------------------------------------------------------- 1 | package com.test.listeners; 2 | 3 | import java.lang.reflect.Constructor; 4 | import java.lang.reflect.Method; 5 | 6 | import org.testng.IAnnotationTransformer; 7 | import org.testng.annotations.ITestAnnotation; 8 | 9 | import com.test.framework.ExcelDataProviderMap; 10 | 11 | /************************************************************************************************************************ 12 | * @Date : Jun 20, 2020 13 | * @Author : nachrist 14 | * @Description : Annotation transformer to call iRetryAnalyzer for each @Test 15 | * @Version : 1.0 16 | ************************************************************************************************************************/ 17 | public class AnnotationTransformer implements IAnnotationTransformer { 18 | 19 | @Override 20 | public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) { 21 | annotation.setRetryAnalyzer(FailureRetryListener.class); 22 | annotation.setDataProviderClass(ExcelDataProviderMap.class); 23 | annotation.setDataProvider("Excel Map Provider"); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/test/listeners/FailureRetryListener.java: -------------------------------------------------------------------------------- 1 | package com.test.listeners; 2 | 3 | import org.testng.IRetryAnalyzer; 4 | import org.testng.ITestResult; 5 | 6 | /************************************************************************************************************************ 7 | * @Date : Jun 20, 2020 8 | * @Author : nachrist 9 | * @Description : IRetryAnalyzer implementation for automatic failed test case 10 | * reruns 11 | * @Version : 1.0 12 | ************************************************************************************************************************/ 13 | public class FailureRetryListener implements IRetryAnalyzer { 14 | 15 | int rerunCounter = 1; 16 | 17 | @Override 18 | public boolean retry(ITestResult result) { 19 | 20 | if (!result.isSuccess() && rerunCounter <= 1) { 21 | rerunCounter++; 22 | return true; 23 | } else { 24 | return false; 25 | } 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/test/listeners/TestNGListener.java: -------------------------------------------------------------------------------- 1 | package com.test.listeners; 2 | 3 | import org.apache.logging.log4j.LogManager; 4 | import org.apache.logging.log4j.Logger; 5 | import org.testng.ITestContext; 6 | import org.testng.ITestListener; 7 | import org.testng.ITestResult; 8 | import org.testng.internal.TestResult; 9 | 10 | import com.aventstack.extentreports.Status; 11 | 12 | import com.test.framework.BaseClass; 13 | 14 | public class TestNGListener implements ITestListener { 15 | 16 | private static final Logger logger = LogManager.getLogger(TestNGListener.class); 17 | 18 | @Override 19 | public void onTestStart(ITestResult result) { 20 | 21 | String methodName; 22 | Double testSetNumber; 23 | 24 | logger.debug("On Test Start"); 25 | 26 | try { 27 | methodName = result.getMethod().getMethodName(); 28 | logger.debug("Test Name : {}", methodName); 29 | 30 | testSetNumber = ((TestResult) result).getParameterIndex() + 1.0; 31 | 32 | BaseClass baseClass = new BaseClass(); 33 | BaseClass.setBaseObj(baseClass); 34 | 35 | BaseClass.getBaseObj().setMethodName(methodName); 36 | BaseClass.getBaseObj().setTestSetNum(testSetNumber); 37 | 38 | BaseClass.getBaseObj().setExtentTest(); 39 | 40 | BaseClass.getBaseObj().browserSelection(); 41 | BaseClass.getBaseObj().fetchUrl(); 42 | 43 | } catch (Exception e) { 44 | logger.debug("Error in Test Start :{}", e); 45 | } 46 | 47 | } 48 | 49 | @Override 50 | public void onTestSuccess(ITestResult result) { 51 | 52 | logger.debug("On Test Success"); 53 | 54 | try { 55 | BaseClass.getBaseObj().closeBrowsers(); 56 | BaseClass.getBaseObj().saveTestRunDetails(result); 57 | BaseClass.getBaseObj().getExtentTest().log(Status.PASS, "PASSED"); 58 | 59 | } catch (Exception e) { 60 | logger.debug("Error in capturing test success details :{}", e); 61 | } 62 | 63 | } 64 | 65 | @Override 66 | public void onTestFailure(ITestResult result) { 67 | 68 | logger.debug("On Test Failure"); 69 | 70 | try { 71 | BaseClass.getBaseObj().saveTestRunDetails(result); 72 | } catch (Exception e) { 73 | 74 | logger.error("Error in capturing test failure details :{} ", e); 75 | } 76 | 77 | } 78 | 79 | @Override 80 | public void onTestSkipped(ITestResult result) { 81 | 82 | logger.debug("On Test Skip"); 83 | 84 | try { 85 | BaseClass.getBaseObj().saveTestRunDetails(result); 86 | BaseClass.getBaseObj().getExtentTest().log(Status.SKIP, "SKIPPED"); 87 | } catch (Exception e) { 88 | logger.error("Error in capturing test skip details :{} ", e); 89 | } 90 | 91 | } 92 | 93 | @Override 94 | public void onStart(ITestContext context) { 95 | 96 | logger.debug("On Start"); 97 | 98 | try { 99 | BaseClass.configureExtentReports(); 100 | } catch (Exception e) { 101 | logger.error("Error in On Start method :{} ", e); 102 | } 103 | } 104 | 105 | @Override 106 | public void onFinish(ITestContext context) { 107 | 108 | logger.debug("On Finish"); 109 | 110 | try { 111 | BaseClass.getExtentReports().flush(); 112 | BaseClass.removeBaseObj(); 113 | } catch (Exception e) { 114 | logger.error("Error in generating final extent report :{} ", e); 115 | } 116 | 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/main/java/com/test/listeners/TestSuiteListener.java: -------------------------------------------------------------------------------- 1 | package com.test.listeners; 2 | 3 | import java.io.IOException; 4 | 5 | import org.apache.logging.log4j.LogManager; 6 | import org.apache.logging.log4j.Logger; 7 | import org.testng.ISuite; 8 | import org.testng.ISuiteListener; 9 | import org.testng.xml.XmlDefine; 10 | import org.testng.xml.XmlGroups; 11 | import org.testng.xml.XmlRun; 12 | 13 | import com.test.constants.CommonProperties; 14 | import com.test.framework.ExcelDataProviderMap; 15 | import com.test.framework.ExcelResultUpdate; 16 | 17 | /************************************************************************************************************************ 18 | * @Date : Jun 20, 2020 19 | * @Author : nachrist 20 | * @Description : Implementation for ISuiteListener to set XML configurations 21 | * and load property values 22 | * @Version : 1.0 23 | ************************************************************************************************************************/ 24 | public class TestSuiteListener implements ISuiteListener { 25 | 26 | private static final Logger logger = LogManager.getLogger(TestSuiteListener.class); 27 | 28 | @Override 29 | public void onStart(ISuite suite) { 30 | 31 | logger.debug("On Suite Start"); 32 | 33 | try { 34 | CommonProperties.loadProperties(); 35 | ExcelDataProviderMap.fetchExcelDataProviderMap(suite.getName()); 36 | setXmlValues(suite); 37 | } catch (Exception e) { 38 | logger.error("Error in Suite Start Block :{}", e); 39 | } 40 | 41 | } 42 | 43 | @Override 44 | public void onFinish(ISuite suite) { 45 | 46 | logger.debug("On Suite Finish"); 47 | 48 | try { 49 | ExcelResultUpdate.excelDataUpdate(suite.getName()); 50 | } catch (IOException e) { 51 | logger.error("Error in Suite Finish Block :{}", e); 52 | } 53 | 54 | } 55 | 56 | /************************************************************************************************************************ 57 | * @Date : Apr 25, 2020 58 | * @Author : nachrist 59 | * @Description : Method to setXml properties 60 | * @Method : setXmlValues 61 | * @Version : 1.0 62 | * @param suite 63 | * @ReturnType : void / 64 | ***********************************************************************************************************************/ 65 | public void setXmlValues(ISuite suite) { 66 | 67 | try { 68 | suite.getXmlSuite().setParallel(CommonProperties.getParallelRun()); 69 | logger.debug("Parallel Run Type :{} ", suite.getXmlSuite().getParallel()); 70 | 71 | suite.getXmlSuite().setThreadCount(CommonProperties.getThreadCount()); 72 | logger.debug("Parallel Thread Count :{} ", suite.getXmlSuite().getThreadCount()); 73 | 74 | suite.getXmlSuite().setDataProviderThreadCount(CommonProperties.getDataproviderThread()); 75 | logger.debug("Data Provider Thread Count :{} ", suite.getXmlSuite().getDataProviderThreadCount()); 76 | 77 | } catch (Exception e) { 78 | logger.error("Error in setting Suite XML properties :{}", e); 79 | } 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/com/test/listeners/WebDriverListener.java: -------------------------------------------------------------------------------- 1 | package com.test.listeners; 2 | 3 | import org.apache.logging.log4j.LogManager; 4 | import org.apache.logging.log4j.Logger; 5 | import org.openqa.selenium.By; 6 | import org.openqa.selenium.OutputType; 7 | import org.openqa.selenium.WebDriver; 8 | import org.openqa.selenium.WebElement; 9 | import org.openqa.selenium.support.events.WebDriverEventListener; 10 | 11 | import com.test.framework.BaseClass; 12 | 13 | public class WebDriverListener implements WebDriverEventListener { 14 | 15 | private static final Logger logger = LogManager.getLogger(WebDriverListener.class); 16 | 17 | @Override 18 | public void beforeAlertAccept(WebDriver driver) { 19 | logger.trace("Before Accepting Alert"); 20 | BaseClass.getBaseObj().takeScreenshot(); 21 | } 22 | 23 | @Override 24 | public void afterAlertAccept(WebDriver driver) { 25 | logger.trace("After Accepting Alert"); 26 | BaseClass.getBaseObj().takeScreenshot(); 27 | } 28 | 29 | @Override 30 | public void afterAlertDismiss(WebDriver driver) { 31 | logger.trace("After Dismissing Alert"); 32 | BaseClass.getBaseObj().takeScreenshot(); 33 | } 34 | 35 | @Override 36 | public void beforeAlertDismiss(WebDriver driver) { 37 | logger.trace("Before Dismissing Alert"); 38 | BaseClass.getBaseObj().takeScreenshot(); 39 | } 40 | 41 | @Override 42 | public void beforeNavigateTo(String url, WebDriver driver) { 43 | logger.trace("Before Navigating to : {}", url); 44 | } 45 | 46 | @Override 47 | public void afterNavigateTo(String url, WebDriver driver) { 48 | logger.trace("After Navigating to : {}", url); 49 | BaseClass.getBaseObj().takeScreenshot(); 50 | } 51 | 52 | @Override 53 | public void beforeNavigateBack(WebDriver driver) { 54 | logger.trace("Before Navigating Back"); 55 | BaseClass.getBaseObj().takeScreenshot(); 56 | } 57 | 58 | @Override 59 | public void afterNavigateBack(WebDriver driver) { 60 | logger.trace("After Navigating Back"); 61 | BaseClass.getBaseObj().takeScreenshot(); 62 | } 63 | 64 | @Override 65 | public void beforeNavigateForward(WebDriver driver) { 66 | logger.trace("Before Navigating Forward"); 67 | BaseClass.getBaseObj().takeScreenshot(); 68 | } 69 | 70 | @Override 71 | public void afterNavigateForward(WebDriver driver) { 72 | logger.trace("After Navigating Forward"); 73 | BaseClass.getBaseObj().takeScreenshot(); 74 | } 75 | 76 | @Override 77 | public void beforeNavigateRefresh(WebDriver driver) { 78 | logger.trace("Before Navigating and Refreshing"); 79 | BaseClass.getBaseObj().takeScreenshot(); 80 | } 81 | 82 | @Override 83 | public void afterNavigateRefresh(WebDriver driver) { 84 | logger.trace("After Navigating and Refreshing"); 85 | BaseClass.getBaseObj().takeScreenshot(); 86 | } 87 | 88 | @Override 89 | public void beforeFindBy(By by, WebElement element, WebDriver driver) { 90 | logger.trace("Before finding element"); 91 | BaseClass.getBaseObj().takeScreenshot(); 92 | } 93 | 94 | @Override 95 | public void afterFindBy(By by, WebElement element, WebDriver driver) { 96 | logger.trace("After finding element"); 97 | BaseClass.getBaseObj().takeScreenshot(); 98 | } 99 | 100 | @Override 101 | public void beforeClickOn(WebElement element, WebDriver driver) { 102 | logger.trace("Before clicking element "); 103 | BaseClass.getBaseObj().takeScreenshot(); 104 | } 105 | 106 | @Override 107 | public void afterClickOn(WebElement element, WebDriver driver) { 108 | logger.trace("After clicking element "); 109 | BaseClass.getBaseObj().takeScreenshot(); 110 | 111 | } 112 | 113 | @Override 114 | public void beforeChangeValueOf(WebElement element, WebDriver driver, CharSequence[] keysToSend) { 115 | logger.trace("Before changing value of element "); 116 | BaseClass.getBaseObj().takeScreenshot(); 117 | } 118 | 119 | @Override 120 | public void afterChangeValueOf(WebElement element, WebDriver driver, CharSequence[] keysToSend) { 121 | logger.trace("After changing value of element "); 122 | BaseClass.getBaseObj().takeScreenshot(); 123 | } 124 | 125 | @Override 126 | public void beforeScript(String script, WebDriver driver) { 127 | logger.trace("Before executing script : {}", script); 128 | BaseClass.getBaseObj().takeScreenshot(); 129 | } 130 | 131 | @Override 132 | public void afterScript(String script, WebDriver driver) { 133 | logger.trace("After executing script : {}", script); 134 | BaseClass.getBaseObj().takeScreenshot(); 135 | } 136 | 137 | @Override 138 | public void beforeSwitchToWindow(String windowName, WebDriver driver) { 139 | logger.trace("Before swtiching to window : {}", windowName); 140 | BaseClass.getBaseObj().takeScreenshot(); 141 | } 142 | 143 | @Override 144 | public void afterSwitchToWindow(String windowName, WebDriver driver) { 145 | logger.trace("After swtiching to window : {}", windowName); 146 | BaseClass.getBaseObj().takeScreenshot(); 147 | } 148 | 149 | @Override 150 | public void onException(Throwable throwable, WebDriver driver) { 151 | logger.trace("Exception in WebDriver Listener"); 152 | } 153 | 154 | @Override 155 | public void beforeGetScreenshotAs(OutputType target) { 156 | logger.trace("Before getting screenshot"); 157 | } 158 | 159 | @Override 160 | public void afterGetScreenshotAs(OutputType target, X screenshot) { 161 | logger.trace("After getting screenshot"); 162 | } 163 | 164 | @Override 165 | public void beforeGetText(WebElement element, WebDriver driver) { 166 | logger.trace("Before getting value of element "); 167 | BaseClass.getBaseObj().takeScreenshot(); 168 | } 169 | 170 | @Override 171 | public void afterGetText(WebElement element, WebDriver driver, String text) { 172 | logger.trace("After getting value of element "); 173 | BaseClass.getBaseObj().takeScreenshot(); 174 | } 175 | 176 | } 177 | -------------------------------------------------------------------------------- /src/main/java/com/test/pageobjects/GoogleHomePage.java: -------------------------------------------------------------------------------- 1 | package com.test.pageobjects; 2 | 3 | import java.util.Map; 4 | 5 | import org.openqa.selenium.By; 6 | 7 | import com.test.framework.UtilityClass; 8 | 9 | /************************************************************************************************************************ 10 | * @Date : Mar 28, 2020 11 | * @Author : nachrist 12 | * @Description : Page object class for GoogleHomePage 13 | * @Version : 1.0 14 | ************************************************************************************************************************/ 15 | public class GoogleHomePage extends UtilityClass { 16 | 17 | private Map map; 18 | 19 | public GoogleHomePage(Map map) { 20 | this.map = map; 21 | } 22 | 23 | By searchTextBox = By.cssSelector("[type='text']"); 24 | 25 | public void searchTextBox() { 26 | textField(searchTextBox, map.get("From Location")); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/test/pageobjects/RahulShettyAcademy.java: -------------------------------------------------------------------------------- 1 | package com.test.pageobjects; 2 | 3 | import org.openqa.selenium.By; 4 | 5 | import com.test.framework.UtilityClass; 6 | 7 | /************************************************************************************************************************ 8 | * @Date : Mar 28, 2020 9 | * @Author : nachrist 10 | * @Description : Page object class for RahulShettyAcademy 11 | * @Version : 1.0 12 | ************************************************************************************************************************/ 13 | public class RahulShettyAcademy extends UtilityClass { 14 | 15 | By courseLink = By.linkText("Course"); 16 | By mentorshipLink = By.linkText("Mentorshi"); 17 | 18 | public void courseLink() { 19 | clickLink(courseLink); 20 | } 21 | 22 | public void mentorshipLink() { 23 | clickLink(mentorshipLink); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/test/pageobjects/RahulShettyPractice.java: -------------------------------------------------------------------------------- 1 | package com.test.pageobjects; 2 | 3 | import java.util.Map; 4 | 5 | import org.openqa.selenium.By; 6 | 7 | import com.test.framework.UtilityClass; 8 | 9 | /************************************************************************************************************************ 10 | * @Date : Apr 25, 2020 11 | * @Author : nachrist 12 | * @Description : Rahul sheety practice page for selenium 13 | * @Version : 1.0 14 | ************************************************************************************************************************/ 15 | public class RahulShettyPractice extends UtilityClass { 16 | 17 | private Map map; 18 | 19 | By suggDropDown = By.xpath("//*[@id='autocomplete']"); 20 | 21 | public RahulShettyPractice(Map map) { 22 | this.map = map; 23 | } 24 | 25 | public void clickRadioButton(int buttonNum) { 26 | clickLink(By.cssSelector("[value='radio" + buttonNum + "']")); 27 | } 28 | 29 | public void selectDropDownValue() { 30 | // TODO Auto-generated method stub 31 | 32 | } 33 | 34 | public void selectCheckBoxValue() { 35 | // TODO Auto-generated method stub 36 | 37 | } 38 | 39 | public void mouseHoverSelection() { 40 | // TODO Auto-generated method stub 41 | 42 | } 43 | 44 | public void checkHiddenElement() { 45 | // TODO Auto-generated method stub 46 | 47 | } 48 | 49 | public void switchWindowCheck() { 50 | // TODO Auto-generated method stub 51 | 52 | } 53 | 54 | public void switchTabCheck() { 55 | // TODO Auto-generated method stub 56 | 57 | } 58 | 59 | public void fetchTableData() { 60 | // TODO Auto-generated method stub 61 | 62 | } 63 | 64 | public void checkiFrame() { 65 | // TODO Auto-generated method stub 66 | 67 | } 68 | 69 | public void javascriptCheck() { 70 | // TODO Auto-generated method stub 71 | 72 | } 73 | 74 | public void selectSuggestiveDropDown() throws InterruptedException { 75 | suggestiveDropdDown(suggDropDown, map.get("countryCode"), map.get("countrySelectionNum")); 76 | 77 | } 78 | 79 | public void enterText() { 80 | // TODO Auto-generated method stub 81 | 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/resources/configuration.properties: -------------------------------------------------------------------------------- 1 | # Properties file to pass common test parameters 2 | 3 | # Browser to be selected for current run 4 | browserType=Chrome 5 | 6 | # Parallel mode for testNG run 7 | parallelRun=Methods 8 | 9 | # Number of parallel threads 10 | threadCount=2 11 | 12 | # Number of data provider parallel threads 13 | dataproviderThread=2 14 | 15 | # To execute tests in headless mode 16 | headlessMode=True 17 | 18 | # To take screenshots for each pass/fail steps 19 | takePassScreenshot=True 20 | 21 | # Common Url's considered for test cases 22 | failTestUrl=https://www.rahulshettyacademy.com/#/index 23 | googleUrl=https://google.com 24 | practiceUrl=https://www.rahulshettyacademy.com/AutomationPractice/ -------------------------------------------------------------------------------- /src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/test/java/com/test/api/GooglePlaceUpdateQA.java: -------------------------------------------------------------------------------- 1 | package com.test.api; 2 | 3 | import static io.restassured.RestAssured.*; 4 | import static org.hamcrest.Matchers.*; 5 | 6 | import org.apache.logging.log4j.LogManager; 7 | import org.apache.logging.log4j.Logger; 8 | import org.testng.annotations.Test; 9 | 10 | import com.test.gui.PassFailTest; 11 | 12 | import io.restassured.RestAssured; 13 | import io.restassured.path.json.JsonPath; 14 | 15 | /************************************************************************************************************************ 16 | * @Date : Jun 1, 2020 17 | * @Author : nachrist 18 | * @Description : Test method to add a new location , update details , fetch and 19 | * verify updated value and response. 20 | * @Version : 1.0 21 | ************************************************************************************************************************/ 22 | public class GooglePlaceUpdateQA { 23 | 24 | private static final Logger logger = LogManager.getLogger(PassFailTest.class); 25 | 26 | /************************************************************************************************************************ 27 | * @Date : Jun 1, 2020 28 | * @Author : nachrist 29 | * @Description : Fetch location 30 | * @Method : locationUpdate 31 | * @Version : 1.0 32 | * @ReturnType : void / 33 | ***********************************************************************************************************************/ 34 | @Test 35 | public void locationUpdate() { 36 | 37 | RestAssured.baseURI = "https://rahulshettyacademy.com"; 38 | String body = "{\r\n" + " \"location\": {\r\n" + " \"lat\": -38.383494,\r\n" + " \"lng\": 33.427362\r\n" 39 | + " },\r\n" + " \"accuracy\": 50,\r\n" + " \"name\": \"Rahul Shetty Academy\",\r\n" 40 | + " \"phone_number\": \"(+91) 983 893 3937\",\r\n" 41 | + " \"address\": \"29, side layout, cohen 09\",\r\n" + " \"types\": [\r\n" + " \"shoe park\",\r\n" 42 | + " \"shop\"\r\n" + " ],\r\n" + " \"website\": \"http://rahulshettyacademy.com\",\r\n" 43 | + " \"language\": \"French-IN\"\r\n" + "}\r\n" + ""; 44 | ; 45 | 46 | String response = given().log().all().queryParam("key", "qaclick123").header("Content-Type", "application/json") 47 | .body(body).when().post("maps/api/place/add/json").then().extract().response().asString(); 48 | 49 | logger.info("Response : "+response); 50 | 51 | JsonPath js = new JsonPath(response); 52 | 53 | String place = js.getString("place_id"); 54 | logger.info("Place ID : " +place); 55 | 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/test/gui/PassFailTest.java: -------------------------------------------------------------------------------- 1 | package com.test.gui; 2 | 3 | import java.util.HashMap; 4 | 5 | import org.apache.logging.log4j.LogManager; 6 | import org.apache.logging.log4j.Logger; 7 | 8 | import org.testng.annotations.Test; 9 | 10 | import com.test.framework.BaseClass; 11 | import com.test.pageobjects.GoogleHomePage; 12 | import com.test.pageobjects.RahulShettyAcademy; 13 | 14 | /************************************************************************************************************************ 15 | * @Date : Apr 2, 2020 16 | * @Author : nachrist 17 | * @Description : Class to check parallel execution google booking site using 18 | * data provider 19 | * @Version : 1.0 20 | ************************************************************************************************************************/ 21 | public class PassFailTest { 22 | 23 | private static final Logger logger = LogManager.getLogger(PassFailTest.class); 24 | 25 | /************************************************************************************************************************ 26 | * @Date : Apr 2, 2020 27 | * @Author : nachrist 28 | * @Description : google booking from excel data provider 29 | * @Method : googleBookingTest1 30 | * @Version : 1.0 31 | * @param fromLocation 32 | * @param toLocation 33 | * @ReturnType : void / 34 | ***********************************************************************************************************************/ 35 | @Test(groups = "Smoke Test") 36 | public void googleTest_TC001(HashMap dataHashMap) { 37 | 38 | try { 39 | 40 | GoogleHomePage googleHomePage = new GoogleHomePage(dataHashMap); 41 | googleHomePage.searchTextBox(); 42 | logger.info(" Data map for validation :" + dataHashMap); 43 | 44 | } catch (Exception e) { 45 | BaseClass.getBaseObj().testFailureException(e); 46 | } 47 | 48 | } 49 | 50 | /************************************************************************************************************************ 51 | * @Date : Apr 2, 2020 52 | * @Author : nachrist 53 | * @Description : google booking from excel data provider 54 | * @Method : googleBookingTest2 55 | * @Version : 1.0 56 | * @param fromLocation 57 | * @param toLocation 58 | * @ReturnType : void / 59 | ***********************************************************************************************************************/ 60 | @Test 61 | public void googleTest_TC002(HashMap dataHashMap) { 62 | 63 | try { 64 | 65 | GoogleHomePage googleHomePage = new GoogleHomePage(dataHashMap); 66 | googleHomePage.searchTextBox(); 67 | logger.info(" Data map for validation :" + dataHashMap); 68 | 69 | } catch (Exception e) { 70 | BaseClass.getBaseObj().testFailureException(e); 71 | } 72 | 73 | } 74 | 75 | /************************************************************************************************************************ 76 | * @Date : Apr 2, 2020 77 | * @Author : nachrist 78 | * @Description : google booking from excel data provider 79 | * @Method : googleBookingTest2 80 | * @Version : 1.0 81 | * @param fromLocation 82 | * @param toLocation 83 | * @ReturnType : void / 84 | ***********************************************************************************************************************/ 85 | @Test 86 | public void googleTest_TC003(HashMap dataHashMap) { 87 | 88 | try { 89 | 90 | GoogleHomePage googleHomePage = new GoogleHomePage(dataHashMap); 91 | googleHomePage.searchTextBox(); 92 | logger.info(" Data map for validation :" + dataHashMap); 93 | 94 | } catch (Exception e) { 95 | BaseClass.getBaseObj().testFailureException(e); 96 | } 97 | } 98 | 99 | /************************************************************************************************************************ 100 | * @Date : Apr 2, 2020 101 | * @Author : nachrist 102 | * @Description : Method to click mentorship button in training page 103 | * @Method : mentorTest 104 | * @Version : 1.0 105 | * @ReturnType : void / 106 | ***********************************************************************************************************************/ 107 | @Test 108 | public void failureTest(HashMap dataHashMap) { 109 | 110 | try { 111 | RahulShettyAcademy rahulShettyAcademy = new RahulShettyAcademy(); 112 | rahulShettyAcademy.mentorshipLink(); 113 | 114 | } catch (Exception e) { 115 | BaseClass.getBaseObj().testFailureException(e); 116 | } 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/test/java/com/test/gui/SeleniumPractice.java: -------------------------------------------------------------------------------- 1 | package com.test.gui; 2 | 3 | import java.util.HashMap; 4 | 5 | import org.testng.annotations.Test; 6 | 7 | import com.test.framework.BaseClass; 8 | import com.test.framework.ExcelDataProviderMap; 9 | import com.test.pageobjects.RahulShettyPractice; 10 | 11 | public class SeleniumPractice extends BaseClass { 12 | 13 | @Test(dataProvider = "Excel Map Provider", dataProviderClass = ExcelDataProviderMap.class) 14 | public void seleniumTest(HashMap hashMap) { 15 | 16 | try { 17 | 18 | RahulShettyPractice rahulShettyPractice = new RahulShettyPractice(hashMap); 19 | rahulShettyPractice.clickRadioButton(2); 20 | rahulShettyPractice.selectSuggestiveDropDown(); 21 | rahulShettyPractice.enterText(); 22 | rahulShettyPractice.selectDropDownValue(); 23 | rahulShettyPractice.selectCheckBoxValue(); 24 | rahulShettyPractice.mouseHoverSelection(); 25 | rahulShettyPractice.checkHiddenElement(); 26 | rahulShettyPractice.switchWindowCheck(); 27 | rahulShettyPractice.switchTabCheck(); 28 | rahulShettyPractice.fetchTableData(); 29 | rahulShettyPractice.checkiFrame(); 30 | rahulShettyPractice.javascriptCheck(); 31 | //calendar 32 | 33 | } catch (Exception e) { 34 | testFailureException(e); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /src/test/resources/TestData.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naveenchr/SeleniumTDD/7535b36e5522db091051bfc570ade81e07cdaa05/src/test/resources/TestData.xlsx -------------------------------------------------------------------------------- /testng.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | --------------------------------------------------------------------------------