├── .gitignore ├── .gitmodules ├── main-pom.xml ├── pom.xml ├── proguard.conf ├── src ├── main │ └── java │ │ └── org │ │ └── imaginea │ │ └── test │ │ └── automation │ │ └── framework │ │ ├── config │ │ ├── ConfigException.java │ │ └── DefaultConfig.java │ │ ├── datadrive │ │ ├── BaseDataDrive.java │ │ ├── ClassParser.java │ │ ├── CsvDataDrive.java │ │ ├── DataDriveException.java │ │ └── ExcelDataDrive.java │ │ ├── datastore │ │ └── GlobalDataStore.java │ │ ├── dom │ │ ├── EWebElement.java │ │ ├── ElementOptions.java │ │ ├── NoEWebElementException.java │ │ └── filter │ │ │ ├── Filter.java │ │ │ ├── FilterType.java │ │ │ ├── NegatedTextMatcher.java │ │ │ ├── PatternTextMatcher.java │ │ │ ├── TextMatcher.java │ │ │ └── TextMatching.java │ │ ├── driver │ │ ├── CacheDriverFactory.java │ │ ├── IDriverFactory.java │ │ ├── IDriverProvider.java │ │ └── InbuiltDriverProvider.java │ │ ├── exceptions │ │ ├── TafException.java │ │ ├── TafRuntimeException.java │ │ └── UnexpectedPageException.java │ │ ├── keywordmodel │ │ ├── KeywordException.java │ │ ├── executor │ │ │ ├── KeywordExecutor.java │ │ │ └── KeywordFactory.java │ │ ├── keywords │ │ │ ├── IKeyword.java │ │ │ ├── KeywordBase.java │ │ │ └── MethodInfo.java │ │ ├── reader │ │ │ ├── CsvKeywordReader.java │ │ │ ├── ExcelKeywordReader.java │ │ │ ├── IKeywordReader.java │ │ │ ├── IKeywordStore.java │ │ │ ├── KeywordReaderException.java │ │ │ ├── ReaderFactory.java │ │ │ └── TafKeywordStore.java │ │ └── suite │ │ │ ├── CsvSuiteFileReader.java │ │ │ ├── ExcelSuiteFileReader.java │ │ │ ├── ISimpleTest.java │ │ │ ├── ISuiteFileReader.java │ │ │ ├── SimpleTest.java │ │ │ └── TestSuite.java │ │ ├── locator │ │ ├── CustomFieldDecorator.java │ │ ├── CustomPageFactory.java │ │ ├── LocatorException.java │ │ ├── locatorfiles │ │ │ ├── ILocatorFile.java │ │ │ ├── LocatorFileFactory.java │ │ │ └── PropertiesLocatorFile.java │ │ └── pagefactory │ │ │ ├── BrowserBasedElementLocator.java │ │ │ ├── BrowserBasedSimpleElementLocator.java │ │ │ ├── DriverBasedElementLocator.java │ │ │ ├── KeywordBasedAnnotations.java │ │ │ ├── KeywordBasedLocatorFactory.java │ │ │ └── SimpleLocatorFactory.java │ │ ├── pagemodel │ │ ├── AbstractPageClass.java │ │ ├── Browser.java │ │ ├── PageClass.java │ │ ├── PageException.java │ │ └── TestClass.java │ │ ├── testng │ │ └── listener │ │ │ ├── CustomTestNGMethod.java │ │ │ └── MethodInvokerListener.java │ │ └── util │ │ ├── PageObjectUtils.java │ │ ├── Utilities.java │ │ ├── VerifyUtil.java │ │ ├── readers │ │ ├── CsvReader.java │ │ └── ExcelReader.java │ │ └── selenium │ │ └── ui │ │ └── CustomExpectedConditions.java └── test │ └── java │ └── org │ └── imaginea │ └── test │ └── automation │ └── framework │ ├── TafTestClass.java │ ├── config │ └── DeafultConfigTest.java │ ├── datadrive │ ├── ClassParserTest.java │ └── TestDataClass.java │ ├── dom │ ├── EWebElementActionsTest.java │ ├── EWebElementTest.java │ └── TextMatcherTest.java │ ├── driver │ ├── CacheDriverFactoryTest.java │ └── TestDriverProviderSample.java │ ├── keywordmodel │ ├── DataDrivenSuiteTest.java │ ├── KeywordFileTest.java │ ├── SimpleKeywordTest.java │ └── TestKeywordDefinitionClass.java │ ├── locator │ └── factory │ │ └── CustomPageFactoryTest.java │ ├── testclasses │ ├── FailingPageClassA.java │ ├── FailingPageClassB.java │ ├── PageFactoryTestClass.java │ ├── PageFactoryTestClassWithFile.java │ ├── PassingPageClassA.java │ └── PassingPageClassB.java │ └── util │ ├── VerifyUtilTest.java │ └── selenium │ └── ui │ └── UtilitiesTest.java └── testng.xml /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | bin 3 | test-output 4 | src/test/resources 5 | .idea 6 | .settings 7 | doc/ 8 | javadoc/ 9 | surefire-reports/ 10 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "taf-test"] 2 | path = taf-test 3 | url = https://github.com/menonvarun/taf-test 4 | -------------------------------------------------------------------------------- /main-pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | org.imaginea 5 | testautomationframework 6 | 0.0.3 7 | jar 8 | TestAutomationFramework 9 | Test automation framework a geb implemntation in java. 10 | http://menonvarun.github.io/taf/index.html 11 | 12 | 13 | org.testng 14 | testng 15 | 6.8 16 | 17 | 18 | 19 | org.seleniumhq.selenium 20 | selenium-java 21 | 2.39.0 22 | 23 | 24 | 25 | xml-apis 26 | xml-apis 27 | 1.4.01 28 | 29 | 30 | org.uncommons 31 | reportng 32 | 1.1.4 33 | test 34 | 40 | 41 | 42 | org.apache.poi 43 | poi-ooxml 44 | 3.9 45 | 46 | 47 | 48 | net.sf.opencsv 49 | opencsv 50 | 2.3 51 | 52 | 53 | com.google.inject 54 | guice 55 | 3.0 56 | test 57 | 58 | 59 | net.sourceforge.htmlunit 60 | htmlunit 61 | 2.15 62 | 63 | 64 | 65 | 66 | 67 | localmvn 68 | file:///H:/opt/github/mvn-repo/snapshots 69 | 70 | 71 | localmvn 72 | file:///H:/opt/github/mvn-repo/releases 73 | 74 | 75 | 76 | 77 | 78 | 79 | org.apache.maven.plugins 80 | maven-compiler-plugin 81 | 82 | utf-8 83 | 1.7 84 | 1.7 85 | 86 | 87 | 88 | default-testCompile 89 | test-compile 90 | 91 | 92 | **/taf-test/*.java 93 | 94 | 95 | 96 | testCompile 97 | 98 | 99 | 100 | 101 | 102 | org.apache.maven.plugins 103 | maven-source-plugin 104 | 105 | 106 | attach-sources 107 | 108 | jar 109 | 110 | 111 | 112 | 113 | 114 | org.apache.maven.plugins 115 | maven-javadoc-plugin 116 | 117 | 118 | attach-javadocs 119 | 120 | jar 121 | 122 | 123 | 124 | 125 | 147 | 220 | 221 | 222 | 223 | 224 | src/main/resources 225 | 226 | 227 | src/main/java 228 | 229 | **/*.java 230 | 231 | 232 | 233 | 234 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | org.imaginea 5 | testautomationframework 6 | 0.0.5 7 | jar 8 | TestAutomationFramework 9 | Test automation framework a geb implementation in java. This contains all the code 10 | http://menonvarun.github.io/taf/index.html 11 | 12 | 13 | 14 | The Apache Software License, Version 2.0 15 | http://www.apache.org/licenses/LICENSE-2.0.txt 16 | repo 17 | 18 | 19 | 20 | 21 | 22 | menonvarun 23 | Varun Menon 24 | mr.varun.menon@gmail.com 25 | 26 | 27 | 28 | 29 | 30 | scm:git:https://github.com/menonvarun/taf.git 31 | scm:git:git@github.com:menonvarun/taf.git 32 | https://github.com/menonvarun/taf 33 | HEAD 34 | 35 | 36 | -Xdoclint:none 37 | 38 | 39 | 40 | 41 | org.testng 42 | testng 43 | 6.8 44 | 45 | 46 | 47 | org.seleniumhq.selenium 48 | selenium-java 49 | 2.44.0 50 | 51 | 52 | 53 | xml-apis 54 | xml-apis 55 | 1.4.01 56 | 57 | 58 | org.uncommons 59 | reportng 60 | 1.1.4 61 | test 62 | 68 | 69 | 70 | org.apache.poi 71 | poi-ooxml 72 | 3.9 73 | 74 | 75 | 76 | net.sf.opencsv 77 | opencsv 78 | 2.3 79 | 80 | 81 | com.google.inject 82 | guice 83 | 3.0 84 | test 85 | 86 | 87 | net.sourceforge.htmlunit 88 | htmlunit 89 | 2.15 90 | 91 | 92 | org.hamcrest 93 | hamcrest-all 94 | 1.3 95 | 96 | 97 | org.mockito 98 | mockito-all 99 | 1.10.19 100 | test 101 | 102 | 103 | 104 | 105 | 106 | 107 | localmvn 108 | file:///H:/opt/github/mvn-repo/snapshots 109 | 110 | 111 | localmvn 112 | file:///H:/opt/github/mvn-repo/releases 113 | 114 | 115 | 116 | 117 | 118 | 119 | maven-clean-plugin 120 | 2.5 121 | 122 | true 123 | 124 | 125 | 126 | org.apache.maven.plugins 127 | maven-compiler-plugin 128 | 129 | utf-8 130 | 1.7 131 | 1.7 132 | 133 | 134 | 135 | default-testCompile 136 | test-compile 137 | 138 | 139 | **/taf-test/*.java 140 | 141 | 142 | 143 | testCompile 144 | 145 | 146 | 147 | 148 | 149 | org.apache.maven.plugins 150 | maven-source-plugin 151 | 152 | 153 | attach-sources 154 | 155 | jar 156 | 157 | 158 | 159 | 160 | 161 | org.apache.maven.plugins 162 | maven-javadoc-plugin 163 | 164 | 165 | attach-javadocs 166 | 167 | jar 168 | 169 | 170 | 171 | 172 | 173 | 187 | 188 | org.apache.maven.plugins 189 | maven-release-plugin 190 | 2.5 191 | 192 | forked-path 193 | true 194 | 195 | 196 | 197 | 198 | 199 | 200 | src/main/resources 201 | 202 | 203 | src/main/java 204 | 205 | **/*.java 206 | 207 | 208 | 209 | 210 | 211 | -------------------------------------------------------------------------------- /proguard.conf: -------------------------------------------------------------------------------- 1 | -keepattributes Exceptions,InnerClasses,Signature,Deprecated, 2 | SourceFile,LineNumberTable,*Annotation*,EnclosingMethod 3 | 4 | -keep public class * { 5 | public protected *; 6 | } 7 | 8 | -keepclassmembernames class * { 9 | java.lang.Class class$(java.lang.String); 10 | java.lang.Class class$(java.lang.String, boolean); 11 | } 12 | 13 | -keepclasseswithmembernames class * { 14 | native ; 15 | } 16 | 17 | -keepclassmembers enum * { 18 | public static **[] values(); 19 | public static ** valueOf(java.lang.String); 20 | } 21 | 22 | -keepclassmembers class * implements java.io.Serializable { 23 | static final long serialVersionUID; 24 | private static final java.io.ObjectStreamField[] serialPersistentFields; 25 | private void writeObject(java.io.ObjectOutputStream); 26 | private void readObject(java.io.ObjectInputStream); 27 | java.lang.Object writeReplace(); 28 | java.lang.Object readResolve(); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/config/ConfigException.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.config; 2 | 3 | 4 | public class ConfigException extends RuntimeException{ 5 | 6 | /** 7 | * 8 | */ 9 | private static final long serialVersionUID = -4836716765409893138L; 10 | 11 | public ConfigException(String message, Throwable e){ 12 | super(message,e); 13 | } 14 | 15 | public ConfigException(String message){ 16 | super(message); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/config/DefaultConfig.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.config; 2 | 3 | import java.io.File; 4 | 5 | import java.io.FileInputStream; 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | import java.util.Properties; 9 | 10 | /** 11 | * Default Config file which loads the base configuraion required for the framework. 12 | *

It looks for the system property "taf.config" for getting the configuration file path. 13 | * If the property returns null, the file try to load the configuration from the default path 14 | * "src/test/resources/taf.properties". 15 | * 16 | *

