├── .gitignore ├── LICENSE.txt ├── README.md ├── pom.xml └── src ├── main ├── assembly │ └── zip.xml ├── java │ └── com │ │ └── automation │ │ └── seletest │ │ ├── core │ │ ├── aspectJ │ │ │ ├── ActionsHandler.java │ │ │ ├── ExceptionHandler.java │ │ │ └── SeletestPointCuts.java │ │ ├── ehcache │ │ │ ├── EhCacheEventListener.java │ │ │ ├── EhCacheEventListenerFactory.java │ │ │ └── EhCacheGenerator.java │ │ ├── jmx │ │ │ ├── MemoryThreadDumper.java │ │ │ ├── MemoryWarningService.java │ │ │ └── mbeans │ │ │ │ ├── LoggerConfigurator.java │ │ │ │ └── MemoryWarningServiceConfigurator.java │ │ ├── listeners │ │ │ ├── AnnotationTransformer.java │ │ │ ├── EventListener.java │ │ │ ├── InitListener.java │ │ │ ├── TestListener.java │ │ │ └── beanUtils │ │ │ │ ├── DriverBeanPostProcessor.java │ │ │ │ └── Events.java │ │ ├── selenium │ │ │ ├── common │ │ │ │ ├── ActionsController.java │ │ │ │ ├── ActionsSeleniumController.java │ │ │ │ ├── ActionsWebDriverController.java │ │ │ │ └── KeyInfo.java │ │ │ ├── configuration │ │ │ │ ├── ConfigurationDriver.java │ │ │ │ └── SessionControl.java │ │ │ ├── mobileAPI │ │ │ │ ├── AppiumController.java │ │ │ │ └── AppiumDriverController.java │ │ │ ├── threads │ │ │ │ ├── SessionContext.java │ │ │ │ └── SessionProperties.java │ │ │ └── webAPI │ │ │ │ ├── DriverBaseController.java │ │ │ │ ├── SeleniumController.java │ │ │ │ ├── WebController.java │ │ │ │ ├── WebDriverController.java │ │ │ │ └── elements │ │ │ │ ├── BySelector.java │ │ │ │ └── Locators.java │ │ ├── services │ │ │ ├── annotations │ │ │ │ ├── DataSource.java │ │ │ │ ├── JSHandle.java │ │ │ │ ├── Monitor.java │ │ │ │ ├── RetryFailure.java │ │ │ │ ├── SeleniumTest.java │ │ │ │ └── VerifyLog.java │ │ │ ├── factories │ │ │ │ └── StrategyFactory.java │ │ │ ├── network │ │ │ │ ├── HttpClient.java │ │ │ │ └── SSHUtils.java │ │ │ ├── utilities │ │ │ │ ├── FilesUtils.java │ │ │ │ ├── LogUtils.java │ │ │ │ ├── MailUtils.java │ │ │ │ └── PerformanceUtils.java │ │ │ └── webSync │ │ │ │ ├── SeleniumWaitStrategy.java │ │ │ │ ├── WaitFor.java │ │ │ │ └── WebDriverWaitStrategy.java │ │ ├── spring │ │ │ ├── ApplicationContextProvider.java │ │ │ ├── AsyncSeletestExecutor.java │ │ │ ├── SeletestDBTestBase.java │ │ │ ├── SeletestWebTestBase.java │ │ │ └── SpringTestBase.java │ │ └── testNG │ │ │ ├── DataSources.java │ │ │ ├── PostConfiguration.java │ │ │ ├── PreConfiguration.java │ │ │ └── assertions │ │ │ ├── Assert.java │ │ │ └── SoftAssert.java │ │ └── pagecomponents │ │ └── pageObjects │ │ ├── AbstractPage.java │ │ ├── Android │ │ └── CalculatorPage.java │ │ └── Web │ │ ├── GitHubSearchPage.java │ │ ├── GitHubSearchResultPage.java │ │ └── GooglePage.java └── resources │ ├── META-INF │ ├── aop.xml │ └── spring │ │ ├── app-context.xml │ │ ├── cache-context.xml │ │ ├── db-context.xml │ │ ├── jmx-context.xml │ │ ├── mail-context.xml │ │ └── thread-pool-context.xml │ ├── core.properties │ ├── ehcache.xml │ ├── jQuerify.js │ └── template.html └── test ├── java ├── AndroidDemoTest │ └── AndroidDemo.java └── WebDemoTest │ ├── GitHubSearch.java │ └── GoogleTest.java └── resources ├── BrowserSettings └── browser.properties ├── DB └── db.properties ├── DataSources ├── Calculator.apk ├── Data.xls └── demoTest.properties ├── META-INF └── spring │ └── test-beans.xml ├── XMLSuites ├── AndroidDemoTest.xml ├── DemoTest.xml └── GitHubSearch.xml └── logback.xml /.gitignore: -------------------------------------------------------------------------------- 1 | .project 2 | .settings/ 3 | target/ 4 | .classpath 5 | *.log 6 | .gitignore 7 | chromedriver.log 8 | .idea/ 9 | test-output/ 10 | 11 | 12 | # Package Files # 13 | *.jar 14 | *.war 15 | *.ear 16 | 17 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 18 | hs_err_pid* 19 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) Giannis Papadakis Intellectual Property Limited. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright notice, this 7 | list of conditions and the following disclaimer. 8 | 9 | * Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | * Neither the name of the Giannis Papadakis Intellectual Property Limited nor the names 14 | of its contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | seletest 2 | ======== 3 | ![seletest](https://cloud.githubusercontent.com/assets/3785668/4871463/ff777690-61b7-11e4-9cb7-916e8d43f616.png) 4 | 5 | 6 | Build Status 7 | 8 | 9 | ***************************************************************************************** 10 | Web and Mobile Automation testing framework based on Spring - Webdriver - Appium in Java. 11 | ***************************************************************************************** 12 | 13 | This is a Java Framework based on WebDriver API to interact with web or mobile applications for performing automated functional tests. 14 | 15 | ******Javadoc: http://giannispapadakis.github.io/seletest/ ****** 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 | 41 | 42 |
Web End to End functionalSupported
DB transactions testsNot supported yet...
Client performance testsSupported
Mobile End to End functionalPartially supported (Android)
Web Security testsUpcoming
43 | 44 | 45 | 46 | 47 | Frameworks - tools:
48 | * Selenium 2 in Java
49 | * TestNG JUnit framework
50 | * Spring Java Framework
51 | * ReportNG
52 | * Appium Java client
53 | * Apache Maven
54 | * AspectJ
55 | * Browsermob-proxy
56 | 57 | 58 | Current Drivers supported:
59 | * ChromeDriver
60 | * InternetExplorerDriver
61 | * FirefoxDriver
62 | * SafariDriver
63 | * OperaDriver
64 | * PhantomJSDriver
65 | * AppiumDriver (IOSDriver-AndroidDriver)
66 | 67 | Features: 68 | * Fluent logging mechanism and error handling using AspectJ support with advices 69 | * Interaction with Page Objects and Page Facades using hard or soft assertions 70 | * Asynchronous execution of verifications with Spring Task Async Executors covering dynamic pages (AngularJS) 71 | * Appium support with custom TouchAction API for interaction with Android devices-emulators 72 | * JS errors collection during execution of tests 73 | * JVM memory usage with JMX client 74 | * HAR file with network traffic logs using browser-mob proxy that can be analyzed in online tools like https://code.google.com/p/harviewer/ 75 | * Custom JQuery selector replaces CSS pseudo-classes support in WebDriver (:contains('') / nth-child) 76 | * Custom Angular selectors (Upcoming) 77 | 78 | 79 | Tips for Internet Explorer execution
80 | On IE 7 or higher on Windows Vista or Windows 7, you must set the Protected Mode settings for each zone to be the same value. The value can be on or off, as long as it is the same for every zone. To set the Protected Mode settings, choose "Internet Options..." from the Tools menu, and click on the Security tab. For each zone, there will be a check box at the bottom of the tab labeled "Enable Protected Mode".
81 | Additionally, "Enhanced Protected Mode" must be disabled for IE 10 and higher. This option is found in the Advanced tab of the Internet Options dialog. 82 | 83 | 84 | ******************************************* 85 | Released versions 86 | ******************************************* 87 | 88 | Seletest has been uploaded in sonatype nexus.
89 | 90 | Add this to your pom.xml:
91 | 92 | Under \ tag
93 | 94 | ![repo](https://cloud.githubusercontent.com/assets/3785668/4512733/cb9308ba-4b43-11e4-8101-905376c28c6e.png) 95 | 96 | Under \ tag:
97 | 98 | ![seletest](https://cloud.githubusercontent.com/assets/3785668/4512750/02aa9048-4b44-11e4-9444-98ba48f35769.png) 99 | 100 | See wiki for setting up Spring Maven Project and running first tests
101 | 102 | You are very welcome to contribute to the project 103 | 104 | Upcoming: 105 | * Set up Appium Server on Windows 7 and run test against android emulator 106 | * Set up Selenium Grid server and register a node 107 | * Use seletestUtils project to automate remote appium-selenium node configuration 108 | 109 | 110 | -------------------------------------------------------------------------------- /src/main/assembly/zip.xml: -------------------------------------------------------------------------------- 1 | 6 | zip 7 | 8 | tar.gz 9 | tar.bz2 10 | zip 11 | 12 | 13 | 14 | ${project.basedir} 15 | / 16 | 17 | README* 18 | LICENSE* 19 | NOTICE* 20 | 21 | 22 | 23 | ${project.build.directory} 24 | / 25 | 26 | *.jar 27 | 28 | 29 | 30 | ${project.build.directory}/site 31 | docs 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/aspectJ/ActionsHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.core.aspectJ; 28 | 29 | 30 | import com.automation.seletest.core.selenium.configuration.SessionControl; 31 | import com.automation.seletest.core.services.utilities.LogUtils; 32 | import org.aspectj.lang.JoinPoint; 33 | import org.aspectj.lang.ProceedingJoinPoint; 34 | import org.aspectj.lang.annotation.After; 35 | import org.aspectj.lang.annotation.AfterReturning; 36 | import org.aspectj.lang.annotation.AfterThrowing; 37 | import org.aspectj.lang.annotation.Around; 38 | import org.aspectj.lang.annotation.Aspect; 39 | import org.aspectj.lang.annotation.Before; 40 | import org.slf4j.LoggerFactory; 41 | import org.springframework.beans.factory.annotation.Autowired; 42 | import org.springframework.stereotype.Component; 43 | import org.testng.Reporter; 44 | 45 | import java.io.IOException; 46 | import java.text.NumberFormat; 47 | 48 | /** 49 | * Aspect that handles logging,screenshots etc. 50 | * @author Giannis Papadakis (mailTo:gpapadakis84@gmail.com) 51 | * 52 | */ 53 | 54 | @Aspect 55 | @Component 56 | public class ActionsHandler extends SeletestPointCuts { 57 | 58 | /**Log service*/ 59 | @Autowired 60 | LogUtils log; 61 | 62 | /** 63 | * Log returning value for get** methods 64 | * @param jp JoinPoint 65 | * @param returnVal Object for returning value 66 | */ 67 | @AfterReturning(pointcut ="getReturningValue()",returning="returnVal") 68 | public void afterReturningAdvice(final JoinPoint jp, Object returnVal) { 69 | log.info("Command: "+jp.getSignature().getName()+" for["+arguments((ProceedingJoinPoint)jp)+"]"+" returned value: "+returnVal); 70 | } 71 | 72 | /** 73 | * Take screencap after exceptions... 74 | * @param joinPoint JoinPoint 75 | * @param ex Throwable 76 | * @throws IOException 77 | */ 78 | @AfterThrowing(pointcut="waitConditions()", throwing = "ex") 79 | public void takeScreenCap(final JoinPoint joinPoint, Throwable ex) throws IOException { 80 | if(Reporter.getCurrentTestResult().getAttribute("verification")==null) { 81 | log.warn("Take screenshot after exception: " + ex.getMessage().split("Build")[0].trim(),"color:orange;"); 82 | SessionControl.webController().takeScreenShot(); 83 | } 84 | } 85 | 86 | 87 | /**Report execution for method @Monitor*/ 88 | @Around(value="monitor()") 89 | public Object monitorLogs(ProceedingJoinPoint pjp) throws Throwable { 90 | Object returnValue ; 91 | long start = System.currentTimeMillis(); 92 | returnValue = pjp.proceed(); 93 | long elapsedTime = System.currentTimeMillis() - start; 94 | if(LoggerFactory.getLogger(ActionsHandler.class).isDebugEnabled()) { 95 | log.info("Execution time for method \"" + pjp.getSignature().getName() + "\": " + elapsedTime + " ms. ("+ elapsedTime/60000 + " minutes)","\"color:#0066CC;\""); 96 | } 97 | return returnValue; 98 | } 99 | 100 | 101 | /**Log memory usage before execution of method*/ 102 | @Before("monitor()") 103 | public void memoryBefore(final JoinPoint pjp) { 104 | if(LoggerFactory.getLogger(ActionsHandler.class).isDebugEnabled()) { 105 | NumberFormat format = NumberFormat.getInstance(); 106 | log.info("JVM memory in use = " + format.format((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024) + " before executing method: " + pjp.getSignature().getName()); 107 | } 108 | } 109 | 110 | /**Log memory usage after execution of method*/ 111 | @After("monitor()") 112 | public void memoryAfter(final JoinPoint pjp) { 113 | if(LoggerFactory.getLogger(ActionsHandler.class).isDebugEnabled()) { 114 | NumberFormat format = NumberFormat.getInstance(); 115 | log.info("JVM memory in use = " + format.format((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024) + " before executing method: " + pjp.getSignature().getName()); 116 | } 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/aspectJ/SeletestPointCuts.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.core.aspectJ; 28 | 29 | import com.automation.seletest.core.services.annotations.JSHandle; 30 | import com.automation.seletest.core.services.annotations.RetryFailure; 31 | import com.automation.seletest.core.services.annotations.VerifyLog; 32 | import com.automation.seletest.core.services.factories.StrategyFactory; 33 | import org.aspectj.lang.JoinPoint; 34 | import org.aspectj.lang.ProceedingJoinPoint; 35 | import org.aspectj.lang.annotation.Pointcut; 36 | import org.aspectj.lang.reflect.MethodSignature; 37 | import org.springframework.beans.factory.annotation.Autowired; 38 | import org.springframework.scheduling.annotation.Async; 39 | 40 | import java.lang.reflect.Method; 41 | 42 | /** 43 | * Super class with common functions 44 | * @author Giannis Papadakis (mailTo:gpapadakis84@gmail.com) 45 | * 46 | */ 47 | public abstract class SeletestPointCuts { 48 | 49 | /**Factories Strategy*/ 50 | @Autowired 51 | StrategyFactory factoryStrategy; 52 | 53 | /**Methods in classpath that have @Monitor*/ 54 | @Pointcut("execution(@com.automation.seletest.core.services.annotations.Monitor * *(..))") 55 | protected void monitor() {} 56 | 57 | /**All methods in ActionsBuilderController*/ 58 | @Pointcut("execution(* com.automation.seletest.core.selenium.common.ActionsController.*(..))") 59 | protected void actionsBuilderController() {} 60 | 61 | /**Methods for taking screenshots!!*/ 62 | @Pointcut("execution(* com.automation.seletest.core.selenium.webAPI.WebController.takeScreenShot*(..))") 63 | protected void takeScreenCap() {} 64 | 65 | /**All Methods of WebController!!*/ 66 | @Pointcut("execution(!boolean com.automation.seletest.core.selenium.webAPI.WebController.*(..))") 67 | protected void webControl() {} 68 | 69 | /**Methods for wait conditions*/ 70 | @Pointcut("execution(* com.automation.seletest.core.services.webSync.*WaitStrategy.*(..))") 71 | protected void waitConditions() {} 72 | 73 | /**Methods that are returning objects*/ 74 | @Pointcut("execution(* com.automation.seletest.core.selenium.webAPI.*.get*(..))") 75 | protected void getReturningValue() {} 76 | 77 | /**Methods for sending email*/ 78 | @Pointcut("execution(* com.automation.seletest.core.services.utilities.MailUtils.*(..))") 79 | protected void sendMail() {} 80 | 81 | @Pointcut("execution(boolean com.automation.seletest.core.selenium.webAPI..*(..))") 82 | protected void componentsStatus() {} 83 | 84 | /** Pointcut for reexecuting methods*/ 85 | @Pointcut("execution(* com.automation.seletest..*(..)) && @annotation(async)") 86 | protected void asynchronous(Async async) {} 87 | 88 | /** Pointcut for async methods*/ 89 | @Pointcut("execution(* com.automation.seletest.core.selenium.webAPI..*(..)) && @annotation(retry)") 90 | protected void retryExecution(RetryFailure retry) {} 91 | 92 | /** Pointcut for logging in Custom Verify methods*/ 93 | @Pointcut("execution(* com.automation.seletest.core.testNG.assertions.Assert.*(..)) && @annotation(verify)") 94 | protected void logVerify(VerifyLog verify) {} 95 | 96 | /** Pointcut for logging PO methods*/ 97 | @Pointcut("execution(* com.automation.seletest.pagecomponents.pageObjects..*(..))") 98 | protected void logPOs() {} 99 | 100 | /**PointCut for executing JS scripts*/ 101 | @Pointcut("execution(* com.automation.seletest.core.selenium.webAPI..*(..)) && @annotation(jshandle)") 102 | protected void jsHandle(JSHandle jshandle) {} 103 | 104 | 105 | /** 106 | * Type of arguments of an executed method 107 | * @param proceedPoint The method to be invoked from aspect advice 108 | * @return String arguments 109 | */ 110 | public String arguments(ProceedingJoinPoint proceedPoint){ 111 | StringBuilder arguments = new StringBuilder(); 112 | for(int i=0; i < proceedPoint.getArgs().length ;i++ ){ 113 | MethodSignature sig = (MethodSignature)proceedPoint.getSignature(); 114 | String methodArgument=""; 115 | if(proceedPoint.getArgs()[i].toString().contains("->")){ 116 | methodArgument=proceedPoint.getArgs()[i].toString().split("->")[1].replace("]", ""); 117 | } else{ 118 | methodArgument=proceedPoint.getArgs()[i].toString(); 119 | } 120 | arguments.append("("+sig.getParameterNames()[i].toString()+" ---> "+methodArgument+") "); 121 | } if(arguments.toString().isEmpty()){ 122 | return ""; 123 | } else { 124 | return arguments.toString().trim(); 125 | } 126 | } 127 | 128 | /** 129 | * Get method arguments 130 | * @param proceedPoint The method to be invoked from aspect advice 131 | * @return arguments of proxied methods 132 | */ 133 | public Object[] methodArguments(ProceedingJoinPoint proceedPoint){ 134 | return proceedPoint.getArgs(); 135 | } 136 | 137 | /** 138 | * Return invoked method 139 | * @param pjp The method to be invoked from aspect advice 140 | * @return invoked Method 141 | */ 142 | public Method invokedMethod(JoinPoint pjp) { 143 | MethodSignature ms = (MethodSignature) pjp.getSignature(); 144 | Method m = ms.getMethod(); 145 | return m; 146 | } 147 | 148 | 149 | } 150 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/ehcache/EhCacheEventListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.core.ehcache; 28 | 29 | import net.sf.ehcache.CacheException; 30 | import net.sf.ehcache.Ehcache; 31 | import net.sf.ehcache.Element; 32 | import net.sf.ehcache.event.CacheEventListener; 33 | import org.slf4j.Logger; 34 | import org.slf4j.LoggerFactory; 35 | 36 | /** 37 | * EhCacheEventListener class. 38 | * @author Giannis Papadakis (mailTo:gpapadakis84@gmail.com) 39 | */ 40 | public class EhCacheEventListener implements CacheEventListener { 41 | 42 | /**Logger for EhCacheEventListener.class*/ 43 | private static final Logger CACHE_EVENT_LISTENER = LoggerFactory.getLogger(EhCacheEventListener.class); 44 | 45 | @Override 46 | public void notifyElementRemoved(Ehcache cache, Element element) throws CacheException { 47 | CACHE_EVENT_LISTENER.debug("Cache element removed ----> "+element.getObjectKey()); 48 | } 49 | 50 | @Override 51 | public void notifyElementPut(Ehcache cache, Element element) throws CacheException { 52 | CACHE_EVENT_LISTENER.debug("Cache element put ----> "+element.getObjectKey()); 53 | } 54 | 55 | @Override 56 | public void notifyElementUpdated(Ehcache cache, Element element) throws CacheException { 57 | CACHE_EVENT_LISTENER.debug("Cache element updated ----> "+element.getObjectKey()); 58 | } 59 | 60 | @Override 61 | public void notifyElementExpired(Ehcache cache, Element element) { 62 | CACHE_EVENT_LISTENER.debug("Cache element expired ----> "+element.getObjectKey()); 63 | } 64 | 65 | @Override 66 | public void notifyElementEvicted(Ehcache cache, Element element) { 67 | CACHE_EVENT_LISTENER.debug("Cache element evicted ----> "+element.getObjectKey()); 68 | } 69 | 70 | @Override 71 | public void notifyRemoveAll(final Ehcache ehcache) { 72 | CACHE_EVENT_LISTENER.debug("All elements removed from cache ----> "+ehcache.getName()); 73 | } 74 | 75 | @Override 76 | public void dispose() { 77 | 78 | } 79 | 80 | @Override 81 | public Object clone() throws CloneNotSupportedException { 82 | throw new CloneNotSupportedException("Singleton instance"); 83 | } 84 | 85 | } -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/ehcache/EhCacheEventListenerFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.core.ehcache; 28 | 29 | import net.sf.ehcache.event.CacheEventListener; 30 | import net.sf.ehcache.event.CacheEventListenerFactory; 31 | 32 | import java.util.Properties; 33 | 34 | /** 35 | * EhCacheEventListenerFactory class. 36 | * @author Giannis Papadakis (mailTo:gpapadakis84@gmail.com) 37 | */ 38 | public class EhCacheEventListenerFactory extends CacheEventListenerFactory { 39 | 40 | @Override 41 | public CacheEventListener createCacheEventListener(Properties properties) { 42 | return new EhCacheEventListener(); 43 | } 44 | } -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/ehcache/EhCacheGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.core.ehcache; 28 | 29 | import com.automation.seletest.core.selenium.threads.SessionContext; 30 | import org.openqa.selenium.WebElement; 31 | import org.openqa.selenium.remote.RemoteWebElement; 32 | import org.openqa.selenium.support.events.EventFiringWebDriver; 33 | import org.springframework.cache.interceptor.KeyGenerator; 34 | import org.springframework.stereotype.Component; 35 | 36 | import java.lang.reflect.Method; 37 | 38 | /** 39 | * EhCacheGenerator class for adding keys to objects cached in Cache 40 | * @author Giannis Papadakis (mailTo:gpapadakis84@gmail.com) 41 | */ 42 | @Component 43 | public class EhCacheGenerator implements KeyGenerator { 44 | 45 | @Override 46 | public Object generate(Object target, Method method, Object... params) { 47 | StringBuilder sb = new StringBuilder(); 48 | sb.append(SessionContext.getSession().getWebDriver().toString()); 49 | sb.append(" ").append(method.getName()); 50 | for (Object param : params) 51 | if (param instanceof WebElement && !(SessionContext.getSession().getWebDriver() instanceof EventFiringWebDriver)) 52 | sb.append(" ").append(((RemoteWebElement) param).getId()); 53 | else if (param instanceof WebElement && SessionContext.getSession().getWebDriver() instanceof EventFiringWebDriver) { 54 | sb.append(" ").append(((WebElement) param).getLocation()); 55 | } else { 56 | sb.append(" ").append(param.toString()); 57 | } 58 | return sb.toString(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/jmx/MemoryThreadDumper.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.core.jmx; 28 | 29 | import java.io.BufferedWriter; 30 | import java.io.File; 31 | import java.io.FileWriter; 32 | import java.io.IOException; 33 | import java.io.Writer; 34 | import java.lang.management.ManagementFactory; 35 | import java.lang.management.ThreadInfo; 36 | import java.lang.management.ThreadMXBean; 37 | import java.text.SimpleDateFormat; 38 | import java.util.Date; 39 | import java.util.HashMap; 40 | import java.util.Map; 41 | 42 | import lombok.extern.slf4j.Slf4j; 43 | 44 | import org.apache.commons.io.IOUtils; 45 | import org.springframework.stereotype.Component; 46 | import org.testng.Reporter; 47 | 48 | @Component 49 | @Slf4j 50 | public class MemoryThreadDumper { 51 | 52 | /** 53 | * It dumps the Thread stacks 54 | * @throws java.io.IOException 55 | */ 56 | public void dumpStacks() { 57 | 58 | String dumps = "stacks.dump"; 59 | 60 | ThreadMXBean mxBean = ManagementFactory.getThreadMXBean(); 61 | ThreadInfo[] threadInfos = mxBean.getThreadInfo(mxBean.getAllThreadIds(), 0); 62 | Map threadInfoMap = new HashMap(); 63 | for (ThreadInfo threadInfo : threadInfos) { 64 | threadInfoMap.put(threadInfo.getThreadId(), threadInfo); 65 | } 66 | 67 | File dumpFile = new File(new File(Reporter.getCurrentTestResult().getTestContext().getSuite().getOutputDirectory()).getParent()+dumps); 68 | BufferedWriter writer = null; 69 | try { 70 | writer = new BufferedWriter(new FileWriter(dumpFile)); 71 | this.dumpTraces(mxBean, threadInfoMap, writer); 72 | log.warn("Stacks dumped to: " + dumps); 73 | 74 | } catch (IOException e) { 75 | throw new IllegalStateException("An exception occurred while writing the thread dump"); 76 | } finally { 77 | IOUtils.closeQuietly(writer); 78 | } 79 | 80 | } 81 | 82 | private void dumpTraces(ThreadMXBean mxBean, 83 | Map threadInfoMap, Writer writer) 84 | throws IOException { 85 | Map stacks = Thread.getAllStackTraces(); 86 | writer.write("Dump of "+stacks.size()+" thread at "+new SimpleDateFormat("yyyy/MM/dd HH:mm:ss z").format(new Date(System.currentTimeMillis())) + "\n\n"); 87 | for (Map.Entry entry : stacks.entrySet()) { 88 | Thread thread = entry.getKey(); 89 | writer.write("\""+thread.getName()+"\" prio="+thread.getPriority()+" tid="+thread.getId()+"\n"); 90 | ThreadInfo threadInfo = threadInfoMap.get(thread.getId()); 91 | if (threadInfo != null) { 92 | writer.write(" native=" + threadInfo.isInNative() 93 | + ", suspended=" + threadInfo.isSuspended() 94 | + ", block=" + threadInfo.getBlockedCount() + ", wait=" 95 | + threadInfo.getWaitedCount() + "\n"); 96 | writer.write(" lock=" + threadInfo.getLockName() 97 | + " owned by " + threadInfo.getLockOwnerName() + " (" 98 | + threadInfo.getLockOwnerId() + "), cpu=" 99 | + mxBean.getThreadCpuTime(threadInfo.getThreadId()) 100 | / 1000000L + ", user=" 101 | + mxBean.getThreadUserTime(threadInfo.getThreadId()) 102 | / 1000000L + "\n"); 103 | } 104 | for (StackTraceElement element : entry.getValue()) { 105 | writer.write(" "); 106 | writer.write(element.toString()); 107 | writer.write("\n"); 108 | } 109 | writer.write("\n"); 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/jmx/MemoryWarningService.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | package com.automation.seletest.core.jmx; 29 | 30 | import java.lang.management.ManagementFactory; 31 | import java.lang.management.MemoryNotificationInfo; 32 | import java.lang.management.MemoryPoolMXBean; 33 | import java.lang.management.MemoryType; 34 | 35 | import javax.annotation.PostConstruct; 36 | import javax.management.Notification; 37 | import javax.management.NotificationEmitter; 38 | import javax.management.NotificationListener; 39 | 40 | import lombok.extern.slf4j.Slf4j; 41 | import org.springframework.beans.factory.annotation.Autowired; 42 | 43 | /** 44 | * A component which sends notifications when the HEAP memory is above a certain 45 | * threshold. 46 | * 47 | */ 48 | @Slf4j 49 | public class MemoryWarningService implements NotificationListener { 50 | 51 | 52 | /**MBean name*/ 53 | public static final String MBEAN_NAME = "seletest.mbeans:type=monitoring,name=MemoryWarningService"; 54 | 55 | @Autowired 56 | private NotificationEmitter memoryMxBean; 57 | 58 | @Autowired 59 | private MemoryThreadDumper threadDumper; 60 | 61 | @PostConstruct 62 | public void completeSetup() { 63 | memoryMxBean.addNotificationListener(this, null, null); 64 | log.info("Notifications listener added to JMX bean"); 65 | } 66 | 67 | /** A pool of Memory MX Beans specialised in HEAP management */ 68 | private static final MemoryPoolMXBean tenuredGenPool = findTenuredGenPool(); 69 | 70 | @Override 71 | public void handleNotification(Notification notification, Object handback) { 72 | 73 | if (notification.getType().equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) { 74 | long maxMemory = tenuredGenPool.getUsage().getMax(); 75 | long usedMemory = tenuredGenPool.getUsage().getUsed(); 76 | log.warn("Memory usage low!!!"); 77 | double percentageUsed = (double) usedMemory / maxMemory; 78 | log.warn("percentageUsed = " + percentageUsed); 79 | threadDumper.dumpStacks(); 80 | } else { 81 | log.info("Other notification received..."+ notification.getMessage()); 82 | } 83 | 84 | } 85 | 86 | /** It sets the threshold percentage.*/ 87 | public void setPercentageUsageThreshold(double percentage) { 88 | if (percentage <= 0.0 || percentage > 1.0) { 89 | throw new IllegalArgumentException("Percentage not in range"); 90 | } else { 91 | log.info("Percentage is: " + percentage); 92 | } 93 | long maxMemory = tenuredGenPool.getUsage().getMax(); 94 | long warningThreshold = (long) (maxMemory * percentage); 95 | tenuredGenPool.setUsageThreshold(warningThreshold); 96 | log.info("Warning Threshold is: " + warningThreshold); 97 | } 98 | 99 | private static MemoryPoolMXBean findTenuredGenPool() { 100 | for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) { 101 | if (pool.getType() == MemoryType.HEAP && pool.isUsageThresholdSupported()) { 102 | return pool; 103 | } 104 | } 105 | throw new AssertionError(); 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/jmx/mbeans/LoggerConfigurator.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | package com.automation.seletest.core.jmx.mbeans; 29 | 30 | import ch.qos.logback.classic.Level; 31 | import ch.qos.logback.classic.Logger; 32 | import lombok.extern.slf4j.Slf4j; 33 | import org.slf4j.LoggerFactory; 34 | import org.springframework.jmx.export.annotation.ManagedOperation; 35 | import org.springframework.jmx.export.annotation.ManagedOperationParameter; 36 | import org.springframework.jmx.export.annotation.ManagedOperationParameters; 37 | import org.springframework.jmx.export.annotation.ManagedResource; 38 | import org.springframework.stereotype.Component; 39 | 40 | /** 41 | * MBean which allows clients to change or retrieve the logging level for a 42 | * Log4j Logger at runtime 43 | */ 44 | @Component 45 | @Slf4j 46 | @ManagedResource(objectName = LoggerConfigurator.MBEAN_NAME, description = "Allows clients to set the Log4j Logger level at runtime") 47 | public class LoggerConfigurator { 48 | 49 | public static final String MBEAN_NAME = "seletest.mbeans:type=config,name=LoggingConfiguration"; 50 | 51 | @ManagedOperation(description = "Returns the Logger LEVEL for the given logger name") 52 | @ManagedOperationParameters({ @ManagedOperationParameter(description = "The Logger Name", name = "loggerName"), }) 53 | public String getLoggerLevel(String loggerName) { 54 | Logger logger = (Logger) LoggerFactory.getLogger(this.getClass()); 55 | Level loggerLevel = logger.getLevel(); 56 | return loggerLevel == null ? "The logger " + loggerName + " has not level" : loggerLevel.toString(); 57 | } 58 | 59 | @ManagedOperation(description = "Set Logger Level") 60 | @ManagedOperationParameters({ 61 | @ManagedOperationParameter(description = "The Logger Name", name = "loggerName"), 62 | @ManagedOperationParameter(description = "The Level to which the Logger must be set", name = "loggerLevel") }) 63 | public void setLoggerLevel(String loggerName, String loggerLevel) { 64 | Logger logger = (Logger) LoggerFactory.getLogger(this.getClass()); 65 | logger.setLevel(Level.INFO); 66 | Logger loggerNew = (Logger) LoggerFactory.getLogger(loggerName); 67 | loggerNew.setLevel(Level.toLevel(loggerLevel, Level.INFO)); 68 | log.info("Set logger " + loggerName + " to level "+ loggerNew.getLevel()); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/jmx/mbeans/MemoryWarningServiceConfigurator.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.core.jmx.mbeans; 28 | 29 | import com.automation.seletest.core.jmx.MemoryWarningService; 30 | import com.automation.seletest.core.spring.ApplicationContextProvider; 31 | import lombok.extern.slf4j.Slf4j; 32 | import org.springframework.jmx.export.annotation.ManagedOperation; 33 | import org.springframework.jmx.export.annotation.ManagedOperationParameter; 34 | import org.springframework.jmx.export.annotation.ManagedOperationParameters; 35 | import org.springframework.jmx.export.annotation.ManagedResource; 36 | import org.springframework.stereotype.Component; 37 | 38 | @Component 39 | @Slf4j 40 | @ManagedResource(objectName = MemoryWarningServiceConfigurator.MBEAN_NAME,description = "Allows clients to set the memory threshold") 41 | public class MemoryWarningServiceConfigurator { 42 | 43 | public static final String MBEAN_NAME = "seletest.mbeans:type=config,name=MemoryWarningServiceConfiguration"; 44 | 45 | @ManagedOperation(description = "Sets the memory threshold for the memory warning system") 46 | @ManagedOperationParameters({ @ManagedOperationParameter(description = "The memory threshold", name = "memoryThreshold"), }) 47 | public void setMemoryThreshold(double memoryThreshold) { 48 | MemoryWarningService memoryWarningService = (MemoryWarningService) ApplicationContextProvider.getApplicationContext().getBean("memoryWarningService"); 49 | memoryWarningService.setPercentageUsageThreshold(memoryThreshold); 50 | log.info("Memory threshold set to " + memoryThreshold); 51 | } 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/listeners/TestListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Giannis Papadakis . 3 | 4 | Copyright (c) 2014, Giannis Papadakis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | package com.automation.seletest.core.listeners; 29 | 30 | import java.io.File; 31 | 32 | import lombok.extern.slf4j.Slf4j; 33 | 34 | import org.openqa.selenium.logging.LogEntries; 35 | import org.openqa.selenium.logging.LogEntry; 36 | import org.openqa.selenium.logging.LogType; 37 | import org.testng.ITestContext; 38 | import org.testng.ITestListener; 39 | import org.testng.ITestNGMethod; 40 | import org.testng.ITestResult; 41 | import org.testng.Reporter; 42 | 43 | import com.automation.seletest.core.selenium.threads.SessionContext; 44 | import com.automation.seletest.core.services.factories.StrategyFactory; 45 | import com.automation.seletest.core.services.utilities.FilesUtils; 46 | import com.automation.seletest.core.services.utilities.MailUtils; 47 | import com.automation.seletest.core.spring.ApplicationContextProvider; 48 | 49 | /** 50 | * Test Listener class. 51 | * @author Giannis Papadakis(mailTo:gpapadakis84@gmail.com) 52 | * 53 | */ 54 | @Slf4j 55 | public class TestListener implements ITestListener{ 56 | 57 | /** Screenshots directory*/ 58 | private static final String screenShots="/html/screenshots"; 59 | 60 | /**Logs directory*/ 61 | private static final String logs="/html/Logs"; 62 | 63 | @Override 64 | public void onStart(ITestContext testContext) { 65 | log.info("Suite: "+testContext.getSuite().getName()+" started at: "+testContext.getStartDate()); 66 | createDirectory(new File(testContext.getSuite().getOutputDirectory()).getParent()+screenShots); 67 | createDirectory(new File(testContext.getSuite().getOutputDirectory()).getParent()+logs); 68 | } 69 | 70 | @Override 71 | public void onFinish(ITestContext context) { 72 | log.info("Suite: "+context.getSuite().getName()+" ended at: "+context.getEndDate()); 73 | 74 | //Remove the passed configuration methods from the report 75 | for(ITestNGMethod m:context.getPassedConfigurations().getAllMethods()){ 76 | if(!m.isBeforeMethodConfiguration()) { 77 | context.getPassedConfigurations().removeResult(m); 78 | } 79 | } 80 | //Remove the skipped configuration methods from the report 81 | for(ITestNGMethod m:context.getSkippedConfigurations().getAllMethods()){ 82 | context.getSkippedConfigurations().removeResult(m); 83 | } 84 | //remove the rerun tests result from report 85 | for(int i=0;iClient Logs

"); 118 | } 119 | catch(Exception ex) { 120 | log.error("Exception trying to collect client logs: {}",ex.getMessage()); 121 | } 122 | 123 | if(System.getProperty("email")!=null) { 124 | log.debug("Send email notification with failure of the @Test to address {} ", System.getProperty("email")); 125 | ApplicationContextProvider.getApplicationContext().getBean(MailUtils.class).sendMail(System.getProperty("email"),"Failure on test: "+testResult.getName(),"Exception occured is: "+testResult.getThrowable().getMessage()); 126 | } 127 | } 128 | 129 | @Override 130 | public void onTestStart(ITestResult result) { 131 | log.debug("Test "+ result.getName()+" started!!!"); 132 | } 133 | 134 | @Override 135 | public void onTestFailedButWithinSuccessPercentage(ITestResult result) { 136 | 137 | } 138 | 139 | private void createDirectory(String dir){ 140 | File currentPath = new File(dir).getAbsoluteFile(); 141 | if(!currentPath.exists()){ 142 | currentPath.mkdirs(); 143 | } 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/listeners/beanUtils/DriverBeanPostProcessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Giannis Papadakis . 3 | 4 | Copyright (c) 2014, Giannis Papadakis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.core.listeners.beanUtils; 28 | 29 | import java.util.logging.Level; 30 | 31 | import org.openqa.selenium.logging.LogType; 32 | import org.openqa.selenium.logging.LoggingPreferences; 33 | import org.openqa.selenium.remote.CapabilityType; 34 | import org.openqa.selenium.remote.DesiredCapabilities; 35 | import org.springframework.beans.BeansException; 36 | import org.springframework.beans.factory.annotation.Autowired; 37 | import org.springframework.beans.factory.config.BeanPostProcessor; 38 | import org.springframework.core.env.Environment; 39 | import org.testng.ITestResult; 40 | import org.testng.Reporter; 41 | 42 | /** 43 | * DriverBeanPostProcessor class 44 | * @author Giannis Papadakis(mailTo:gpapadakis84@gmail.com) 45 | * 46 | */ 47 | public class DriverBeanPostProcessor implements BeanPostProcessor{ 48 | 49 | @Autowired 50 | Environment env; 51 | 52 | /** 53 | * Actions before initializing beans 54 | */ 55 | @Override 56 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { 57 | return bean; 58 | } 59 | 60 | /** 61 | * Actions after initializing beans 62 | */ 63 | @Override 64 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { 65 | String browserType=null; 66 | String clientLogs=null; 67 | 68 | ITestResult result=Reporter.getCurrentTestResult(); 69 | 70 | if(result!=null) { 71 | browserType=Reporter.getCurrentTestResult().getMethod().getTestClass().getXmlTest().getAllParameters().get(env.getProperty("browser")); 72 | clientLogs=Reporter.getCurrentTestResult().getMethod().getTestClass().getXmlTest().getAllParameters().get(env.getProperty("logs")); 73 | } 74 | 75 | if(bean instanceof DesiredCapabilities) { 76 | 77 | /**Collect Javascript console errors*/ 78 | if(clientLogs!=null && Boolean.parseBoolean(clientLogs)) { 79 | LoggingPreferences loggingprefs = new LoggingPreferences(); 80 | loggingprefs.enable(LogType.BROWSER, Level.ALL);// Javascript console errors 81 | DesiredCapabilities logCaps=new DesiredCapabilities(); 82 | logCaps.setCapability(CapabilityType.LOGGING_PREFS,loggingprefs); 83 | ((DesiredCapabilities) bean).merge(logCaps); 84 | } 85 | 86 | /**Defines browser capability for selenium grid requests*/ 87 | if(browserType!=null) { 88 | if(browserType.compareTo("chrome") == 0) { 89 | ((DesiredCapabilities) bean).merge(DesiredCapabilities.chrome()); 90 | } else if(browserType.compareTo("firefox") == 0) { 91 | ((DesiredCapabilities) bean).merge(DesiredCapabilities.firefox()); 92 | } else if(browserType.compareTo("ie") == 0) { 93 | ((DesiredCapabilities) bean).merge(DesiredCapabilities.internetExplorer()); 94 | } else if(browserType.compareTo("phantomJs") == 0) { 95 | ((DesiredCapabilities) bean).merge(DesiredCapabilities.phantomjs()); 96 | } 97 | } 98 | 99 | } 100 | 101 | return bean; 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/listeners/beanUtils/Events.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Giannis Papadakis . 3 | 4 | Copyright (c) 2014, Giannis Papadakis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | package com.automation.seletest.core.listeners.beanUtils; 29 | 30 | import lombok.Getter; 31 | import lombok.Setter; 32 | 33 | import org.springframework.context.ApplicationEvent; 34 | import org.testng.ITestContext; 35 | 36 | import com.automation.seletest.core.services.annotations.SeleniumTest; 37 | 38 | /** 39 | * Event class for custom events 40 | * @author Giannis Papadakis(mailTo:gpapadakis84@gmail.com) 41 | * 42 | */ 43 | public class Events extends ApplicationEvent{ 44 | private static final long serialVersionUID = -5308299518665062983L; 45 | 46 | public Events(Object source) { 47 | super(source); 48 | } 49 | 50 | /** 51 | * Class for events regarding initialization of web or mobile session 52 | * @author Giannis Papadakis(mailTo:gpapadakis84@gmail.com) 53 | * 54 | */ 55 | public static class InitializationEvent extends Events { 56 | /**General Message for event*/ 57 | @Getter @Setter private String message; 58 | 59 | /**Host url to run tests*/ 60 | @Getter @Setter private String hostUrl; 61 | 62 | /**If performance metrics enabled*/ 63 | @Getter @Setter private boolean performance; 64 | 65 | /**TestContext interface*/ 66 | @Getter @Setter private ITestContext testcontext; 67 | 68 | private static final long serialVersionUID = -5308299518665062983L; 69 | 70 | /** 71 | * Initialize event 72 | * @param source Object source 73 | * @param msg String message 74 | * @param hostUrl String url 75 | * @param performance boolean peformance 76 | * @param context ITestContext context 77 | */ 78 | public InitializationEvent( 79 | Object source, 80 | String msg, 81 | String hostUrl, 82 | boolean performance, 83 | ITestContext context) { 84 | super(source); 85 | this.message=msg; 86 | this.hostUrl=hostUrl; 87 | this.performance=performance; 88 | this.testcontext=context; 89 | } 90 | } 91 | 92 | /** 93 | * Class for events regarding TestNG configuration 94 | * @author Giannis Papadakis(mailTo:gpapadakis84@gmail.com) 95 | * 96 | */ 97 | public static class TestNGEvent extends Events { 98 | 99 | public TestNGEvent( 100 | Object source, 101 | SeleniumTest selenium, 102 | String msg) { 103 | super(source); 104 | this.test=selenium; 105 | this.message=msg; 106 | } 107 | 108 | private static final long serialVersionUID = 1L; 109 | 110 | /**SeleniuTest interface*/ 111 | @Getter @Setter private SeleniumTest test; 112 | 113 | /**General Message for event*/ 114 | @Getter @Setter private String message; 115 | 116 | 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/selenium/common/ActionsController.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.core.selenium.common; 28 | 29 | 30 | public interface ActionsController { 31 | 32 | /** 33 | * Clicks in the middle of the given element. Equivalent to: Actions.moveToElement(onElement).click() 34 | * @param locator Object locator ca be String or WebElement 35 | * @return instance of ActionBuilder 36 | */ 37 | T click(Object locator); 38 | 39 | /** 40 | * Moves the mouse to the middle of the element 41 | * @param locator Object locator ca be String or WebElement 42 | * @return instance of ActionBuilder 43 | */ 44 | T mouseOver(Object locator); 45 | 46 | /** 47 | * Performs a modifier key release. 48 | * Releasing a non-depressed modifier key will yield undefined behaviour. 49 | * @param key keyInfo event 50 | * @return instance of ActionBuilder 51 | */ 52 | T mouseUp(KeyInfo key); 53 | 54 | /** 55 | * Performs a modifier key press. 56 | * Does not release the modifier key - subsequent interactions may assume it's kept pressed. 57 | * Note that the modifier key is never released implicitly - either keyUp(theKey) or sendKeys(Keys.NULL) 58 | * must be called to release the modifier. 59 | * @param key KeInfo event 60 | * @return instance of ActionBuilder 61 | */ 62 | T mouseDown(KeyInfo key); 63 | 64 | /** 65 | * Move to element first and then perform mouseDown 66 | * @param locator Object locator ca be String or WebElement 67 | * @param key KeyInfo event 68 | * @return instance of ActionBuilder 69 | */ 70 | T mouseDown(Object locator, KeyInfo key); 71 | 72 | /** 73 | * Move to element and then perform mouseUp 74 | * @param locator Object locator ca be String or WebElement 75 | * @param key KeyInfo event 76 | * @return instance of ActionBuilder 77 | */ 78 | T mouseUp(Object locator, KeyInfo key); 79 | 80 | /** 81 | * Clicks (without releasing) in the middle of the given element. This is equivalent to: Actions.moveToElement(onElement).clickAndHold() 82 | * @param locator of WebElement to click and hold 83 | * @return instance of ActionBuilder 84 | */ 85 | T clickAndHold(Object locator); 86 | 87 | /** 88 | * Performs the sequence of webSync represented by this instance 89 | * @return instance of ActionBuilder 90 | */ 91 | T performActions(); 92 | 93 | /** 94 | * Performs the sequence of TouchAction represented by this instance 95 | * @return instance of ActionBuilder 96 | */ 97 | T performTouchActions(); 98 | 99 | /** 100 | * Tap on WebElement in native apps 101 | * @param locator element to tap 102 | * @return instance of ActionBuilder 103 | */ 104 | T tap(Object locator); 105 | 106 | /** 107 | * Tap an element, offset from upper left corner 108 | * @param locator locator element to tap 109 | * @param x x offset 110 | * @param y y offset 111 | * @return instance of ActionBuilder 112 | */ 113 | T tap(Object locator,int x, int y); 114 | 115 | /** 116 | * Tap on specific location in screen 117 | * @param x x coordinate 118 | * @param y y coordinate 119 | * @return instance of ActionBuilder 120 | */ 121 | T tap(int x, int y); 122 | 123 | /** 124 | * Press on an absolute position on the screen 125 | * @param x x coordinate 126 | * @param y y coordinate 127 | * @return ActionsBuilder 128 | */ 129 | T press(int x, int y); 130 | 131 | /** 132 | * Press on WebElement in native apps 133 | * @param locator element to press 134 | * @return instance of ActionBuilder 135 | */ 136 | T press(Object locator); 137 | 138 | /** 139 | * Press an element, offset from upper left corner 140 | * @param locator locator element to press 141 | * @param x x offset 142 | * @param y y offset 143 | * @return instance of ActionBuilder 144 | */ 145 | T press(Object locator, int x, int y); 146 | 147 | /** 148 | * Drags elements from one location to another 149 | * @param draglocator Object tto drag 150 | * @param droplocator Object to drop 151 | * @return instance of ActionBuilder 152 | */ 153 | T dragndrop(Object draglocator, Object droplocator); 154 | 155 | /** 156 | * Press a keyboard key 157 | * @param key KeyInfo event 158 | * @return instance of ActionBuilder 159 | */ 160 | T press(KeyInfo key); 161 | 162 | 163 | } 164 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/selenium/common/KeyInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Giannis Papadakis . 3 | 4 | Copyright (c) 2014, Giannis Papadakis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.core.selenium.common; 28 | 29 | import java.awt.event.KeyEvent; 30 | 31 | import org.openqa.selenium.Keys; 32 | 33 | 34 | /** 35 | * @author Giannis Papadakis(mailTo:gpapadakis84@gmail.com) 36 | * 37 | */ 38 | 39 | public enum KeyInfo { 40 | CANCEL (Keys.CANCEL,KeyEvent.VK_CANCEL), 41 | HELP (Keys.HELP,KeyEvent.VK_HELP), 42 | BACK_SPACE (Keys.BACK_SPACE,KeyEvent.VK_BACK_SPACE), 43 | TAB (Keys.TAB,KeyEvent.VK_TAB), 44 | CLEAR (Keys.CLEAR,KeyEvent.VK_CLEAR), 45 | RETURN (Keys.RETURN,KeyEvent.VK_ENTER), 46 | ENTER (Keys.ENTER,KeyEvent.VK_ENTER), 47 | SHIFT (Keys.SHIFT,KeyEvent.VK_SHIFT), 48 | LEFT_SHIFT (Keys.LEFT_SHIFT,KeyEvent.VK_SHIFT), 49 | CONTROL (Keys.CONTROL,KeyEvent.VK_CONTROL), 50 | LEFT_CONTROL (Keys.LEFT_CONTROL,KeyEvent.VK_CONTROL), 51 | ALT (Keys.ALT,KeyEvent.VK_ALT), 52 | LEFT_ALT (Keys.LEFT_ALT,KeyEvent.VK_ALT), 53 | PAUSE (Keys.PAUSE,KeyEvent.VK_PAUSE), 54 | ESCAPE (Keys.ESCAPE,KeyEvent.VK_ESCAPE), 55 | SPACE (Keys.SPACE,KeyEvent.VK_SPACE), 56 | PAGE_UP (Keys.PAGE_UP,KeyEvent.VK_PAGE_UP), 57 | PAGE_DOWN (Keys.PAGE_DOWN,KeyEvent.VK_PAGE_DOWN), 58 | END (Keys.END,KeyEvent.VK_END), 59 | HOME (Keys.HOME,KeyEvent.VK_HOME), 60 | LEFT (Keys.LEFT,KeyEvent.VK_LEFT), 61 | ARROW_LEFT (Keys.ARROW_LEFT,KeyEvent.VK_LEFT), 62 | UP (Keys.UP,KeyEvent.VK_UP), 63 | ARROW_UP (Keys.ARROW_UP,KeyEvent.VK_UP), 64 | RIGHT (Keys.RIGHT,KeyEvent.VK_RIGHT), 65 | ARROW_RIGHT (Keys.ARROW_RIGHT,KeyEvent.VK_RIGHT), 66 | DOWN (Keys.DOWN,KeyEvent.VK_DOWN), 67 | ARROW_DOWN (Keys.ARROW_DOWN,KeyEvent.VK_DOWN), 68 | INSERT (Keys.INSERT,KeyEvent.VK_INSERT), 69 | DELETE (Keys.DELETE,KeyEvent.VK_DELETE), 70 | SEMICOLON (Keys.SEMICOLON,KeyEvent.VK_SEMICOLON), 71 | EQUALS (Keys.EQUALS,KeyEvent.VK_EQUALS), 72 | NUMPAD0 (Keys.NUMPAD0,KeyEvent.VK_NUMPAD0), 73 | NUMPAD1 (Keys.NUMPAD1,KeyEvent.VK_NUMPAD1), 74 | NUMPAD2 (Keys.NUMPAD2,KeyEvent.VK_NUMPAD2), 75 | NUMPAD3 (Keys.NUMPAD3,KeyEvent.VK_NUMPAD3), 76 | NUMPAD4 (Keys.NUMPAD4,KeyEvent.VK_NUMPAD4), 77 | NUMPAD5 (Keys.NUMPAD5,KeyEvent.VK_NUMPAD5), 78 | NUMPAD6 (Keys.NUMPAD6,KeyEvent.VK_NUMPAD6), 79 | NUMPAD7 (Keys.NUMPAD7,KeyEvent.VK_NUMPAD7), 80 | NUMPAD8 (Keys.NUMPAD8,KeyEvent.VK_NUMPAD8), 81 | NUMPAD9 (Keys.NUMPAD9,KeyEvent.VK_NUMPAD9), 82 | MULTIPLY (Keys.MULTIPLY,KeyEvent.VK_MULTIPLY), 83 | ADD (Keys.ADD,KeyEvent.VK_ADD), 84 | SEPARATOR (Keys.SEPARATOR,KeyEvent.VK_SEPARATOR), 85 | SUBTRACT (Keys.SUBTRACT,KeyEvent.VK_SUBTRACT), 86 | DECIMAL (Keys.DECIMAL,KeyEvent.VK_DECIMAL), 87 | DIVIDE (Keys.DIVIDE,KeyEvent.VK_DIVIDE), 88 | F1 (Keys.F1,KeyEvent.VK_F1), 89 | F2 (Keys.F2,KeyEvent.VK_F2), 90 | F3 (Keys.F3,KeyEvent.VK_F3), 91 | F4 (Keys.F4,KeyEvent.VK_F4), 92 | F5 (Keys.F5,KeyEvent.VK_F5), 93 | F6 (Keys.F6,KeyEvent.VK_F6), 94 | F7 (Keys.F7,KeyEvent.VK_F7), 95 | F8 (Keys.F8,KeyEvent.VK_F8), 96 | F9 (Keys.F9,KeyEvent.VK_F9), 97 | F10 (Keys.F10,KeyEvent.VK_F10), 98 | F11 (Keys.F11,KeyEvent.VK_F11), 99 | F12 (Keys.F12,KeyEvent.VK_F12), 100 | META (Keys.META,KeyEvent.VK_META), 101 | COMMAND (Keys.COMMAND,KeyEvent.VK_META), 102 | ; 103 | 104 | 105 | private Keys mappedKey; 106 | private int mappedEvent; 107 | 108 | KeyInfo(Keys mapThisKey, int toThisEvent ) { 109 | mappedKey = mapThisKey; 110 | mappedEvent = toThisEvent; 111 | } 112 | 113 | 114 | public Keys getKey() { 115 | return mappedKey; 116 | } 117 | 118 | public String getEvent() { 119 | return String.valueOf(mappedEvent); 120 | } 121 | 122 | @Override 123 | public String toString() { 124 | return "KeyInfo[mappedKey="+mappedKey+" is mapped to event "+mappedEvent+"]"; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/selenium/configuration/SessionControl.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.core.selenium.configuration; 28 | 29 | import io.appium.java_client.TouchAction; 30 | 31 | import org.openqa.selenium.interactions.Actions; 32 | 33 | import com.automation.seletest.core.selenium.threads.SessionContext; 34 | import com.automation.seletest.core.selenium.webAPI.WebController; 35 | import com.automation.seletest.core.services.webSync.WaitFor; 36 | import com.automation.seletest.core.services.factories.StrategyFactory; 37 | import com.automation.seletest.core.spring.ApplicationContextProvider; 38 | import com.automation.seletest.core.testNG.assertions.Assert; 39 | import com.thoughtworks.selenium.Selenium; 40 | 41 | /** 42 | * This class returns all the interfaces - objects used for testing 43 | * @author Giannis Papadakis(mailTo:gpapadakis84@gmail.com) 44 | * 45 | */ 46 | public final class SessionControl { 47 | 48 | /** 49 | * AssertTest 50 | * @return AssertTest instance 51 | */ 52 | public static Assert verifyController(){ 53 | return SessionContext.session().getAssertion(); 54 | } 55 | 56 | /** 57 | * Actions builder 58 | * @return Actions instance 59 | */ 60 | public static Actions actionsBuilder(){ 61 | return SessionContext.session().getActions(); 62 | } 63 | 64 | 65 | /** 66 | * TouchAction builder 67 | * @return TouchAction instance 68 | */ 69 | public static TouchAction touchactionsBuilder(){ 70 | return SessionContext.session().getTouchAction(); 71 | } 72 | 73 | /** 74 | * Selenium 75 | * @return Selenium instance 76 | */ 77 | public static Selenium selenium(){ 78 | return SessionContext.session().getSelenium(); 79 | } 80 | 81 | /** 82 | * Wait Strategy 83 | * @return WaitFor 84 | */ 85 | public static WaitFor waitController() { 86 | return ApplicationContextProvider.getApplicationContext().getBean(StrategyFactory.class).getWaitStrategy(SessionContext.getSession().getWaitStrategy()); 87 | } 88 | 89 | /** 90 | * Web Strategy 91 | * @return WebController 92 | */ 93 | public static WebController webController() { 94 | return ApplicationContextProvider.getApplicationContext().getBean(StrategyFactory.class).getControllerStrategy(SessionContext.getSession().getControllerStrategy()); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/selenium/threads/SessionContext.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | This file is part of the Seletest by Papadakis Giannis . 4 | 5 | Copyright (c) 2014, Papadakis Giannis 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without modification, 9 | are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | package com.automation.seletest.core.selenium.threads; 29 | 30 | import com.automation.seletest.core.spring.ApplicationContextProvider; 31 | import io.appium.java_client.AppiumDriver; 32 | import lombok.Getter; 33 | import lombok.Setter; 34 | import lombok.extern.slf4j.Slf4j; 35 | import org.openqa.selenium.remote.RemoteWebDriver; 36 | import org.springframework.aop.target.ThreadLocalTargetSource; 37 | import org.testng.Reporter; 38 | 39 | import java.util.Stack; 40 | 41 | 42 | /** 43 | * SessionContext 44 | * @author Giannis Papadakis(mailTo:gpapadakis84@gmail.com) 45 | * 46 | */ 47 | @Slf4j 48 | @SuppressWarnings("rawtypes") 49 | public class SessionContext { 50 | 51 | /**Constant for session*/ 52 | private final static String session="session"; 53 | 54 | /** 55 | * Get the thread in parallel execution from a target Source 56 | * @return SessionProperties instance 57 | */ 58 | public static SessionProperties session(){ 59 | return (SessionProperties) innerContext(ThreadLocalTargetSource.class).getTarget(); 60 | } 61 | 62 | /** 63 | * Session object 64 | * @return SessionProperties instance 65 | */ 66 | public static SessionProperties getSession(){ 67 | return (SessionProperties) Reporter.getCurrentTestResult().getAttribute(session); 68 | } 69 | 70 | /** 71 | * Return the ThreadLocalTargetSource 72 | * @param targetBean Class for target bean to be ThreadLocal 73 | * @return ThreadLocalTargetSource instance 74 | */ 75 | protected static ThreadLocalTargetSource innerContext(Class targetBean) { 76 | return (ThreadLocalTargetSource) ApplicationContextProvider.getApplicationContext().getBean(targetBean); 77 | } 78 | 79 | /** 80 | * Destroy instances of the thread 81 | * @throws Exception 82 | */ 83 | public static void cleanSession() throws Exception{ 84 | threadStack.removeElement(getSession());//remove element from thread stack 85 | getSession().cleanSession(); 86 | innerContext(ThreadLocalTargetSource.class).destroy(); 87 | log.debug("*********************Object removed from thread stack, new size is: {}*****************************", threadStack.size()); 88 | } 89 | 90 | /** 91 | * Log thread instance 92 | */ 93 | public static void setSessionProperties(){ 94 | threadStack.push(session()); 95 | log.debug("{} stored in {}",session(),threadStack); 96 | String driver=""; 97 | if(session().getWebDriver() instanceof RemoteWebDriver && !(session().getWebDriver() instanceof AppiumDriver)) { 98 | driver="Web Test: "+session().getWebDriver().toString().split(":")[0]; 99 | } else if(session().getWebDriver() instanceof AppiumDriver) { 100 | driver="Mobile Test: "+session().getWebDriver().toString().split(":")[0]; 101 | } 102 | log.info("Session started with type of driver: {}", driver); 103 | Thread.currentThread().setName("SeletestFramework ["+driver+"] - session Active "+System.currentTimeMillis()%2048); 104 | } 105 | 106 | /**Clean all active threads stored in stack 107 | * @throws Exception 108 | * 109 | */ 110 | public static void cleanSessionsFromStack() throws Exception { 111 | while(!threadStack.isEmpty()){ 112 | SessionContext.stopSession(0); 113 | } 114 | } 115 | /** 116 | * Clean specific thread from a Stack with threads 117 | * @param index Index in stack 118 | * @throws Exception 119 | */ 120 | public static void stopSession(int index) throws Exception { 121 | threadStack.get(index).cleanSession(); 122 | innerContext(ThreadLocalTargetSource.class).destroy(); 123 | threadStack.removeElement(threadStack.get(index)); 124 | log.debug("*********************Object removed from thread stack, new size is: {}*****************************", threadStack.size()); 125 | } 126 | 127 | /**Stack for storing instances of thread objects*/ 128 | @Getter @Setter 129 | public static Stack threadStack = new Stack<>(); 130 | 131 | } 132 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/selenium/threads/SessionProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | package com.automation.seletest.core.selenium.threads; 29 | 30 | 31 | 32 | import com.automation.seletest.core.selenium.configuration.SessionControl; 33 | import com.automation.seletest.core.selenium.webAPI.WebController.CloseSession; 34 | import com.automation.seletest.core.services.utilities.PerformanceUtils; 35 | import com.automation.seletest.core.testNG.assertions.Assert; 36 | import com.thoughtworks.selenium.Selenium; 37 | import io.appium.java_client.TouchAction; 38 | import lombok.Getter; 39 | import lombok.Setter; 40 | import lombok.extern.slf4j.Slf4j; 41 | import org.openqa.selenium.WebDriver; 42 | import org.openqa.selenium.WebElement; 43 | import org.openqa.selenium.interactions.Actions; 44 | 45 | import java.util.ArrayList; 46 | import java.util.List; 47 | import java.util.concurrent.Future; 48 | 49 | 50 | /** 51 | * Custom objects per session 52 | * @author Giannis Papadakis(mailTo:gpapadakis84@gmail.com) 53 | * @param 54 | */ 55 | @Slf4j 56 | public class SessionProperties { 57 | 58 | /**The wait until timeout*/ 59 | @Getter @Setter 60 | int waitUntil = 5; 61 | 62 | /**The remoteWebDriver object*/ 63 | @Getter @Setter 64 | T webDriver; 65 | 66 | /**The selenium object*/ 67 | @Getter @Setter 68 | Selenium selenium; 69 | 70 | /**Actions class**/ 71 | @Getter @Setter 72 | Actions actions; 73 | 74 | /**List of all asynchronous verifications**/ 75 | @Getter @Setter 76 | ArrayList> verifications; 77 | 78 | /**Performance class**/ 79 | @Getter @Setter 80 | PerformanceUtils performance; 81 | 82 | /**Assertions class**/ 83 | @Getter @Setter 84 | Assert assertion; 85 | 86 | /**TouchAction class**/ 87 | @Getter @Setter 88 | TouchAction touchAction; 89 | 90 | /** Wait Strategy*/ 91 | @Getter @Setter 92 | String waitStrategy="webDriverWait"; 93 | 94 | /** WebDriver-Selenium controller strategy*/ 95 | @Getter @Setter 96 | String controllerStrategy="webDriverControl"; 97 | 98 | /** WebDriver-Selenium webSync strategy*/ 99 | @Getter @Setter 100 | String actionsStrategy="webDriverActions"; 101 | 102 | /**List of web elements*/ 103 | @Getter @Setter 104 | List webElements; 105 | 106 | /** 107 | * Initialize objects per session and close session!!! 108 | */ 109 | public void cleanSession(){ 110 | 111 | //Quits driver 112 | if(webDriver!=null){ 113 | SessionControl.webController().quit(CloseSession.QUIT); 114 | } 115 | 116 | log.info("Session {} closed!!!", webDriver.toString().replace("(null)", "")); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/selenium/webAPI/elements/Locators.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.core.selenium.webAPI.elements; 28 | 29 | 30 | import io.appium.java_client.MobileBy; 31 | 32 | import org.openqa.selenium.By; 33 | 34 | @SuppressWarnings("unchecked") 35 | public enum Locators { 36 | 37 | //-------------------------------------------------- CoreProperties for Locators --------------------->>>>>>>>>>>>>>>>> 38 | /** The Constant XPATH. */ 39 | XPATH("xpath"){ 40 | 41 | @Override 42 | public By setLocator(String locator) { 43 | return By.xpath(findLocatorSubstring(locator)); 44 | } 45 | }, 46 | 47 | /** The Constant CSS. */ 48 | CSS("css"){ 49 | 50 | @Override 51 | public By setLocator(String locator) { 52 | return By.cssSelector(findLocatorSubstring(locator)); 53 | } 54 | }, 55 | 56 | /** The Constant XPATHEXPR. */ 57 | XPATHEXPR("//"){ 58 | 59 | @Override 60 | public By setLocator(String locator) { 61 | return By.xpath(locator); 62 | } 63 | }, 64 | 65 | 66 | /** The Constant NAME. */ 67 | NAME("name"){ 68 | 69 | @Override 70 | public By setLocator(String locator) { 71 | return By.name(findLocatorSubstring(locator)); 72 | } 73 | }, 74 | 75 | 76 | /** The Constant LINK. */ 77 | LINK("link"){ 78 | 79 | @Override 80 | public By setLocator(String locator) { 81 | return By.linkText(findLocatorSubstring(locator)); 82 | } 83 | }, 84 | 85 | /** The Constant ID. */ 86 | ID("id"){ 87 | 88 | @Override 89 | public By setLocator(String locator) { 90 | return By.id(findLocatorSubstring(locator)); 91 | } 92 | }, 93 | 94 | /** The Constant TAGNAME. */ 95 | TAGNAME("tagname"){ 96 | 97 | @Override 98 | public By setLocator(String locator) { 99 | return By.tagName(findLocatorSubstring(locator)); 100 | } 101 | }, 102 | 103 | /** The Constant JQUERY. */ 104 | JQUERY("jquery"){ 105 | 106 | @Override 107 | public By setLocator(String locator) { 108 | return BySelector.ByJQuery(findLocatorSubstring(locator)); 109 | } 110 | }, 111 | 112 | /** The Constant CLASSNAME. */ 113 | CLASSNAME("className"){ 114 | 115 | @Override 116 | public By setLocator(String locator) { 117 | return By.className(findLocatorSubstring(locator)); 118 | } 119 | }, 120 | 121 | /** The Constant ANDROIDUIAUTOMATOR. */ 122 | ANDROIDUIAUTOMATOR("androidUIAutomator"){ 123 | 124 | @Override 125 | public MobileBy setLocator(String locator) { 126 | return (MobileBy) MobileBy.AndroidUIAutomator(findLocatorSubstring(locator)); 127 | } 128 | }, 129 | 130 | /** The Constant IOSUIAUTOMATOR. */ 131 | IOSUIAUTOMATOR("iOSUIAutomator"){ 132 | 133 | @Override 134 | public MobileBy setLocator(String locator) { 135 | return (MobileBy) MobileBy.IosUIAutomation(findLocatorSubstring(locator)); 136 | } 137 | }, 138 | 139 | /** The Constant ACCESSIBILITYID. */ 140 | ACCESSIBILITYID("accessibilityId"){ 141 | 142 | @Override 143 | public MobileBy setLocator(String locator) { 144 | return (MobileBy) MobileBy.AccessibilityId(findLocatorSubstring(locator)); 145 | } 146 | }, 147 | ; 148 | public abstract T setLocator(String locator); 149 | 150 | /**The value of enum type*/ 151 | private String value; 152 | 153 | private Locators(final String locator) { 154 | this.value = locator; 155 | 156 | } 157 | 158 | synchronized static String findLocatorSubstring(String locator){ 159 | return locator.substring(locator.indexOf('=')+1); 160 | } 161 | 162 | /**Get locator by value 163 | * 164 | * @return locator 165 | */ 166 | public String getLocator() { 167 | return value; 168 | } 169 | 170 | /** 171 | * Return enum for given value 172 | * @param locator String lcoator to use 173 | * @return Locators enum object 174 | */ 175 | static synchronized public Locators findByLocator(String locator) { 176 | if (locator != null) { 177 | for (Locators locatorUsed : Locators.values()) { 178 | if (locator.startsWith(locatorUsed.getLocator())) { 179 | return locatorUsed; 180 | } 181 | } 182 | } 183 | 184 | return null; 185 | } 186 | 187 | 188 | 189 | } 190 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/services/annotations/DataSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.core.services.annotations; 28 | 29 | import static java.lang.annotation.ElementType.CONSTRUCTOR; 30 | import static java.lang.annotation.ElementType.METHOD; 31 | import static java.lang.annotation.ElementType.TYPE; 32 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 33 | 34 | import java.lang.annotation.Documented; 35 | import java.lang.annotation.Retention; 36 | import java.lang.annotation.Target; 37 | 38 | /** 39 | * DataDriven custom annotation 40 | * @author Giannis Papadakis (mailTo:gpapadakis84@gmail.com) 41 | * 42 | */ 43 | @Documented 44 | @Retention(RUNTIME) 45 | @Target({CONSTRUCTOR, METHOD, TYPE}) 46 | public @interface DataSource { 47 | 48 | /** 49 | * The filePath 50 | * @return filePath the File Path in order to load properties 51 | */ 52 | String filePath() default ""; 53 | 54 | /** 55 | * Enum for data type 56 | * @author Giannis Papadakis (mailTo:gpapadakis84@gmail.com) 57 | * 58 | */ 59 | public enum Data{CSV,PROPERTIES,EXCEL} 60 | 61 | /** 62 | * Data type to be used 63 | * @return enum data type (csv/ excel sheet/ properties) 64 | */ 65 | Data dataType() default Data.PROPERTIES; 66 | 67 | 68 | 69 | 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/services/annotations/JSHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.core.services.annotations; 28 | 29 | import static java.lang.annotation.ElementType.CONSTRUCTOR; 30 | import static java.lang.annotation.ElementType.METHOD; 31 | import static java.lang.annotation.ElementType.TYPE; 32 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 33 | 34 | import java.lang.annotation.Documented; 35 | import java.lang.annotation.Retention; 36 | import java.lang.annotation.Target; 37 | 38 | /** 39 | * JSHandle interface for executing JS scripts with aspects. 40 | * @author Giannis Papadakis (mailTo:gpapadakis84@gmail.com) 41 | * 42 | */ 43 | @Documented 44 | @Retention(RUNTIME) 45 | @Target({CONSTRUCTOR, METHOD, TYPE}) 46 | public @interface JSHandle { 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/services/annotations/Monitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.core.services.annotations; 28 | 29 | import static java.lang.annotation.ElementType.CONSTRUCTOR; 30 | import static java.lang.annotation.ElementType.METHOD; 31 | import static java.lang.annotation.ElementType.TYPE; 32 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 33 | 34 | import java.lang.annotation.Documented; 35 | import java.lang.annotation.Retention; 36 | import java.lang.annotation.Target; 37 | 38 | /** 39 | * Monitor interface for getting iformation of executed method by aspect advice 40 | * @author Giannis Papadakis (mailTo:gpapadakis84@gmail.com) 41 | * 42 | */ 43 | @Documented 44 | @Retention(RUNTIME) 45 | @Target({CONSTRUCTOR, METHOD, TYPE}) 46 | public @interface Monitor { 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/services/annotations/RetryFailure.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | package com.automation.seletest.core.services.annotations; 29 | 30 | import java.lang.annotation.Documented; 31 | import java.lang.annotation.ElementType; 32 | import java.lang.annotation.Retention; 33 | import java.lang.annotation.RetentionPolicy; 34 | import java.lang.annotation.Target; 35 | 36 | /** 37 | * This is a custom annotation for retrying execution of methods using aspectJ advices 38 | * @author Giannis Papadakis(mailTo:gpapadakis84@gmail.com) 39 | * 40 | */ 41 | @Documented 42 | @Retention(RetentionPolicy.RUNTIME) 43 | @Target(ElementType.METHOD) 44 | public @interface RetryFailure { 45 | 46 | /** 47 | * sleepMillis 48 | * @return The thread sleep before reexecuting invoked method 49 | */ 50 | int sleepMillis() default 1000; 51 | 52 | /** 53 | * retryCount 54 | * @return the number of method invocation count 55 | */ 56 | int retryCount() default 1; 57 | 58 | /** 59 | * message 60 | * @return message the message after throwing RunTime exception if after retry the result is the same 61 | */ 62 | String message() default "Retry limit exceeded."; 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/services/annotations/SeleniumTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.core.services.annotations; 28 | 29 | import java.lang.annotation.Documented; 30 | import java.lang.annotation.Retention; 31 | import java.lang.annotation.Target; 32 | 33 | import static java.lang.annotation.ElementType.CONSTRUCTOR; 34 | import static java.lang.annotation.ElementType.METHOD; 35 | import static java.lang.annotation.ElementType.TYPE; 36 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 37 | 38 | /** 39 | * This annotation defines Web Test 40 | * @author Giannis Papadakis (mailTo:gpapadakis84@gmail.com) 41 | * 42 | */ 43 | @Documented 44 | @Retention(RUNTIME) 45 | @Target({CONSTRUCTOR, METHOD, TYPE}) 46 | public @interface SeleniumTest { 47 | 48 | /** 49 | * AssertionType enum to specify type of assertion level (SOFT - HARD) 50 | */ 51 | public enum AssertionType{SOFT,HARD} 52 | 53 | /** 54 | * DriverType to specify if selenium 1 or webdriver api are used for @Test 55 | */ 56 | public enum DriverType{SELENIUM,WEBDRIVER,APPIUMDRIVER} 57 | 58 | /** 59 | * driver The driver type for the @Test 60 | * @return the type of driver 61 | */ 62 | DriverType driver() default DriverType.WEBDRIVER; 63 | 64 | /** 65 | * AssertioType 66 | * @return AssertionType the type of assertion to apply to @Test 67 | */ 68 | AssertionType assertion() default AssertionType.SOFT; 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/services/annotations/VerifyLog.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Giannis Papadakis . 3 | 4 | Copyright (c) 2014, Giannis Papadakis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.core.services.annotations; 28 | 29 | import java.lang.annotation.Documented; 30 | import java.lang.annotation.ElementType; 31 | import java.lang.annotation.Retention; 32 | import java.lang.annotation.RetentionPolicy; 33 | import java.lang.annotation.Target; 34 | 35 | /** 36 | * VerifyLog interface 37 | * @author Giannis Papadakis(mailTo:gpapadakis84@gmail.com) 38 | * 39 | */ 40 | @Documented 41 | @Retention(RetentionPolicy.RUNTIME) 42 | @Target(ElementType.METHOD) 43 | public @interface VerifyLog { 44 | 45 | 46 | /** 47 | * messagePass 48 | * @return the message displayed in HTML report for passed assertion 49 | */ 50 | String messagePass(); 51 | 52 | /** 53 | * messageFail 54 | * @return the message displayed in HTML report for failed assertion 55 | */ 56 | String messageFail(); 57 | 58 | /** 59 | * message 60 | * @return the message displayed in HTML report displaying parameters of invoked method 61 | */ 62 | String message(); 63 | 64 | /** 65 | * Defines if we want to take screenshot of web page after assertion is failed... 66 | * @return true if we want to capture screenshot on error 67 | */ 68 | boolean screenShot() default true; 69 | 70 | /** 71 | * highlight element after assertion passed or failed 72 | * @return true if we want to highlight elements 73 | */ 74 | boolean highlight() default false; 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/services/factories/StrategyFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.core.services.factories; 28 | 29 | 30 | import com.automation.seletest.core.selenium.common.ActionsController; 31 | import com.automation.seletest.core.selenium.webAPI.WebController; 32 | import com.automation.seletest.core.services.webSync.WaitFor; 33 | 34 | /** 35 | * WaitStrategyFactory 36 | * @author Giannis Papadakis (mailTo:gpapadakis84@gmail.com) 37 | */ 38 | public interface StrategyFactory { 39 | 40 | /**Gets the strategy for waiting for conditions*/ 41 | WaitFor getWaitStrategy(String waitController); 42 | 43 | /**Gets the elementController type*/ 44 | WebController getControllerStrategy(String elementController); 45 | 46 | /**Gets the actionsController type*/ 47 | ActionsController getActionsStrategy(String actionsController); 48 | 49 | } 50 | 51 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/services/network/HttpClient.java: -------------------------------------------------------------------------------- 1 | package com.automation.seletest.core.services.network; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Service; 5 | import org.springframework.web.client.RestTemplate; 6 | 7 | /** 8 | * HttpClient class. 9 | * @author Giannis Papadakis (mailTo:gpapadakis84@gmail.com) 10 | * 11 | */ 12 | @Service 13 | public class HttpClient { 14 | 15 | @Autowired 16 | RestTemplate template; 17 | 18 | /** 19 | * GET http request to Rest API 20 | * @param uri The uri to send GET request 21 | * @param responseType The class of the response type 22 | * @param arguments Object... for arguments to send GET request 23 | * @param 24 | * @return T 25 | */ 26 | public T getHTTPRequest(String uri, Class responseType, Object... arguments){ 27 | return (T) template.getForObject(uri,responseType, arguments); 28 | } 29 | 30 | /** 31 | * POST http reqest to Rest API 32 | * @param uri The uri to send POST request 33 | * @param request The object request 34 | * @param responseType The class of the response type 35 | * @param arguments Object... for arguments to send POST request 36 | * @param 37 | * @return T 38 | */ 39 | public T postHTTPRequest(String uri, Object request, Class responseType, Object... arguments){ 40 | return (T) template.postForObject(uri, request, responseType, arguments); 41 | } 42 | 43 | 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/services/network/SSHUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Giannis Papadakis . 3 | 4 | Copyright (c) 2014, Giannis Papadakis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.core.services.network; 28 | 29 | import java.io.BufferedReader; 30 | import java.io.BufferedWriter; 31 | import java.io.InputStreamReader; 32 | import java.io.OutputStreamWriter; 33 | 34 | import lombok.Getter; 35 | import lombok.Setter; 36 | import lombok.extern.slf4j.Slf4j; 37 | 38 | import org.springframework.stereotype.Component; 39 | 40 | import com.jcraft.jsch.Channel; 41 | import com.jcraft.jsch.ChannelExec; 42 | import com.jcraft.jsch.JSch; 43 | import com.jcraft.jsch.Session; 44 | import com.jcraft.jsch.UIKeyboardInteractive; 45 | import com.jcraft.jsch.UserInfo; 46 | 47 | /** 48 | * SSHUtils class. 49 | * @author Giannis Papadakis(mailTo:gpapadakis84@gmail.com) 50 | * 51 | */ 52 | @Component 53 | @Slf4j 54 | public class SSHUtils { 55 | 56 | /** 57 | * Execute command 58 | * @param host 59 | * @param user 60 | * @param passwd 61 | * @param cmd 62 | * @return String the reply of remote session 63 | */ 64 | public String execCmd (String host, String user, String passwd, String cmd){ 65 | String replyy = ""; 66 | String reply = null; 67 | try{ 68 | JSch jsch=new JSch(); 69 | Session session=jsch.getSession(user, host, 22); 70 | UserInfo ui = new MyUserInfo(passwd); 71 | session.setUserInfo(ui); 72 | session.setTimeout(600000); 73 | session.connect(); 74 | Channel channel=session.openChannel("exec"); 75 | ((ChannelExec)channel).setCommand(cmd); 76 | channel.setInputStream(null); 77 | InputStreamReader in = new InputStreamReader(channel.getInputStream()); 78 | OutputStreamWriter out = new OutputStreamWriter(channel.getOutputStream()); 79 | BufferedWriter bw = new BufferedWriter(out); 80 | BufferedReader br = new BufferedReader(in); 81 | channel.connect(); 82 | while ((reply = br.readLine()) != null) { 83 | bw.write(reply); 84 | replyy=replyy+"\n"+reply; 85 | bw.flush(); 86 | Thread.sleep(100); 87 | } 88 | while(true){ 89 | if(channel.isClosed()){ 90 | break; 91 | } try{ 92 | Thread.sleep(1500); 93 | } catch(Exception ee){ 94 | } 95 | } 96 | in.close(); 97 | out.close(); 98 | br.close(); 99 | bw.close(); 100 | channel.disconnect(); 101 | session.disconnect(); 102 | } 103 | catch(Exception e){ 104 | log.error("ERROR , Possible no connection with : "+user+" "+passwd+ " "+host+"\n\t\t please check LAN and vpn connection or host"); 105 | } 106 | return replyy; 107 | } 108 | } 109 | 110 | class MyUserInfo implements UserInfo, UIKeyboardInteractive{ 111 | 112 | @Getter @Setter public String password; 113 | 114 | public MyUserInfo(String passwd) { 115 | password = passwd; 116 | } 117 | 118 | @Override 119 | public boolean promptYesNo(String str){ 120 | return true; 121 | } 122 | 123 | @Override 124 | public String getPassphrase(){ 125 | return null; 126 | } 127 | 128 | @Override 129 | public boolean promptPassphrase(String message){ 130 | return true; 131 | } 132 | 133 | @Override 134 | public boolean promptPassword(String message){ 135 | return true; 136 | } 137 | 138 | @Override 139 | public void showMessage(String message){ 140 | 141 | } 142 | 143 | @Override 144 | public String[] promptKeyboardInteractive(String destination, 145 | String name, 146 | String instruction, 147 | String[] prompt, 148 | boolean[] echo){ 149 | return new String[]{password}; 150 | } 151 | 152 | 153 | } 154 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/services/utilities/LogUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.core.services.utilities; 28 | 29 | import javax.annotation.PostConstruct; 30 | 31 | import lombok.extern.slf4j.Slf4j; 32 | 33 | import org.springframework.stereotype.Service; 34 | import org.testng.Reporter; 35 | 36 | /** 37 | * Methods for logging 38 | * @author Giannis Papadakis(mailTo:gpapadakis84@gmail.com) 39 | * 40 | */ 41 | @Service("loggingService") 42 | @Slf4j 43 | public class LogUtils { 44 | 45 | 46 | @PostConstruct 47 | public void init(){ 48 | System.setProperty("org.uncommons.reportng.escape-output", "false"); 49 | } 50 | 51 | 52 | /** 53 | * Info log to console and in HTML report 54 | * @param message 55 | * @param style 56 | */ 57 | public void info(String message, String style) { 58 | log.info(message); 59 | Reporter.log("

" + message + "

"); 60 | } 61 | 62 | /** 63 | * Default info 64 | * @param message 65 | */ 66 | public void info(String message) { 67 | info(message, "\"color:black; font-size:1em;\""); 68 | } 69 | 70 | /** 71 | * Warn log to console and in HTML report 72 | * @param message 73 | * @param style 74 | */ 75 | public void warn(String message, String style) { 76 | log.warn(message); 77 | Reporter.log("

" + message + "

"); 78 | } 79 | 80 | /** 81 | * Default warn 82 | * @param message 83 | */ 84 | public void warn(String message) { 85 | warn(message, "\"color:#663366; font-size:1em;\""); 86 | } 87 | 88 | /** 89 | * Error log to console and in HTML report 90 | * @param message 91 | * @param style 92 | */ 93 | public void error(String message, String style) { 94 | log.error(message); 95 | Reporter.log("

" + message + "

"); 96 | } 97 | 98 | /** 99 | * Default error 100 | * @param message 101 | */ 102 | public void error(String message) { 103 | error(message, "\"color:red; font-size:1em;\""); 104 | } 105 | 106 | /** 107 | * Error message for verification methods 108 | * @param message 109 | */ 110 | public void verificationError(String message) { 111 | log.error(message); 112 | String alertmessage=""; 113 | String beforeSplitMessage=""; 114 | if(message.contains("------")){ 115 | alertmessage=message.replace("'", "\"").split("------")[1]; 116 | beforeSplitMessage=message.split("------")[0];} 117 | else { 118 | alertmessage="Error without StackTrace!!!"; 119 | beforeSplitMessage=message; 120 | } 121 | Reporter.log("

"+beforeSplitMessage+"

"); 122 | } 123 | 124 | 125 | } -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/services/utilities/MailUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | package com.automation.seletest.core.services.utilities; 29 | 30 | import org.springframework.beans.factory.annotation.Autowired; 31 | import org.springframework.mail.MailSender; 32 | import org.springframework.mail.SimpleMailMessage; 33 | import org.springframework.stereotype.Service; 34 | 35 | /** 36 | * This class used as a service for sending email runtime... 37 | * @author Giannis Papadakis(mailTo:gpapadakis84@gmail.com) 38 | * 39 | */ 40 | @Service("mailService") 41 | public class MailUtils { 42 | 43 | @Autowired 44 | private MailSender mailSender; 45 | 46 | @Autowired 47 | private SimpleMailMessage preConfiguredMessage; 48 | 49 | /** 50 | * This method will send compose and send the message 51 | * */ 52 | public void sendMail(String to, String subject, String body) 53 | { 54 | SimpleMailMessage message = new SimpleMailMessage(); 55 | message.setTo(to); 56 | message.setSubject(subject); 57 | message.setText(body); 58 | mailSender.send(message); 59 | } 60 | 61 | /** 62 | * This method will send a pre-configured message 63 | * */ 64 | public void sendPreConfiguredMail(String message) 65 | { 66 | SimpleMailMessage mailMessage = new SimpleMailMessage(preConfiguredMessage); 67 | mailMessage.setText(message); 68 | mailSender.send(mailMessage); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/services/utilities/PerformanceUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | package com.automation.seletest.core.services.utilities; 29 | 30 | import java.io.FileOutputStream; 31 | import java.io.IOException; 32 | 33 | import lombok.Getter; 34 | import lombok.Setter; 35 | import lombok.extern.slf4j.Slf4j; 36 | import net.lightbody.bmp.core.har.Har; 37 | import net.lightbody.bmp.proxy.ProxyServer; 38 | 39 | import org.openqa.selenium.Proxy; 40 | import org.springframework.beans.factory.config.ConfigurableBeanFactory; 41 | import org.springframework.context.annotation.Scope; 42 | import org.springframework.stereotype.Service; 43 | 44 | /** 45 | * Performance class 46 | * @author Giannis Papadakis (mailTo:gpapadakis84@gmail.com) 47 | * 48 | */ 49 | @Service("performanceService") 50 | @Slf4j 51 | @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) 52 | public class PerformanceUtils { 53 | 54 | @Getter @Setter ProxyServer server; 55 | @Getter @Setter Proxy proxy; 56 | @Getter @Setter Har har; 57 | 58 | /** 59 | * Starts the proxy server 60 | * @param port 61 | * @return 62 | * @throws Exception 63 | */ 64 | public ProxyServer proxyServer(int port) throws Exception{ 65 | ProxyServer server = new ProxyServer(port); 66 | server.start(); 67 | server.setCaptureHeaders(true); 68 | server.setCaptureContent(true); 69 | this.server=server; 70 | return server; 71 | } 72 | 73 | /** 74 | * Get the Selenium Proxy object 75 | * @param port 76 | * @return Proxy the selenium proxy 77 | */ 78 | public Proxy proxy(int port){ 79 | Proxy proxy = new Proxy(); 80 | proxy.setHttpProxy("localhost:"+port+""); 81 | return proxy; 82 | } 83 | 84 | /** 85 | * Gets performance data 86 | * @param server 87 | * @return 88 | */ 89 | public Har getPerformanceData(ProxyServer server){ 90 | Har har = server.getHar(); 91 | this.har=har; 92 | return har; 93 | } 94 | 95 | /** 96 | * writes performance data to file in har format 97 | * @param path 98 | * @param harFile 99 | * @throws IOException 100 | */ 101 | public void writePerformanceData(String path, Har harFile){ 102 | try{ 103 | FileOutputStream fos = new FileOutputStream(path); 104 | harFile.writeTo(fos);} 105 | catch(Exception ex){ 106 | log.error("Cannot write to external file: {}",ex.getMessage()); 107 | } 108 | } 109 | 110 | /** 111 | * Stops proxy server 112 | * @param server 113 | * @return 114 | * @throws Exception 115 | */ 116 | public PerformanceUtils stopServer(ProxyServer server){ 117 | try { 118 | server.stop(); 119 | } catch (Exception e) { 120 | log.error("Exception while trying to stop proxy server {}",e.getMessage()); 121 | } 122 | return this; 123 | } 124 | 125 | /** 126 | * Creates new har 127 | * @param name The name of the har file 128 | * @return The instance of the class 129 | */ 130 | public PerformanceUtils newHar(String name){ 131 | server.newHar(name); 132 | return this; 133 | } 134 | } -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/services/webSync/WaitFor.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.core.services.webSync; 28 | 29 | import org.openqa.selenium.Alert; 30 | 31 | 32 | /** 33 | * Interface for waiting methods 34 | * @author Giannis Papadakis(mailTo:gpapadakis84@gmail.com) * 35 | */ 36 | public interface WaitFor { 37 | 38 | 39 | /** Wait for element to be present in DOM 40 | * @param locator the locator of the WebElement to wait to be present in DOM 41 | * @return WebElement that is present in screen 42 | */ 43 | T waitForElementPresence(Object locator); 44 | 45 | /** Wait for element to be visible 46 | * @param locator the locator of the WebElement to wait for visibility 47 | * @return WebElement that is visible 48 | */ 49 | T waitForElementVisibility(Object locator); 50 | 51 | /** 52 | * Wait for element to be clickable 53 | * @param locator the locator of the WebElement to wait to be clickable 54 | * @return WebElement that is clickable 55 | */ 56 | T waitForElementToBeClickable(Object locator); 57 | 58 | /** 59 | * Wait for alert 60 | * @return Alert 61 | */ 62 | Alert waitForAlert(); 63 | 64 | /** 65 | * Wait for element to be invisble 66 | * @param locator the locator of the WebElement to wait to become invisible 67 | * @return true if element is invisible or false otherwise 68 | */ 69 | boolean waitForElementInvisibility(String locator); 70 | 71 | /** 72 | * Wait for text to be present in Element 73 | * @param locator 74 | * @return true if text present in webElement or false otherwise 75 | */ 76 | boolean waitForTextPresentinElement(Object locator,String text); 77 | 78 | /** 79 | * Wait for text to be present in attribute value 80 | * @param locator 81 | * @return true if text present in attribute value or false otherwise 82 | */ 83 | boolean waitForTextPresentinValue(Object locator,String text); 84 | 85 | 86 | /** 87 | * Wait for elements with matching locator to be present in screen 88 | * @param locator 89 | * @return List the elements to be present in screen 90 | */ 91 | T waitForPresenceofAllElements(String locator); 92 | 93 | /** 94 | * Wait for elements with matching locator to be visible in screen 95 | * @param locator 96 | * @return List the elements to be visible in screen 97 | */ 98 | T waitForVisibilityofAllElements(String locator); 99 | 100 | /** 101 | * Waits for a page to load 102 | */ 103 | void waitForPageLoaded(); 104 | 105 | /** 106 | * Waits for ajax call to be completed 107 | * @param timeout the timeout to wait 108 | */ 109 | void waitForAjaxCallCompleted(final long timeout); 110 | 111 | 112 | /** 113 | * Waits for element not to be present on screen 114 | * @param locator 115 | * @return true if element is not persent or false if element present 116 | */ 117 | boolean waitForElementNotPresent(String locator); 118 | 119 | /** 120 | * Waits for element to become invisible 121 | * @param locator 122 | * true if element is invisible 123 | */ 124 | boolean waitForElementInvisible(String locator); 125 | 126 | /** 127 | *Wait for title of page 128 | * @param title 129 | * @return true if title is the one provided 130 | */ 131 | boolean waitForPageTitle(String title); 132 | 133 | 134 | /** 135 | * Wait for element to become not clickable 136 | * @param locator 137 | * @return true if element is no more clickable 138 | */ 139 | boolean waitForElementNotClickable(Object locator); 140 | 141 | /** 142 | * Wait for Javascript finish loading in UI 143 | */ 144 | void waitForJSToLoad(); 145 | 146 | } 147 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/spring/ApplicationContextProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | package com.automation.seletest.core.spring; 29 | 30 | import org.springframework.beans.BeansException; 31 | import org.springframework.context.ApplicationContext; 32 | import org.springframework.context.ApplicationContextAware; 33 | import org.springframework.context.ApplicationEventPublisher; 34 | import org.springframework.context.ApplicationEventPublisherAware; 35 | import org.springframework.context.ConfigurableApplicationContext; 36 | import org.springframework.stereotype.Component; 37 | import org.testng.ITestContext; 38 | 39 | import com.automation.seletest.core.listeners.beanUtils.Events; 40 | import com.automation.seletest.core.services.annotations.SeleniumTest; 41 | 42 | 43 | /** 44 | * ApplicationContextProvider serves to get static instance of ApplicationContext 45 | * @author Giannis Papadakis(mailTo:gpapadakis84@gmail.com) 46 | * 47 | */ 48 | @Component 49 | @SuppressWarnings("static-access") 50 | public class ApplicationContextProvider implements ApplicationContextAware,ApplicationEventPublisherAware { 51 | 52 | /**Static access to ApplicatonCotext*/ 53 | private static ApplicationContext applicationContext; 54 | 55 | /**Publisher*/ 56 | private static ApplicationEventPublisher publisher; 57 | 58 | 59 | @Override 60 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 61 | this.applicationContext = applicationContext; 62 | } 63 | 64 | @Override 65 | public void setApplicationEventPublisher(ApplicationEventPublisher publisher) { 66 | this.publisher = publisher; 67 | } 68 | 69 | 70 | /** 71 | * Gets static application context 72 | * @return 73 | */ 74 | public static ApplicationContext getApplicationContext() { 75 | return applicationContext; 76 | } 77 | 78 | /** 79 | * Gets configurable application context 80 | * @return 81 | */ 82 | public static ConfigurableApplicationContext getConfigurableApplicationContext() { 83 | return (ConfigurableApplicationContext)applicationContext; 84 | } 85 | 86 | /** 87 | * Publish event for initializing a session (against Web or Mobile Application) 88 | * @param message 89 | */ 90 | public void publishInitializationEvent(String message, String hostUrl, boolean performance, ITestContext ctx) { 91 | this.publisher.publishEvent(new Events.InitializationEvent(this, message, hostUrl, performance,ctx)); 92 | } 93 | 94 | /** 95 | * Publish event for TestNG configuration 96 | * @param selenium 97 | * @param message 98 | */ 99 | public void publishTestNGEvent(SeleniumTest selenium, String message) { 100 | this.publisher.publishEvent(new Events.TestNGEvent(this, selenium, message)); 101 | } 102 | 103 | } -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/spring/AsyncSeletestExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Giannis Papadakis . 3 | 4 | Copyright (c) 2014, Giannis Papadakis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.core.spring; 28 | 29 | import com.automation.seletest.core.selenium.threads.SessionContext; 30 | import com.automation.seletest.core.testNG.assertions.SoftAssert; 31 | import lombok.extern.slf4j.Slf4j; 32 | import org.springframework.core.task.AsyncTaskExecutor; 33 | 34 | import java.util.concurrent.Callable; 35 | import java.util.concurrent.ExecutionException; 36 | import java.util.concurrent.Future; 37 | import java.util.concurrent.RejectedExecutionException; 38 | 39 | /** 40 | * ExceptionHandlingAsyncTaskExecutor class. 41 | * @author Giannis Papadakis(mailTo:gpapadakis84@gmail.com) 42 | * @param 43 | * 44 | */ 45 | @Slf4j 46 | public class AsyncSeletestExecutor implements AsyncTaskExecutor { 47 | 48 | /**The AsyncTaskExecutor*/ 49 | private final AsyncTaskExecutor executor; 50 | 51 | public AsyncSeletestExecutor(AsyncTaskExecutor executor) { 52 | this.executor = executor; 53 | } 54 | 55 | /* (non-Javadoc) 56 | * @see org.springframework.core.task.TaskExecutor#execute(java.lang.Runnable) 57 | */ 58 | @Override 59 | public void execute(Runnable task) { 60 | executor.execute(createWrappedRunnable(task)); 61 | } 62 | 63 | /* (non-Javadoc) 64 | * @see org.springframework.core.task.AsyncTaskExecutor#execute(java.lang.Runnable, long) 65 | */ 66 | @Override 67 | public void execute(Runnable task, long startTimeout) { 68 | executor.execute(createWrappedRunnable(task), startTimeout); 69 | } 70 | 71 | /* (non-Javadoc) 72 | * @see org.springframework.core.task.AsyncTaskExecutor#submit(java.lang.Runnable) 73 | */ 74 | @Override 75 | public Future submit(Runnable task) { 76 | return executor.submit(createWrappedRunnable(task)); 77 | } 78 | 79 | /* (non-Javadoc) 80 | * @see org.springframework.core.task.AsyncTaskExecutor#submit(java.util.concurrent.Callable) 81 | */ 82 | @Override 83 | public Future submit(Callable task) { 84 | Future futureTask; 85 | try { 86 | futureTask = executor.submit(createCallable(task)); 87 | if(!((SessionContext.getSession().getAssertion()).getAssertion() instanceof SoftAssert)){ 88 | futureTask.get(); 89 | log.debug("Assertion finished: {} , proceed to the next one if exists!!!", task); 90 | } else { 91 | SessionContext.getSession().getVerifications().add(futureTask); 92 | } 93 | log.debug("Future task submitted {}", task.toString()); 94 | } catch (InterruptedException | ExecutionException e) { 95 | log.error(String.format("Exception during executing future task: %s, stop submitting any further tasks!",e.getMessage())); 96 | throw new RejectedExecutionException(String.format("Reject any other verification task due to hard assertion error ----> %s ",e 97 | .getMessage())); 98 | 99 | } 100 | return futureTask; 101 | } 102 | 103 | /** 104 | * Create callable task 105 | * @param task 106 | * @return Callable 107 | */ 108 | private Callable createCallable(final Callable task) { 109 | return new Callable() { 110 | @Override 111 | public T call() throws Exception { 112 | try { 113 | log.debug("Thread Id {} for thread: ", Thread.currentThread().getId(),Thread.currentThread().getName()); 114 | return (T) task.call(); 115 | } catch (Exception ex) { 116 | handle(ex); 117 | throw ex; 118 | } 119 | } 120 | }; 121 | } 122 | 123 | 124 | /** 125 | * Create runnable task 126 | * @param task 127 | * @return Runnable 128 | */ 129 | private Runnable createWrappedRunnable(final Runnable task) { 130 | return new Runnable() { 131 | @Override 132 | public void run() { 133 | try { 134 | task.run(); 135 | } catch (Exception ex) { 136 | handle(ex); 137 | } 138 | } 139 | }; 140 | } 141 | 142 | /** 143 | * Handle exception for asynchronous execution method 144 | * @param ex 145 | * @throws Exception 146 | */ 147 | private void handle(Exception ex){ 148 | log.error("Error during @Async execution: {}", ex); 149 | } 150 | } -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/spring/SeletestDBTestBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | package com.automation.seletest.core.spring; 29 | 30 | import java.lang.reflect.Method; 31 | 32 | import org.springframework.test.context.ContextConfiguration; 33 | import org.springframework.test.context.testng.AbstractTransactionalTestNGSpringContextTests; 34 | import org.springframework.test.context.transaction.AfterTransaction; 35 | import org.springframework.test.context.transaction.BeforeTransaction; 36 | import org.springframework.test.context.transaction.TransactionConfiguration; 37 | import org.springframework.transaction.annotation.Transactional; 38 | import org.testng.annotations.AfterMethod; 39 | import org.testng.annotations.BeforeMethod; 40 | 41 | /** 42 | * This class is used as a base class for DB testing 43 | * @author Giannis Papadakis(mailTo:gpapadakis84@gmail.com) 44 | * 45 | */ 46 | @Transactional 47 | @TransactionConfiguration(defaultRollback = false) 48 | @ContextConfiguration({"classpath*:META-INF/spring/db*-context.xml" }) 49 | public abstract class SeletestDBTestBase extends AbstractTransactionalTestNGSpringContextTests { 50 | 51 | @BeforeMethod(alwaysRun = true) 52 | @Override 53 | protected synchronized void springTestContextBeforeTestMethod(Method testMethod) throws Exception { 54 | super.springTestContextBeforeTestMethod(testMethod); 55 | } 56 | 57 | 58 | @AfterMethod(alwaysRun = true) 59 | @Override 60 | protected synchronized void springTestContextAfterTestMethod(Method testMethod) throws Exception { 61 | super.springTestContextAfterTestMethod(testMethod); 62 | } 63 | 64 | @BeforeTransaction 65 | public void beforeTransaction(){ 66 | //TODO 67 | } 68 | 69 | @AfterTransaction 70 | public void afterTransaction(){ 71 | //TODO 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/spring/SpringTestBase.java: -------------------------------------------------------------------------------- 1 | package com.automation.seletest.core.spring; 2 | 3 | /** 4 | * Created by uocgp on 11/9/2015. 5 | */ 6 | 7 | import ch.qos.logback.classic.Level; 8 | import ch.qos.logback.classic.Logger; 9 | import com.automation.seletest.core.selenium.configuration.ConfigurationDriver; 10 | import org.slf4j.LoggerFactory; 11 | import org.springframework.test.context.ContextConfiguration; 12 | import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; 13 | import org.testng.annotations.BeforeClass; 14 | import org.testng.annotations.BeforeSuite; 15 | import org.testng.annotations.BeforeTest; 16 | 17 | /** 18 | * Test Base for TestNG test suites 19 | * Created by uocgp on 4/5/2015. 20 | */ 21 | @ContextConfiguration(classes=ConfigurationDriver.class) 22 | public class SpringTestBase extends AbstractTestNGSpringContextTests { 23 | 24 | @BeforeSuite(alwaysRun = true) 25 | @BeforeClass(alwaysRun = true) 26 | @BeforeTest(alwaysRun = true) 27 | @Override 28 | protected void springTestContextPrepareTestInstance() throws Exception { 29 | Logger root = (Logger) LoggerFactory.getLogger("com.automation.seletest"); 30 | if(System.getProperty("logging.level")!=null) { 31 | if (System.getProperty("logging.level").compareTo("INFO") == 0) { 32 | root.setLevel(Level.INFO); 33 | } else if (System.getProperty("logging.level").compareTo("DEBUG") == 0) { 34 | root.setLevel(Level.DEBUG); 35 | } else if (System.getProperty("logging.level").compareTo("WARN") == 0) { 36 | root.setLevel(Level.WARN); 37 | } else if (System.getProperty("logging.level").compareTo("ERROR") == 0) { 38 | root.setLevel(Level.ERROR); 39 | } 40 | } 41 | prepareTest(); 42 | } 43 | 44 | /** 45 | * Prepare Test loading application context 46 | * @throws Exception 47 | */ 48 | private void prepareTest() throws Exception { 49 | if (applicationContext == null) { 50 | super.springTestContextPrepareTestInstance(); 51 | } 52 | } 53 | 54 | } -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/testNG/DataSources.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.core.testNG; 28 | 29 | import java.lang.reflect.Method; 30 | import java.util.Map; 31 | 32 | import javax.annotation.PostConstruct; 33 | 34 | import org.springframework.beans.factory.annotation.Autowired; 35 | import org.springframework.stereotype.Component; 36 | import org.testng.ITestContext; 37 | import org.testng.annotations.DataProvider; 38 | 39 | import com.automation.seletest.core.services.utilities.FilesUtils; 40 | import com.automation.seletest.core.spring.ApplicationContextProvider; 41 | 42 | 43 | /** 44 | * DataSources class 45 | * @author Giannis Papadakis (mailTo:gpapadakis84@gmail.com) 46 | * 47 | */ 48 | @Component 49 | public class DataSources { 50 | 51 | /**Constant for excel file*/ 52 | private final static String EXCEL="xls"; 53 | 54 | /**Constant for excel sheet*/ 55 | private final static String EXCELSHEET="xlsSheet"; 56 | 57 | /**Constant for excel table*/ 58 | private final static String EXCELTABLE="xlsTable"; 59 | 60 | private static FilesUtils file; 61 | 62 | @Autowired 63 | private FilesUtils wiredfile; 64 | 65 | @PostConstruct 66 | public void init() { 67 | DataSources.file = wiredfile; 68 | } 69 | 70 | /** 71 | * Generic DataProvider that returns data from a Map 72 | * @param method 73 | * @return Object[][] with the Map that contains properties 74 | * @throws Exception 75 | */ 76 | @DataProvider(name = "GenericDataProvider") 77 | public static Object[][] getDataProvider(final Method method) throws Exception { 78 | Map map = ApplicationContextProvider.getApplicationContext().getBean(FilesUtils.class).readData(method); 79 | return new Object[][] { { map } }; 80 | } 81 | 82 | @DataProvider(name = "ExcelDataProvider",parallel=true) 83 | public static Object[][] createData(ITestContext context) throws Exception{ 84 | String testParam = context.getCurrentXmlTest().getParameter(EXCEL); 85 | String testParamSheet = context.getCurrentXmlTest().getParameter(EXCELSHEET); 86 | String testParamTable = context.getCurrentXmlTest().getParameter(EXCELTABLE); 87 | Object[][] retObjArr=file.getTableArray(testParam,testParamSheet,testParamTable); 88 | return(retObjArr); 89 | } 90 | 91 | 92 | 93 | 94 | 95 | 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/testNG/PostConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | package com.automation.seletest.core.testNG; 29 | 30 | import java.lang.annotation.Documented; 31 | import java.lang.annotation.ElementType; 32 | import java.lang.annotation.Inherited; 33 | import java.lang.annotation.Retention; 34 | import java.lang.annotation.RetentionPolicy; 35 | import java.lang.annotation.Target; 36 | 37 | import com.automation.seletest.pagecomponents.pageObjects.AbstractPage; 38 | 39 | /** 40 | * This annotation executes method of a class after invocation of a method 41 | * @author Giannis Papadakis(mailTo:gpapadakis84@gmail.com) 42 | * 43 | */ 44 | @Documented 45 | @Retention(RetentionPolicy.RUNTIME) 46 | @Target({ElementType.METHOD,ElementType.TYPE}) 47 | @Inherited 48 | public @interface PostConfiguration { 49 | 50 | /**As class we have any Page Object that extends AbstarctPage*/ 51 | Class> classReference(); 52 | 53 | /**Define the method name to execute*/ 54 | String method(); 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/testNG/PreConfiguration.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | This file is part of the Seletest by Papadakis Giannis . 4 | 5 | Copyright (c) 2014, Papadakis Giannis 6 | All rights reserved. 7 | 8 | Redistribution and use in source and binary forms, with or without modification, 9 | are permitted provided that the following conditions are met: 10 | 11 | * Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimer. 13 | * Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 21 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | package com.automation.seletest.core.testNG; 30 | 31 | import java.lang.annotation.Documented; 32 | import java.lang.annotation.ElementType; 33 | import java.lang.annotation.Inherited; 34 | import java.lang.annotation.Retention; 35 | import java.lang.annotation.RetentionPolicy; 36 | import java.lang.annotation.Target; 37 | 38 | import com.automation.seletest.pagecomponents.pageObjects.AbstractPage; 39 | 40 | /** 41 | * This annotation executes method of a class before invocation of a method 42 | * @author Giannis Papadakis(mailTo:gpapadakis84@gmail.com) 43 | * 44 | */ 45 | @Documented 46 | @Retention(RetentionPolicy.RUNTIME) 47 | @Target({ElementType.METHOD,ElementType.TYPE}) 48 | @Inherited 49 | public @interface PreConfiguration { 50 | 51 | /**As class we have any Page Object that extends AbstarctPage*/ 52 | Class> classReference(); 53 | 54 | /**Define the method name to execute*/ 55 | String method(); 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/core/testNG/assertions/SoftAssert.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.core.testNG.assertions; 28 | 29 | import java.util.Map; 30 | 31 | import org.springframework.beans.factory.annotation.Autowired; 32 | import org.springframework.beans.factory.annotation.Configurable; 33 | import org.testng.ITestResult; 34 | import org.testng.Reporter; 35 | import org.testng.asserts.Assertion; 36 | import org.testng.asserts.IAssert; 37 | import org.testng.collections.Maps; 38 | 39 | import com.automation.seletest.core.services.utilities.LogUtils; 40 | 41 | /** 42 | * This class used for executing soft assertions 43 | * @author Giannis Papadakis(mailTo:gpapadakis84@gmail.com) 44 | * 45 | */ 46 | @Configurable 47 | public class SoftAssert extends Assertion { 48 | 49 | @Autowired 50 | LogUtils log; 51 | 52 | /** LinkedHashMap to preserve the order*/ 53 | private static final Map m_errors = Maps.newLinkedHashMap(); 54 | 55 | @Override 56 | public void executeAssert(IAssert a) { 57 | try { 58 | a.doAssert(); 59 | log.info("[EXPECTED]:"+a.getExpected()+" [ACTUAL]:"+ a.getActual()+"***** ----> VERIFICATION: "+a.getMessage(),"color:green; margin-left:20px;"); 60 | } catch(AssertionError ex) { 61 | log.verificationError("*****[EXPECTED]:"+a.getExpected()+" [ACTUAL]:"+ a.getActual()+"***** ----> VERIFICATION: "+a.getMessage()+ "------StackTrace:\\n"+findLineExceptionOccured(ex)); 62 | onAssertFailure(a, ex); 63 | m_errors.put(ex, a); 64 | } 65 | } 66 | 67 | /** 68 | * Assert failures after test execution 69 | */ 70 | public void assertAll() { 71 | if (! m_errors.isEmpty()) { 72 | StringBuilder sb = new StringBuilder("The following asserts failed:\n"); 73 | boolean first = true; 74 | for (Map.Entry ae : m_errors.entrySet()) { 75 | if (first) { 76 | first = false; 77 | } else { 78 | sb.append(", "); 79 | } 80 | sb.append(ae.getKey()); 81 | } 82 | //set the test as failed 83 | Reporter.getCurrentTestResult().setStatus(ITestResult.FAILURE); 84 | org.testng.Reporter.setCurrentTestResult(Reporter.getCurrentTestResult()); 85 | m_errors.clear(); 86 | } 87 | } 88 | 89 | /** 90 | * Display stackTrace to HTML report 91 | * @param ex 92 | * @return StackTrace to String 93 | */ 94 | private String findLineExceptionOccured(AssertionError ex){ 95 | StringBuilder sb = new StringBuilder(""); 96 | 97 | for(StackTraceElement line:ex.getStackTrace()){ 98 | if(line.getClassName().startsWith("com.automation.seletest")) { 99 | sb.append("Class: "+line.getClassName()+ " method: "+line.getMethodName()+" line: "+line.getLineNumber()+"\\n"); 100 | } 101 | } 102 | return sb.toString(); 103 | 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/pagecomponents/pageObjects/AbstractPage.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.pagecomponents.pageObjects; 28 | 29 | import com.automation.seletest.core.selenium.common.ActionsController; 30 | import com.automation.seletest.core.selenium.threads.SessionContext; 31 | import com.automation.seletest.core.selenium.webAPI.WebController; 32 | import com.automation.seletest.core.services.factories.StrategyFactory; 33 | import com.automation.seletest.core.spring.SeletestWebTestBase; 34 | import org.openqa.selenium.support.PageFactory; 35 | import org.openqa.selenium.support.ui.ExpectedCondition; 36 | import org.openqa.selenium.support.ui.FluentWait; 37 | import org.openqa.selenium.support.ui.Wait; 38 | import org.springframework.beans.factory.annotation.Autowired; 39 | import org.springframework.stereotype.Component; 40 | 41 | import java.util.concurrent.TimeUnit; 42 | 43 | /** 44 | * Abstract super class serves as base page object 45 | * @author Giannis Papadakis (mailTo:gpapadakis84@gmail.com) 46 | * 47 | * @param 48 | */ 49 | @SuppressWarnings({ "unchecked", "rawtypes" }) 50 | @Component 51 | public abstract class AbstractPage extends SeletestWebTestBase{ 52 | 53 | @Autowired 54 | StrategyFactory strategy; 55 | 56 | /**Timeout to load a page*/ 57 | private static final int LOAD_TIMEOUT = 30; 58 | 59 | /**Polling time*/ 60 | private static final int REFRESH_RATE = 2; 61 | 62 | /** 63 | * Opens a page object 64 | * @param clazz 65 | * @return T the type of object 66 | */ 67 | public T openPage(Class clazz) { 68 | T page = PageFactory.initElements(SessionContext.getSession().getWebDriver(), clazz); 69 | ExpectedCondition pageLoadCondition = ((AbstractPage) page).getPageLoadCondition(); 70 | waitForPageToLoad(pageLoadCondition); 71 | return page; 72 | } 73 | 74 | /** 75 | * Condition for loading a page object 76 | * @return ExpectedCondition condition to load a page 77 | */ 78 | protected abstract ExpectedCondition getPageLoadCondition(); 79 | 80 | /** 81 | * Wait for page to load 82 | * @param pageLoadCondition 83 | */ 84 | private void waitForPageToLoad(ExpectedCondition pageLoadCondition) { 85 | Wait wait = new FluentWait(SessionContext.getSession().getWebDriver()) 86 | .withTimeout(LOAD_TIMEOUT, TimeUnit.SECONDS) 87 | .pollingEvery(REFRESH_RATE, TimeUnit.SECONDS); 88 | 89 | wait.until(pageLoadCondition); 90 | } 91 | 92 | 93 | public WebController webControl() { 94 | return strategy.getControllerStrategy(SessionContext.getSession().getControllerStrategy()); 95 | } 96 | 97 | public ActionsController actionsControl() { 98 | return strategy.getActionsStrategy(SessionContext.getSession().getActionsStrategy()); 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/pagecomponents/pageObjects/Android/CalculatorPage.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Giannis Papadakis . 3 | 4 | Copyright (c) 2014, Giannis Papadakis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.pagecomponents.pageObjects.Android; 28 | 29 | import com.automation.seletest.core.selenium.mobileAPI.AppiumController; 30 | import com.automation.seletest.core.selenium.webAPI.elements.Locators; 31 | import com.automation.seletest.pagecomponents.pageObjects.AbstractPage; 32 | import org.openqa.selenium.support.ui.ExpectedCondition; 33 | import org.openqa.selenium.support.ui.ExpectedConditions; 34 | import org.springframework.beans.factory.annotation.Autowired; 35 | import org.springframework.stereotype.Component; 36 | 37 | import java.text.MessageFormat; 38 | 39 | /** 40 | * @author Giannis Papadakis(mailTo:gpapadakis84@gmail.com) 41 | * 42 | */ 43 | @Component 44 | public class CalculatorPage extends AbstractPage{ 45 | 46 | @Autowired 47 | AppiumController appium; 48 | 49 | public enum CalculatorLocators { 50 | 51 | IPF_RESULT("id=my.android.calc:id/input") { 52 | @Override 53 | public String log() { 54 | return "Result field " + IPF_RESULT.get() + "'!!!"; 55 | } 56 | }, 57 | 58 | BTN_1("id=my.android.calc:id/b030") { 59 | @Override 60 | public String log() { 61 | return "Button 1 " + BTN_1.get() + "'!!!"; 62 | } 63 | }, 64 | BTN_3("id=my.android.calc:id/b032") { 65 | @Override 66 | public String log() { 67 | return "Button 3: '" + BTN_3.get() + "'!!!"; 68 | } 69 | }, 70 | BTN_X("id=my.android.calc:id/b023") { 71 | @Override 72 | public String log() { 73 | return "Button x: '" + BTN_X.get() + "'!!!"; 74 | } 75 | }, 76 | BTN_EQUALS("id=my.android.calc:id/b044") { 77 | @Override 78 | public String log() { 79 | return "Button equals: '" + BTN_EQUALS.get() + "'!!!"; 80 | } 81 | }, 82 | 83 | BTN_CLEAR("id=my.android.calc:id/b000") { 84 | @Override 85 | public String log() { 86 | return "Button clear: '" + BTN_CLEAR.get() + "'!!!"; 87 | } 88 | }, 89 | ; 90 | 91 | private final String myLocator; 92 | 93 | CalculatorLocators(String locator) { 94 | myLocator = locator; 95 | } 96 | 97 | public String get() { 98 | return myLocator; 99 | } 100 | 101 | public String getWithParams(Object... params) { 102 | return MessageFormat.format(myLocator, params); 103 | } 104 | 105 | // Abstract method which need to be implemented 106 | public abstract String log(); 107 | 108 | } 109 | 110 | /** 111 | * Press the "C" button to clear previous result 112 | * @return CalculatorPage 113 | */ 114 | public CalculatorPage clearResult() { 115 | webControl().click(CalculatorLocators.BTN_CLEAR.get()); 116 | return this; 117 | } 118 | 119 | /** 120 | * Executes Multiplication for two numbers 121 | * @param button1 122 | * @param button2 123 | * @return CalculatorPage 124 | */ 125 | public CalculatorPage calculateMultiplication(String button1, String button2) { 126 | actionsControl(). 127 | tap(button1). 128 | tap(CalculatorLocators.BTN_X.get()). 129 | tap(button2). 130 | tap(CalculatorLocators.BTN_EQUALS.get()). 131 | performTouchActions(); 132 | return this; 133 | } 134 | 135 | /* (non-Javadoc) 136 | * @see com.automation.seletest.pagecomponents.pageObjects.AbstractPage#getPageLoadCondition() 137 | */ 138 | @Override 139 | protected ExpectedCondition getPageLoadCondition() { 140 | return ExpectedConditions.presenceOfElementLocated(Locators.findByLocator(CalculatorLocators.BTN_X.get()).setLocator(CalculatorLocators.BTN_X.get())); 141 | 142 | } 143 | 144 | } 145 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/pagecomponents/pageObjects/Web/GitHubSearchPage.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Giannis Papadakis . 3 | 4 | Copyright (c) 2014, Giannis Papadakis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.pagecomponents.pageObjects.Web; 28 | 29 | import java.text.MessageFormat; 30 | 31 | import lombok.extern.slf4j.Slf4j; 32 | 33 | import org.openqa.selenium.support.ui.ExpectedCondition; 34 | import org.openqa.selenium.support.ui.ExpectedConditions; 35 | import org.springframework.stereotype.Component; 36 | 37 | import com.automation.seletest.core.selenium.common.KeyInfo; 38 | import com.automation.seletest.core.selenium.webAPI.elements.Locators; 39 | import com.automation.seletest.pagecomponents.pageObjects.AbstractPage; 40 | 41 | /** 42 | * @author Giannis Papadakis(mailTo:gpapadakis84@gmail.com) 43 | * 44 | */ 45 | @Component 46 | @Slf4j 47 | public class GitHubSearchPage extends AbstractPage{ 48 | 49 | 50 | 51 | public enum GitHubPageLocators { 52 | 53 | DIV_PARENT("$(\"[class*='container clearfix']\").css(\"borderStyle\", \"dotted\" )") { 54 | @Override 55 | public String log() { 56 | return "Parent div element" + DIV_PARENT.get() + "'!!!"; 57 | } 58 | }, 59 | BTN_SIGN_IN("jquery=a:contains(Sign in)") { 60 | @Override 61 | public String log() { 62 | return "Button \"Sign in\" used with locator: '" + BTN_SIGN_IN.get() + "'!!!"; 63 | } 64 | }, 65 | BTN_SEARCH("name=q") { 66 | @Override 67 | public String log() { 68 | return "Button \"Search\" used with locator: '" + BTN_SEARCH.get() + "'!!!"; 69 | } 70 | }, 71 | ; 72 | 73 | private final String myLocator; 74 | 75 | GitHubPageLocators(String locator) { 76 | myLocator = locator; 77 | } 78 | 79 | public String get() { 80 | return myLocator; 81 | } 82 | 83 | public String getWithParams(Object... params) { 84 | return MessageFormat.format(myLocator, params); 85 | } 86 | 87 | // Abstract method which need to be implemented 88 | public abstract String log(); 89 | 90 | } 91 | 92 | public GitHubSearchPage searchRepository(String search) { 93 | webControl().type(GitHubPageLocators.BTN_SEARCH.get(),search); 94 | actionsControl().press(KeyInfo.ENTER).performActions(); 95 | return this; 96 | } 97 | 98 | 99 | public GitHubSearchPage openPage() { 100 | openPage(GitHubSearchPage.class); 101 | for(GitHubPageLocators s: GitHubPageLocators.values()) { 102 | log.info("The following locator will be used in GitHubPage PO : "+s.log()); 103 | } 104 | webControl().executeJS(GitHubPageLocators.DIV_PARENT.get()); 105 | return this; 106 | } 107 | 108 | /* (non-Javadoc) 109 | * @see com.automation.seletest.pagecomponents.pageObjects.AbstractPage#getPageLoadCondition() 110 | */ 111 | @Override 112 | protected ExpectedCondition getPageLoadCondition() { 113 | return ExpectedConditions.presenceOfElementLocated(Locators.findByLocator(GitHubPageLocators.BTN_SEARCH.get()).setLocator(GitHubPageLocators.BTN_SEARCH.get())); 114 | 115 | } 116 | 117 | 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/pagecomponents/pageObjects/Web/GitHubSearchResultPage.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Giannis Papadakis . 3 | 4 | Copyright (c) 2014, Giannis Papadakis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.pagecomponents.pageObjects.Web; 28 | 29 | import java.text.MessageFormat; 30 | 31 | import org.openqa.selenium.support.ui.ExpectedCondition; 32 | import org.openqa.selenium.support.ui.ExpectedConditions; 33 | import org.springframework.stereotype.Component; 34 | 35 | import com.automation.seletest.core.selenium.webAPI.elements.Locators; 36 | import com.automation.seletest.pagecomponents.pageObjects.AbstractPage; 37 | 38 | /** 39 | * @author Giannis Papadakis(mailTo:gpapadakis84@gmail.com) 40 | * 41 | */ 42 | @Component 43 | public class GitHubSearchResultPage extends AbstractPage{ 44 | public enum GitHubSearchPageLocators { 45 | 46 | TXT_RESULT_HEADER("jquery=a:contains({0})") { 47 | @Override 48 | public String log() { 49 | return "Header of the result with locator " + TXT_RESULT_HEADER.get() + "!!!"; 50 | } 51 | }, 52 | DIV_SEARCH_MENU("css=div.search-menu-container") { 53 | @Override 54 | public String log() { 55 | return "Search menu with locator " + DIV_SEARCH_MENU.get() + "!!!"; 56 | } 57 | }, 58 | ; 59 | 60 | private final String myLocator; 61 | 62 | GitHubSearchPageLocators(String locator) { 63 | myLocator = locator; 64 | } 65 | 66 | public String get() { 67 | return myLocator; 68 | } 69 | 70 | public String getWithParams(Object... params) { 71 | return MessageFormat.format(myLocator, params); 72 | } 73 | 74 | // Abstract method which need to be implemented 75 | public abstract String log(); 76 | } 77 | 78 | /* (non-Javadoc) 79 | * @see com.automation.seletest.pagecomponents.pageObjects.AbstractPage#getPageLoadCondition() 80 | */ 81 | @Override 82 | protected ExpectedCondition getPageLoadCondition() { 83 | return ExpectedConditions.presenceOfElementLocated(Locators.findByLocator(GitHubSearchPageLocators.DIV_SEARCH_MENU.get()).setLocator(GitHubSearchPageLocators.DIV_SEARCH_MENU.get())); 84 | 85 | } 86 | 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/com/automation/seletest/pagecomponents/pageObjects/Web/GooglePage.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Papadakis Giannis . 3 | 4 | Copyright (c) 2014, Papadakis Giannis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package com.automation.seletest.pagecomponents.pageObjects.Web; 28 | 29 | import java.text.MessageFormat; 30 | 31 | import org.openqa.selenium.support.ui.ExpectedCondition; 32 | import org.openqa.selenium.support.ui.ExpectedConditions; 33 | import org.springframework.beans.factory.annotation.Autowired; 34 | import org.springframework.stereotype.Component; 35 | 36 | import com.automation.seletest.core.selenium.webAPI.elements.Locators; 37 | import com.automation.seletest.core.services.utilities.LogUtils; 38 | import com.automation.seletest.pagecomponents.pageObjects.AbstractPage; 39 | 40 | @Component 41 | public class GooglePage extends AbstractPage{ 42 | 43 | @Autowired 44 | LogUtils log; 45 | 46 | public enum GooglePageLocators { 47 | 48 | IPF_SEARCH("name=q") { 49 | @Override 50 | public String log() { 51 | return "TextField \"Search\" used with locator: '" + IPF_SEARCH.get() + "'!!!"; 52 | } 53 | }, 54 | BTN_SUBMIT("name=btnG") { 55 | @Override 56 | public String log() { 57 | return "Button \"Search\" used with locator: '" + BTN_SUBMIT.get() + "'!!!"; 58 | } 59 | }, 60 | ; 61 | 62 | private final String myLocator; 63 | 64 | GooglePageLocators(String locator) { 65 | myLocator = locator; 66 | } 67 | 68 | public String get() { 69 | return myLocator; 70 | } 71 | 72 | public String getWithParams(Object... params) { 73 | return MessageFormat.format(myLocator, params); 74 | } 75 | 76 | // Abstract method which need to be implemented 77 | public abstract String log(); 78 | 79 | } 80 | 81 | 82 | public GooglePage typeSearch(String text){ 83 | webControl().getLocation(GooglePageLocators.IPF_SEARCH.get()); 84 | webControl().type(GooglePageLocators.IPF_SEARCH.get(), text); 85 | return this; 86 | } 87 | 88 | /** 89 | * Press search with Actions Builder 90 | * @return 91 | */ 92 | public GooglePage buttonSearch(){ 93 | webControl().click(GooglePageLocators.BTN_SUBMIT.get()); 94 | return this; 95 | } 96 | 97 | 98 | /** 99 | * Opens this page object 100 | * @return 101 | */ 102 | public GooglePage open() { 103 | for(GooglePageLocators s:GooglePageLocators.values()){ 104 | log.info(s.log()); 105 | } 106 | return openPage(GooglePage.class); 107 | } 108 | 109 | /* (non-Javadoc) 110 | * @see com.automation.seletest.pagecomponents.pageObjects.AbstractPage#getPageLoadCondition() 111 | */ 112 | @Override 113 | protected ExpectedCondition getPageLoadCondition() { 114 | return ExpectedConditions.presenceOfElementLocated(Locators.findByLocator(GooglePageLocators.IPF_SEARCH.get()).setLocator(GooglePageLocators.IPF_SEARCH.get())); 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/aop.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/spring/app-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 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 | 41 | 42 | 43 | 44 | 45 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/spring/cache-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 22 | 23 | 24 | 27 | 28 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/spring/db-context.xml: -------------------------------------------------------------------------------- 1 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | ${hibernate.hbm2ddl.auto} 29 | ${hibernate.dialect} 30 | ${hibernate.import} 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/spring/jmx-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 15 | 16 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 27 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/spring/mail-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | smtp 24 | true 25 | true 26 | true 27 | 28 | 29 | 30 | 31 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/spring/thread-pool-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/main/resources/core.properties: -------------------------------------------------------------------------------- 1 | #verification attributes 2 | elementLocator=The element with locator 3 | found=was found in screen 4 | notfound=was not found in screen 5 | notfoundVisible=was not found visible 6 | foundVisible=was found visible 7 | foundwithText=was found with text 8 | notfoundwithText=was not found with text 9 | foundEditable=was found editable 10 | notfoundEditable=was not found editable 11 | foundClickable=was found clickable 12 | notfoundClickable=was not found clickable 13 | numberElements=Number of elements 14 | 15 | #String parameters for core 16 | web_browser=browserType 17 | client_logs=clientLogs 18 | jvm_logs=JVMLogs 19 | api_logs=APILogs 20 | application_type=applicationType 21 | 22 | #The parameter that determines that application is Web based. 23 | test_type_web=web 24 | 25 | #The parameter that determines that application is Mobile based (Android-iOS). 26 | test_type_mobile=mobile 27 | 28 | #The parameter that determines the capabilities that will be used to start a new WebDriver object. 29 | selenium_cap=capabilities 30 | 31 | #The parameter that determines the android capabilities that will be used to start a new AppiumDriver object. 32 | android_cap=androidcapabilities 33 | 34 | ######### The parameter that determines the iOS capabilities that will be used to start a new AppiumDriver object. ######### 35 | ios_cap=ioscapabilities 36 | 37 | ######### The parameter that determines the profile to start a new WebDriver object. ######### 38 | profile_Web=profileDriver 39 | 40 | ######### The parameter that determines the appium profile to start a new AppiumDriver object. ######### 41 | profile_Mobile=profileAppium 42 | 43 | ######### The parameter that determines the performance measurements. ######### 44 | performance=performance 45 | 46 | ######### The parameter that determines the Grid host. ######### 47 | grid_host=gridHost 48 | 49 | ######### The parameter that determines the Grid port. ######### 50 | grid_port=gridPort 51 | 52 | #########Parameter that determined the URL of the web app under test######### 53 | host=hostURL 54 | 55 | 56 | #MOBILE PROPERTIES 57 | ######### The parameter that determines the app path######### 58 | app_path=app 59 | 60 | ######### The parameter that determines of the app will be launched automatically######### 61 | auto_lauch=autoLaunch 62 | 63 | ######### The parameter that determines app launch######### 64 | app_act=appActivity 65 | 66 | ######### The parameter that determines udid for iOS real device######### 67 | udid=udid 68 | 69 | ######### The parameter that determines appPackage######### 70 | app_package=appPackage 71 | 72 | #CoreProperties used for test status-actions on UI 73 | color_pass=Chartreuse 74 | color_fail=FireBrick 75 | color_action=BurlyWood 76 | dotted=dotted 77 | 78 | #CoreProperties used for initialization phase 79 | ######### The parameter for true string*/ 80 | true=true 81 | 82 | ######### The parameter for false string*/ 83 | false=false 84 | 85 | ###########CoreProperties for locators##### 86 | #########The Constant XPATH.######### 87 | xpath=xpath 88 | 89 | ######### The Constant CSS. ######### 90 | css=css 91 | 92 | ######### The Constant NAME.######### 93 | name=name 94 | 95 | ######### The Constant LINK. ######### 96 | link=link 97 | 98 | ######### The Constant ID. ######### 99 | id=id 100 | 101 | ######### The Constant TAGNAME. ######### 102 | tagname=tagname 103 | 104 | ######### The Constant JQUERY. ######### 105 | jquery=jquery 106 | 107 | ######### JMX CONSTANTS ######### 108 | seletest.jmx.rmi.port=9999 109 | jmx.username=giannis 110 | jmx.password=giannis -------------------------------------------------------------------------------- /src/main/resources/ehcache.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 16 | 17 | 18 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/main/resources/jQuerify.js: -------------------------------------------------------------------------------- 1 | /** dynamically load jQuery */ 2 | (function(jqueryUrl, callback) { 3 | if (typeof jqueryUrl != 'string') { 4 | jqueryUrl = 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'; 5 | } 6 | if (typeof jQuery == 'undefined') { 7 | var script = document.createElement('script'); 8 | var head = document.getElementsByTagName('head')[0]; 9 | var done = false; 10 | script.onload = script.onreadystatechange = (function() { 11 | if (!done && (!this.readyState || this.readyState == 'loaded' 12 | || this.readyState == 'complete')) { 13 | done = true; 14 | script.onload = script.onreadystatechange = null; 15 | head.removeChild(script); 16 | callback(); 17 | } 18 | }); 19 | script.src = jqueryUrl; 20 | head.appendChild(script); 21 | } 22 | else { 23 | callback(); 24 | } 25 | })(arguments[0], arguments[arguments.length - 1]); -------------------------------------------------------------------------------- /src/main/resources/template.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | $title 7 | 8 | $body 9 | 10 | -------------------------------------------------------------------------------- /src/test/java/AndroidDemoTest/AndroidDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Giannis Papadakis . 3 | 4 | Copyright (c) 2014, Giannis Papadakis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package AndroidDemoTest; 28 | 29 | import java.util.concurrent.ExecutionException; 30 | 31 | import org.springframework.beans.factory.annotation.Autowired; 32 | import org.testng.annotations.Test; 33 | 34 | import com.automation.seletest.core.selenium.configuration.SessionControl; 35 | import com.automation.seletest.core.services.annotations.SeleniumTest; 36 | import com.automation.seletest.core.spring.SeletestWebTestBase; 37 | import com.automation.seletest.core.testNG.PreConfiguration; 38 | import com.automation.seletest.pagecomponents.pageObjects.Android.CalculatorPage; 39 | import com.automation.seletest.pagecomponents.pageObjects.Android.CalculatorPage.CalculatorLocators; 40 | 41 | /** 42 | * @author Giannis Papadakis(mailTo:gpapadakis84@gmail.com) 43 | * 44 | */ 45 | public class AndroidDemo extends SeletestWebTestBase{ 46 | 47 | @Autowired 48 | CalculatorPage calculate; 49 | 50 | @SeleniumTest 51 | @Test 52 | @PreConfiguration(classReference = CalculatorPage.class, method = "clearResult") 53 | public void CalculateMultiplication() throws InterruptedException, ExecutionException{ 54 | calculate.calculateMultiplication(CalculatorLocators.BTN_1.get(), CalculatorLocators.BTN_3.get()); 55 | SessionControl.verifyController().textPresentinElement(CalculatorLocators.IPF_RESULT.get(), "3").get(); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/WebDemoTest/GitHubSearch.java: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of the Seletest by Giannis Papadakis . 3 | 4 | Copyright (c) 2014, Giannis Papadakis 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | package WebDemoTest; 28 | 29 | import java.util.Map; 30 | import java.util.concurrent.ExecutionException; 31 | 32 | import org.springframework.beans.factory.annotation.Autowired; 33 | import org.testng.annotations.Test; 34 | 35 | import com.automation.seletest.core.selenium.configuration.SessionControl; 36 | import com.automation.seletest.core.services.annotations.DataSource; 37 | import com.automation.seletest.core.services.annotations.SeleniumTest; 38 | import com.automation.seletest.core.services.annotations.SeleniumTest.AssertionType; 39 | import com.automation.seletest.core.services.annotations.SeleniumTest.DriverType; 40 | import com.automation.seletest.core.spring.SeletestWebTestBase; 41 | import com.automation.seletest.pagecomponents.pageObjects.Web.GitHubSearchPage; 42 | import com.automation.seletest.pagecomponents.pageObjects.Web.GitHubSearchResultPage.GitHubSearchPageLocators; 43 | 44 | 45 | 46 | @DataSource(filePath="./target/test-classes/DataSources/demoTest.properties") 47 | @SeleniumTest 48 | public class GitHubSearch extends SeletestWebTestBase{ 49 | 50 | @Autowired 51 | GitHubSearchPage gitHub; 52 | 53 | @SeleniumTest(assertion=AssertionType.HARD, driver=DriverType.SELENIUM) 54 | @Test 55 | public void gitHubSearch(Map map) throws InterruptedException, ExecutionException{ 56 | gitHub.openPage().searchRepository(map.get("gitHubsearch")); 57 | SessionControl.verifyController().elementPresent(GitHubSearchPageLocators.TXT_RESULT_HEADER.getWithParams(map.get("gitHubExpectedResult"))).get(); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/WebDemoTest/GoogleTest.java: -------------------------------------------------------------------------------- 1 | package WebDemoTest; 2 | 3 | import java.util.Map; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.testng.annotations.Test; 7 | 8 | import com.automation.seletest.core.selenium.configuration.SessionControl; 9 | import com.automation.seletest.core.services.annotations.DataSource; 10 | import com.automation.seletest.core.services.annotations.SeleniumTest; 11 | import com.automation.seletest.core.services.annotations.SeleniumTest.AssertionType; 12 | import com.automation.seletest.core.services.annotations.SeleniumTest.DriverType; 13 | import com.automation.seletest.core.spring.SeletestWebTestBase; 14 | import com.automation.seletest.pagecomponents.pageObjects.Web.GooglePage; 15 | 16 | @DataSource(filePath="./target/test-classes/DataSources/demoTest.properties") 17 | @SeleniumTest 18 | public class GoogleTest extends SeletestWebTestBase{ 19 | 20 | @Autowired 21 | GooglePage googlePage; 22 | 23 | @SeleniumTest(assertion=AssertionType.HARD, driver=DriverType.SELENIUM) 24 | @Test 25 | public void googleSearch(Map map){ 26 | googlePage.typeSearch(map.get("GoogleSearch")).buttonSearch(); 27 | SessionControl.verifyController().elementPresent(map.get("ExpectedResult")); 28 | } 29 | 30 | @SeleniumTest(assertion=AssertionType.SOFT) 31 | @Test 32 | public void googleSearch2(Map map){ 33 | googlePage.typeSearch(map.get("GoogleSearch2")).buttonSearch(); 34 | SessionControl.verifyController().elementPresent(map.get("ExpectedResult")); 35 | SessionControl.verifyController().elementPresent("//text1"); 36 | SessionControl.verifyController().elementPresent("//text2"); 37 | 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/test/resources/BrowserSettings/browser.properties: -------------------------------------------------------------------------------- 1 | ########################################################### 2 | #################Driver Executables######################## 3 | ########################################################### 4 | browser.chromedriver=http://chromedriver.storage.googleapis.com/2.14/chromedriver 5 | browser.chromedriver.path=./target/test-classes/BrowserSettings/chromedriver 6 | browser.iedriver.path=./target/test-classes/BrowserSettings/IEDriverServer_Win32_2.42.0.zip 7 | browser.iedriver=https://selenium.googlecode.com/files/IEDriverServer.exe 8 | browser.phantomJs=./target/test-classes/BrowserSettings/phantomjs-1.9.7-windows/phantomjs.exe 9 | browser.phantomJs.path=https://bitbucket.org/ariya/phantomjs/downloads/phantomjs 10 | browser.chrome.properties=.... 11 | 12 | ########################################################### 13 | #################Email Configuration######################## 14 | ########################################################### 15 | email.name=seletest.giannis@gmail.com 16 | email.password=????? 17 | 18 | 19 | ########################################################### 20 | #################Networking################################ 21 | ########################################################### 22 | ##net.host=???? 23 | ##net.port=80 -------------------------------------------------------------------------------- /src/test/resources/DB/db.properties: -------------------------------------------------------------------------------- 1 | jdbc.driverClassName=com.mysql.jdbc.Driver 2 | jdbc.url=jdbc:mysql://localhost:3306/selenium 3 | jdbc.username=root 4 | jdbc.password=password -------------------------------------------------------------------------------- /src/test/resources/DataSources/Calculator.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gpap84/seletest/b5f5e14991601ed3932dcefaeea18ca268441789/src/test/resources/DataSources/Calculator.apk -------------------------------------------------------------------------------- /src/test/resources/DataSources/Data.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Gpap84/seletest/b5f5e14991601ed3932dcefaeea18ca268441789/src/test/resources/DataSources/Data.xls -------------------------------------------------------------------------------- /src/test/resources/DataSources/demoTest.properties: -------------------------------------------------------------------------------- 1 | GoogleSearch=https://github.com/GiannisPapadakis 2 | ExpectedResult=//*[contains(text(),'Giannis Papadakis')] 3 | GoogleSearch2=Nothing 4 | 5 | 6 | gitHubsearch=seletest 7 | gitHubExpectedResult=GiannisPapadakis 8 | -------------------------------------------------------------------------------- /src/test/resources/META-INF/spring/test-beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/test/resources/XMLSuites/AndroidDemoTest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/test/resources/XMLSuites/DemoTest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 18 | 19 | 20 | 22 | 23 | 24 | 25 | 26 | 28 | 29 | 30 | 31 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/test/resources/XMLSuites/GitHubSearch.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | Seletest.log 10 | true 11 | 12 | %-4relative [%thread] %-5level %logger{35} - %msg%n 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | --------------------------------------------------------------------------------