This is a singleton class so incase you need to create an object of this class 17 | * please call the static method getDefaultConfig(). 18 | * 19 | * @author Varun Menon 20 | * 21 | */ 22 | public class DefaultConfig { 23 | private static DefaultConfig defaultConfig = null; 24 | Properties configData = null; 25 | 26 | private DefaultConfig() { 27 | this.loadConfig(); 28 | } 29 | 30 | /** 31 | * Returns the singleton object of the DefaultConfig class. 32 | * @return DefaultConfig class object. 33 | */ 34 | public static DefaultConfig getDefaultConfig(){ 35 | if(defaultConfig==null){ 36 | defaultConfig = new DefaultConfig(); 37 | } 38 | return defaultConfig; 39 | } 40 | 41 | /** 42 | * Returns the value of the passed configuration name from the loaded config file. 43 | * 44 | * @param configuration - whose value is required from the config file. 45 | * @return Configuration value of the said configuration or empty string 46 | * if the value is not found. 47 | */ 48 | public String getConfigValue(String configuration){ 49 | return configData.getProperty(configuration,""); 50 | } 51 | 52 | /** 53 | * Sets the configuration and its value to the config value. 54 | * 55 | * @param configuration - Configuration name to be stored 56 | * @param value - Value to be stored. 57 | */ 58 | public void setConfigValue(String configuration,String value){ 59 | configData.setProperty(configuration, value); 60 | } 61 | 62 | private void loadConfig() { 63 | String path = System.getProperty("taf.config"); 64 | InputStream configFile; 65 | configData = new Properties(); 66 | try { 67 | if (path == null) { 68 | configFile = this.getClass().getClassLoader().getResourceAsStream("taf.properties"); 69 | } else { 70 | configFile = new FileInputStream(path); 71 | } 72 | configData.load(configFile); 73 | } catch (IOException e) { 74 | throw new ConfigException( 75 | "Unable to load default properties file from path: " + path + 76 | ".Please make sure that the propertis taf.properties is deifned under src/test/resources folder of your project.\n " + 77 | "Or the path to the properties is set to the property 'taf.config'.", e); 78 | } catch (Exception e) { 79 | throw new ConfigException("Unable to load file because of: " 80 | + e.getMessage()); 81 | } 82 | } 83 | 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/datadrive/BaseDataDrive.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.datadrive; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import org.imaginea.test.automation.framework.datadrive.ClassParser.ClassParserException; 7 | import org.imaginea.test.automation.framework.datadrive.ClassParser.DataNotAvailableException; 8 | 9 | 10 | /** 11 | * Base Data Drive abstract class providing common methods to get the Parsed data of respective 12 | * data files to be used for data drive. 13 | * @author Varun Menon 14 | * 15 | */ 16 | public abstract class BaseDataDrive { 17 | 18 | private ClassParser clsParser = new ClassParser(); 19 | 20 | /** 21 | * Method to be implemented by the extending class for providing the parsed Data of the respective data file. 22 | * 23 | * @return Map of keys as column names and List of values present in the said column. 24 | */ 25 | protected abstract Map> getData(); 26 | 27 | /** 28 | * Method to be used to parse the data file and to create data objects of the respective passed class. 29 | * Mainly used to provide data drive variables for testng data drive methods. 30 | * @param type Class type for which the object has to be created for each entry in the row of the data file. 31 | * @param The type of data object to be returned 32 | * @return {@link Object}[][] containing the objects of the Class - type passed as argument 33 | * @throws ClassParserException in case of any issues while parsing the said class 34 | * @throws DataNotAvailableException in case no column for the variable present in the class is present in the data file. 35 | */ 36 | public Object[][] getTestngData(Class type) throws ClassParserException,DataNotAvailableException{ 37 | Map> dataMap = this.getData(); 38 | return clsParser.getTestngData(type, dataMap); 39 | } 40 | 41 | /** 42 | * Method to be used to parse the data file and to create data objects of the respective passed class. 43 | * 44 | * @param type Class type for which the object has to be created for each entry in the row of the data file. 45 | * @param The type of data object to be returned 46 | * @return {@link List} containing the objects of the Class - type passed as argument 47 | * @throws ClassParserException in case of any issues while parsing the said class 48 | * @throws DataNotAvailableException in case no column for the variable present in the class is present in the data file. 49 | * */ 50 | public List getClassObjectList(Class type) throws ClassParserException,DataNotAvailableException{ 51 | Map> dataMap = this.getData(); 52 | return clsParser.getClassObjectList(type, dataMap); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/datadrive/ClassParser.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.datadrive; 2 | 3 | import java.lang.reflect.Field; 4 | import java.lang.reflect.Modifier; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | public class ClassParser { 10 | 11 | public Object[][] getTestngData(Class type, Map> dataMap) throws ClassParserException,DataNotAvailableException{ 12 | List dataObject = this.getClassObjectList(type, dataMap); 13 | int dataObjectSize = dataObject.size(); 14 | Object[][] testngData = new Object[dataObjectSize][1]; 15 | for(int i = 0 ; i < dataObjectSize; i++){ 16 | testngData[i][0] = dataObject.get(i); 17 | } 18 | return testngData; 19 | } 20 | 21 | @SuppressWarnings("unchecked") 22 | public List getClassObjectList(Class type, Map> dataMap) throws ClassParserException,DataNotAvailableException{ 23 | 24 | boolean dataNotAvailable = false; 25 | List notAvialableFieldData = new ArrayList(); 26 | List dataObject = new ArrayList(); 27 | try { 28 | Field[] fields=type.getDeclaredFields(); 29 | List tempKeys = new ArrayList(dataMap.keySet()); 30 | int noOfDataSets = dataMap.get(tempKeys.get(0)).size(); 31 | for (int i = 0; i < noOfDataSets; i++) { 32 | Object cls = type.newInstance(); 33 | for(Field field: fields){ 34 | if(field.getModifiers()==Modifier.PUBLIC){ 35 | String fieldName = field.getName(); 36 | if(dataMap.containsKey(fieldName)){ 37 | List dataValues = dataMap.get(fieldName); 38 | String dataValue = dataValues.get(i); 39 | this.setValue(field, cls, dataValue); 40 | } else { 41 | dataNotAvailable = true; 42 | notAvialableFieldData.add(fieldName); 43 | } 44 | } 45 | } 46 | dataObject.add((T)cls); 47 | } 48 | if(dataNotAvailable){ 49 | throw new DataNotAvailableException("Data for the fields :"+ notAvialableFieldData +"is not available in the provided map."); 50 | } 51 | 52 | 53 | } catch (Exception e) { 54 | throw new DataNotAvailableException(e.toString()); 55 | } 56 | return dataObject; 57 | } 58 | 59 | public void setValue(Field field, Object obj, String value) throws ClassParserException{ 60 | Class fieldType = field.getType(); 61 | try { 62 | Object data = null; 63 | if (fieldType == int.class || fieldType == Integer.class) { 64 | data = value.length() == 0 ? null : Integer.parseInt(value); 65 | } else if (fieldType == String.class) { 66 | data = value.length() == 0 ? null : value; 67 | } else if (fieldType == Boolean.class || fieldType == boolean.class) { 68 | data = value.length() == 0 ? null : Boolean.parseBoolean(value); 69 | } else if (fieldType == float.class || fieldType == Float.class) { 70 | data = value.length() == 0 ? null : Float.parseFloat(value); 71 | } else if (fieldType == long.class || fieldType == Long.class) { 72 | data = value.length() == 0 ? null : Long.parseLong(value); 73 | } else if (fieldType == double.class || fieldType == Double.class) { 74 | data = value.length() == 0 ? null : Double.parseDouble(value); 75 | } else if (fieldType == short.class || fieldType == Short.class) { 76 | data = value.length() == 0 ? null : Short.parseShort(value); 77 | } else if (fieldType == char.class || fieldType == Character.class) { 78 | data = value.length() == 0 ? null : value.charAt(0); 79 | } else if (fieldType == byte.class || fieldType == Byte.class) { 80 | data = value.length() == 0 ? null : Byte.valueOf(value); 81 | } else{ 82 | throw new ClassParserException("Unable to convert the value:" + value + "to required class:" + fieldType); 83 | } 84 | field.set(obj, data); 85 | } catch (Exception e) { 86 | throw new ClassParserException("Unable to convert the value:" + value + "to required class:" + fieldType); 87 | } 88 | 89 | } 90 | 91 | @SuppressWarnings("serial") 92 | public class ClassParserException extends Exception{ 93 | 94 | public ClassParserException(String message, Throwable cause){ 95 | super(message, cause); 96 | } 97 | 98 | public ClassParserException(String message){ 99 | this(message,null); 100 | } 101 | 102 | } 103 | 104 | @SuppressWarnings("serial") 105 | public class DataNotAvailableException extends Exception{ 106 | public DataNotAvailableException(String message, Throwable e){ 107 | super(message, e); 108 | } 109 | 110 | public DataNotAvailableException(String message){ 111 | super(message); 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/datadrive/CsvDataDrive.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.datadrive; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.util.ArrayList; 6 | import java.util.HashMap; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | import org.imaginea.test.automation.framework.util.readers.CsvReader; 11 | 12 | 13 | public class CsvDataDrive extends BaseDataDrive{ 14 | 15 | CsvReader csvReader = null; 16 | public CsvDataDrive(String filePath){ 17 | this(new File(filePath)); 18 | } 19 | 20 | public CsvDataDrive(File file){ 21 | try { 22 | csvReader = new CsvReader(file); 23 | } catch (IOException e) { 24 | throw new DataDriveException(e); 25 | } 26 | } 27 | 28 | public CsvDataDrive(String filePath, char separator,char quotecharacter){ 29 | this(new File(filePath),separator,quotecharacter); 30 | } 31 | 32 | public CsvDataDrive(File file, char separator,char quotecharacter){ 33 | try { 34 | csvReader = new CsvReader(file, separator, quotecharacter); 35 | } catch (IOException e) { 36 | throw new DataDriveException(e); 37 | } 38 | 39 | } 40 | 41 | @Override 42 | protected Map> getData() { 43 | 44 | HashMap> data = new HashMap>(); 45 | int rowCount = csvReader.getNoOfRows(); 46 | int zeroRowColumns = csvReader.getNoOfColumn(); 47 | 48 | for (int column = 0; column < zeroRowColumns; column++) { 49 | String key = csvReader.getData(0, column); 50 | 51 | List valueList = new ArrayList(); 52 | 53 | for (int row = 1; row < rowCount; row++) { 54 | String value = csvReader.getData(row, column); 55 | valueList.add(value); 56 | } 57 | data.put(key, valueList); 58 | } 59 | // TODO Auto-generated method stub 60 | return data; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/datadrive/DataDriveException.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.datadrive; 2 | 3 | import org.imaginea.test.automation.framework.exceptions.TafRuntimeException; 4 | 5 | /** 6 | * Created by varunm on 26-02-2015. 7 | */ 8 | public class DataDriveException extends TafRuntimeException { 9 | public DataDriveException(){ 10 | super(); 11 | } 12 | 13 | public DataDriveException(String message){ 14 | super(message); 15 | } 16 | 17 | public DataDriveException(Throwable t){ 18 | super(t); 19 | } 20 | 21 | public DataDriveException(String message, Throwable t){ 22 | super(message, t); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/datadrive/ExcelDataDrive.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.datadrive; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.util.ArrayList; 6 | import java.util.HashMap; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | import org.imaginea.test.automation.framework.util.readers.ExcelReader; 11 | 12 | 13 | public class ExcelDataDrive extends BaseDataDrive{ 14 | 15 | ExcelReader excelReader = null; 16 | public ExcelDataDrive(String filePath){ 17 | this(new File(filePath)); 18 | } 19 | 20 | public ExcelDataDrive(File file){ 21 | try { 22 | excelReader = new ExcelReader(file); 23 | } catch (IOException e) { 24 | throw new DataDriveException(e); 25 | } 26 | } 27 | 28 | public ExcelDataDrive(String filePath, int sheetNo){ 29 | this(new File(filePath),sheetNo); 30 | } 31 | 32 | public ExcelDataDrive(File file, int sheetNo){ 33 | try { 34 | excelReader = new ExcelReader(file, sheetNo); 35 | } catch (IOException e) { 36 | throw new DataDriveException(e); 37 | } 38 | 39 | } 40 | 41 | @Override 42 | protected Map> getData() { 43 | HashMap> data = new HashMap>(); 44 | int rowCount = excelReader.getNoOfRows(); 45 | int zeroRowColumns = excelReader.getNoOfColumn(); 46 | 47 | for (int column = 0; column < zeroRowColumns; column++) { 48 | String key = excelReader.getData(0, column); 49 | 50 | List valueList = new ArrayList(); 51 | 52 | for (int row = 1; row < rowCount; row++) { 53 | String value = excelReader.getData(row, column); 54 | valueList.add(value); 55 | } 56 | data.put(key, valueList); 57 | } 58 | // TODO Auto-generated method stub 59 | return data; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/datastore/GlobalDataStore.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.datastore; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | /** 6 | * A global data store class to store the data that can be used in your tests. 7 | * The class provide utility to store the data as a static data as well as for a thread. 8 | * This is helpful when you want to share a particular data across multiple tests in a execution or in a 9 | * particular thread when you are executing tests in parallel. 10 | * @author Varun Menon 11 | * 12 | */ 13 | 14 | public class GlobalDataStore { 15 | 16 | private static Map staticData; 17 | private static ThreadLocal> threadedMap; 18 | private static GlobalDataStore INSTANCE; 19 | private GlobalDataStore(){ 20 | init(); 21 | } 22 | 23 | /** 24 | * Use this method to get the instance of the of this class. 25 | * 26 | * @return {@link GlobalDataStore} singleton instance 27 | */ 28 | public static GlobalDataStore getInstance(){ 29 | if(INSTANCE == null) 30 | INSTANCE = new GlobalDataStore(); 31 | return INSTANCE; 32 | } 33 | 34 | private void init(){ 35 | staticData = new HashMap(); 36 | threadedMap = new ThreadLocal>(); 37 | } 38 | 39 | private void initThreadData() { 40 | synchronized (GlobalDataStore.class) { 41 | if (threadedMap.get() == null) 42 | threadedMap.set(new HashMap()); 43 | } 44 | } 45 | 46 | /** 47 | * Stores data in a static way this data will available to the whole execution. 48 | * @param key Name to be used to refer to the said data. 49 | * @param value The data object that you need to store this can be any object. 50 | */ 51 | public void putStaticData(String key, Object value){ 52 | storeStaticData(key, value); 53 | } 54 | 55 | /** 56 | * Stores data in way that is will be available for a particular thread. 57 | * This usefule when you executing tests in a multi-threaded environment and want to share certain 58 | * data across particular thread and not across whole execution. 59 | * @param key Name to be used to refer to the said data. 60 | * @param value The data object that you need to store this can be any object. 61 | */ 62 | public synchronized void putThreadData(String key, String value){ 63 | initThreadData(); 64 | storeThreadedData(key, value); 65 | } 66 | 67 | /** 68 | * Use this method to retrieve the data that has been stored for a particular thread. 69 | * @param key The key which was used to store the data 70 | * @param The type of data object to be returned 71 | * @return The value stored for the said key or null in case no key was found. 72 | */ 73 | @SuppressWarnings("unchecked") 74 | public synchronized T getThreadData(String key){ 75 | initThreadData(); 76 | synchronized (GlobalDataStore.class) { 77 | Map dataMap = threadedMap.get(); 78 | if(dataMap.containsKey(key)) 79 | return (T) dataMap.get(key); 80 | return null; 81 | } 82 | 83 | } 84 | 85 | /** 86 | * Use this method to retrieve the data that has been stored to be available across the whole execution. 87 | * @param key The key which was used to store the data 88 | * @param The type of data object to be returned 89 | * @return The value stored for the said key or null in case no key was found. 90 | */ 91 | @SuppressWarnings("unchecked") 92 | public T getStaticData(String key) { 93 | synchronized (GlobalDataStore.class) { 94 | if(staticData.containsKey(key)) 95 | return (T) staticData.get(key); 96 | return null; 97 | } 98 | } 99 | 100 | /** 101 | * Use this method to retrieve the data that has been stored for a particular thread. 102 | * @param key The key which was used to store the data 103 | * @param defaultValue The default value that needs to be returned in case the key is not found. 104 | * @param The type of data object to be returned 105 | * 106 | * @return The value stored for the said key or the given defaultValue in case no key was found. 107 | */ 108 | @SuppressWarnings("unchecked") 109 | public T getThreadData(String key, Object defaultValue){ 110 | Object data = getThreadData(key); 111 | if(data == null) 112 | data = defaultValue; 113 | return (T) data; 114 | } 115 | 116 | /** 117 | * Use this method to retrieve the data that has been stored to be available across the whole execution. 118 | * @param key The key which was used to store the data 119 | * @param defaultValue The default value that needs to be returned in case the key is not found. 120 | * @param The type of data object to be returned 121 | * 122 | * @return The value stored for the said key or the given defaultValue in case no key was found. 123 | */ 124 | @SuppressWarnings("unchecked") 125 | public T getStaticData(String key, Object defaultValue) { 126 | Object data = getStaticData(key); 127 | if(data == null) 128 | data = defaultValue; 129 | return (T) data; 130 | } 131 | 132 | private static synchronized void storeStaticData(String key, Object value){ 133 | staticData.put(key, value); 134 | } 135 | 136 | private static synchronized void storeThreadedData(String key, Object value){ 137 | threadedMap.get().put(key, value); 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/dom/ElementOptions.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.dom; 2 | 3 | import org.imaginea.test.automation.framework.pagemodel.PageClass; 4 | 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.Target; 7 | 8 | import static java.lang.annotation.ElementType.FIELD; 9 | 10 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 11 | 12 | /** 13 | * Created by varunm on 03-03-2015. 14 | */ 15 | @Retention(RUNTIME) 16 | @Target({FIELD }) 17 | public @interface ElementOptions { 18 | String name() default ""; 19 | Class[] navigablePageClasses() default {}; 20 | boolean required() default true; 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/dom/NoEWebElementException.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.dom; 2 | 3 | public class NoEWebElementException extends RuntimeException { 4 | 5 | /** 6 | * 7 | */ 8 | private static final long serialVersionUID = -2230600018510579752L; 9 | 10 | public NoEWebElementException(){ 11 | super(); 12 | } 13 | 14 | public NoEWebElementException(String message) { 15 | super(message); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/dom/filter/Filter.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.dom.filter; 2 | 3 | /** 4 | * Created by menonvarun on 03-12-2014. 5 | * 6 | * Filters that is used for filtering the WebElements. Mainily used By EWebElement class 7 | */ 8 | public class Filter { 9 | 10 | private FilterType filterType; 11 | private String attributeName; 12 | private TextMatcher textMatcher; 13 | 14 | public Filter(FilterType filterType, String attributeName, TextMatcher textMatcher){ 15 | this.filterType = filterType; 16 | this.attributeName = attributeName; 17 | this.textMatcher = textMatcher; 18 | } 19 | 20 | /** 21 | * Returns the filter Type stored in the said object. 22 | * @return FilterType stored 23 | */ 24 | public FilterType getFilterType() { 25 | return filterType; 26 | } 27 | 28 | /** 29 | * Returns the attribute name stored in the said object 30 | * @return Attribute name 31 | */ 32 | public String getAttributeName() { 33 | return attributeName; 34 | } 35 | 36 | /** 37 | * Returns the TextMatcher stored 38 | * @return 39 | */ 40 | public TextMatcher getTextMatcher() { 41 | return textMatcher; 42 | } 43 | 44 | 45 | /** 46 | * Returns the filter to exactly match the id attribute value 47 | * @param idValue The value to compare 48 | * @return 49 | */ 50 | public static Filter withId(String idValue){ 51 | return whereId(TextMatching.equalsValue(idValue)); 52 | } 53 | 54 | /** 55 | * Returns the filter to exactly match the name attribute value 56 | * @param nameValue The value to compare 57 | * @return 58 | */ 59 | public static Filter withName(String nameValue){ 60 | return whereName(TextMatching.equalsValue(nameValue)); 61 | } 62 | 63 | /** 64 | * Returns the filter to exactly match the class attribute value 65 | * @param classValue The value to compare 66 | * @return 67 | */ 68 | public static Filter withClass(String classValue){ 69 | return whereClass(TextMatching.equalsValue(classValue)); 70 | } 71 | 72 | /** 73 | * Returns the filter to exactly match the text value 74 | * @param textValue The value to compare 75 | * @return 76 | */ 77 | public static Filter withText(String textValue){ 78 | return whereText(TextMatching.equalsValue(textValue)); 79 | } 80 | 81 | /** 82 | * Returns the filter to exactly match the respective attributeName value 83 | * @param attributeName The attribute name whose value have to be compared 84 | * @param attributeValue The value to compare 85 | * @return 86 | */ 87 | public static Filter withAttribute(String attributeName, String attributeValue){ 88 | return whereAttribute(attributeName, TextMatching.equalsValue(attributeValue)); 89 | } 90 | 91 | /** 92 | * Returns filter for id attribute using given TextMatcher. 93 | * Please use the static methods available inside the {@link TextMatching} class to get the 94 | * respective TextMatcher. 95 | * @param textMatcher 96 | * @return 97 | */ 98 | public static Filter whereId(TextMatcher textMatcher){ 99 | return new Filter(FilterType.ID, FilterType.ID.name(),textMatcher); 100 | } 101 | 102 | /** 103 | * Returns filter for name attribute using given TextMatcher. 104 | * Please use the static methods available inside the {@link TextMatching} class to get the 105 | * respective TextMatcher. 106 | * @param textMatcher 107 | * @return 108 | */ 109 | public static Filter whereName(TextMatcher textMatcher){ 110 | return new Filter(FilterType.NAME, FilterType.NAME.name(),textMatcher); 111 | } 112 | 113 | /** 114 | * Returns filter for class attribute using given TextMatcher. 115 | * Please use the static methods available inside the {@link TextMatching} class to get the 116 | * respective TextMatcher 117 | * @param textMatcher 118 | * @return 119 | */ 120 | public static Filter whereClass(TextMatcher textMatcher){ 121 | return new Filter(FilterType.CLASS,FilterType.CLASS.name(),textMatcher); 122 | } 123 | 124 | /** 125 | * Returns filter for filtering text of a element for a given TextMatcher. 126 | * Please use the static methods available inside the {@link TextMatching} class to get the 127 | * respective TextMatcher 128 | * @param textMatcher 129 | * @return 130 | */ 131 | public static Filter whereText(TextMatcher textMatcher){ 132 | return new Filter(FilterType.TEXT,FilterType.TEXT.name(),textMatcher); 133 | } 134 | 135 | /** 136 | * Returns a filter for the given attributeName value using given TextMatcher. 137 | * Please use the static methods available inside the {@link TextMatching} class to get the 138 | * respective TextMatcher. 139 | * @param attributeName 140 | * @param textMatcher 141 | * @return 142 | */ 143 | public static Filter whereAttribute(String attributeName, TextMatcher textMatcher){ 144 | return new Filter(FilterType.ATTRIBUTE, attributeName,textMatcher); 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/dom/filter/FilterType.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.dom.filter; 2 | 3 | /** 4 | * Created by menonvarun on 03-12-2014. 5 | * 6 | * Different filter types supported 7 | */ 8 | public enum FilterType { 9 | CLASS,NAME,ID,TEXT,ATTRIBUTE 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/dom/filter/NegatedTextMatcher.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.dom.filter; 2 | 3 | /** 4 | * Created by menonvarun on 03-12-2014. 5 | * 6 | * A negative text matcher 7 | */ 8 | public class NegatedTextMatcher implements TextMatcher { 9 | final TextMatcher matcher; 10 | 11 | public NegatedTextMatcher(TextMatcher matcher) { 12 | this.matcher = matcher; 13 | } 14 | 15 | public boolean matches(String text) { 16 | return !matcher.matches(text); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/dom/filter/PatternTextMatcher.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.dom.filter; 2 | 3 | import java.util.regex.Pattern; 4 | 5 | /** 6 | * Created by menonvarun on 03-12-2014. 7 | * 8 | * A pattern based TextMatcher 9 | */ 10 | public class PatternTextMatcher implements TextMatcher { 11 | 12 | final Pattern pattern; 13 | 14 | public PatternTextMatcher(CharSequence pattern) { 15 | this.pattern = Pattern.compile(pattern.toString(), Pattern.DOTALL); 16 | } 17 | 18 | public boolean matches(String text) { 19 | return pattern.matcher(text).matches(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/dom/filter/TextMatcher.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.dom.filter; 2 | 3 | /** 4 | * Created by menonvarun on 03-12-2014. 5 | */ 6 | public interface TextMatcher { 7 | 8 | /** 9 | * Matches the TextMatcher for the given text 10 | * @param text The text that needs to be matched 11 | * @return true if it matches else false. 12 | */ 13 | boolean matches(String text); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/driver/CacheDriverFactory.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.driver; 2 | 3 | import org.imaginea.test.automation.framework.config.DefaultConfig; 4 | import org.openqa.selenium.WebDriver; 5 | import org.openqa.selenium.remote.UnreachableBrowserException; 6 | 7 | 8 | /** 9 | * CacheDriverFactory provides a utility for creating and maintaining Selenium WebDriver instance. 10 | *

Driver Creation

11 | *

The framework supports an in-build implementation of driver creation as well as provide the flexibility to allow user 12 | * to provide his own driver implementation.

13 | * 14 | * In-build driver supports firefox,ie,chrome,htmlunit. Thes values can be set to the property test.name 15 | * inside taf.properties file. 16 | * For user defined driver, User have to implement a class implementing the {@link IDriverProvider} interface and add the path to the said class onto 17 | * the property userdefined.driverclass inside taf.properties file. 18 | * 19 | *

Driver Management

20 | *

The class provides two different implementation of driver factory: 21 | *

    22 | *
  1. Simple Driver Instance - In this driver instance management mode the driver object will be same across all the threads.
  2. 23 | *
  3. Threaded Driver Instance - In this driver instance management mode the driver will be different for each thread instance 24 | * that is getting executed.
  4. 25 | *
26 | * 27 | * By default "Simple Driver Instance" management is chosen by the framework. But in case you need a "Threaded Driver Instance" 28 | * management you can configure it by setting property thread.based.driver to true inside taf.properties 29 | * file. 30 | * 31 | * @author Varun Menon 32 | * 33 | */ 34 | public class CacheDriverFactory { 35 | 36 | private static DefaultConfig config; 37 | private boolean threadBasedDriver = true; 38 | private static IDriverFactory driverFactory = null; 39 | private static IDriverProvider driverProvider= null; 40 | 41 | /** 42 | * Default Constructor which will create the CacheDriverFactory object and uses the default config class object. 43 | */ 44 | public CacheDriverFactory(){ 45 | CacheDriverFactory.config = DefaultConfig.getDefaultConfig(); 46 | } 47 | 48 | /** 49 | * Default Constructor which will create the CacheDriverFactory object using the {@link DefaultConfig} class object provided. 50 | * @param config {@link DefaultConfig} class object that needs to be used by this class. 51 | */ 52 | public CacheDriverFactory(DefaultConfig config){ 53 | CacheDriverFactory.config = config; 54 | } 55 | 56 | /** 57 | * Return true or false based on the condition whether the driver object is thread based or not 58 | * @return true or false 59 | */ 60 | public boolean getThreadBasedDriver(){ 61 | return this.threadBasedDriver; 62 | } 63 | 64 | /** 65 | * Sets the thread based driver configuration with the given value. 66 | * @param value 67 | */ 68 | public void setThreadBasedDriver(boolean value){ 69 | this.threadBasedDriver = value; 70 | } 71 | 72 | /** 73 | * Create or return the current driver based on the configuration provided inside the taf.properties file. 74 | * @return {@link WebDriver} object 75 | */ 76 | public WebDriver getDriver(){ 77 | IDriverProvider currentDriverProvider = getDriverProvider(); 78 | IDriverFactory driverFactory = getDriverFactory(); 79 | WebDriver driver = driverFactory.getCurrentDriver(currentDriverProvider); 80 | return driver; 81 | } 82 | 83 | /** 84 | * Clears the current driver from the factory and return the old driver back 85 | * @return {@link WebDriver} object 86 | */ 87 | public WebDriver clearDriver(){ 88 | IDriverFactory driverFactory = getDriverFactory(); 89 | WebDriver driver = driverFactory.clearCurrentDriver(); 90 | return driver; 91 | } 92 | 93 | /** 94 | * Clears the current driver from the factory and then quits the said driver object 95 | */ 96 | public static void clearCacheAndQuitDriver(){ 97 | if(CacheDriverFactory.driverFactory!=null){ 98 | WebDriver driver = CacheDriverFactory.driverFactory.clearCurrentDriver(); 99 | if(driver != null) 100 | driver.quit(); 101 | } 102 | } 103 | 104 | 105 | private IDriverFactory getDriverFactory(){ 106 | if(CacheDriverFactory.driverFactory==null){ 107 | String threadBasedDriverValue = config.getConfigValue("thread.based.driver"); 108 | if(Boolean.parseBoolean(threadBasedDriverValue)){ 109 | CacheDriverFactory.driverFactory = new ThreadedDriver(); 110 | } else 111 | CacheDriverFactory.driverFactory = new SimpleDriver(); 112 | } 113 | return CacheDriverFactory.driverFactory; 114 | 115 | } 116 | 117 | private static class ThreadedDriver implements IDriverFactory{ 118 | private static final ThreadLocal threadedDriver = new ThreadLocal(); 119 | 120 | @Override 121 | synchronized public WebDriver getCurrentDriver(IDriverProvider driverProvider) { 122 | WebDriver driver = threadedDriver.get(); 123 | if(driver==null){ 124 | driver = driverProvider.getDriver(); 125 | threadedDriver.set(driver); 126 | addShutdownHookToDriver(driver); 127 | } 128 | return driver; 129 | } 130 | 131 | @Override 132 | synchronized public WebDriver clearCurrentDriver() { 133 | WebDriver oldDriver = threadedDriver.get(); 134 | threadedDriver.set(null); 135 | return oldDriver; 136 | } 137 | } 138 | 139 | private static class SimpleDriver implements IDriverFactory{ 140 | 141 | WebDriver driver = null; 142 | 143 | @Override 144 | public WebDriver getCurrentDriver(IDriverProvider driverProvider) { 145 | if(driver==null){ 146 | driver = driverProvider.getDriver(); 147 | addShutdownHookToDriver(driver); 148 | } 149 | return driver; 150 | } 151 | 152 | @Override 153 | public WebDriver clearCurrentDriver() { 154 | WebDriver oldDriver = driver; 155 | driver = null; 156 | return oldDriver; 157 | } 158 | } 159 | 160 | /** 161 | * Returns the Driver Provider class object of the class that has been provided by the user for Driver creation 162 | * @return {@link IDriverProvider} object or null if no class have been defined. 163 | */ 164 | public IDriverProvider getUserDefinedDriverProvider(){ 165 | String userDefinedClassName =config.getConfigValue("userdefined.driverclass"); 166 | IDriverProvider userDefinedClassObject = null; 167 | if(!userDefinedClassName.contentEquals("")){ 168 | ClassLoader clsLoader = this.getClass().getClassLoader(); 169 | try { 170 | Class userDefinedClass = clsLoader.loadClass(userDefinedClassName); 171 | if(IDriverProvider.class.isAssignableFrom(userDefinedClass)){ 172 | userDefinedClassObject = (IDriverProvider)userDefinedClass.newInstance(); 173 | }else{ 174 | throw new RuntimeException("The defined userdefined driver class does not extend the interface 'IDriverProvider'."); 175 | } 176 | } catch (IllegalAccessException|InstantiationException|ClassNotFoundException e) { 177 | throw new RuntimeException(e); 178 | } 179 | } 180 | return userDefinedClassObject; 181 | } 182 | 183 | /** 184 | * Returns the driver provider to be used for the execution. In case a user defined driver provider is available the 185 | * said class object is returned else it will return the {@link InbuiltDriverProvider} class instance. 186 | * @return {@link IDriverProvider} object of the driver provider class. 187 | */ 188 | public IDriverProvider getDriverProvider(){ 189 | if(CacheDriverFactory.driverProvider == null){ 190 | IDriverProvider driverProvider = getUserDefinedDriverProvider(); 191 | if(driverProvider == null){ 192 | driverProvider = new InbuiltDriverProvider(); 193 | } 194 | CacheDriverFactory.driverProvider = driverProvider; 195 | } 196 | 197 | return CacheDriverFactory.driverProvider; 198 | 199 | } 200 | 201 | /** 202 | * Sets the Driver Provider 203 | * @param driverProvider A IDriverProvider implementation object 204 | */ 205 | public void setDriverProvider(IDriverProvider driverProvider){ 206 | CacheDriverFactory.driverProvider = driverProvider; 207 | } 208 | 209 | private synchronized static void addShutdownHookToDriver(WebDriver driver){ 210 | CacheDriverFactory driverfactory = new CacheDriverFactory(); 211 | Runtime.getRuntime().addShutdownHook(driverfactory.new DriverShutdownHook(driver)); 212 | } 213 | 214 | private class DriverShutdownHook extends Thread{ 215 | WebDriver driver; 216 | public DriverShutdownHook(WebDriver driver){ 217 | this.driver = driver; 218 | } 219 | @Override 220 | public void run(){ 221 | try{ 222 | driver.quit(); 223 | }catch(UnreachableBrowserException e){ 224 | 225 | } 226 | } 227 | 228 | } 229 | 230 | 231 | 232 | } 233 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/driver/IDriverFactory.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.driver; 2 | 3 | import org.openqa.selenium.WebDriver; 4 | 5 | /** 6 | * Driver Factory interface to be used for driver management. 7 | *

Currently custom implementation is not supported by implementing this interface. But going forward it may be supported. 8 | * @author Varun Menon 9 | * 10 | */ 11 | public interface IDriverFactory { 12 | 13 | public WebDriver getCurrentDriver(IDriverProvider driverProvider); 14 | public WebDriver clearCurrentDriver(); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/driver/IDriverProvider.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.driver; 2 | 3 | import org.openqa.selenium.WebDriver; 4 | 5 | /** 6 | * This interface allow users to provide their own implementation to be used for driver creation. 7 | * After implementing this interface please set the path of your class to the property userdefined.driverclass 8 | * inside taf.properties file. 9 | * 10 | * @author Varun Menon 11 | * 12 | */ 13 | public interface IDriverProvider { 14 | 15 | /** 16 | * Creates and returns the driver object at runtime. 17 | * 18 | *

19 | * Note: While implemnting the interface create and configure your driver inside this method and return it. 20 | * @return {@link WebDriver} 21 | */ 22 | public WebDriver getDriver(); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/driver/InbuiltDriverProvider.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.driver; 2 | 3 | import org.imaginea.test.automation.framework.config.DefaultConfig; 4 | import org.openqa.selenium.WebDriver; 5 | import org.openqa.selenium.chrome.ChromeDriver; 6 | import org.openqa.selenium.firefox.FirefoxDriver; 7 | import org.openqa.selenium.htmlunit.HtmlUnitDriver; 8 | import org.openqa.selenium.ie.InternetExplorerDriver; 9 | 10 | 11 | /** 12 | * In-build driver provider class which creates and returns the driver object based on the property 13 | * test.name inside taf.properties file. 14 | * @author Varun Menon 15 | * 16 | */ 17 | class InbuiltDriverProvider implements IDriverProvider{ 18 | DefaultConfig config = DefaultConfig.getDefaultConfig(); 19 | 20 | @Override 21 | public WebDriver getDriver() { 22 | String driverName = config.getConfigValue("driver.name"); 23 | return getInbuildDriver(driverName); 24 | } 25 | 26 | private WebDriver getInbuildDriver(String driverName){ 27 | WebDriver driver = null; 28 | switch (driverName) { 29 | case "firefox": 30 | driver = new FirefoxDriver(); 31 | break; 32 | case "ie": 33 | driver = new InternetExplorerDriver(); 34 | break; 35 | case "chrome": 36 | driver = new ChromeDriver(); 37 | break; 38 | case "htmlunit": 39 | driver = new HtmlUnitDriver(); 40 | break; 41 | default: 42 | throw new DriverNotAvailableException("Driver name: " + driverName +" set to the property 'driver.name' is not supported"); 43 | } 44 | driver.manage().window().maximize(); 45 | return driver; 46 | } 47 | 48 | @SuppressWarnings("serial") 49 | private class DriverNotAvailableException extends RuntimeException{ 50 | public DriverNotAvailableException(String message){ 51 | super(message); 52 | } 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/exceptions/TafException.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.exceptions; 2 | 3 | /** 4 | * Created by varunm on 18-12-2014. 5 | */ 6 | public class TafException extends Exception { 7 | public TafException(){ 8 | super(); 9 | } 10 | 11 | public TafException(Throwable t){ 12 | super(t); 13 | } 14 | 15 | public TafException(String message){ 16 | super(message); 17 | } 18 | 19 | public TafException(String message, Throwable t){ 20 | super(message, t); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/exceptions/TafRuntimeException.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.exceptions; 2 | 3 | /** 4 | * Created by varunm on 18-12-2014. 5 | */ 6 | public class TafRuntimeException extends RuntimeException { 7 | public TafRuntimeException() { 8 | super(); 9 | } 10 | 11 | public TafRuntimeException(Throwable t) { 12 | super(t); 13 | } 14 | 15 | public TafRuntimeException(String message) { 16 | super(message); 17 | } 18 | 19 | public TafRuntimeException(String message, Throwable t) { 20 | super(message, t); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/exceptions/UnexpectedPageException.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.exceptions; 2 | 3 | /** 4 | * Created by varunm on 10-03-2015. 5 | */ 6 | public class UnexpectedPageException extends TafRuntimeException { 7 | public UnexpectedPageException(String message){ 8 | super(message); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/keywordmodel/KeywordException.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.keywordmodel; 2 | 3 | public class KeywordException extends RuntimeException{ 4 | 5 | /** 6 | * 7 | */ 8 | private static final long serialVersionUID = -7148208171169997215L; 9 | 10 | public KeywordException(){ 11 | super(); 12 | } 13 | 14 | public KeywordException(String message){ 15 | super(message); 16 | } 17 | 18 | public KeywordException(Throwable cause){ 19 | super(cause); 20 | } 21 | 22 | public KeywordException(String message,Throwable cause){ 23 | super(message, cause); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/keywordmodel/executor/KeywordExecutor.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.keywordmodel.executor; 2 | 3 | import java.io.File; 4 | import java.util.List; 5 | 6 | import org.imaginea.test.automation.framework.keywordmodel.reader.IKeywordStore; 7 | import org.imaginea.test.automation.framework.keywordmodel.reader.ReaderFactory; 8 | import org.openqa.selenium.WebDriver; 9 | 10 | 11 | /** 12 | * Base Keyword Executor class that helps in reading a specified keyword file 13 | * and executing the respective keyword and its arguments. 14 | * @author Varun Menon 15 | * 16 | */ 17 | public class KeywordExecutor { 18 | 19 | WebDriver driver; 20 | KeywordFactory keyfactory; 21 | ReaderFactory readerFactory; 22 | 23 | /** 24 | * Main {@link KeywordExecutor} class constructor 25 | * 26 | * @param driver {@link WebDriver} object to be set for Keyword classes 27 | * @param file {@link File} object of the keyword file 28 | * @param args {@link Object Object[]} of any extra arguments that needs to be passed. 29 | * Ex. Sheet Name for excel or separator for the csv file. 30 | */ 31 | public KeywordExecutor(WebDriver driver, File file, String...args){ 32 | this.driver = driver; 33 | keyfactory = new KeywordFactory(driver); 34 | readerFactory = new ReaderFactory(file, args); 35 | } 36 | 37 | /** 38 | * {@link KeywordExecutor} class constructor which accepts the following params 39 | * and sets the {@link WebDriver} object for the Keyword classes as null. 40 | * 41 | *

Use this constructor when your Keyword implementation classes don't need 42 | * WebDriver object for executing your keywords. 43 | * 44 | * @param file {@link File} object of the keyword file 45 | * @param args {@link Object Object[]} of any extra arguments that needs to be passed. 46 | */ 47 | public KeywordExecutor(File file, String...args){ 48 | this(null,file,args); 49 | } 50 | 51 | public KeywordExecutor(File file, List arguments) { 52 | this(null, file, arguments); 53 | } 54 | 55 | public KeywordExecutor(WebDriver driver, File file, List arguments) { 56 | this(driver, file, (String[]) arguments.toArray()); 57 | } 58 | 59 | /** 60 | * {@link KeywordExecutor} class constructor which accepts the following params 61 | * and sets the {@link WebDriver} object for the Keyword classes as null. 62 | * 63 | *

Use this constructor when your Keyword implementation classes don't need 64 | * WebDriver object for executing your keywords. 65 | * 66 | * @param file {@link File} object of the keyword file 67 | */ 68 | public KeywordExecutor(File file){ 69 | this(null,file,(String[])null); 70 | } 71 | 72 | /** 73 | * {@link KeywordExecutor} class constructor which accepts the following params 74 | * 75 | * @param driver {@link WebDriver} object to be set for Keyword classes 76 | * @param file {@link File} object of the keyword file 77 | */ 78 | public KeywordExecutor(WebDriver driver, File file){ 79 | this(driver,file,(String[])null); 80 | } 81 | 82 | /** 83 | *Executes keyword file that was passed while creating the object of {@link KeywordExecutor this} class. 84 | */ 85 | public void execute(){ 86 | List keys = readerFactory.getKeywordTestData(); 87 | for(IKeywordStore key: keys){ 88 | String keyword = key.getKeyword(); 89 | List arguments = key.getArguments(); 90 | keyfactory.executeKeyword(keyword, arguments.toArray()); 91 | } 92 | } 93 | 94 | 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/keywordmodel/executor/KeywordFactory.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.keywordmodel.executor; 2 | 3 | import java.lang.reflect.Constructor; 4 | import java.lang.reflect.InvocationTargetException; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import org.imaginea.test.automation.framework.config.DefaultConfig; 9 | import org.imaginea.test.automation.framework.keywordmodel.KeywordException; 10 | import org.imaginea.test.automation.framework.keywordmodel.keywords.IKeyword; 11 | import org.openqa.selenium.WebDriver; 12 | 13 | 14 | /** 15 | * Factory class to identify the Keyword implementation classes that implement the IKeyword 16 | * interface and execute the keywords with respective arguments. 17 | * @author Varun Menon 18 | * 19 | */ 20 | public class KeywordFactory { 21 | 22 | DefaultConfig config = DefaultConfig.getDefaultConfig(); 23 | List keywordClassObjects; 24 | WebDriver driver; 25 | 26 | public KeywordFactory(WebDriver driver){ 27 | this.driver = driver; 28 | this.keywordClassObjects = getKeywordImplementations(); 29 | } 30 | 31 | private List getKeywordImplementations(){ 32 | String[] keywordClasses = config.getConfigValue("listeners").split(","); 33 | ClassLoader cloader = this.getClass().getClassLoader(); 34 | List> listenerClasses = new ArrayList>(); 35 | List keywordClsObjs = new ArrayList(); 36 | for(String keywordClass:keywordClasses){ 37 | try{ 38 | Class cls = cloader.loadClass(keywordClass); 39 | listenerClasses.add(cls); 40 | }catch(ClassNotFoundException e){ 41 | throw new KeywordException("Unable to find class with name as mentione in listner property: "+ 42 | keywordClass+" Make sure the class is present in the classpath."); 43 | } 44 | } 45 | 46 | for (Class cls : listenerClasses) { 47 | if (IKeyword.class.isAssignableFrom(cls)) { 48 | IKeyword obj = null; 49 | try { 50 | Constructor constructor = cls 51 | .getConstructor(WebDriver.class); 52 | obj = (IKeyword) constructor.newInstance(this.driver); 53 | } catch (IllegalAccessException | InstantiationException 54 | | SecurityException | NoSuchMethodException 55 | | IllegalArgumentException | InvocationTargetException e) { 56 | throw new KeywordException( 57 | "Unable to find a constructor that accepts the WebDriver object for the keyword class:" 58 | + cls.getName()); 59 | } 60 | if (obj != null) { 61 | keywordClsObjs.add(obj); 62 | } 63 | 64 | } 65 | } 66 | return keywordClsObjs; 67 | } 68 | 69 | /** 70 | * Keyword executor method, finds the supporting keyword implementation class 71 | * and execute the said keyword using the arguments passed. 72 | * @param keyword Keyword to be executed 73 | * @param args Arguments that needs to be used to execute the particular keyword 74 | */ 75 | public void executeKeyword(String keyword, Object[] args){ 76 | boolean executed = false; 77 | for(IKeyword keywordCls : keywordClassObjects){ 78 | boolean supported = keywordCls.isSupported(keyword, args); 79 | if(supported){ 80 | keywordCls.execute(keyword, args); 81 | executed = true; 82 | } 83 | } 84 | if(!executed){ 85 | throw new KeywordException("Unable to find any keyword class that support keyword: \"" 86 | +keyword+"\" and arguments: \""+args+"\"."); 87 | } 88 | 89 | } 90 | 91 | 92 | 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/keywordmodel/keywords/IKeyword.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.keywordmodel.keywords; 2 | 3 | /** 4 | * Base interface for the keyword implementation classes. 5 | * @author Varun Menon 6 | * 7 | */ 8 | public interface IKeyword { 9 | 10 | /** 11 | * Verifies whether the said keyword with the arguments is supported by the implementing class or not. 12 | * @param keyword Keyword that needs to be executed 13 | * @param args Arguments that needs to be used to execute the said keyword 14 | * @return true or false depending upon the condition whether the "keyword" 15 | * with specified no. of arguments is supported or not. 16 | */ 17 | public boolean isSupported(String keyword, Object[] args); 18 | 19 | /** 20 | * Executes the specified keyword with specified given arguments. 21 | * @param keyword Keyword to be executed. 22 | * @param args Arguments to be used for the keyword execution. 23 | */ 24 | public void execute(String keyword, Object[] args); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/keywordmodel/keywords/KeywordBase.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.keywordmodel.keywords; 2 | 3 | import java.lang.reflect.InvocationTargetException; 4 | import java.lang.reflect.Method; 5 | import java.util.ArrayList; 6 | import java.util.Arrays; 7 | import java.util.HashMap; 8 | import java.util.Iterator; 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | import org.imaginea.test.automation.framework.keywordmodel.KeywordException; 13 | 14 | 15 | /** 16 | * Base keyword class that implements the IKeyword interface. 17 | * This class provides utility to execute the keywords using the Java reflection api. 18 | *

Extend this class if you want your methods to be used as keywords. 19 | * 20 | * @author Varun Menon 21 | * 22 | */ 23 | public abstract class KeywordBase implements IKeyword{ 24 | 25 | Map>> methods = new HashMap>>(); 26 | private Object executingObject=null; 27 | private boolean initialized = false; 28 | 29 | protected KeywordBase() { 30 | initialize(); 31 | } 32 | 33 | private void initialize(){ 34 | executingObject = this; 35 | initialize(executingObject); 36 | } 37 | 38 | /** 39 | * Initializes the class to collect the information of the methods available in the said class. 40 | * Use this method if you want to initialize methods from some other class object. 41 | * @param obj Object of the class whose method you to use for keyword execution. 42 | */ 43 | protected void initialize(Object obj){ 44 | Class cls = obj.getClass(); 45 | methods.clear(); 46 | Iterator it = Arrays.asList(cls.getMethods()).iterator(); 47 | while (it.hasNext()) { 48 | Method method = it.next(); 49 | MethodInfo methodInfo = new MethodInfo(method); 50 | List infoList; 51 | Map> paramMethodMap; 52 | String methodName = method.getName(); 53 | int noOfParams = method.getParameterTypes().length; 54 | 55 | if(methods.containsKey(methodName)){ 56 | paramMethodMap = methods.get(methodName); 57 | if(paramMethodMap.containsKey(noOfParams)){ 58 | infoList = paramMethodMap.get(noOfParams); 59 | } else { 60 | infoList = new ArrayList(); 61 | } 62 | infoList.add(methodInfo); 63 | paramMethodMap.put(noOfParams, infoList); 64 | } else { 65 | paramMethodMap = new HashMap>(); 66 | infoList = new ArrayList(); 67 | infoList.add(methodInfo); 68 | paramMethodMap.put(noOfParams, infoList); 69 | } 70 | 71 | methods.put(methodName, paramMethodMap); 72 | } 73 | this.initialized = true; 74 | } 75 | 76 | @Override 77 | public boolean isSupported(String methodName, Object[] args){ 78 | if(!initialized){ 79 | initialize(); 80 | } 81 | if(!methods.containsKey(methodName)){ 82 | return false; 83 | } 84 | Map> paramMethodInfos = methods.get(methodName); 85 | boolean supported = false; 86 | 87 | if(paramMethodInfos.containsKey(args.length)){ 88 | supported = true; 89 | } 90 | 91 | return supported; 92 | } 93 | 94 | @Override 95 | public void execute(String keyword, Object[] args){ 96 | Map> paramMethodInfos = methods.get(keyword); 97 | boolean executed = false; 98 | boolean canBeExecuted = false; 99 | if(paramMethodInfos.containsKey(args.length)){ 100 | List methodInfos = paramMethodInfos.get(args.length); 101 | for(MethodInfo methodInfo:methodInfos){ 102 | Object[] convertedParams = convertParamTypes(methodInfo.getPrameterTypes(), args); 103 | if(convertedParams != null){ 104 | canBeExecuted = true; 105 | } 106 | if(canBeExecuted){ 107 | Method method = methodInfo.getMethodObject(); 108 | try { 109 | method.invoke(executingObject, convertedParams); 110 | executed = true; 111 | break; 112 | } catch (IllegalAccessException | IllegalArgumentException escape){ 113 | /* 114 | * Intentionally escaping the exception so that we can continue with the execution 115 | * of any other supported method that is available. 116 | */ 117 | }catch(InvocationTargetException e) { 118 | throw new KeywordException(e); 119 | } 120 | } 121 | 122 | } 123 | } 124 | if(!executed){ 125 | throw new KeywordException("Unable to find any key word with name: \""+keyword+ 126 | "\" and arguments: \""+args.toString()+" in class: \""+ 127 | this.getClass().getName()+"\"."); 128 | } 129 | } 130 | 131 | private Object[] convertParamTypes(Class[] methodParams, Object[] passedParams){ 132 | List paramTypes = new ArrayList(); 133 | for(int itr = 0; itr < methodParams.length; itr++){ 134 | Class paramType = methodParams[itr]; 135 | Object data = getConvertedParam(paramType, passedParams[itr]); 136 | if(data == null){ 137 | return null; 138 | } 139 | paramTypes.add(data); 140 | } 141 | 142 | return paramTypes.toArray(); 143 | } 144 | 145 | private Object getConvertedParam(Class fieldType, Object obj) { 146 | String value = (String) obj; 147 | 148 | Object data = null; 149 | try { 150 | if (fieldType == int.class || fieldType == Integer.class) { 151 | data = value.length() == 0 ? null : Integer.parseInt(value); 152 | } else if (fieldType == String.class) { 153 | data = value.length() == 0 ? null : value; 154 | } else if (fieldType == Boolean.class || fieldType == boolean.class) { 155 | data = value.length() == 0 ? null : Boolean.parseBoolean(value); 156 | } else if (fieldType == float.class || fieldType == Float.class) { 157 | data = value.length() == 0 ? null : Float.parseFloat(value); 158 | } else if (fieldType == long.class || fieldType == Long.class) { 159 | data = value.length() == 0 ? null : Long.parseLong(value); 160 | } else if (fieldType == double.class || fieldType == Double.class) { 161 | data = value.length() == 0 ? null : Double.parseDouble(value); 162 | } else if (fieldType == short.class || fieldType == Short.class) { 163 | data = value.length() == 0 ? null : Short.parseShort(value); 164 | } else if (fieldType == char.class || fieldType == Character.class) { 165 | data = value.length() == 0 ? null : value.charAt(0); 166 | } else if (fieldType == byte.class || fieldType == Byte.class) { 167 | data = value.length() == 0 ? null : Byte.valueOf(value); 168 | } 169 | } catch (NumberFormatException e) { 170 | 171 | } 172 | return data; 173 | } 174 | 175 | 176 | } 177 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/keywordmodel/keywords/MethodInfo.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.keywordmodel.keywords; 2 | 3 | import java.lang.reflect.Method; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | /** 8 | * Stores method information of each of the method present inside 9 | * the keyword class. 10 | * @author Varun Menon 11 | * 12 | */ 13 | public class MethodInfo { 14 | 15 | private String methodName; 16 | private int noOfParams; 17 | private Method methodObject; 18 | private Class[] prameterTypes; 19 | private List> parameterTypesAsList; 20 | 21 | public MethodInfo(Method method){ 22 | this.methodObject = method; 23 | this.methodName = method.getName(); 24 | this.noOfParams = method.getParameterTypes().length; 25 | this.prameterTypes = method.getParameterTypes(); 26 | this.parameterTypesAsList = Arrays.asList(prameterTypes); 27 | } 28 | 29 | public String getMethodName() { 30 | return methodName; 31 | } 32 | public void setMethodName(String methodName) { 33 | this.methodName = methodName; 34 | } 35 | public int getNoOfParams() { 36 | return noOfParams; 37 | } 38 | public void setNoOfParams(int noOfParams) { 39 | this.noOfParams = noOfParams; 40 | } 41 | public Method getMethodObject() { 42 | return methodObject; 43 | } 44 | public void setMethodObject(Method methodObject) { 45 | this.methodObject = methodObject; 46 | } 47 | public Class[] getPrameterTypes() { 48 | return prameterTypes; 49 | } 50 | public void setPrameterTypes(Class[] prameterTypes) { 51 | this.prameterTypes = prameterTypes; 52 | } 53 | public List> getParameterTypesAsList() { 54 | return parameterTypesAsList; 55 | } 56 | public void setParameterTypesAsList(List> parameterTypesAsList) { 57 | this.parameterTypesAsList = parameterTypesAsList; 58 | } 59 | 60 | 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/keywordmodel/reader/CsvKeywordReader.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.keywordmodel.reader; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import org.imaginea.test.automation.framework.util.readers.CsvReader; 9 | /** 10 | * CsvKeywordReader supports reading CSV based keyword files. 11 | * @author Varun Menon 12 | * 13 | */ 14 | public class CsvKeywordReader implements IKeywordReader{ 15 | 16 | @Override 17 | public boolean isSupported(File file) { 18 | boolean supported = false; 19 | if(file.getName().endsWith(".csv")) 20 | supported = true; 21 | return supported; 22 | } 23 | 24 | @Override 25 | public List readFile(File file) { 26 | CsvReader csvReader = null; 27 | try { 28 | csvReader = new CsvReader(file); 29 | } catch (IOException e) { 30 | throw new RuntimeException(e); 31 | } 32 | return this.readData(csvReader); 33 | } 34 | 35 | @Override 36 | public List readFile(File file, String... args) { 37 | CsvReader csvReader = null; 38 | try { 39 | csvReader = new CsvReader(file,args[0],args[1]); 40 | } catch (IOException e) { 41 | throw new RuntimeException(e); 42 | } 43 | return this.readData(csvReader); 44 | } 45 | 46 | private List readData(CsvReader csvReader) { 47 | int noOfRows = csvReader.getNoOfRows(); 48 | List keyStores = new ArrayList(); 49 | 50 | for (int rowNo = 1; rowNo < noOfRows; rowNo++) { 51 | 52 | String key = csvReader.getData(rowNo, 0); 53 | List valueList = new ArrayList(); 54 | 55 | for (int columnNo = 1; columnNo < csvReader.getNoOfColumn(rowNo); columnNo++) { 56 | String data = csvReader.getData(rowNo, columnNo); 57 | valueList.add(data); 58 | } 59 | 60 | IKeywordStore keyStore = new TafKeywordStore(); 61 | keyStore.setKeyword(key); 62 | keyStore.setArguments(valueList); 63 | keyStores.add(keyStore); 64 | } 65 | return keyStores; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/keywordmodel/reader/ExcelKeywordReader.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.keywordmodel.reader; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import org.imaginea.test.automation.framework.util.readers.ExcelReader; 9 | 10 | /** 11 | * ExcelKeywordReader supports reading Excel based keyword files. 12 | * 13 | * @author Varun Menon 14 | * 15 | */ 16 | public class ExcelKeywordReader implements IKeywordReader { 17 | 18 | @Override 19 | public boolean isSupported(File file) { 20 | boolean supported = false; 21 | String fileName = file.getName(); 22 | if (fileName.endsWith(".xls") || fileName.endsWith(".xlsx")) 23 | supported = true; 24 | return supported; 25 | } 26 | 27 | @Override 28 | public List readFile(File file) { 29 | ExcelReader excelReader = null; 30 | try { 31 | excelReader = new ExcelReader(file, 0); 32 | } catch (IOException e) { 33 | throw new RuntimeException(e); 34 | } 35 | return this.readData(excelReader); 36 | } 37 | 38 | @Override 39 | public List readFile(File file, String... args) { 40 | ExcelReader excelReader = null; 41 | try { 42 | excelReader = new ExcelReader(file, args[0]); 43 | } catch (IOException e) { 44 | throw new RuntimeException(e); 45 | } 46 | return this.readData(excelReader); 47 | } 48 | 49 | private List readData(ExcelReader excelReader) { 50 | int noOfRows = excelReader.getNoOfRows(); 51 | List keyStores = new ArrayList(); 52 | 53 | for (int rowNo = 1; rowNo < noOfRows; rowNo++) { 54 | 55 | String key = excelReader.getData(rowNo, 0); 56 | List valueList = new ArrayList(); 57 | 58 | for (int columnNo = 1; columnNo < excelReader.getNoOfColumn(rowNo); columnNo++) { 59 | String data = excelReader.getData(rowNo, columnNo); 60 | valueList.add(data); 61 | } 62 | 63 | IKeywordStore keyStore = new TafKeywordStore(); 64 | keyStore.setKeyword(key); 65 | keyStore.setArguments(valueList); 66 | keyStores.add(keyStore); 67 | } 68 | return keyStores; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/keywordmodel/reader/IKeywordReader.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.keywordmodel.reader; 2 | 3 | import java.io.File; 4 | import java.util.List; 5 | 6 | /** 7 | * Base Interface for the keyword readers 8 | * @author Varun Menon 9 | * 10 | */ 11 | public interface IKeywordReader { 12 | 13 | /** 14 | * Should return true or false based on the criteria whether 15 | * the said file is supported or not. 16 | * 17 | * @param file - That contains the keywords and respective arguments 18 | * @return true or false depending upon whether 19 | * file is supported by the said class or not. 20 | */ 21 | public boolean isSupported(File file); 22 | 23 | /** 24 | * Parses the particular file and returns a List containing the {@link IKeywordStore IKeywordStore} object 25 | * @param file - That contains the keywords and respective arguments 26 | * @return Returns a {@link List List} containing the IKeywordStore object. 27 | */ 28 | public List readFile(File file); 29 | 30 | /** 31 | * Parses the particular file and returns a List containing the {@link IKeywordStore IKeywordStore} object 32 | * @param file - That contains the keywords and respective arguments 33 | * @param args - Any extra arguments that may be passed as part of the reading task. 34 | * @return Returns a {@link List List} containing the {@link IKeywordStore IKeywordStore} object. 35 | */ 36 | public List readFile(File file, String... args); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/keywordmodel/reader/IKeywordStore.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.keywordmodel.reader; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Basic interface to store the keyword and its arguments. 7 | * @author Varun Menon 8 | * 9 | */ 10 | public interface IKeywordStore { 11 | 12 | /** 13 | * Sets the keyword name 14 | * @param keyword - The keyword to be stored 15 | */ 16 | public void setKeyword(String keyword); 17 | 18 | /** 19 | * Get the stored keyword name 20 | * @return Actual keyword stored or an empty string if no value is stored 21 | */ 22 | public String getKeyword(); 23 | 24 | /** 25 | * Sets the keyword arguments 26 | * @param args - Keyword arguments as {@link List List} of {@link Object Object} 27 | */ 28 | public void setArguments(List args); 29 | 30 | /** 31 | * Returns the stored list of arguments as {@link List List} of {@link Object Object}. 32 | * @return The stored list of arguments or an empty list is no arguments is being stored. 33 | */ 34 | public List getArguments(); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/keywordmodel/reader/KeywordReaderException.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.keywordmodel.reader; 2 | 3 | public class KeywordReaderException extends RuntimeException{ 4 | 5 | /** 6 | * 7 | */ 8 | private static final long serialVersionUID = 1482142907389535385L; 9 | 10 | public KeywordReaderException(){ 11 | super(); 12 | } 13 | 14 | public KeywordReaderException(String message){ 15 | super(message); 16 | } 17 | 18 | public KeywordReaderException(Throwable cause){ 19 | super(cause); 20 | } 21 | 22 | public KeywordReaderException(String message,Throwable cause){ 23 | super(message, cause); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/keywordmodel/reader/ReaderFactory.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.keywordmodel.reader; 2 | 3 | import java.io.File; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | /** 8 | * Factory class to find the supported readers for the keyword files. 9 | * This class also provides utils to parse the keyword files. 10 | * @author Varun Menon 11 | * 12 | */ 13 | public class ReaderFactory { 14 | File file; 15 | String[] arguments; 16 | List keyReaders = new ArrayList(); 17 | 18 | /** 19 | * Creates {@link ReaderFactory} object by using the {@link File} object passed. 20 | * @param file {@link File} object of the keyword file 21 | */ 22 | public ReaderFactory(File file){ 23 | this.file = file; 24 | this.arguments = null; 25 | initialize(); 26 | } 27 | 28 | /** 29 | * Creates {@link ReaderFactory} object by using the {@link File} object passed. 30 | * @param file {@link File} object of the keyword file 31 | * @param arguments {@link Object Object[]} of any extra arguments that needs to be passed. 32 | * Ex. Sheet Name for excel or separator for the csv file. 33 | */ 34 | public ReaderFactory(File file, String... arguments){ 35 | this.file = file; 36 | this.arguments = arguments; 37 | initialize(); 38 | } 39 | 40 | private void initialize(){ 41 | keyReaders.add(new ExcelKeywordReader()); 42 | keyReaders.add(new CsvKeywordReader()); 43 | } 44 | 45 | /** 46 | * Get the keyword test case data stored in the file. 47 | * @return List of {@link org.imaginea.test.automation.framework.keywordmodel.reader.IKeywordStore IKeywordStore} 48 | * after parsing the file passed to the constructor
{@link #ReaderFactory(File)} or {@link #ReaderFactory(File, String...)} 49 | */ 50 | public List getKeywordTestData(){ 51 | boolean supported = false; 52 | IKeywordReader supportedReader = null; 53 | for(IKeywordReader reader : keyReaders){ 54 | if(reader.isSupported(file)){ 55 | supported = true; 56 | supportedReader = reader; 57 | break; 58 | } 59 | } 60 | if(supported){ 61 | return getData(supportedReader); 62 | }else{ 63 | throw new KeywordReaderException("Unable to find any supported reader for file: "+ file.getName()); 64 | } 65 | 66 | } 67 | 68 | private List getData(IKeywordReader reader){ 69 | if(this.arguments == null){ 70 | return reader.readFile(this.file); 71 | }else{ 72 | return reader.readFile(file, arguments); 73 | } 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/keywordmodel/reader/TafKeywordStore.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.keywordmodel.reader; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * TAF implementation of the interface IKeywordStore 8 | * @author Varun Menon 9 | * 10 | */ 11 | public class TafKeywordStore implements IKeywordStore{ 12 | private String keyword = ""; 13 | private List arguments = new ArrayList(); 14 | 15 | @Override 16 | public void setKeyword(String keyword) { 17 | this.keyword = keyword; 18 | } 19 | 20 | @Override 21 | public String getKeyword() { 22 | return this.keyword; 23 | } 24 | 25 | @Override 26 | public void setArguments(List args) { 27 | this.arguments = args; 28 | } 29 | 30 | @Override 31 | public List getArguments() { 32 | return this.arguments; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/keywordmodel/suite/CsvSuiteFileReader.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.keywordmodel.suite; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import org.imaginea.test.automation.framework.util.readers.CsvReader; 9 | 10 | 11 | public class CsvSuiteFileReader implements ISuiteFileReader{ 12 | 13 | @Override 14 | public boolean isSupported(File file) { 15 | boolean supported = false; 16 | if(file.getName().endsWith(".csv")) 17 | supported = true; 18 | return supported; 19 | } 20 | 21 | @Override 22 | public List read(File file, List arguments) { 23 | CsvReader csvReader; 24 | try{ 25 | if(arguments.size()>2) 26 | csvReader = new CsvReader(file, arguments.get(0), arguments.get(1)); 27 | else 28 | csvReader = new CsvReader(file); 29 | } catch(IOException e){ 30 | throw new RuntimeException(e); 31 | } 32 | return this.getTests(csvReader); 33 | } 34 | 35 | private List getTests(CsvReader csvReader){ 36 | List tests = new ArrayList(); 37 | int noOfTestRows = csvReader.getNoOfRows(); 38 | for(int row = 1; row < noOfTestRows; row++){ 39 | int noOfColumn = csvReader.getNoOfColumn(row); 40 | if(noOfColumn < 4){ 41 | throw new RuntimeException("Test suite file fhsoul contain a minimum of 4 values for each test." 42 | +"These values ar Test-id, Test-Name, Enabled/Disabled and Filepath"); 43 | } 44 | String testId = csvReader.getData(row, 0); 45 | String testName = csvReader.getData(row, 1); 46 | String enabledValue = csvReader.getData(row, 2); 47 | boolean enabled = enabledValue.equalsIgnoreCase("Y") ? true : false; 48 | String filePath = csvReader.getData(row, 3); 49 | List arguments = new ArrayList(); 50 | 51 | if(noOfColumn>4){ 52 | for(int column = 4;column < noOfColumn;column++){ 53 | arguments.add(csvReader.getData(row, column)); 54 | } 55 | } 56 | ISimpleTest simpleTest = new SimpleTest(testName, testId, enabled, filePath, arguments); 57 | tests.add(simpleTest); 58 | } 59 | return tests; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/keywordmodel/suite/ExcelSuiteFileReader.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.keywordmodel.suite; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import org.imaginea.test.automation.framework.util.readers.ExcelReader; 9 | 10 | 11 | 12 | public class ExcelSuiteFileReader implements ISuiteFileReader{ 13 | 14 | @Override 15 | public boolean isSupported(File file) { 16 | boolean supported = false; 17 | String fileName = file.getName(); 18 | if (fileName.endsWith(".xls") || fileName.endsWith(".xlsx")) 19 | supported = true; 20 | return supported; 21 | } 22 | 23 | @Override 24 | public List read(File file, List arguments) { 25 | ExcelReader excelReader; 26 | try{ 27 | if(arguments.size()>1) 28 | excelReader = new ExcelReader(file, arguments.get(0)); 29 | else 30 | excelReader = new ExcelReader(file); 31 | } catch(IOException e){ 32 | throw new RuntimeException(e); 33 | } 34 | return this.getTests(excelReader); 35 | } 36 | 37 | private List getTests(ExcelReader excelReader){ 38 | List tests = new ArrayList(); 39 | int noOfTestRows = excelReader.getNoOfRows(); 40 | for(int row = 1; row < noOfTestRows; row++){ 41 | int noOfColumn = excelReader.getNoOfColumn(row); 42 | if(noOfColumn < 4){ 43 | throw new RuntimeException("Test suite file fhsoul contain a minimum of 4 values for each test." 44 | +"These values ar Test-id, Test-Name, Enabled/Disabled and Filepath"); 45 | } 46 | String testId = excelReader.getData(row, 0); 47 | String testName = excelReader.getData(row, 1); 48 | String enabledValue = excelReader.getData(row, 2); 49 | boolean enabled = enabledValue.equalsIgnoreCase("Y") ? true : false; 50 | String filePath = excelReader.getData(row, 3); 51 | List arguments = new ArrayList(); 52 | if(noOfColumn>4){ 53 | for(int column = 4;column < noOfColumn;column++){ 54 | arguments.add(excelReader.getData(row, column)); 55 | } 56 | } 57 | ISimpleTest simpleTest = new SimpleTest(testName, testId, enabled, filePath, arguments); 58 | tests.add(simpleTest); 59 | } 60 | return tests; 61 | } 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/keywordmodel/suite/ISimpleTest.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.keywordmodel.suite; 2 | 3 | import java.util.List; 4 | /** 5 | * Interface to represent a single test in the suite file. 6 | * @author Varun Menon 7 | * 8 | */ 9 | public interface ISimpleTest { 10 | /** 11 | * Get the test name that is set i the suite file 12 | * @return 13 | */ 14 | public String getTestName(); 15 | 16 | /** 17 | * Set the test name for the said test 18 | * @param testName 19 | */ 20 | public void setTestName(String testName); 21 | 22 | /** 23 | * Gets the test-id mentioned in the suite file for the specified the test 24 | * @return 25 | */ 26 | public String getTestId(); 27 | 28 | /** 29 | * Sets the test-id mentioned in the suite file for the specified the test 30 | */ 31 | public void setTestId(String testId); 32 | 33 | /** 34 | * Return true or false based on the condition whether the test is enabled for execution or not. 35 | * @return true or false 36 | */ 37 | public boolean isEnabled(); 38 | 39 | /** 40 | * Sets the test to enabled or disabled state. 41 | * @param enabled boolean value true or false 42 | */ 43 | public void setEnabled(boolean enabled); 44 | 45 | /** 46 | * Gets the test file path for the test 47 | * @return Path of the file which contains the keywords for the said test. 48 | */ 49 | public String getTestFilePath(); 50 | 51 | /** 52 | * Sets the file path of the said test. 53 | * @param testFilePath 54 | */ 55 | public void setTestFilePath(String testFilePath); 56 | 57 | /** 58 | * Returns any extra arguments that is provided in the suite file for the specified test as List 59 | * These arguments are mainly related the path of suite file, sheetname(in case of excel), delimiters (in case of csv), separators(in case of csv). 60 | * @return List of the extra arguments provided in the suite file for the said test. 61 | * This list will be empty if no extra arguments have been provided. 62 | */ 63 | public List getExtraArguments(); 64 | 65 | /** 66 | * Sets any extra argument that may be required for the said test. 67 | * These arguments are mainly related the path of suite file, sheetname(in case of excel), delimiters (in case of csv), separators(in case of csv). 68 | * @param arguments List of the arguments that needs to be set. 69 | */ 70 | public void setExtraArguments(List arguments); 71 | 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/keywordmodel/suite/ISuiteFileReader.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.keywordmodel.suite; 2 | 3 | import java.io.File; 4 | import java.util.List; 5 | 6 | 7 | /** 8 | * An interface to represent the Suite file reader for reading and parsing the test-suite files. 9 | * @author Varun Menon 10 | * 11 | */ 12 | public interface ISuiteFileReader { 13 | 14 | /** 15 | * Methods to identify whether the said suite file is supported by the implementing class or not. 16 | * @param file - File object of the test-suite file. 17 | * @return true or false based on whether file is supported or not. 18 | */ 19 | public boolean isSupported(File file); 20 | 21 | /** 22 | * Method to parse and return the test instances of the test present inside the said suite file. 23 | * @param file {@link File} object of the test-suite file. 24 | * @param arguments - {@link List} of {@link String} required to read or parse the said test-suite file. 25 | * These arguments are mainly related to the path of suite file, sheetname(in case of excel), delimiters (in case of csv), separators(in case of csv). 26 | * @return {@link List} of {@link ISimpleTest} after parsing the test-suite file. 27 | */ 28 | public List read(File file, List arguments); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/keywordmodel/suite/SimpleTest.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.keywordmodel.suite; 2 | 3 | import java.util.List; 4 | 5 | public class SimpleTest implements ISimpleTest{ 6 | 7 | private String testName; 8 | private String testId; 9 | private boolean enabled; 10 | private String testFilePath; 11 | private List arguments; 12 | 13 | public SimpleTest(String testName, String testId, boolean enabled,String testFilePath, List arguments){ 14 | this.testName = testName; 15 | this.testId = testId; 16 | this.enabled = enabled; 17 | this.testFilePath = testFilePath; 18 | this.arguments = arguments; 19 | } 20 | 21 | @Override 22 | public String getTestName() { 23 | return this.testName; 24 | } 25 | 26 | @Override 27 | public void setTestName(String testName) { 28 | this.testName = testName; 29 | 30 | } 31 | 32 | @Override 33 | public String getTestId() { 34 | return this.testId; 35 | } 36 | 37 | @Override 38 | public void setTestId(String testId) { 39 | this.testId = testId; 40 | } 41 | 42 | @Override 43 | public boolean isEnabled() { 44 | return this.enabled; 45 | } 46 | 47 | @Override 48 | public void setEnabled(boolean enabled) { 49 | this.enabled = enabled; 50 | } 51 | 52 | @Override 53 | public List getExtraArguments() { 54 | return this.arguments; 55 | } 56 | 57 | @Override 58 | public void setExtraArguments(List arguments) { 59 | this.arguments = arguments; 60 | } 61 | 62 | @Override 63 | public String getTestFilePath() { 64 | return testFilePath; 65 | } 66 | 67 | @Override 68 | public void setTestFilePath(String testFilePath) { 69 | this.testFilePath = testFilePath; 70 | } 71 | 72 | @Override 73 | public String toString(){ 74 | String testN = "Test name: " + testName; 75 | String testI = "Test ID: " + testId; 76 | String enbld = "Enabled: " + enabled; 77 | String filePath = "FilePath: " + testFilePath; 78 | String args = "Arguments: " + arguments.toString(); 79 | return testN +","+testI+","+enbld+","+filePath+","+args; 80 | 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/keywordmodel/suite/TestSuite.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.keywordmodel.suite; 2 | 3 | import java.io.File; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | /** 8 | * Utility to read and parse test-suites and return {@link ISimpleTest} object of the tests present in the suite file. 9 | * @author Varun Menon 10 | * 11 | */ 12 | public class TestSuite { 13 | 14 | private List suiteReaders = new ArrayList(); 15 | private File file; 16 | private List arguments; 17 | private ISuiteFileReader suiteReader; 18 | /** 19 | * Constructor to create {@link TestSuite} object. 20 | * @param file - {@link File} object of the test-suite file. 21 | * @param arguments - Any extra arguments required for reading the suite file like sheetname, sheetindex, delimiter, separator. 22 | */ 23 | public TestSuite(File file, List arguments){ 24 | this.file = file; 25 | this.arguments = arguments; 26 | init(); 27 | } 28 | 29 | private void init(){ 30 | suiteReaders.add(new CsvSuiteFileReader()); 31 | suiteReaders.add(new ExcelSuiteFileReader()); 32 | } 33 | 34 | /** 35 | * This method internally identifies the supported {@link ISuiteFileReader} implementation in the framework and accordingly parses 36 | * the suite file and return {@link ISimpleTest} objects for all the tests present in the suite file. 37 | * @return {@link List} or {@link ISimpleTest} for all the tests present inside the said test-suite file. 38 | */ 39 | public List getAllTestsAsList(){ 40 | boolean fileSupported = false; 41 | for(ISuiteFileReader suiteReader : suiteReaders){ 42 | if(suiteReader.isSupported(file)){ 43 | fileSupported = true; 44 | this.suiteReader = suiteReader; 45 | break; 46 | } 47 | } 48 | if(!fileSupported) 49 | throw new RuntimeException("None of the existing suite reader " + 50 | "supports the given file: "+file.getName()); 51 | 52 | return this.suiteReader.read(this.file, this.arguments); 53 | } 54 | 55 | /** 56 | * This method internally identifies the supported {@link ISuiteFileReader} implementation in the framework and accordingly parses 57 | * the suite file and return {@link ISimpleTest} objects for all the tests present in the suite file. 58 | * This method is mainly used as a Data provider for the TestNG data driven methods. 59 | * @return {@link Object}[][] containing object of {@link ISimpleTest} for all the tests present inside the said test-suite file. 60 | */ 61 | public Object[][] getAllTestsForDataDrive(){ 62 | List tests = this.getAllTestsAsList(); 63 | Object[][] returnData = new Object[tests.size()][1]; 64 | for(int i = 0; i< tests.size();i++){ 65 | returnData[i][0] = tests.get(i); 66 | } 67 | 68 | return returnData; 69 | } 70 | 71 | /** 72 | * This method internally identifies the supported {@link ISuiteFileReader} implementation in the framework and accordingly parses 73 | * the suite file and return {@link ISimpleTest} objects of only those tests that are enabled in the suite file. 74 | * This method is mainly used as a Data provider for the TestNG data driven methods. 75 | * @return {@link Object}[][] containing object of {@link ISimpleTest} for the enabled tests present inside the said test-suite file. 76 | */ 77 | public Object[][] getTobeExecutedTests(){ 78 | List tests = this.getAllTestsAsList(); 79 | List enabledTests = new ArrayList(); 80 | 81 | for(int i = 0; i< tests.size();i++){ 82 | ISimpleTest test = tests.get(i); 83 | if(test.isEnabled()) 84 | enabledTests.add(test); 85 | } 86 | 87 | Object[][] returnData = new Object[enabledTests.size()][1]; 88 | for(int i = 0; i< enabledTests.size();i++){ 89 | returnData[i][0] = enabledTests.get(i); 90 | } 91 | 92 | return returnData; 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/locator/CustomFieldDecorator.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.locator; 2 | 3 | import java.lang.reflect.Field; 4 | import java.lang.reflect.InvocationHandler; 5 | import java.lang.reflect.Proxy; 6 | import java.util.ArrayList; 7 | import java.util.Arrays; 8 | import java.util.List; 9 | 10 | import org.imaginea.test.automation.framework.dom.EWebElement; 11 | import org.imaginea.test.automation.framework.dom.ElementOptions; 12 | import org.imaginea.test.automation.framework.pagemodel.Browser; 13 | import org.imaginea.test.automation.framework.pagemodel.PageClass; 14 | import org.openqa.selenium.WebDriver; 15 | import org.openqa.selenium.WebElement; 16 | import org.openqa.selenium.support.pagefactory.DefaultFieldDecorator; 17 | import org.openqa.selenium.support.pagefactory.ElementLocator; 18 | import org.openqa.selenium.support.pagefactory.ElementLocatorFactory; 19 | import org.openqa.selenium.support.pagefactory.internal.LocatingElementListHandler; 20 | 21 | 22 | /** 23 | * Default decorator for use with PageFactory. Will decorate 1) all of the 24 | * WebElement fields and 2) List fields that have {@literal @FindBy} 25 | * , {@literal @FindBys}, or {@literal @FindAll} annotation with a proxy that 26 | * locates the elements using the passed in ElementLocatorFactory. 27 | */ 28 | public class CustomFieldDecorator extends DefaultFieldDecorator { 29 | 30 | protected ElementLocatorFactory factory; 31 | protected WebDriver driver; 32 | protected Browser browser; 33 | 34 | public CustomFieldDecorator(ElementLocatorFactory factory) { 35 | super(factory); 36 | this.factory = factory; 37 | } 38 | 39 | public CustomFieldDecorator(Browser browser, ElementLocatorFactory factory) { 40 | super(factory); 41 | this.factory = factory; 42 | this.browser = browser; 43 | } 44 | 45 | public CustomFieldDecorator(WebDriver driver, ElementLocatorFactory factory) { 46 | super(factory); 47 | this.factory = factory; 48 | this.browser = new Browser(); 49 | this.browser.setDriver(driver); 50 | } 51 | 52 | 53 | 54 | public Object decorate(ClassLoader loader, Field field) { 55 | Object decoratedField = super.decorate(loader, field); 56 | if (decoratedField != null) { 57 | return decoratedField; 58 | 59 | } 60 | if (!EWebElement.class.isAssignableFrom(field.getType())) 61 | return null; 62 | 63 | ElementLocator locator = factory.createLocator(field); 64 | if (locator == null) { 65 | return null; 66 | } 67 | 68 | if (EWebElement.class.isAssignableFrom(field.getType())) { 69 | return proxyForEWebElement(this.browser, loader, locator, field); 70 | } else { 71 | return null; 72 | } 73 | } 74 | 75 | /** 76 | * Return eWebelement object 77 | * 78 | * @param loader 79 | * @param locator 80 | * @return 81 | */ 82 | @SuppressWarnings("unchecked") 83 | protected EWebElement proxyForEWebElement(Browser browser, ClassLoader loader, 84 | ElementLocator locator, Field field) { 85 | 86 | InvocationHandler handler = new LocatingElementListHandler(locator); 87 | String name = ""; 88 | List> navigablePageClasses = new ArrayList<>(); 89 | boolean required = true; 90 | List proxy; 91 | proxy = (List) Proxy.newProxyInstance(loader, 92 | new Class[] { List.class }, handler); 93 | 94 | if(field.isAnnotationPresent(ElementOptions.class)){ 95 | ElementOptions options = field.getAnnotation(ElementOptions.class); 96 | name = options.name(); 97 | navigablePageClasses = Arrays.asList(options.navigablePageClasses()); 98 | required = options.required(); 99 | } 100 | if(name.contentEquals("")){ 101 | name = field.getName(); 102 | } 103 | EWebElement eWebElement = new EWebElement(browser, proxy); 104 | eWebElement.setName(name); 105 | eWebElement.setRequired(required); 106 | eWebElement.setNavigablePageClasses(navigablePageClasses); 107 | return eWebElement; 108 | 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/locator/LocatorException.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.locator; 2 | 3 | public class LocatorException extends RuntimeException{ 4 | 5 | /** 6 | * 7 | */ 8 | private static final long serialVersionUID = -3979115040542424409L; 9 | 10 | public LocatorException() { 11 | super("An unknown Locator Exception has been thrown"); 12 | } 13 | 14 | public LocatorException(String message){ 15 | super(message); 16 | } 17 | 18 | public LocatorException(Throwable cause){ 19 | super(cause); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/locator/locatorfiles/ILocatorFile.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.locator.locatorfiles; 2 | 3 | import java.io.File; 4 | /** 5 | * Base Locator file interface for referring to the locator file 6 | * @author Varun Menon 7 | * 8 | */ 9 | 10 | public interface ILocatorFile { 11 | 12 | /** 13 | * Gets the respective locator for the keyword from the locator file. 14 | * @param keyword For which the locator have to be fetched 15 | * @return Respective locator for "keyword" from the file. May return null or 16 | * an empty string depending upon the implementation in the implementing class. 17 | */ 18 | public String getLocatorFor(String keyword); 19 | 20 | /** 21 | * Utility to know whether the said type of locator storing file is supported 22 | * by the particular implementation or not. 23 | * @param file File object of the file which have to checked whether its supported or not. 24 | * @return true or false depending upon the condition 25 | * whether the file is supported or not. 26 | */ 27 | public boolean isSupported(File file); 28 | 29 | /** 30 | * Load the respective file for parsing if the implementation class supports 31 | * the particular file. 32 | * @param file File object of the locator file that have to be loaded. 33 | */ 34 | public void loadFile(File file); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/locator/locatorfiles/LocatorFileFactory.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.locator.locatorfiles; 2 | 3 | import java.io.File; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import org.imaginea.test.automation.framework.locator.LocatorException; 8 | 9 | 10 | /** 11 | * Locator file factory for identifying the supported locator storage files/types 12 | * and parsing the respective {@link ILocatorFile} implementation. 13 | * 14 | * @author Varun Menon 15 | * 16 | */ 17 | public class LocatorFileFactory { 18 | List locators = new ArrayList(); 19 | 20 | public LocatorFileFactory(){ 21 | locators.add(new PropertiesLocatorFile()); 22 | } 23 | 24 | /** 25 | * Identifies the supported {@link ILocatorFile} implementation for the passed {@link File} object of the locator file passed. 26 | * @param file {@link File} object of the locator file 27 | * @return {@link ILocatorFile} object of the supported implementing locator class if supported else fails with {@link LocatorException} 28 | * 29 | */ 30 | public ILocatorFile getLocatorFile(File file){ 31 | 32 | for(ILocatorFile lFile : locators){ 33 | if(lFile.isSupported(file)){ 34 | lFile.loadFile(file); 35 | return lFile; 36 | } 37 | 38 | } 39 | throw new LocatorException("File: "+file.getName()+" is not currently supported."); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/locator/locatorfiles/PropertiesLocatorFile.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.locator.locatorfiles; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.IOException; 6 | import java.util.Properties; 7 | 8 | import org.imaginea.test.automation.framework.locator.LocatorException; 9 | 10 | 11 | public class PropertiesLocatorFile implements ILocatorFile{ 12 | 13 | Properties prop; 14 | 15 | @Override 16 | public String getLocatorFor(String keyword) { 17 | String locatorValue = prop.getProperty(keyword); 18 | if(locatorValue==null) 19 | throw new LocatorException("Unable to find the locator value for keyword: " + keyword); 20 | return locatorValue; 21 | } 22 | 23 | @Override 24 | public boolean isSupported(File file) { 25 | boolean supported = false; 26 | if(file.getName().endsWith(".properties")) 27 | supported = true; 28 | return supported; 29 | } 30 | 31 | @Override 32 | public void loadFile(File file) { 33 | this.prop = new Properties(); 34 | try { 35 | prop.load(new FileInputStream(file)); 36 | } catch (IOException e) { 37 | throw new LocatorException(e); 38 | } 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/locator/pagefactory/BrowserBasedElementLocator.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.locator.pagefactory; 2 | 3 | import java.lang.reflect.Field; 4 | import java.util.List; 5 | 6 | import org.imaginea.test.automation.framework.locator.locatorfiles.ILocatorFile; 7 | import org.imaginea.test.automation.framework.pagemodel.Browser; 8 | import org.openqa.selenium.By; 9 | import org.openqa.selenium.SearchContext; 10 | import org.openqa.selenium.WebElement; 11 | import org.openqa.selenium.support.pagefactory.Annotations; 12 | import org.openqa.selenium.support.pagefactory.ElementLocator; 13 | 14 | 15 | /** 16 | * Page model based Element locator implementation uses the {@link Browser} bject to get the driver at runtime and get the element. 17 | * 18 | * @author Varun Menon 19 | * 20 | */ 21 | public class BrowserBasedElementLocator implements ElementLocator { 22 | private final Browser browser; 23 | private final boolean shouldCache; 24 | private final By by; 25 | private WebElement cachedElement; 26 | private List cachedElementList; 27 | 28 | public BrowserBasedElementLocator(ILocatorFile locatorFile, Browser browser, Field field) { 29 | this.browser = browser; 30 | Annotations annotations = new KeywordBasedAnnotations(locatorFile,field); 31 | shouldCache = annotations.isLookupCached(); 32 | by = annotations.buildBy(); 33 | } 34 | 35 | /** 36 | * Find the element. 37 | */ 38 | public WebElement findElement() { 39 | if (cachedElement != null && shouldCache) { 40 | return cachedElement; 41 | } 42 | SearchContext searchContext = browser.getDriver(); 43 | WebElement element = searchContext.findElement(by); 44 | if (shouldCache) { 45 | cachedElement = element; 46 | } 47 | 48 | return element; 49 | } 50 | 51 | /** 52 | * Find the element list. 53 | */ 54 | public List findElements() { 55 | if (cachedElementList != null && shouldCache) { 56 | return cachedElementList; 57 | } 58 | 59 | SearchContext searchContext = browser.getDriver(); 60 | List elements = searchContext.findElements(by); 61 | if (shouldCache) { 62 | cachedElementList = elements; 63 | } 64 | 65 | return elements; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/locator/pagefactory/BrowserBasedSimpleElementLocator.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.locator.pagefactory; 2 | 3 | import java.lang.reflect.Field; 4 | import java.util.List; 5 | 6 | import org.imaginea.test.automation.framework.pagemodel.Browser; 7 | import org.openqa.selenium.By; 8 | import org.openqa.selenium.SearchContext; 9 | import org.openqa.selenium.WebElement; 10 | import org.openqa.selenium.support.pagefactory.Annotations; 11 | import org.openqa.selenium.support.pagefactory.ElementLocator; 12 | 13 | 14 | /** 15 | * Page model based Element locator implementation uses the {@link Browser} bject to get the driver at runtime and get the element. 16 | * 17 | * @author Varun Menon 18 | * 19 | */ 20 | public class BrowserBasedSimpleElementLocator implements ElementLocator { 21 | private final Browser browser; 22 | private final boolean shouldCache; 23 | private final By by; 24 | private WebElement cachedElement; 25 | private List cachedElementList; 26 | 27 | public BrowserBasedSimpleElementLocator(Browser browser, Field field) { 28 | this.browser = browser; 29 | Annotations annotations = new Annotations(field); 30 | shouldCache = annotations.isLookupCached(); 31 | by = annotations.buildBy(); 32 | } 33 | 34 | /** 35 | * Find the element. 36 | */ 37 | public WebElement findElement() { 38 | if (cachedElement != null && shouldCache) { 39 | return cachedElement; 40 | } 41 | SearchContext searchContext = browser.getDriver(); 42 | WebElement element = searchContext.findElement(by); 43 | if (shouldCache) { 44 | cachedElement = element; 45 | } 46 | 47 | return element; 48 | } 49 | 50 | /** 51 | * Find the element list. 52 | */ 53 | public List findElements() { 54 | if (cachedElementList != null && shouldCache) { 55 | return cachedElementList; 56 | } 57 | 58 | SearchContext searchContext = browser.getDriver(); 59 | List elements = searchContext.findElements(by); 60 | if (shouldCache) { 61 | cachedElementList = elements; 62 | } 63 | 64 | return elements; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/locator/pagefactory/DriverBasedElementLocator.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.locator.pagefactory; 2 | 3 | import java.lang.reflect.Field; 4 | import java.util.List; 5 | 6 | import org.imaginea.test.automation.framework.locator.locatorfiles.ILocatorFile; 7 | import org.openqa.selenium.By; 8 | import org.openqa.selenium.SearchContext; 9 | import org.openqa.selenium.WebElement; 10 | import org.openqa.selenium.support.pagefactory.Annotations; 11 | import org.openqa.selenium.support.pagefactory.ElementLocator; 12 | 13 | 14 | /** 15 | * Simple driver baed elelment locator implementation for Page Factory 16 | * @author Varun Menon 17 | * 18 | */ 19 | public class DriverBasedElementLocator implements ElementLocator { 20 | private final SearchContext searchContext; 21 | private final boolean shouldCache; 22 | private final By by; 23 | private WebElement cachedElement; 24 | private List cachedElementList; 25 | 26 | public DriverBasedElementLocator(ILocatorFile locatorFile, SearchContext searchContext, Field field) { 27 | this.searchContext = searchContext; 28 | Annotations annotations = new KeywordBasedAnnotations(locatorFile,field); 29 | shouldCache = annotations.isLookupCached(); 30 | by = annotations.buildBy(); 31 | } 32 | 33 | /** 34 | * Find the element. 35 | */ 36 | public WebElement findElement() { 37 | if (cachedElement != null && shouldCache) { 38 | return cachedElement; 39 | } 40 | 41 | WebElement element = searchContext.findElement(by); 42 | if (shouldCache) { 43 | cachedElement = element; 44 | } 45 | 46 | return element; 47 | } 48 | 49 | /** 50 | * Find the element list. 51 | */ 52 | public List findElements() { 53 | if (cachedElementList != null && shouldCache) { 54 | return cachedElementList; 55 | } 56 | 57 | List elements = searchContext.findElements(by); 58 | if (shouldCache) { 59 | cachedElementList = elements; 60 | } 61 | 62 | return elements; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/locator/pagefactory/KeywordBasedAnnotations.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.locator.pagefactory; 2 | 3 | import java.lang.reflect.Field; 4 | 5 | import org.imaginea.test.automation.framework.locator.locatorfiles.ILocatorFile; 6 | import org.openqa.selenium.By; 7 | import org.openqa.selenium.support.ByIdOrName; 8 | import org.openqa.selenium.support.FindBy; 9 | import org.openqa.selenium.support.How; 10 | import org.openqa.selenium.support.pagefactory.Annotations; 11 | 12 | 13 | /** 14 | * Extension of the Page factory Annotation 15 | * @author Varun Menon 16 | * 17 | */ 18 | public class KeywordBasedAnnotations extends Annotations{ 19 | ILocatorFile locatorFile; 20 | Field field; 21 | 22 | public KeywordBasedAnnotations(ILocatorFile locatorFile,Field field) { 23 | super(field); 24 | this.field = field; 25 | this.locatorFile = locatorFile; 26 | } 27 | 28 | protected By buildByFromLongFindBy(FindBy findBy) { 29 | How how = findBy.how(); 30 | String using = locatorFile.getLocatorFor(findBy.using()); 31 | 32 | switch (how) { 33 | case CLASS_NAME: 34 | return By.className(using); 35 | 36 | case CSS: 37 | return By.cssSelector(using); 38 | 39 | case ID: 40 | return By.id(using); 41 | 42 | case ID_OR_NAME: 43 | return new ByIdOrName(using); 44 | 45 | case LINK_TEXT: 46 | return By.linkText(using); 47 | 48 | case NAME: 49 | return By.name(using); 50 | 51 | case PARTIAL_LINK_TEXT: 52 | return By.partialLinkText(using); 53 | 54 | case TAG_NAME: 55 | return By.tagName(using); 56 | 57 | case XPATH: 58 | return By.xpath(using); 59 | 60 | default: 61 | // Note that this shouldn't happen (eg, the above matches all 62 | // possible values for the How enum) 63 | throw new IllegalArgumentException("Cannot determine how to locate element " + this.field); 64 | } 65 | 66 | } 67 | 68 | protected By buildByFromShortFindBy(FindBy findBy) { 69 | if (!"".equals(findBy.className())) 70 | return By.className(locatorFile.getLocatorFor(findBy.className())); 71 | 72 | if (!"".equals(findBy.css())) 73 | return By.cssSelector(locatorFile.getLocatorFor(findBy.css())); 74 | 75 | if (!"".equals(findBy.id())) 76 | return By.id(locatorFile.getLocatorFor(findBy.id())); 77 | 78 | if (!"".equals(findBy.linkText())) 79 | return By.linkText(locatorFile.getLocatorFor(findBy.linkText())); 80 | 81 | if (!"".equals(findBy.name())) 82 | return By.name(locatorFile.getLocatorFor(findBy.name())); 83 | 84 | if (!"".equals(findBy.partialLinkText())) 85 | return By.partialLinkText(locatorFile.getLocatorFor(findBy.partialLinkText())); 86 | 87 | if (!"".equals(findBy.tagName())) 88 | return By.tagName(locatorFile.getLocatorFor(findBy.tagName())); 89 | 90 | if (!"".equals(findBy.xpath())) 91 | return By.xpath(locatorFile.getLocatorFor(findBy.xpath())); 92 | 93 | // Fall through 94 | return null; 95 | 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/locator/pagefactory/KeywordBasedLocatorFactory.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.locator.pagefactory; 2 | 3 | import java.lang.reflect.Field; 4 | 5 | import org.imaginea.test.automation.framework.locator.locatorfiles.ILocatorFile; 6 | import org.imaginea.test.automation.framework.pagemodel.Browser; 7 | import org.openqa.selenium.SearchContext; 8 | import org.openqa.selenium.support.pagefactory.ElementLocator; 9 | import org.openqa.selenium.support.pagefactory.ElementLocatorFactory; 10 | 11 | 12 | /** 13 | * Factory to identify the respective Element locator based on whether the {@link Browser} object was set or not. 14 | * @author Varun Menon 15 | * 16 | */ 17 | public class KeywordBasedLocatorFactory implements ElementLocatorFactory{ 18 | 19 | private final SearchContext searchContext; 20 | private final ILocatorFile locatorFile; 21 | private final Browser browser; 22 | 23 | public KeywordBasedLocatorFactory(ILocatorFile locatorFile,SearchContext searchContext) { 24 | this.locatorFile = locatorFile; 25 | this.searchContext = searchContext; 26 | this.browser =null; 27 | } 28 | 29 | public KeywordBasedLocatorFactory(ILocatorFile locatorFile,Browser browser) { 30 | this.locatorFile = locatorFile; 31 | this.searchContext = null; 32 | this.browser = browser; 33 | } 34 | 35 | @Override 36 | public ElementLocator createLocator(Field field) { 37 | ElementLocator elementLocator = null; 38 | if(this.browser!=null){ 39 | elementLocator = new BrowserBasedElementLocator(locatorFile, browser, field); 40 | } else { 41 | elementLocator = new DriverBasedElementLocator(locatorFile, searchContext, field); 42 | } 43 | return elementLocator; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/locator/pagefactory/SimpleLocatorFactory.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.locator.pagefactory; 2 | 3 | import java.lang.reflect.Field; 4 | 5 | import org.imaginea.test.automation.framework.pagemodel.Browser; 6 | import org.openqa.selenium.support.pagefactory.ElementLocator; 7 | import org.openqa.selenium.support.pagefactory.ElementLocatorFactory; 8 | 9 | 10 | /** 11 | * Factory to identify the respective Element locator based on whether the {@link Browser} object was set or not. 12 | * @author Varun Menon 13 | * 14 | */ 15 | public class SimpleLocatorFactory implements ElementLocatorFactory{ 16 | 17 | private final Browser browser; 18 | 19 | public SimpleLocatorFactory(Browser browser) { 20 | this.browser = browser; 21 | } 22 | 23 | @Override 24 | public ElementLocator createLocator(Field field) { 25 | ElementLocator elementLocator = null; 26 | elementLocator = new BrowserBasedSimpleElementLocator(browser, field); 27 | return elementLocator; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/pagemodel/AbstractPageClass.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.pagemodel; 2 | 3 | import java.io.File; 4 | import java.net.URL; 5 | 6 | import org.imaginea.test.automation.framework.util.PageObjectUtils; 7 | import org.imaginea.test.automation.framework.util.Utilities; 8 | import org.openqa.selenium.WebDriver; 9 | 10 | 11 | /** 12 | * Utility class to support Page classes for the Page Object Model implementation 13 | * @author Varun Menon 14 | * 15 | */ 16 | public abstract class AbstractPageClass extends PageObjectUtils { 17 | 18 | private boolean initialized = false; 19 | 20 | protected File locatorFile=null; 21 | 22 | /** 23 | * Intialization method for the Page class 24 | * @param browser 25 | */ 26 | public void init(Browser browser){ 27 | this.browser = browser; 28 | config = browser.getConfig(); 29 | initialized = true; 30 | this.init(); 31 | } 32 | 33 | /** 34 | * Return true or false based on the coniditon whether the said object has been 35 | * initialized by the TAF framework or its just an object. 36 | * @return true or false 37 | */ 38 | public boolean isInitialized(){ 39 | return this.initialized; 40 | } 41 | 42 | /** 43 | * Sets the driver object for use with this page class. 44 | * @param driver {@link WebDriver} object to be set for use. 45 | */ 46 | protected void setDriver(WebDriver driver){ 47 | this.browser.setDriver(driver); 48 | } 49 | 50 | /** 51 | * Returns the driver object(if set) for this Page class else return the driver object from the {@link Browser} class object. 52 | * @return 53 | */ 54 | protected WebDriver getDriver(){ 55 | return this.browser.getDriver(); 56 | } 57 | 58 | /** 59 | * Return the locator file which have to be used for initializing the WebElements of the current Page class. 60 | * 61 | * @return File 62 | */ 63 | public File getLocatorFile(){ 64 | return this.locatorFile; 65 | } 66 | 67 | /** 68 | * Sets the locator file which have to be used for initializing the WebElements of the current Page class. 69 | * Use this method if you want to specify some file else the default behavior of the Selenium PageFactory will be used. 70 | * @param file 71 | */ 72 | public void setLocatorFile(File file){ 73 | this.locatorFile = file; 74 | } 75 | 76 | public File evaluateLocatorFile(String fileName) { 77 | URL fileStream = this.toString().getClass().getResource(fileName); 78 | if(fileStream == null) 79 | return null; 80 | else 81 | return new File(fileStream.getPath()); 82 | } 83 | 84 | /** 85 | * The url for the said page. Please implement this method in your page classes and return the respective url for the page. 86 | * In case the page dont have any url just return and empty string. * 87 | * 88 | *

89 | * Note:Do not append the base url to this url as it is automatically appended at runtime. 90 | * @return - Page url without appending the base url. 91 | */ 92 | public abstract String toUrl(); 93 | 94 | /** 95 | * Method used to verify whether the driver object is on the said page or not. 96 | * Return true or false based on the criteria to identify whether driver object is on the said page or not. 97 | * 98 | *

This is a very important method as it will help in making you Page object model tests robust as it will help 99 | * you to validate the Page is shown before any of the util methods of the said page is executed. 100 | * Note: For better results do not store your evaluated condition in a variable. Try to evaluate the success condition everytime this method gets executed. 101 | * @return true or false based on the page verification condition. 102 | */ 103 | public abstract boolean at(); 104 | 105 | /** 106 | * Use this method in case you want to initialize some variables or data while creating an Object of you Page class. 107 | * This method will automatically get executed whenever you use {@link #to(Class)} or {@link #at(Class)} utils. 108 | * In case you have nothing initialize just implement an empty method. 109 | */ 110 | public abstract void init(); 111 | 112 | } 113 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/pagemodel/Browser.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.pagemodel; 2 | 3 | import org.imaginea.test.automation.framework.config.DefaultConfig; 4 | import org.imaginea.test.automation.framework.driver.CacheDriverFactory; 5 | import org.imaginea.test.automation.framework.util.PageObjectUtils; 6 | import org.openqa.selenium.WebDriver; 7 | 8 | /** 9 | * Utility to provide Page Object Model support in the framework. This class provides all the utilities to create and navigate between page objects. 10 | * 11 | * @author Varun Menon 12 | * 13 | */ 14 | public class Browser extends PageObjectUtils { 15 | 16 | private WebDriver driver; 17 | private String baseUrl; 18 | 19 | public Browser(){ 20 | config = getConfig(); 21 | browser = this; 22 | } 23 | 24 | /** 25 | * Returns the stored {@link WebDriver} object(if any) else fetches the {@link WebDriver} object from the {@link CacheDriverFactory} class. 26 | * @return {@link WebDriver} object. 27 | */ 28 | public WebDriver getDriver() { 29 | String inbuiltDriverRequired = getConfig().getConfigValue("use.inbuilt.driver"); 30 | 31 | if(this.driver==null){ 32 | if(!inbuiltDriverRequired.contentEquals("false")) 33 | return new CacheDriverFactory(getConfig()).getDriver(); 34 | else 35 | throw new PageException("Inbulit driver provider feature is set to false. " + 36 | "Please explicitly create the driver object and set it to the browser object using the 'setDriver' method." + 37 | " Or set the value of 'use.inbuilt.driver' in taf config file to true"); 38 | } else{ 39 | return driver; 40 | } 41 | } 42 | 43 | /** 44 | * Sets the {@link WebDriver} object into this Browser class object. 45 | * 46 | * @param driver - {@link WebDriver} to be set and used by the Browser object. 47 | */ 48 | public void setDriver(WebDriver driver) { 49 | this.driver = driver; 50 | } 51 | 52 | /** 53 | * Returns the currently stored configuration object. 54 | * @return stored {@link DefaultConfig} object(if any) else create and get the {@link DefaultConfig} object 55 | */ 56 | public DefaultConfig getConfig() { 57 | if(config ==null){ 58 | config = DefaultConfig.getDefaultConfig(); 59 | } 60 | return config; 61 | } 62 | 63 | /** 64 | * Set the Default Config object to this object. 65 | * @param config 66 | */ 67 | public void setConfig(DefaultConfig config) { 68 | this.config = config; 69 | } 70 | 71 | /** 72 | * Get the base url for the Browser object 73 | * @return 74 | */ 75 | public String getBaseUrl() { 76 | if(baseUrl.equalsIgnoreCase("")) 77 | baseUrl = config.getConfigValue("base_url"); 78 | return baseUrl; 79 | } 80 | 81 | /** 82 | * Sets the base Url 83 | * @param baseUrl 84 | */ 85 | public void setBaseUrl(String baseUrl) { 86 | this.baseUrl = baseUrl; 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/pagemodel/PageClass.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.pagemodel; 2 | 3 | public class PageClass extends AbstractPageClass { 4 | 5 | @Override 6 | public String toUrl() { 7 | return ""; 8 | } 9 | 10 | @Override 11 | public boolean at() { 12 | return true; 13 | } 14 | 15 | @Override 16 | public void init() { 17 | 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/pagemodel/PageException.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.pagemodel; 2 | 3 | public class PageException extends RuntimeException{ 4 | 5 | /** 6 | * 7 | */ 8 | private static final long serialVersionUID = 2467276407146491151L; 9 | 10 | public PageException(){ 11 | super(); 12 | } 13 | 14 | public PageException(String message){ 15 | super(message); 16 | } 17 | 18 | public PageException(Throwable cause){ 19 | super(cause); 20 | } 21 | 22 | public PageException(String message,Throwable cause){ 23 | super(message, cause); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/pagemodel/TestClass.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.pagemodel; 2 | 3 | import org.imaginea.test.automation.framework.util.PageObjectUtils; 4 | import org.imaginea.test.automation.framework.util.Utilities; 5 | import org.openqa.selenium.WebDriver; 6 | 7 | 8 | /** 9 | * Base Class to be extended by your Test classes required to be executed for using the in-built 10 | * Page Object Model supported by the framework. 11 | * @author Varun Menon 12 | * 13 | */ 14 | public class TestClass extends PageObjectUtils { 15 | protected WebDriver driver; 16 | 17 | public TestClass(){ 18 | initialize(); 19 | } 20 | 21 | private void initialize(){ 22 | this.browser = new Browser(); 23 | this.config = browser.getConfig(); 24 | } 25 | 26 | /** 27 | * Sets the driver for this Test class 28 | * @param driver {@link WebDriver} object to be set for the Test class 29 | */ 30 | protected void setDriver(WebDriver driver){ 31 | this.browser.setDriver(driver); 32 | } 33 | 34 | /** 35 | * Return the current driver object for the said Test Class 36 | * @return 37 | */ 38 | protected WebDriver getDriver(){ 39 | return this.browser.getDriver(); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/testng/listener/MethodInvokerListener.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.testng.listener; 2 | 3 | 4 | import java.lang.reflect.Field; 5 | 6 | import org.imaginea.test.automation.framework.keywordmodel.suite.ISimpleTest; 7 | import org.testng.IInvokedMethod; 8 | import org.testng.IInvokedMethodListener; 9 | import org.testng.ITestNGMethod; 10 | import org.testng.ITestResult; 11 | import org.testng.internal.TestResult; 12 | 13 | 14 | public class MethodInvokerListener implements IInvokedMethodListener{ 15 | 16 | @Override 17 | public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { 18 | // TODO Auto-generated method stub 19 | 20 | } 21 | 22 | @Override 23 | public void afterInvocation(IInvokedMethod method, ITestResult testResult) { 24 | ITestNGMethod testNGMethod = testResult.getMethod(); 25 | Object[] params = testResult.getParameters(); 26 | ISimpleTest testDetails=null; 27 | if(params.length>0){ 28 | Object tempDetails = params[0]; 29 | if(tempDetails instanceof ISimpleTest) 30 | testDetails = (ISimpleTest)tempDetails; 31 | 32 | } 33 | changeTestMethodName(testResult,testDetails); 34 | ITestNGMethod customMethod = new CustomTestNGMethod(testNGMethod, testDetails); 35 | ((TestResult)testResult).setMethod(customMethod); 36 | } 37 | 38 | private void changeTestMethodName(ITestResult result,ISimpleTest testDetails){ 39 | String methodName=""; 40 | if(testDetails!=null){ 41 | methodName = testDetails.getTestId()+" : "+testDetails.getTestName(); 42 | 43 | try { 44 | @SuppressWarnings("rawtypes") 45 | Class cls = result.getClass(); 46 | Field methodNameF; 47 | methodNameF = cls.getDeclaredField("m_name"); 48 | methodNameF.setAccessible(true); 49 | methodNameF.set(result, methodName); 50 | } catch (NoSuchFieldException e) { 51 | // TODO Auto-generated catch block 52 | e.printStackTrace(); 53 | } catch (SecurityException e) { 54 | // TODO Auto-generated catch block 55 | e.printStackTrace(); 56 | } catch (IllegalArgumentException e) { 57 | // TODO Auto-generated catch block 58 | e.printStackTrace(); 59 | } catch (IllegalAccessException e) { 60 | // TODO Auto-generated catch block 61 | e.printStackTrace(); 62 | } 63 | 64 | 65 | 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/util/readers/CsvReader.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.util.readers; 2 | 3 | import java.io.*; 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | import java.util.Iterator; 7 | import java.util.List; 8 | 9 | import au.com.bytecode.opencsv.CSVReader; 10 | 11 | /** 12 | * Util class to read csv files. 13 | * @author Varun Menon 14 | * 15 | */ 16 | public class CsvReader { 17 | 18 | 19 | CSVReader csvReader = null; 20 | List> rows=null; 21 | 22 | /** 23 | * Creates the CsvReader class object 24 | * @param filePath - File path of the csv file to be read 25 | * @param separator - Data separator to be used. Default value is ',' 26 | * @param quotechar - Quote character for the data. Default value is '"' 27 | * @throws IOException 28 | */ 29 | public CsvReader(String filePath, char separator, char quotechar) throws IOException{ 30 | this(new FileReader(filePath),separator,quotechar); 31 | } 32 | 33 | /** 34 | * Creates the CsvReader class object 35 | * @param inpFile - Input csv file to be read 36 | * @param separator - Data separator to be used. Default value is ',' 37 | * @param quotechar - Quote character for the data. Default value is '"' 38 | * @throws IOException 39 | */ 40 | public CsvReader(File inpFile , char separator, char quotechar) throws IOException{ 41 | this(new FileReader(inpFile),separator,quotechar); 42 | } 43 | 44 | public CsvReader(File inpFile , String separator, String quotechar) throws IOException{ 45 | this(new FileReader(inpFile),separator.charAt(0),quotechar.charAt(0)); 46 | } 47 | 48 | public CsvReader(InputStream fileStream , String separator, String quotechar) throws IOException{ 49 | this(new InputStreamReader(fileStream),separator.charAt(0),quotechar.charAt(0)); 50 | } 51 | 52 | public CsvReader(String filePath) throws IOException{ 53 | this(new FileReader(filePath),',','"'); 54 | } 55 | 56 | public CsvReader(File inpFile) throws IOException{ 57 | this(new FileReader(inpFile),',','"'); 58 | } 59 | 60 | public CsvReader(InputStream fileStream) throws IOException { 61 | this(new InputStreamReader(fileStream), ',', '"'); 62 | } 63 | 64 | /** 65 | * Creates the CsvReader class object 66 | * @param reader - Reader object of the file to be read 67 | * @param separator - Data separator to be used. Default value is ',' 68 | * @param quotechar - Quote character for the data. Default value is '"' 69 | * @throws IOException 70 | */ 71 | public CsvReader(Reader reader , char separator, char quotechar) throws IOException { 72 | csvReader = new CSVReader(reader,separator,quotechar); 73 | List rowsTemp = csvReader.readAll(); 74 | rows = new ArrayList>(); 75 | Iterator rowsIterator = rowsTemp.iterator(); 76 | // handling empty lines from csv by adding only non-empty lines to rows 77 | while (rowsIterator.hasNext()) { 78 | List tempList = Arrays.asList(rowsIterator.next()); 79 | if (!(tempList.size() == 1 && tempList.get(0).equals(""))) { 80 | rows.add(tempList); 81 | } 82 | } 83 | } 84 | 85 | /** 86 | * Gets the data from csv file based on column and row number 87 | * @param column Column number 88 | * @param row Row number 89 | * @return The data at the said position. If the said row or column don't exists then return an empty string 90 | */ 91 | public String getData(int row, int column){ 92 | String data=null; 93 | if(row < 0 && ((row + 1) > rows.size())){ 94 | return ""; 95 | } 96 | List rowData= rows.get(row); 97 | if(column < 0 || (column >= rowData.size())){ 98 | return ""; 99 | } 100 | 101 | data=rowData.get(column); 102 | 103 | return data; 104 | } 105 | 106 | /** 107 | * Get the number of rows in the said csv file 108 | * @return Return no of rows present in the said csv file 109 | */ 110 | public int getNoOfRows(){ 111 | return rows.size(); 112 | } 113 | 114 | /** 115 | * Return the number of column in the first row of the csv file 116 | * @return return the no. of column in the first row of the csv file 117 | */ 118 | public int getNoOfColumn(){ 119 | return rows.get(0).size(); 120 | } 121 | 122 | /** 123 | * Returns the number of the column of the said row number passed 124 | * @param rowNo - row number for which the number columns needs to be returned. 125 | * @return return the no. of column in the specified row of the csv file 126 | */ 127 | public int getNoOfColumn(int rowNo){ 128 | return rows.get(rowNo).size(); 129 | } 130 | 131 | 132 | 133 | } 134 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/util/readers/ExcelReader.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.util.readers; 2 | 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.util.ArrayList; 8 | import java.util.Date; 9 | import java.util.LinkedHashMap; 10 | import java.util.List; 11 | import java.util.Map; 12 | import java.text.SimpleDateFormat; 13 | 14 | 15 | import org.apache.poi.openxml4j.exceptions.InvalidFormatException; 16 | import org.apache.poi.ss.usermodel.*; 17 | import org.imaginea.test.automation.framework.exceptions.TafRuntimeException; 18 | 19 | /** 20 | * Utility to read Excel files. This file makes use of apache poi for reading excel files. 21 | * It supports both "xls" and "xlsx" file extension. 22 | * @author Varun Menon 23 | * 24 | */ 25 | public class ExcelReader { 26 | private Cell openCell; 27 | private Row openRow; 28 | private Sheet openSheet; 29 | private Workbook openWorkbook; 30 | public static int noOfSheet = 0; 31 | 32 | private Map> storedData = new LinkedHashMap>(); 33 | 34 | /** 35 | * Creates a ExcelReader object based on filePath 36 | * @param filePath File path of the file to be opened 37 | * @throws FileNotFoundException 38 | * @throws IOException 39 | */ 40 | public ExcelReader(String filePath) throws FileNotFoundException, 41 | IOException { 42 | this(new File(filePath)); 43 | } 44 | 45 | /** 46 | * Creates a ExcelReader object based on File object passed 47 | * @param file File object of the file to be opened. 48 | * @throws IOException 49 | * @throws FileNotFoundException 50 | */ 51 | public ExcelReader(File file) throws IOException, FileNotFoundException { 52 | this.openFile(file, 0); 53 | } 54 | 55 | public ExcelReader(InputStream fileStream) throws IOException, FileNotFoundException { 56 | this.openFile(fileStream, 0); 57 | } 58 | 59 | /** 60 | * 61 | * @param filePath 62 | * @param sheetNo 63 | * @throws IOException 64 | * @throws FileNotFoundException 65 | */ 66 | public ExcelReader(String filePath, int sheetNo) throws IOException, FileNotFoundException { 67 | this.openFile(filePath, sheetNo); 68 | } 69 | 70 | public ExcelReader(InputStream fileStream, int sheetNo) throws IOException, FileNotFoundException { 71 | this.openFile(fileStream, sheetNo); 72 | } 73 | 74 | /** 75 | * 76 | * @param filePath 77 | * @param sheetName 78 | * @throws IOException 79 | * @throws FileNotFoundException 80 | */ 81 | public ExcelReader(String filePath, String sheetName) throws IOException, FileNotFoundException { 82 | this.openFile(filePath, sheetName); 83 | } 84 | 85 | public ExcelReader(InputStream fileStream, String sheetName) throws IOException, FileNotFoundException { 86 | this.openFile(fileStream, sheetName); 87 | } 88 | 89 | /** 90 | * 91 | * @param file 92 | * @param sheetNo 93 | * @throws IOException 94 | * @throws FileNotFoundException 95 | */ 96 | public ExcelReader(File file, int sheetNo) throws IOException, FileNotFoundException { 97 | this.openFile(file, sheetNo); 98 | } 99 | 100 | /** 101 | * 102 | * @param file 103 | * @param sheetName 104 | * @throws IOException 105 | * @throws FileNotFoundException 106 | */ 107 | public ExcelReader(File file, String sheetName) throws IOException, FileNotFoundException { 108 | this.openFile(file, sheetName); 109 | } 110 | 111 | /** 112 | * 113 | */ 114 | public ExcelReader() { 115 | 116 | } 117 | 118 | /** 119 | * 120 | * @param file 121 | * @param sheetNo 122 | * @throws IOException 123 | * @throws FileNotFoundException 124 | */ 125 | public void openFile(File file, int sheetNo) throws IOException, 126 | FileNotFoundException { 127 | this.openWorkbook(file); 128 | openSheet = openWorkbook.getSheetAt(sheetNo); 129 | } 130 | 131 | public void openFile(InputStream fileStream, int sheetNo) throws IOException, 132 | FileNotFoundException { 133 | this.openWorkbook(fileStream); 134 | openSheet = openWorkbook.getSheetAt(sheetNo); 135 | } 136 | 137 | /** 138 | * 139 | * @param filePath 140 | * @param sheetNo 141 | * @throws FileNotFoundException 142 | * @throws IOException 143 | */ 144 | public void openFile(String filePath, int sheetNo) 145 | throws FileNotFoundException, IOException { 146 | this.openFile(new File(filePath), sheetNo); 147 | } 148 | 149 | public void openFile(File file, String sheetName) 150 | throws FileNotFoundException, IOException { 151 | this.openWorkbook(file); 152 | openSheet = openWorkbook.getSheet(sheetName); 153 | } 154 | 155 | public void openFile(String filePath, String sheetName) 156 | throws FileNotFoundException, IOException { 157 | this.openWorkbook(filePath); 158 | openSheet = openWorkbook.getSheet(sheetName); 159 | } 160 | 161 | public void openFile(InputStream fileStream, String sheetName) 162 | throws FileNotFoundException, IOException { 163 | this.openWorkbook(fileStream); 164 | openSheet = openWorkbook.getSheet(sheetName); 165 | } 166 | 167 | private void openWorkbook(String filePath) throws FileNotFoundException, 168 | IOException { 169 | this.openWorkbook(new File(filePath)); 170 | } 171 | 172 | private void openWorkbook(File file) throws FileNotFoundException, 173 | IOException { 174 | try{ 175 | openWorkbook = WorkbookFactory.create(file); 176 | } catch (InvalidFormatException e ){ 177 | throw new TafRuntimeException(e); 178 | } 179 | } 180 | 181 | private void openWorkbook(InputStream fileStream) throws FileNotFoundException, 182 | IOException { 183 | try { 184 | openWorkbook = WorkbookFactory.create(fileStream); 185 | } catch (InvalidFormatException e ){ 186 | throw new TafRuntimeException(e); 187 | } 188 | } 189 | 190 | public void openSheet(int sheetNo){ 191 | openSheet = openWorkbook.getSheetAt(sheetNo); 192 | } 193 | 194 | public void openSheet(String sheetName){ 195 | openSheet = openWorkbook.getSheet(sheetName); 196 | } 197 | 198 | public Workbook getOpenWorkbook(){ 199 | return openWorkbook; 200 | } 201 | 202 | /** 203 | * Gets the data from the currently opened sheet based on row and column number 204 | * @param row Row no. from which the value has to be fetched 205 | * @param column Respective column no. in the row from which the value has to be fetched 206 | * @return The data present in the respective row & column. If no value is found it returns and empty String. 207 | */ 208 | public String getData(int row, int column) { 209 | String data = ""; 210 | try { 211 | 212 | openRow = openSheet.getRow(row); 213 | openCell = openRow.getCell(column); 214 | int cellType = openCell.getCellType(); 215 | switch (cellType) { 216 | case 0: 217 | if (DateUtil.isCellDateFormatted(openCell)) { 218 | Date dt = openCell.getDateCellValue(); 219 | SimpleDateFormat sdf = new SimpleDateFormat( 220 | "dd MM yyyy HH:mm:ss"); 221 | data = sdf.format(dt); 222 | } else 223 | data = Long.toString(Math.round(openCell 224 | .getNumericCellValue())); 225 | break; 226 | case 1: 227 | data = openCell.getRichStringCellValue().getString(); 228 | break; 229 | case 2: 230 | data = openCell.getRichStringCellValue().getString(); 231 | break; 232 | case 3: 233 | data = openCell.getRichStringCellValue().getString(); 234 | break; 235 | case 4: 236 | data = Boolean.toString(openCell.getBooleanCellValue()); 237 | break; 238 | case 5: 239 | data = Byte.toString(openCell.getErrorCellValue()); 240 | break; 241 | default: 242 | data = openCell.getRichStringCellValue().getString(); 243 | } 244 | 245 | if (data == null) { 246 | data = ""; 247 | } 248 | return data; 249 | } catch (Exception e) { 250 | if (openRow == null || openCell == null || data == null) { 251 | data = ""; 252 | return data; 253 | } else { 254 | System.out.println(e); 255 | return ""; 256 | } 257 | } 258 | 259 | } 260 | 261 | /** 262 | * Gets the no. of rows in the currently opened sheet 263 | * @return The actual no of physical rows present 264 | */ 265 | public int getNoOfRows() { 266 | return openSheet.getPhysicalNumberOfRows(); 267 | } 268 | 269 | /** 270 | * Gets the no. of column present in the first row of the currently opened sheet. 271 | * @return Return the no. of column present in the first row of the currently opened sheet. 272 | */ 273 | public int getNoOfColumn() { 274 | return this.getNoOfColumn(0); 275 | } 276 | 277 | /** 278 | * Gets the no. of column present in the specified row of the currently opened sheet. 279 | * 280 | * @param rowNo Row no. for which the no. of column have to evaluated. 281 | * @return Return the no. of column present in the specified row of the currently opened sheet. 282 | */ 283 | public int getNoOfColumn(int rowNo) { 284 | Row rw = openSheet.getRow(rowNo); 285 | return rw.getPhysicalNumberOfCells(); 286 | } 287 | 288 | /** 289 | * Stores the whole data of the currently opened sheet in a Map containing keys 290 | */ 291 | public void storeData() { 292 | Row rw; 293 | int rowCount = openSheet.getPhysicalNumberOfRows(); 294 | storedData.clear(); 295 | for (int i = 1; i < rowCount; i++) { 296 | rw = openSheet.getRow(i); 297 | String key = this.getData(0, i); 298 | 299 | List valueList = new ArrayList(); 300 | storedData.put(key, valueList); 301 | 302 | for (int j = 1; j <= rw.getPhysicalNumberOfCells(); j++) { 303 | String data = this.getData(j, i); 304 | valueList.add(data); 305 | } 306 | } 307 | } 308 | 309 | public Map> getStoredData() { 310 | if(storedData.isEmpty()){ 311 | this.storeData(); 312 | } 313 | return storedData; 314 | } 315 | } 316 | -------------------------------------------------------------------------------- /src/main/java/org/imaginea/test/automation/framework/util/selenium/ui/CustomExpectedConditions.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.util.selenium.ui; 2 | 3 | 4 | import org.imaginea.test.automation.framework.dom.EWebElement; 5 | import org.imaginea.test.automation.framework.pagemodel.Browser; 6 | import org.imaginea.test.automation.framework.pagemodel.PageClass; 7 | import org.openqa.selenium.NoSuchElementException; 8 | import org.openqa.selenium.WebDriver; 9 | import org.openqa.selenium.WebElement; 10 | import org.openqa.selenium.support.ui.ExpectedCondition; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * Created by varunm on 24-02-2015. 16 | */ 17 | public class CustomExpectedConditions { 18 | 19 | public static ExpectedCondition presenceOfElement( 20 | final WebElement element) { 21 | return new ExpectedCondition() { 22 | @Override 23 | public Boolean apply(WebDriver driver) { 24 | try{ 25 | element.getTagName(); 26 | }catch(NoSuchElementException e){ 27 | return false; 28 | } 29 | return true; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "presence of element located by: " + element; 35 | } 36 | }; 37 | } 38 | 39 | public static ExpectedCondition presenceOfElement( 40 | final EWebElement eWebElement) { 41 | return new ExpectedCondition() { 42 | @Override 43 | public Boolean apply(WebDriver driver) { 44 | try{ 45 | eWebElement.getTagName(); 46 | }catch(NoSuchElementException e){ 47 | return false; 48 | } 49 | return true; 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return "presence of element located by: " + eWebElement; 55 | } 56 | }; 57 | } 58 | 59 | public static ExpectedCondition presenceOfElements( 60 | final List elements) { 61 | return new ExpectedCondition() { 62 | @Override 63 | public Boolean apply(WebDriver driver) { 64 | if(elements.size()>0) 65 | return true; 66 | return false; 67 | } 68 | 69 | @Override 70 | public String toString() { 71 | return "presence of element located by: " + elements; 72 | } 73 | }; 74 | } 75 | 76 | public static ExpectedCondition visibilityOf( 77 | final EWebElement eWebElement) { 78 | return new ExpectedCondition() { 79 | @Override 80 | public EWebElement apply(WebDriver driver) { 81 | boolean isVisible = false; 82 | try{ 83 | isVisible = eWebElement.isDisplayed(); 84 | }catch(NoSuchElementException e){ 85 | /*Intentionally skipping as there is a possibility that element may not be available on the page.*/ 86 | } 87 | if(isVisible) 88 | return eWebElement; 89 | else 90 | return null; 91 | } 92 | 93 | @Override 94 | public String toString() { 95 | return "visibility of " + eWebElement; 96 | } 97 | }; 98 | } 99 | 100 | public static ExpectedCondition presenceOfPage(final Browser browser, 101 | final Class pageClass) { 102 | return new ExpectedCondition() { 103 | 104 | @Override 105 | public Boolean apply(WebDriver driver) { 106 | return (Boolean)browser.isAt(pageClass); 107 | } 108 | 109 | @Override 110 | public String toString() { 111 | return "Presence of page: " + pageClass.getName(); 112 | } 113 | }; 114 | } 115 | 116 | public static ExpectedCondition presenceOfPage(final Browser browser, 117 | final PageClass pageObject) { 118 | return new ExpectedCondition() { 119 | 120 | @Override 121 | public Boolean apply(WebDriver driver) { 122 | return (Boolean)browser.isAt(pageObject); 123 | } 124 | 125 | @Override 126 | public String toString() { 127 | return "Presence of page: " + pageObject.getClass().getName(); 128 | } 129 | }; 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /src/test/java/org/imaginea/test/automation/framework/TafTestClass.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework; 2 | 3 | import org.imaginea.test.automation.framework.pagemodel.Browser; 4 | import org.openqa.selenium.WebDriver; 5 | 6 | import java.net.URISyntaxException; 7 | 8 | /** 9 | * Created by varunm on 04-12-2014. 10 | */ 11 | public class TafTestClass { 12 | protected Browser browser; 13 | public TafTestClass (){ 14 | initialize(); 15 | } 16 | 17 | private void initialize(){ 18 | this.browser = new Browser(); 19 | } 20 | 21 | public String getHtmlFile(String fileName){ 22 | return "file:/"+ClassLoader.getSystemResource("html/"+fileName).getPath(); 23 | } 24 | 25 | public String getFilePathFromResource(String fileName){ 26 | return ClassLoader.getSystemResource(fileName).getPath(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/org/imaginea/test/automation/framework/config/DeafultConfigTest.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.config; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.Test; 5 | 6 | public class DeafultConfigTest { 7 | 8 | @Test 9 | public void testSingletonConfigObject(){ 10 | DefaultConfig configA = DefaultConfig.getDefaultConfig(); 11 | DefaultConfig configB = DefaultConfig.getDefaultConfig(); 12 | 13 | Assert.assertEquals(configA, configB); 14 | } 15 | 16 | @Test(description="Verify that the stored value in properties file is returned") 17 | public void verifyStoredConfigValue(){ 18 | DefaultConfig config = DefaultConfig.getDefaultConfig(); 19 | String value = config.getConfigValue("driver.name"); 20 | 21 | Assert.assertEquals(value, "htmlunit"); 22 | } 23 | 24 | @Test(description="Verify the stored config value can be modified") 25 | public void verifyModifyingStoredConfigValue(){ 26 | 27 | DefaultConfig config = DefaultConfig.getDefaultConfig(); 28 | String originalValue = config.getConfigValue("driver.name"); 29 | 30 | config.setConfigValue("driver.name", "chrome"); 31 | 32 | String actualValue = config.getConfigValue("driver.name"); 33 | 34 | config.setConfigValue("driver.name", originalValue); 35 | 36 | Assert.assertEquals(actualValue, "chrome"); 37 | 38 | } 39 | 40 | @Test(description="Verify and empty string is returned when the key is not present in config") 41 | public void verifyEmptyValueForNotAvailableKey(){ 42 | 43 | DefaultConfig config = DefaultConfig.getDefaultConfig(); 44 | String actualValue = config.getConfigValue("testing.empty"); 45 | 46 | Assert.assertEquals(actualValue, ""); 47 | } 48 | 49 | 50 | @Test(description="Verify a value can be stored in the config when the key is not present in config") 51 | public void verifyStoringValueForNotAvailableKey(){ 52 | 53 | DefaultConfig config = DefaultConfig.getDefaultConfig(); 54 | config.setConfigValue("testing.empty","testing"); 55 | 56 | String actualValue = config.getConfigValue("testing.empty"); 57 | 58 | Assert.assertEquals(actualValue, "testing"); 59 | } 60 | 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/org/imaginea/test/automation/framework/datadrive/ClassParserTest.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.datadrive; 2 | 3 | import org.imaginea.test.automation.framework.TafTestClass; 4 | import org.imaginea.test.automation.framework.datadrive.ClassParser.ClassParserException; 5 | import org.imaginea.test.automation.framework.datadrive.ClassParser.DataNotAvailableException; 6 | import org.testng.Assert; 7 | import org.testng.annotations.DataProvider; 8 | import org.testng.annotations.Test; 9 | 10 | import java.util.Arrays; 11 | import java.util.HashMap; 12 | import java.util.List; 13 | import java.util.Map; 14 | 15 | 16 | public class ClassParserTest extends TafTestClass { 17 | 18 | @Test 19 | public void verifyClassParserListMethod(){ 20 | 21 | ClassParser clsP = new ClassParser(); 22 | List data1 = Arrays.asList(new String[]{"testing1","testing2","testing3"}); 23 | List data2 = Arrays.asList(new String[]{"101","102","103"}); 24 | List data3 = Arrays.asList(new String[]{"10.201f","10.202f","10.203f"}); 25 | Map> testData = new HashMap>(); 26 | testData.put("stringValue", data1); 27 | testData.put("integerValue", data2); 28 | testData.put("byteValue", data2); 29 | testData.put("floatValue", data3); 30 | 31 | try { 32 | List test = clsP.getClassObjectList(TestDataClass.class, testData); 33 | Assert.assertEquals(test.size(),3); 34 | TestDataClass testObject = test.get(0); 35 | Assert.assertEquals(testObject.stringValue,"testing1"); 36 | Assert.assertEquals(testObject.integerValue,101); 37 | Assert.assertEquals(testObject.byteValue,101); 38 | Assert.assertEquals(testObject.floatValue,10.201f); 39 | } catch (ClassParserException e) { 40 | Assert.fail("Class parser test failed",e); 41 | } catch (DataNotAvailableException e) { 42 | Assert.fail("Class parser test failed",e); 43 | } 44 | } 45 | 46 | @Test 47 | public void csvDataTest(){ 48 | CsvDataDrive csD = new CsvDataDrive(getFilePathFromResource("DataDriveTest.csv")); 49 | try { 50 | List test = csD.getClassObjectList(TestDataClass.class); 51 | Assert.assertEquals(test.size(),4); 52 | TestDataClass testObject = test.get(0); 53 | Assert.assertEquals(testObject.stringValue,"testing1"); 54 | Assert.assertEquals(testObject.integerValue,1); 55 | Assert.assertEquals(testObject.byteValue,100); 56 | Assert.assertEquals(testObject.floatValue,10.201f); 57 | } catch (ClassParserException e) { 58 | Assert.fail("parsing a csv file failed",e); 59 | } catch (DataNotAvailableException e) { 60 | Assert.fail("parsing a csv file failed",e); 61 | } 62 | } 63 | 64 | @Test 65 | public void excelDataTest(){ 66 | ExcelDataDrive esD = new ExcelDataDrive(getFilePathFromResource("DataDriveTest.xls")); 67 | try { 68 | List test = esD.getClassObjectList(TestDataClass.class); 69 | Assert.assertEquals(test.size(),4); 70 | TestDataClass testObject = test.get(0); 71 | Assert.assertEquals(testObject.stringValue,"testing1"); 72 | Assert.assertEquals(testObject.integerValue,1); 73 | Assert.assertEquals(testObject.byteValue,100); 74 | Assert.assertEquals(testObject.floatValue,10.201f); 75 | } catch (ClassParserException e) { 76 | Assert.fail("parsing a xls file failed",e); 77 | } catch (DataNotAvailableException e) { 78 | Assert.fail("parsing a xls file failed",e); 79 | } 80 | } 81 | 82 | @Test 83 | public void verifyTestNgDataReturnedByTheCSVDataDriveUtility() throws ClassParserException, DataNotAvailableException{ 84 | CsvDataDrive csD = new CsvDataDrive(getFilePathFromResource("DataDriveTest.csv")); 85 | Object[][] returnData = csD.getTestngData(TestDataClass.class); 86 | Assert.assertEquals(returnData.length,4); 87 | Object[] object = returnData[0]; 88 | Assert.assertEquals(object.length,1); 89 | Assert.assertTrue(object[0] instanceof TestDataClass); 90 | TestDataClass testObject = (TestDataClass)object[0]; 91 | Assert.assertEquals(testObject.stringValue,"testing1"); 92 | Assert.assertEquals(testObject.integerValue,1); 93 | Assert.assertEquals(testObject.byteValue,100); 94 | Assert.assertEquals(testObject.floatValue,10.201f); 95 | } 96 | 97 | @Test 98 | public void verifyTestNgDataReturnedByTheExcelDataDriveUtility() throws ClassParserException, DataNotAvailableException{ 99 | ExcelDataDrive csD = new ExcelDataDrive(getFilePathFromResource("DataDriveTest.xls")); 100 | Object[][] returnData = csD.getTestngData(TestDataClass.class); 101 | Object[] object = returnData[0]; 102 | Assert.assertEquals(object.length,1); 103 | Assert.assertTrue(object[0] instanceof TestDataClass); 104 | TestDataClass testObject = (TestDataClass)object[0]; 105 | Assert.assertEquals(testObject.stringValue,"testing1"); 106 | Assert.assertEquals(testObject.integerValue,1); 107 | Assert.assertEquals(testObject.byteValue,100); 108 | Assert.assertEquals(testObject.floatValue,10.201f); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/test/java/org/imaginea/test/automation/framework/datadrive/TestDataClass.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.datadrive; 2 | 3 | public class TestDataClass { 4 | public String stringValue; 5 | public int integerValue; 6 | public byte byteValue; 7 | public float floatValue; 8 | 9 | @Override 10 | public String toString() { 11 | return "TestDataClass [stringValue=" + stringValue + ",integerValue=" + integerValue + ", byteValue=" 12 | + byteValue + ", floatValue=" + floatValue + "]"; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/org/imaginea/test/automation/framework/dom/EWebElementActionsTest.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.dom; 2 | 3 | import org.imaginea.test.automation.framework.exceptions.UnexpectedPageException; 4 | import org.imaginea.test.automation.framework.pagemodel.Browser; 5 | import org.imaginea.test.automation.framework.pagemodel.PageClass; 6 | import org.imaginea.test.automation.framework.testclasses.FailingPageClassA; 7 | import org.imaginea.test.automation.framework.testclasses.FailingPageClassB; 8 | import org.imaginea.test.automation.framework.testclasses.PassingPageClassA; 9 | import org.imaginea.test.automation.framework.testclasses.PassingPageClassB; 10 | import org.mockito.Mock; 11 | import static org.mockito.Mockito.*; 12 | import org.mockito.MockitoAnnotations; 13 | import org.openqa.selenium.By; 14 | import org.openqa.selenium.NoSuchElementException; 15 | import org.openqa.selenium.WebElement; 16 | import org.testng.Assert; 17 | import org.testng.annotations.BeforeMethod; 18 | import org.testng.annotations.Test; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | /** 24 | * Created by varunm on 26-02-2015. 25 | */ 26 | public class EWebElementActionsTest { 27 | 28 | List elements; 29 | @Mock WebElement element1; 30 | @Mock WebElement element2; 31 | @Mock WebElement element3; 32 | @Mock WebElement element4; 33 | 34 | 35 | @BeforeMethod 36 | public void setup(){ 37 | MockitoAnnotations.initMocks(this); 38 | elements = new ArrayList<>(); 39 | elements.add(element1); 40 | elements.add(element2); 41 | } 42 | 43 | @Test 44 | public void testClickFunction(){ 45 | EWebElement eWebElement = new EWebElement(elements); 46 | eWebElement.click(); 47 | verify(element1).click(); 48 | } 49 | 50 | @Test 51 | public void testClickFunctionReturnFirstSuccessfulPageValidation(){ 52 | EWebElement eWebElement = new EWebElement(new Browser(), elements); 53 | List> navigablePageClassesA = new ArrayList<>(); 54 | navigablePageClassesA.add(PassingPageClassA.class); 55 | navigablePageClassesA.add(PassingPageClassB.class); 56 | 57 | eWebElement.setNavigablePageClasses(navigablePageClassesA); 58 | PageClass pageA = eWebElement.click(); 59 | Assert.assertTrue(pageA instanceof PassingPageClassA); 60 | 61 | 62 | List> navigablePageClassesB = new ArrayList<>(); 63 | navigablePageClassesB.add(FailingPageClassA.class); 64 | navigablePageClassesB.add(PassingPageClassB.class); 65 | 66 | eWebElement.setNavigablePageClasses(navigablePageClassesB); 67 | PageClass pageB = eWebElement.click(); 68 | Assert.assertTrue(pageB instanceof PassingPageClassB); 69 | } 70 | 71 | @Test(expectedExceptions = {UnexpectedPageException.class}, expectedExceptionsMessageRegExp = "Browser is not on any of the specified pages.*" ) 72 | public void testClickFunctionThrowsExceptionIfPageValidationFails(){ 73 | EWebElement eWebElement = new EWebElement(new Browser(), elements); 74 | List> navigablePageClasses = new ArrayList<>(); 75 | navigablePageClasses.add(FailingPageClassA.class); 76 | navigablePageClasses.add(FailingPageClassB.class); 77 | 78 | eWebElement.setNavigablePageClasses(navigablePageClasses); 79 | eWebElement.click(); 80 | } 81 | 82 | @Test 83 | public void testClickFunctionPageValidationCanBeDisabledWhileUsingClick(){ 84 | EWebElement eWebElement = new EWebElement(new Browser(), elements); 85 | List> navigablePageClasses = new ArrayList<>(); 86 | navigablePageClasses.add(PassingPageClassA.class); 87 | navigablePageClasses.add(PassingPageClassB.class); 88 | 89 | eWebElement.setNavigablePageClasses(navigablePageClasses); 90 | PageClass page = eWebElement.click(false); 91 | Assert.assertNull(page, "Expected page object to be null when page navigation validation is disabled but found " 92 | + page + " object."); 93 | } 94 | 95 | @Test 96 | public void testClickAllFunction(){ 97 | EWebElement eWebElement = new EWebElement(elements); 98 | eWebElement.clickAll(); 99 | verify(element1).click(); 100 | verify(element2).click(); 101 | } 102 | 103 | @Test 104 | public void testClearFunction(){ 105 | EWebElement eWebElement = new EWebElement(elements); 106 | eWebElement.clear(); 107 | verify(element1).clear(); 108 | } 109 | 110 | @Test 111 | public void testFirstElementFunction(){ 112 | EWebElement eWebElement = new EWebElement(elements); 113 | Assert.assertEquals(eWebElement.firstElement(),element1); 114 | } 115 | 116 | @Test(expectedExceptions = {NoSuchElementException.class}) 117 | public void testFirstElementFunctionThrowsExceptionWhenNoElementPresent(){ 118 | EWebElement eWebElement = new EWebElement(); 119 | eWebElement.firstElement(); 120 | } 121 | 122 | @Test 123 | public void testGetAttributeFunction(){ 124 | EWebElement eWebElement = new EWebElement(elements); 125 | eWebElement.getAttribute("attr"); 126 | verify(element1).getAttribute("attr"); 127 | } 128 | 129 | @Test 130 | public void testChildFunction(){ 131 | EWebElement eWebElement = new EWebElement(elements); 132 | eWebElement.child(); 133 | verify(element1).findElement(By.xpath("*[1]")); 134 | } 135 | 136 | @Test 137 | public void testChildrenFunction(){ 138 | By selector = By 139 | .xpath("descendant-or-self::*"); 140 | EWebElement eWebElement = new EWebElement(elements); 141 | eWebElement.children(); 142 | verify(element1).findElements(selector); 143 | } 144 | 145 | @Test 146 | public void testTypeFunction(){ 147 | EWebElement eWebElement = new EWebElement(elements); 148 | eWebElement.type("test"); 149 | verify(element1).sendKeys("test"); 150 | } 151 | 152 | @Test 153 | public void testFirstEWebElementFunction(){ 154 | EWebElement eWebElement = new EWebElement(elements); 155 | EWebElement firstEWebElement = eWebElement.firstEWebElement(); 156 | Assert.assertEquals(firstEWebElement.firstElement(),element1); 157 | } 158 | 159 | @Test(expectedExceptions = {NoEWebElementException.class}) 160 | public void testFirstEWebElementFunctionThrowsException(){ 161 | EWebElement eWebElement = new EWebElement(); 162 | eWebElement.firstEWebElement(); 163 | } 164 | 165 | @Test 166 | public void testLastEWebElementFunction(){ 167 | EWebElement eWebElement = new EWebElement(elements); 168 | EWebElement lastEWebElement = eWebElement.lastEWebElement(); 169 | Assert.assertEquals(lastEWebElement.firstElement(),element2); 170 | } 171 | 172 | @Test(expectedExceptions = {NoEWebElementException.class}) 173 | public void testLastEWebElementFunctionThrowsException(){ 174 | EWebElement eWebElement = new EWebElement(); 175 | eWebElement.lastEWebElement(); 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /src/test/java/org/imaginea/test/automation/framework/dom/EWebElementTest.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.dom; 2 | 3 | import org.imaginea.test.automation.framework.TafTestClass; 4 | import org.mockito.Mockito; 5 | import org.openqa.selenium.By; 6 | import org.openqa.selenium.WebDriver; 7 | import org.openqa.selenium.WebElement; 8 | import org.testng.Assert; 9 | import org.testng.annotations.BeforeClass; 10 | import org.testng.annotations.Test; 11 | 12 | import static org.imaginea.test.automation.framework.dom.filter.Filter.*; 13 | import static org.imaginea.test.automation.framework.dom.filter.TextMatching.*; 14 | 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | 19 | /** 20 | * Created by menonvarun on 04-12-2014. 21 | */ 22 | public class EWebElementTest extends TafTestClass{ 23 | 24 | WebDriver driver; 25 | 26 | @BeforeClass 27 | public void beforeClass(){ 28 | driver = browser.getDriver(); 29 | driver.get(getHtmlFile("index.html")); 30 | } 31 | 32 | @Test 33 | public void testBasicEWebElementCreation(){ 34 | List elements = driver.findElements(By.cssSelector("span")); 35 | EWebElement eWebElement = new EWebElement(elements); 36 | Assert.assertTrue(eWebElement.size()>0); 37 | } 38 | 39 | @Test 40 | public void testEmptyEWebElementCreation(){ 41 | EWebElement eWebElement = new EWebElement(); 42 | Assert.assertTrue(eWebElement.size()==0); 43 | } 44 | 45 | @Test 46 | public void testWithNameFilterCriteria(){ 47 | List elements = driver.findElements(By.cssSelector("span")); 48 | EWebElement eWebElement = new EWebElement(elements).filter(withName("name")); 49 | Assert.assertEquals(eWebElement.size(), 1); 50 | } 51 | 52 | @Test 53 | public void testWhereNameWithAFilterCriteria(){ 54 | List elements = driver.findElements(By.cssSelector("span")); 55 | EWebElement eWebElement = new EWebElement(elements).filter(whereName(contains("name"))); 56 | Assert.assertEquals(eWebElement.size(), 4); 57 | } 58 | 59 | @Test 60 | public void testWithNameFilterCriteriaWhenNoElementFound(){ 61 | List elements = driver.findElements(By.cssSelector("span")); 62 | EWebElement eWebElement = new EWebElement(elements).filter(withName("test")); 63 | Assert.assertEquals(eWebElement.size(), 0); 64 | } 65 | 66 | @Test 67 | public void testWhereNameWithAFilterCriteriaWhenNoElementFound(){ 68 | List elements = driver.findElements(By.cssSelector("span")); 69 | EWebElement eWebElement = new EWebElement(elements).filter(whereName(contains("test"))); 70 | Assert.assertEquals(eWebElement.size(), 0); 71 | } 72 | 73 | @Test 74 | public void testWithIdFilterCriteria(){ 75 | List elements = driver.findElements(By.cssSelector("span")); 76 | EWebElement eWebElement = new EWebElement(elements).filter(withId("id")); 77 | Assert.assertEquals(eWebElement.size(), 1); 78 | } 79 | 80 | @Test 81 | public void testWhereIdWithAFilterCriteria(){ 82 | List elements = driver.findElements(By.cssSelector("span")); 83 | EWebElement eWebElement = new EWebElement(elements).filter(whereId(contains("id"))); 84 | Assert.assertEquals(eWebElement.size(), 4); 85 | } 86 | 87 | @Test 88 | public void testWithIdFilterCriteriaWhenNoElementFound(){ 89 | List elements = driver.findElements(By.cssSelector("span")); 90 | EWebElement eWebElement = new EWebElement(elements).filter(withId("test")); 91 | Assert.assertEquals(eWebElement.size(), 0); 92 | } 93 | 94 | @Test 95 | public void testWhereIdWithAFilterCriteriaWhenNoElementFound(){ 96 | List elements = driver.findElements(By.cssSelector("span")); 97 | EWebElement eWebElement = new EWebElement(elements).filter(whereId(contains("test"))); 98 | Assert.assertEquals(eWebElement.size(), 0); 99 | } 100 | 101 | @Test 102 | public void testWithClassFilterCriteria(){ 103 | List elements = driver.findElements(By.cssSelector("span")); 104 | EWebElement eWebElement = new EWebElement(elements).filter(withClass("small")); 105 | Assert.assertEquals(eWebElement.size(), 5); 106 | } 107 | 108 | @Test 109 | public void testWhereClassWithAFilterCriteria(){ 110 | List elements = driver.findElements(By.cssSelector("span")); 111 | EWebElement eWebElement = new EWebElement(elements).filter(whereClass(contains("sma"))); 112 | Assert.assertEquals(eWebElement.size(), 5); 113 | } 114 | 115 | @Test 116 | public void testWithClassFilterCriteriaWhenNoElementFound(){ 117 | List elements = driver.findElements(By.cssSelector("span")); 118 | EWebElement eWebElement = new EWebElement(elements).filter(withClass("test")); 119 | Assert.assertEquals(eWebElement.size(), 0); 120 | } 121 | 122 | @Test 123 | public void testWhereClassWithAFilterCriteriaWhenNoElementFound(){ 124 | List elements = driver.findElements(By.cssSelector("span")); 125 | EWebElement eWebElement = new EWebElement(elements).filter(whereClass(contains("test"))); 126 | Assert.assertEquals(eWebElement.size(), 0); 127 | } 128 | 129 | @Test 130 | public void testWithTextFilterCriteria(){ 131 | List elements = driver.findElements(By.cssSelector("span")); 132 | EWebElement eWebElement = new EWebElement(elements).filter(withText("Small 1")); 133 | Assert.assertEquals(eWebElement.size(), 1); 134 | } 135 | 136 | @Test 137 | public void testWhereTextWithAFilterCriteria(){ 138 | List elements = driver.findElements(By.cssSelector("span")); 139 | EWebElement eWebElement = new EWebElement(elements).filter(whereText(contains("Small"))); 140 | Assert.assertEquals(eWebElement.size(), 5); 141 | } 142 | 143 | @Test 144 | public void testWithTextFilterCriteriaWhenNoElementFound(){ 145 | List elements = driver.findElements(By.cssSelector("span")); 146 | EWebElement eWebElement = new EWebElement(elements).filter(withText("test")); 147 | Assert.assertEquals(eWebElement.size(), 0); 148 | } 149 | 150 | @Test 151 | public void testWhereTextWithAFilterCriteriaWhenNoElementFound(){ 152 | List elements = driver.findElements(By.cssSelector("span")); 153 | EWebElement eWebElement = new EWebElement(elements).filter(whereText(contains("test"))); 154 | Assert.assertEquals(eWebElement.size(), 0); 155 | } 156 | 157 | @Test 158 | public void testWithAttributeFilterCriteria(){ 159 | List elements = driver.findElements(By.cssSelector("input")); 160 | EWebElement eWebElement = new EWebElement(elements).filter(withAttribute("value","John")); 161 | Assert.assertEquals(eWebElement.size(), 4); 162 | } 163 | 164 | @Test 165 | public void testWhereAttributeWithAFilterCriteria(){ 166 | List elements = driver.findElements(By.cssSelector("input")); 167 | EWebElement eWebElement = new EWebElement(elements).filter(whereAttribute("value",contains("Do"))); 168 | Assert.assertEquals(eWebElement.size(), 1); 169 | } 170 | 171 | @Test 172 | public void testWithAttributeFilterCriteriaWhenNoElementFound(){ 173 | List elements = driver.findElements(By.cssSelector("input")); 174 | EWebElement eWebElement = new EWebElement(elements).filter(withAttribute("value","test")); 175 | Assert.assertEquals(eWebElement.size(), 0); 176 | } 177 | 178 | @Test 179 | public void testWhereAttributeWithAFilterCriteriaWhenNoElementFound(){ 180 | List elements = driver.findElements(By.cssSelector("input")); 181 | EWebElement eWebElement = new EWebElement(elements).filter(whereAttribute("value", contains("test"))); 182 | Assert.assertEquals(eWebElement.size(), 0); 183 | } 184 | 185 | @Test 186 | public void testEWebElementCreationUsingASingleWebElement(){ 187 | WebElement element = driver.findElement(By.cssSelector("input")); 188 | EWebElement eWebElement = new EWebElement(element); 189 | Assert.assertEquals(eWebElement.size(),1); 190 | Assert.assertEquals(eWebElement.firstElement(), element); 191 | } 192 | 193 | @Test 194 | public void testClickFunction(){ 195 | List elements = new ArrayList<>(); 196 | WebElement element1 = Mockito.mock(WebElement.class); 197 | WebElement element2 = Mockito.mock(WebElement.class); 198 | 199 | elements.add(element1); 200 | elements.add(element2); 201 | 202 | EWebElement eWebElement = new EWebElement(elements); 203 | eWebElement.click(); 204 | Mockito.verify(element1).click(); 205 | 206 | } 207 | } 208 | -------------------------------------------------------------------------------- /src/test/java/org/imaginea/test/automation/framework/driver/CacheDriverFactoryTest.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.driver; 2 | 3 | import org.imaginea.test.automation.framework.config.DefaultConfig; 4 | import org.openqa.selenium.By; 5 | import org.openqa.selenium.WebDriver; 6 | import org.openqa.selenium.WebDriverException; 7 | import org.testng.Assert; 8 | import org.testng.annotations.Test; 9 | 10 | /** 11 | * Created by varunm on 08-12-2014. 12 | */ 13 | public class CacheDriverFactoryTest { 14 | @Test 15 | public void verifyGettingTheDefaultThreadBasedDriver(){ 16 | CacheDriverFactory cacheDriverFactory = new CacheDriverFactory(); 17 | Assert.assertEquals(cacheDriverFactory.getThreadBasedDriver(),true); 18 | } 19 | 20 | @Test 21 | public void verifyGettingTheThreadBasedDriverAfterManuallySetting(){ 22 | CacheDriverFactory cacheDriverFactory = new CacheDriverFactory(); 23 | cacheDriverFactory.setThreadBasedDriver(false); 24 | Assert.assertEquals(cacheDriverFactory.getThreadBasedDriver(),false); 25 | } 26 | 27 | @Test 28 | public void verifyGettingDefaultDriverProvider(){ 29 | CacheDriverFactory cacheDriverFactory = new CacheDriverFactory(); 30 | IDriverProvider driverProvider = cacheDriverFactory.getDriverProvider(); 31 | Assert.assertTrue(driverProvider instanceof InbuiltDriverProvider); 32 | } 33 | 34 | @Test 35 | public void verifySettingCustomDriverProvider(){ 36 | CacheDriverFactory cacheDriverFactory = new CacheDriverFactory(); 37 | cacheDriverFactory.setDriverProvider(new TestDriverProviderSample()); 38 | IDriverProvider driverProvider = cacheDriverFactory.getDriverProvider(); 39 | Assert.assertTrue(driverProvider instanceof TestDriverProviderSample); 40 | } 41 | 42 | @Test 43 | public void verifyGettingUserDefinedDriverProviderWhenItsNotSet(){ 44 | CacheDriverFactory cacheDriverFactory = new CacheDriverFactory(); 45 | IDriverProvider driverProvider = cacheDriverFactory.getUserDefinedDriverProvider(); 46 | Assert.assertEquals(driverProvider, null); 47 | } 48 | 49 | @Test 50 | public void verifyGettingUserDefinedDriverProviderWhenItsSet(){ 51 | DefaultConfig config = DefaultConfig.getDefaultConfig(); 52 | config.setConfigValue("userdefined.driverclass","org.imaginea.test.automation.framework.driver.TestDriverProviderSample"); 53 | CacheDriverFactory cacheDriverFactory = new CacheDriverFactory(); 54 | IDriverProvider driverProvider = cacheDriverFactory.getUserDefinedDriverProvider(); 55 | Assert.assertTrue(driverProvider instanceof TestDriverProviderSample); 56 | } 57 | 58 | @Test(expectedExceptions = {RuntimeException.class}) 59 | public void verifyExceptionThrownWhenUserDefinedDriverClassNotAvailable(){ 60 | DefaultConfig config = DefaultConfig.getDefaultConfig(); 61 | String originalUserDefinedValue = config.getConfigValue("userdefined.driverclass"); 62 | try { 63 | config.setConfigValue("userdefined.driverclass", "TestDriverProvider"); 64 | CacheDriverFactory cacheDriverFactory = new CacheDriverFactory(); 65 | cacheDriverFactory.getUserDefinedDriverProvider(); 66 | } finally { 67 | config.setConfigValue("userdefined.driverclass",originalUserDefinedValue); 68 | } 69 | } 70 | 71 | @Test 72 | public void verifyNewDriverCreatedWhenItsNull(){ 73 | CacheDriverFactory cacheDriverFactory = new CacheDriverFactory(); 74 | WebDriver driver = cacheDriverFactory.getDriver(); 75 | Assert.assertNotEquals(driver, null); 76 | } 77 | 78 | @Test 79 | public void verifySameDriverObjectIsReturnedByGetDriver(){ 80 | CacheDriverFactory cacheDriverFactory = new CacheDriverFactory(); 81 | WebDriver driver1 = cacheDriverFactory.getDriver(); 82 | WebDriver driver2 = cacheDriverFactory.getDriver(); 83 | Assert.assertEquals(driver1, driver2); 84 | } 85 | 86 | @Test 87 | public void verifyAnewDriverIsReturnedAfterClearingDriver(){ 88 | CacheDriverFactory cacheDriverFactory = new CacheDriverFactory(); 89 | WebDriver driver1 = cacheDriverFactory.getDriver(); 90 | CacheDriverFactory.clearCacheAndQuitDriver(); 91 | WebDriver driver2 = cacheDriverFactory.getDriver(); 92 | Assert.assertNotEquals(driver1, driver2); 93 | } 94 | 95 | @Test(expectedExceptions = {WebDriverException.class}) 96 | public void verifyExistingDriverHasBeenQuitWhileClearCache(){ 97 | CacheDriverFactory cacheDriverFactory = new CacheDriverFactory(); 98 | WebDriver driver = cacheDriverFactory.getDriver(); 99 | CacheDriverFactory.clearCacheAndQuitDriver(); 100 | driver.findElement(By.tagName("html")); 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /src/test/java/org/imaginea/test/automation/framework/driver/TestDriverProviderSample.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.driver; 2 | 3 | import org.openqa.selenium.WebDriver; 4 | 5 | /** 6 | * Created by varunm on 08-12-2014. 7 | */ 8 | public class TestDriverProviderSample implements IDriverProvider { 9 | public WebDriver getDriver(){ 10 | return null; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/org/imaginea/test/automation/framework/keywordmodel/DataDrivenSuiteTest.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.keywordmodel; 2 | 3 | import org.imaginea.test.automation.framework.config.DefaultConfig; 4 | import org.imaginea.test.automation.framework.keywordmodel.executor.KeywordExecutor; 5 | import org.imaginea.test.automation.framework.keywordmodel.suite.ISimpleTest; 6 | import org.imaginea.test.automation.framework.keywordmodel.suite.TestSuite; 7 | import org.testng.annotations.BeforeClass; 8 | import org.testng.annotations.DataProvider; 9 | import org.testng.annotations.Test; 10 | 11 | import java.io.File; 12 | import java.util.ArrayList; 13 | 14 | 15 | public class DataDrivenSuiteTest { 16 | @BeforeClass 17 | public void setListener(){ 18 | DefaultConfig config = DefaultConfig.getDefaultConfig(); 19 | config.setConfigValue("listeners", "org.imaginea.test.automation.framework.keywordmodel.TestKeywordDefinitionClass"); 20 | } 21 | 22 | @Test(dataProvider="CsvData") 23 | public void testExecutorUsingCsvSuiteInput(ISimpleTest simpleTest){ 24 | File file = new File(simpleTest.getTestFilePath()); 25 | KeywordExecutor keyExecutor = new KeywordExecutor(file); 26 | keyExecutor.execute(); 27 | } 28 | 29 | @Test(dataProvider="XlsData") 30 | public void testExecutorUsingXlsSuiteInput(ISimpleTest simpleTest){ 31 | File file = new File(simpleTest.getTestFilePath()); 32 | KeywordExecutor keyExecutor = new KeywordExecutor(file); 33 | keyExecutor.execute(); 34 | } 35 | 36 | @DataProvider(name="CsvData") 37 | public Object[][] getTestDataUsingCsv(){ 38 | File file = new File("src/test/resources/keyword/simpletest/suite-csv.csv"); 39 | TestSuite suiteReader = new TestSuite(file, new ArrayList()); 40 | return suiteReader.getTobeExecutedTests(); 41 | } 42 | 43 | @DataProvider(name="XlsData") 44 | public Object[][] getTestDataUsingXlsx(){ 45 | File file = new File("src/test/resources/keyword/simpletest/suite-xls.xlsx"); 46 | TestSuite suiteReader = new TestSuite(file, new ArrayList()); 47 | return suiteReader.getTobeExecutedTests(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/org/imaginea/test/automation/framework/keywordmodel/KeywordFileTest.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.keywordmodel; 2 | 3 | import org.imaginea.test.automation.framework.config.DefaultConfig; 4 | import org.imaginea.test.automation.framework.keywordmodel.executor.KeywordExecutor; 5 | import org.testng.annotations.BeforeClass; 6 | import org.testng.annotations.Test; 7 | 8 | import java.io.File; 9 | 10 | 11 | public class KeywordFileTest { 12 | 13 | @BeforeClass 14 | public void setListener(){ 15 | DefaultConfig config = DefaultConfig.getDefaultConfig(); 16 | config.setConfigValue("listeners", "org.imaginea.test.automation.framework.keywordmodel.TestKeywordDefinitionClass"); 17 | } 18 | 19 | @Test 20 | public void testMethod(){ 21 | File file = new File("src/test/resources/keyword/simpletest/test-keyword.csv"); 22 | KeywordExecutor keyExecutor = new KeywordExecutor(file); 23 | keyExecutor.execute(); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/org/imaginea/test/automation/framework/keywordmodel/SimpleKeywordTest.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.keywordmodel; 2 | 3 | import org.imaginea.test.automation.framework.keywordmodel.executor.KeywordFactory; 4 | import org.testng.annotations.Test; 5 | 6 | 7 | public class SimpleKeywordTest { 8 | 9 | @Test 10 | public void test(){ 11 | KeywordFactory fact = new KeywordFactory(null); 12 | Object[] obj = new Object[1]; 13 | obj[0] = "42949672961231231231321313131313"; 14 | fact.executeKeyword("testing", obj); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/org/imaginea/test/automation/framework/keywordmodel/TestKeywordDefinitionClass.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.keywordmodel; 2 | 3 | import org.imaginea.test.automation.framework.keywordmodel.keywords.KeywordBase; 4 | import org.openqa.selenium.WebDriver; 5 | 6 | 7 | public class TestKeywordDefinitionClass extends KeywordBase { 8 | 9 | public TestKeywordDefinitionClass(WebDriver driver){ 10 | 11 | } 12 | public void testing(String t){ 13 | 14 | } 15 | 16 | public void testing(String t, int i){ 17 | 18 | } 19 | 20 | public void testing(int i){ 21 | 22 | } 23 | 24 | public void testing(long i){ 25 | 26 | } 27 | 28 | public void testing(double i){ 29 | 30 | } 31 | 32 | public void testing(float i){ 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/imaginea/test/automation/framework/locator/factory/CustomPageFactoryTest.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.locator.factory; 2 | 3 | import org.imaginea.test.automation.framework.TafTestClass; 4 | import org.imaginea.test.automation.framework.locator.CustomPageFactory; 5 | 6 | import org.imaginea.test.automation.framework.pagemodel.PageClass; 7 | import org.imaginea.test.automation.framework.testclasses.PageFactoryTestClass; 8 | import org.imaginea.test.automation.framework.testclasses.PageFactoryTestClassWithFile; 9 | import org.imaginea.test.automation.framework.testclasses.PassingPageClassA; 10 | import org.imaginea.test.automation.framework.util.VerifyUtil; 11 | import org.openqa.selenium.WebDriver; 12 | import org.testng.Assert; 13 | import org.testng.annotations.BeforeClass; 14 | import org.testng.annotations.BeforeMethod; 15 | import org.testng.annotations.Test; 16 | 17 | /** 18 | * Created by varunm on 03-03-2015. 19 | */ 20 | public class CustomPageFactoryTest extends TafTestClass{ 21 | private WebDriver driver; 22 | PageFactoryTestClass pageFactoryTestClass; 23 | private VerifyUtil verifyUtil; 24 | 25 | @BeforeClass 26 | public void beforeClass(){ 27 | driver = browser.getDriver(); 28 | browser.navigateTo(getHtmlFile("index.html")); 29 | } 30 | 31 | @BeforeMethod 32 | public void beforeMethod(){ 33 | verifyUtil = new VerifyUtil(); 34 | } 35 | 36 | @Test 37 | public void testingPresenceOfElementOptionsWithBrowser(){ 38 | PageFactoryTestClass testClass = CustomPageFactory.initElements(browser,PageFactoryTestClass.class); 39 | 40 | verifyUtil.verifyEquals(testClass.elementWithoutName.getName(), "elementWithoutName"); 41 | verifyUtil.verifyEquals(testClass.elementWithoutName.isRequired(), true); 42 | verifyUtil.verifyEquals(testClass.elementWithoutName.getNavigablePageClasses().size(), 0); 43 | 44 | verifyUtil.verifyEquals(testClass.elementWithOptions.getName(), "Element with name"); 45 | verifyUtil.verifyEquals(testClass.elementWithOptions.isRequired(), false); 46 | verifyUtil.verifyEquals(testClass.elementWithOptions.getNavigablePageClasses().size(), 2); 47 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 48 | } 49 | 50 | @Test 51 | public void testingPresenceOfElementOptionsWithDriver(){ 52 | PageFactoryTestClass testClass = CustomPageFactory.initElements(driver,PageFactoryTestClass.class); 53 | 54 | verifyUtil.verifyEquals(testClass.elementWithoutName.getName(), "elementWithoutName"); 55 | verifyUtil.verifyEquals(testClass.elementWithoutName.isRequired(), true); 56 | verifyUtil.verifyEquals(testClass.elementWithoutName.getNavigablePageClasses().size(), 0); 57 | 58 | verifyUtil.verifyEquals(testClass.elementWithOptions.getName(), "Element with name"); 59 | verifyUtil.verifyEquals(testClass.elementWithOptions.isRequired(), false); 60 | verifyUtil.verifyEquals(testClass.elementWithOptions.getNavigablePageClasses().size(), 2); 61 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 62 | } 63 | 64 | 65 | @Test 66 | public void testingPresenceOfElementOptionsWithBrowserUsingDefaultLocatorFile(){ 67 | PageFactoryTestClassWithFile testClass = CustomPageFactory.initElements(browser,PageFactoryTestClassWithFile.class); 68 | 69 | verifyUtil.verifyEquals(testClass.eWebElementUsingLongFindBy.getName(), "eWebElementUsingLongFindBy"); 70 | verifyUtil.verifyEquals(testClass.eWebElementUsingLongFindBy.isRequired(), true); 71 | verifyUtil.verifyEquals(testClass.eWebElementUsingLongFindBy.getNavigablePageClasses().size(), 0); 72 | 73 | verifyUtil.verifyEquals(testClass.eWebElementUsingShortFindBy.getName(), "eWebElementUsingShortFindBy"); 74 | verifyUtil.verifyEquals(testClass.eWebElementUsingShortFindBy.isRequired(), true); 75 | verifyUtil.verifyEquals(testClass.eWebElementUsingShortFindBy.getNavigablePageClasses().size(), 0); 76 | 77 | 78 | verifyUtil.verifyEquals(testClass.elementWithOptions.getName(), "Element with name"); 79 | verifyUtil.verifyEquals(testClass.elementWithOptions.isRequired(), false); 80 | verifyUtil.verifyEquals(testClass.elementWithOptions.getNavigablePageClasses().size(), 2); 81 | 82 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 83 | } 84 | 85 | @Test 86 | public void testingPresenceOfElementOptionsWithDriverUsingDefaultLocatorFile(){ 87 | PageFactoryTestClassWithFile testClass = CustomPageFactory.initElements(driver,PageFactoryTestClassWithFile.class); 88 | 89 | verifyUtil.verifyEquals(testClass.eWebElementUsingLongFindBy.getName(), "eWebElementUsingLongFindBy"); 90 | verifyUtil.verifyEquals(testClass.eWebElementUsingLongFindBy.isRequired(), true); 91 | verifyUtil.verifyEquals(testClass.eWebElementUsingLongFindBy.getNavigablePageClasses().size(), 0); 92 | 93 | verifyUtil.verifyEquals(testClass.eWebElementUsingShortFindBy.getName(), "eWebElementUsingShortFindBy"); 94 | verifyUtil.verifyEquals(testClass.eWebElementUsingShortFindBy.isRequired(), true); 95 | verifyUtil.verifyEquals(testClass.eWebElementUsingShortFindBy.getNavigablePageClasses().size(), 0); 96 | 97 | verifyUtil.verifyEquals(testClass.elementWithOptions.getName(), "Element with name"); 98 | verifyUtil.verifyEquals(testClass.elementWithOptions.isRequired(), false); 99 | verifyUtil.verifyEquals(testClass.elementWithOptions.getNavigablePageClasses().size(), 2); 100 | 101 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 102 | } 103 | 104 | @Test 105 | public void testingPresenceOfElementOptionsWithBrowserUsingCustomLocatorFile(){ 106 | 107 | PageFactoryTestClassWithFile testClass = CustomPageFactory.initElements(browser,PageFactoryTestClassWithFile.class, 108 | "src/test/resources/locator/factory/PageFactoryTestClassCustomFile.properties"); 109 | 110 | verifyUtil.verifyEquals(testClass.eWebElementUsingLongFindBy.getName(), "eWebElementUsingLongFindBy"); 111 | verifyUtil.verifyEquals(testClass.eWebElementUsingLongFindBy.isRequired(), true); 112 | verifyUtil.verifyEquals(testClass.eWebElementUsingLongFindBy.getNavigablePageClasses().size(), 0); 113 | 114 | verifyUtil.verifyEquals(testClass.eWebElementUsingShortFindBy.getName(), "eWebElementUsingShortFindBy"); 115 | verifyUtil.verifyEquals(testClass.eWebElementUsingShortFindBy.isRequired(), true); 116 | verifyUtil.verifyEquals(testClass.eWebElementUsingShortFindBy.getNavigablePageClasses().size(), 0); 117 | 118 | 119 | verifyUtil.verifyEquals(testClass.elementWithOptions.getName(), "Element with name"); 120 | verifyUtil.verifyEquals(testClass.elementWithOptions.isRequired(), false); 121 | verifyUtil.verifyEquals(testClass.elementWithOptions.getNavigablePageClasses().size(), 2); 122 | 123 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 124 | } 125 | 126 | @Test 127 | public void testingPresenceOfElementOptionsWithDriverUsingCustomLocatorFile(){ 128 | PageFactoryTestClassWithFile testClass = CustomPageFactory.initElements(driver,PageFactoryTestClassWithFile.class, 129 | "src/test/resources/locator/factory/PageFactoryTestClassCustomFile.properties"); 130 | 131 | verifyUtil.verifyEquals(testClass.eWebElementUsingLongFindBy.getName(), "eWebElementUsingLongFindBy"); 132 | verifyUtil.verifyEquals(testClass.eWebElementUsingLongFindBy.isRequired(), true); 133 | verifyUtil.verifyEquals(testClass.eWebElementUsingLongFindBy.getNavigablePageClasses().size(), 0); 134 | 135 | verifyUtil.verifyEquals(testClass.eWebElementUsingShortFindBy.getName(), "eWebElementUsingShortFindBy"); 136 | verifyUtil.verifyEquals(testClass.eWebElementUsingShortFindBy.isRequired(), true); 137 | verifyUtil.verifyEquals(testClass.eWebElementUsingShortFindBy.getNavigablePageClasses().size(), 0); 138 | 139 | verifyUtil.verifyEquals(testClass.elementWithOptions.getName(), "Element with name"); 140 | verifyUtil.verifyEquals(testClass.elementWithOptions.isRequired(), false); 141 | verifyUtil.verifyEquals(testClass.elementWithOptions.getNavigablePageClasses().size(), 2); 142 | 143 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 144 | } 145 | 146 | @Test 147 | public void testingPageNavigationValidationWithBrowser(){ 148 | PageFactoryTestClassWithFile testClass = CustomPageFactory.initElements(browser,PageFactoryTestClassWithFile.class); 149 | 150 | PageClass page = testClass.elementWithOptions.click(); 151 | 152 | Assert.assertTrue(page instanceof PassingPageClassA, String.format("Expected click action should return object of type %s but found it to be %s.", 153 | PassingPageClassA.class.getName(), page.getClass().getName()) ); 154 | } 155 | 156 | @Test 157 | public void testingPageNavigationValidationWithDriver(){ 158 | PageFactoryTestClassWithFile testClass = CustomPageFactory.initElements(driver,PageFactoryTestClassWithFile.class); 159 | 160 | PageClass page = testClass.elementWithOptions.click(); 161 | 162 | Assert.assertTrue(page instanceof PassingPageClassA, String.format("Expected click action should return object of type %s but found it to be %s.", 163 | PassingPageClassA.class.getName(), page.getClass().getName()) ); 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /src/test/java/org/imaginea/test/automation/framework/testclasses/FailingPageClassA.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.testclasses; 2 | 3 | import org.imaginea.test.automation.framework.pagemodel.PageClass; 4 | 5 | /** 6 | * Created by varunm on 10-03-2015. 7 | */ 8 | public class FailingPageClassA extends PageClass { 9 | 10 | @Override 11 | public boolean at(){ 12 | return false; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/org/imaginea/test/automation/framework/testclasses/FailingPageClassB.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.testclasses; 2 | 3 | import org.imaginea.test.automation.framework.pagemodel.PageClass; 4 | 5 | /** 6 | * Created by varunm on 10-03-2015. 7 | */ 8 | public class FailingPageClassB extends PageClass { 9 | 10 | @Override 11 | public boolean at(){ 12 | return false; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/org/imaginea/test/automation/framework/testclasses/PageFactoryTestClass.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.testclasses; 2 | 3 | import org.imaginea.test.automation.framework.dom.EWebElement; 4 | import org.imaginea.test.automation.framework.dom.ElementOptions; 5 | import org.openqa.selenium.WebElement; 6 | import org.openqa.selenium.support.FindBy; 7 | 8 | /** 9 | * Created by varunm on 03-03-2015. 10 | */ 11 | public class PageFactoryTestClass { 12 | 13 | @FindBy 14 | public WebElement id; 15 | 16 | @FindBy(id = "id2") 17 | public WebElement idWebElement; 18 | 19 | @FindBy(id = "location") 20 | public EWebElement elementWithoutName; 21 | 22 | @FindBy(css="#id[name=\"name\"]") 23 | @ElementOptions(name = "Element with name", required = false, navigablePageClasses = {PassingPageClassA.class,PassingPageClassB.class}) 24 | public EWebElement elementWithOptions; 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/org/imaginea/test/automation/framework/testclasses/PageFactoryTestClassWithFile.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.testclasses; 2 | 3 | import org.imaginea.test.automation.framework.dom.EWebElement; 4 | import org.imaginea.test.automation.framework.dom.ElementOptions; 5 | import org.openqa.selenium.WebElement; 6 | import org.openqa.selenium.support.FindBy; 7 | import org.openqa.selenium.support.How; 8 | 9 | import java.io.File; 10 | 11 | /** 12 | * Created by varunm on 03-03-2015. 13 | */ 14 | public class PageFactoryTestClassWithFile { 15 | 16 | public WebElement id; 17 | 18 | @FindBy(id = "idWebElement") 19 | public WebElement elementUsingShortFindBy; 20 | 21 | @FindBy(how = How.ID, using = "elementUsingLongAndShortFindBy") 22 | public WebElement elementUsingLongFindBy; 23 | 24 | @FindBy(how = How.ID, using = "elementUsingLongAndShortFindBy") 25 | public EWebElement eWebElementUsingLongFindBy; 26 | 27 | @FindBy(id = "elementUsingLongAndShortFindBy") 28 | public EWebElement eWebElementUsingShortFindBy; 29 | 30 | @FindBy(css="elementWithOptions") 31 | @ElementOptions(name = "Element with name", required = false, navigablePageClasses = {PassingPageClassA.class,PassingPageClassB.class}) 32 | public EWebElement elementWithOptions; 33 | 34 | public File getLocatorFile(){ 35 | File file = new File("src/test/resources/locator/factory/PageFactoryTestClassFile.properties"); 36 | return file; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/org/imaginea/test/automation/framework/testclasses/PassingPageClassA.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.testclasses; 2 | 3 | import org.imaginea.test.automation.framework.pagemodel.PageClass; 4 | 5 | /** 6 | * Created by varunm on 10-03-2015. 7 | */ 8 | public class PassingPageClassA extends PageClass { 9 | } 10 | -------------------------------------------------------------------------------- /src/test/java/org/imaginea/test/automation/framework/testclasses/PassingPageClassB.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.testclasses; 2 | 3 | import org.imaginea.test.automation.framework.pagemodel.PageClass; 4 | 5 | /** 6 | * Created by varunm on 10-03-2015. 7 | */ 8 | public class PassingPageClassB extends PageClass { 9 | } 10 | -------------------------------------------------------------------------------- /src/test/java/org/imaginea/test/automation/framework/util/VerifyUtilTest.java: -------------------------------------------------------------------------------- 1 | package org.imaginea.test.automation.framework.util; 2 | 3 | import org.testng.Assert; 4 | import org.testng.annotations.BeforeMethod; 5 | import org.testng.annotations.DataProvider; 6 | import org.testng.annotations.Test; 7 | 8 | /** 9 | * Created by varunm on 05-03-2015. 10 | */ 11 | public class VerifyUtilTest { 12 | 13 | private VerifyUtil verifyUtil; 14 | 15 | @BeforeMethod 16 | public void setup(){ 17 | verifyUtil = new VerifyUtil(); 18 | } 19 | 20 | @Test 21 | public void testStringVerifyEquals() { 22 | verifyUtil.verifyEquals("string", "string"); 23 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 24 | } 25 | 26 | @Test 27 | public void testIntegerVerifyEquals() { 28 | verifyUtil.verifyEquals(10, 10); 29 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 30 | } 31 | 32 | @Test 33 | public void testFloatVerifyEquals() { 34 | verifyUtil.verifyEquals(10.1F, 10.1F, 0.1F); 35 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 36 | } 37 | 38 | @Test 39 | public void testDoubleVerifyEquals() { 40 | verifyUtil.verifyEquals(10.1D, 10.1D, 0.1D); 41 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 42 | } 43 | 44 | @Test 45 | public void testLongVerifyEquals() { 46 | verifyUtil.verifyEquals(100L, 100L); 47 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 48 | } 49 | 50 | @Test 51 | public void testBooleanVerifyEquals() { 52 | verifyUtil.verifyEquals(true , true); 53 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 54 | } 55 | 56 | @Test 57 | public void testByteVerifyEquals() { 58 | verifyUtil.verifyEquals((byte)1, (byte)1); 59 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 60 | } 61 | 62 | @Test 63 | public void testCharVerifyEquals() { 64 | verifyUtil.verifyEquals('c', 'c'); 65 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 66 | } 67 | 68 | @Test 69 | public void testShortVerifyEquals() { 70 | verifyUtil.verifyEquals((short)1, (short)1); 71 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 72 | } 73 | 74 | @Test 75 | public void testVerifySame() { 76 | Object a = new Object(); 77 | verifyUtil.verifySame(a, a); 78 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 79 | } 80 | 81 | @Test 82 | public void testVerifyTrue() { 83 | verifyUtil.verifyTrue(true); 84 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 85 | } 86 | 87 | @Test 88 | public void testVerifyFalse() { 89 | verifyUtil.verifyFalse(false); 90 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 91 | } 92 | 93 | @Test 94 | public void testFailWithACause() { 95 | verifyUtil.fail("Testing fail message with cause", new Exception("test exception")); 96 | Assert.assertFalse(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 97 | } 98 | 99 | @Test(expectedExceptions = {AssertionError.class}) 100 | public void testVerifyAssertMethod() { 101 | verifyUtil.fail(); 102 | verifyUtil.assertVerify(); 103 | } 104 | 105 | @Test 106 | public void testVerifyNotNull() { 107 | verifyUtil.verifyNotNull("test"); 108 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 109 | } 110 | 111 | @Test 112 | public void testVerifyNull() { 113 | verifyUtil.verifyNull(null); 114 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 115 | } 116 | 117 | @Test 118 | public void testStringVerifyNotEquals() { 119 | verifyUtil.verifyNotEquals("string", "teststring"); 120 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 121 | } 122 | 123 | @Test 124 | public void testIntegerVerifyNotEquals() { 125 | verifyUtil.verifyNotEquals(10, 11); 126 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 127 | } 128 | 129 | @Test 130 | public void testFloatVerifyNotEquals() { 131 | verifyUtil.verifyNotEquals(10.1F, 12.1F, 0.1F); 132 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 133 | } 134 | 135 | @Test 136 | public void testDoubleVerifyNotEquals() { 137 | verifyUtil.verifyNotEquals(10.1D, 12.1D, 0.1D); 138 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 139 | } 140 | 141 | @Test 142 | public void testLongVerifyNotEquals() { 143 | verifyUtil.verifyNotEquals(100L, 110L); 144 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 145 | } 146 | 147 | @Test 148 | public void testBooleanVerifyNotEquals() { 149 | verifyUtil.verifyNotEquals(true , false); 150 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 151 | } 152 | 153 | @Test 154 | public void testByteVerifyNotEquals() { 155 | verifyUtil.verifyNotEquals((byte)1, (byte)2); 156 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 157 | } 158 | 159 | @Test 160 | public void testCharVerifyNotEquals() { 161 | verifyUtil.verifyNotEquals('c', 'd'); 162 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 163 | } 164 | 165 | @Test 166 | public void testShortVerifyNotEquals() { 167 | verifyUtil.verifyNotEquals((short) 1, (short) 2); 168 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 169 | } 170 | 171 | @Test 172 | public void testVerifyNotSame() { 173 | Object a = new Object(); 174 | Object b = new Object(); 175 | verifyUtil.verifyNotSame(a, b); 176 | Assert.assertTrue(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 177 | } 178 | 179 | @Test 180 | public void testStringFailingVerifyEquals() { 181 | verifyUtil.verifyEquals("string", "some string"); 182 | Assert.assertFalse(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 183 | } 184 | 185 | @Test 186 | public void testIntegerFailingVerifyEquals() { 187 | verifyUtil.verifyEquals(10, 11); 188 | Assert.assertFalse(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 189 | } 190 | 191 | @Test 192 | public void testFloatFailingVerifyEquals() { 193 | verifyUtil.verifyEquals(10.1F, 12.1F, 0.1F); 194 | Assert.assertFalse(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 195 | } 196 | 197 | @Test 198 | public void testDoubleFailingVerifyEquals() { 199 | verifyUtil.verifyEquals(10.1D, 12.1D, 0.1D); 200 | Assert.assertFalse(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 201 | } 202 | 203 | @Test 204 | public void testLongFailingVerifyEquals() { 205 | verifyUtil.verifyEquals(100L, 110L); 206 | Assert.assertFalse(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 207 | } 208 | 209 | @Test 210 | public void testBooleanFailingVerifyEquals() { 211 | verifyUtil.verifyEquals(true , false); 212 | Assert.assertFalse(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 213 | } 214 | 215 | @Test 216 | public void testByteFailingVerifyEquals() { 217 | verifyUtil.verifyEquals((byte)1, (byte)2); 218 | Assert.assertFalse(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 219 | } 220 | 221 | @Test 222 | public void testCharFailingVerifyEquals() { 223 | verifyUtil.verifyEquals('c', 'd'); 224 | Assert.assertFalse(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 225 | } 226 | 227 | @Test 228 | public void testFailingVerifyNotNull() { 229 | verifyUtil.verifyNotNull(null); 230 | Assert.assertFalse(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 231 | } 232 | 233 | @Test 234 | public void testFailingVerifyNull() { 235 | verifyUtil.verifyNull("test"); 236 | Assert.assertFalse(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 237 | } 238 | 239 | @Test 240 | public void testStringFailingVerifyNotEquals() { 241 | verifyUtil.verifyNotEquals("string", "string"); 242 | Assert.assertFalse(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 243 | } 244 | 245 | @Test 246 | public void testIntegerFailingVerifyNotEquals() { 247 | verifyUtil.verifyNotEquals(10, 10); 248 | Assert.assertFalse(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 249 | } 250 | 251 | @Test 252 | public void testFloatFailingVerifyNotEquals() { 253 | verifyUtil.verifyNotEquals(10.1F, 10F, 0.2F); 254 | Assert.assertFalse(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 255 | } 256 | 257 | @Test 258 | public void testDoubleFailingVerifyNotEquals() { 259 | verifyUtil.verifyNotEquals(10.1D, 10D, 0.1D); 260 | Assert.assertFalse(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 261 | } 262 | 263 | @Test 264 | public void testLongFailingVerifyNotEquals() { 265 | verifyUtil.verifyNotEquals(100L, 100L); 266 | Assert.assertFalse(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 267 | } 268 | 269 | @Test 270 | public void testBooleanFailingVerifyNotEquals() { 271 | verifyUtil.verifyNotEquals(true , true); 272 | Assert.assertFalse(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 273 | } 274 | 275 | @Test 276 | public void testByteFailingVerifyNotEquals() { 277 | verifyUtil.verifyNotEquals((byte)1, (byte)1); 278 | Assert.assertFalse(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 279 | } 280 | 281 | @Test 282 | public void testCharFailingVerifyNotEquals() { 283 | verifyUtil.verifyNotEquals('c', 'c'); 284 | Assert.assertFalse(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 285 | } 286 | 287 | @Test 288 | public void testFailingShortVerifyEquals() { 289 | verifyUtil.verifyEquals((short)1, (short)2); 290 | Assert.assertFalse(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 291 | } 292 | 293 | @Test 294 | public void testFailingVerifySame() { 295 | Object a = new Object(); 296 | Object b = new Object(); 297 | verifyUtil.verifySame(a, b); 298 | Assert.assertFalse(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 299 | } 300 | 301 | @Test 302 | public void testFailingShortVerifyNotEquals() { 303 | verifyUtil.verifyNotEquals((short)1, (short)1); 304 | Assert.assertFalse(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 305 | } 306 | 307 | @Test 308 | public void testFailingVerifyNotSame() { 309 | Object a = new Object(); 310 | verifyUtil.verifyNotSame(a, a); 311 | Assert.assertFalse(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 312 | } 313 | 314 | @Test 315 | public void testFailingVerifyTrue() { 316 | verifyUtil.verifyTrue(false); 317 | Assert.assertFalse(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 318 | } 319 | 320 | @Test 321 | public void testFailingVerifyFalse() { 322 | verifyUtil.verifyFalse(true); 323 | Assert.assertFalse(verifyUtil.isPassed(), verifyUtil.getFailureMessage()); 324 | } 325 | 326 | 327 | 328 | 329 | 330 | } 331 | -------------------------------------------------------------------------------- /testng.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | --------------------------------------------------------------------------------