use of com.seleniumtests.core.Filter in project seleniumRobot by bhecquet.
the class CSVHelper method getDataFromCSVFile.
/**
* Reads data from csv file.
* class : null => filename : entire path of file
* class : this.getClass(), filename : the filename will be search in the same directory of the class
*
* @param clazz
* @param filename
* @param filter
* @param readHeaders
* @param delimiter
* @param supportDPFilter
* @return
*/
public static Iterator<Object[]> getDataFromCSVFile(final Class<?> clazz, final String filename, Filter filter, final boolean readHeaders, final String delimiter, final boolean supportDPFilter) {
Filter newFilter = filter;
try (InputStream is = (clazz != null) ? clazz.getResourceAsStream(filename) : new FileInputStream(filename)) {
if (is == null) {
return new ArrayList<Object[]>().iterator();
}
// Get the sheet
String[][] csvData = read(is, delimiter);
if (csvData == null) {
return new ArrayList<Object[]>().iterator();
}
List<Object[]> sheetData = new ArrayList<>();
if (readHeaders) {
List<Object> rowData = new ArrayList<>();
for (int j = 0; j < csvData[0].length; j++) {
rowData.add(csvData[0][j]);
}
sheetData.add(rowData.toArray(new Object[rowData.size()]));
}
// Check for blank rows first
// First row is the header
StringBuilder sbBlank = new StringBuilder();
if (sbBlank.length() > 0) {
sbBlank.deleteCharAt(sbBlank.length() - 1);
throw new CustomSeleniumTestsException("Blank TestTitle found on Row(s) " + sbBlank.toString() + ".");
}
// Support include tags and exclude tags
if (supportDPFilter) {
Filter dpFilter = SpreadSheetHelper.getDPFilter();
if (dpFilter != null) {
if (newFilter == null) {
newFilter = dpFilter;
} else {
newFilter = Filter.and(newFilter, dpFilter);
}
}
}
// The first row is the header data
for (int i = 1; i < csvData.length; i++) {
Map<String, Object> rowDataMap = new HashMap<>();
List<Object> rowData = new ArrayList<>();
// Create the mapping between headers and column data
for (int j = 0; j < csvData[i].length; j++) {
rowDataMap.put(csvData[0][j], csvData[i][j]);
}
for (int j = 0; j < csvData[0].length; j++) {
// expected.
if (csvData[i].length > j) {
rowData.add(csvData[i][j]);
} else {
rowData.add(null);
}
}
// To support include tags and exclude tags
if (supportDPFilter) {
SpreadSheetHelper.formatDPTags(rowDataMap);
}
if (newFilter == null || newFilter.match(rowDataMap)) {
sheetData.add(rowData.toArray(new Object[rowData.size()]));
}
}
if ((!readHeaders && sheetData.isEmpty()) || (readHeaders && sheetData.size() <= 1)) {
logger.warn("No matching data found on csv file: " + filename + " with filter criteria: " + newFilter.toString());
}
return sheetData.iterator();
} catch (Exception e) {
throw new DatasetException(e.getMessage());
}
}
use of com.seleniumtests.core.Filter in project seleniumRobot by bhecquet.
the class SpreadSheetHelper method getDPFilter.
/**
* Return the filter defined in Context.
* TestEntity.TEST_DP_TAGS the line of headers (define in TestEntity.java)
* getDPTagsInclude : the tags that have to be in the entities lines to select (at least one of them)
* getDPTagsExclude : the tags have to be absent in the entities lines to select (if one of them : not selected)
*
* @return
*/
protected static Filter getDPFilter() {
String includedTags = SeleniumTestsContextManager.getGlobalContext().getDPTagsInclude();
String excludedTags = SeleniumTestsContextManager.getGlobalContext().getDPTagsExclude();
Filter dpFilter = null;
if (includedTags != null && includedTags.trim().length() > 0) {
String[] includeTagsArray = includedTags.split(",");
for (int idx = 0; includeTagsArray.length > 0 && idx < includeTagsArray.length; idx++) {
if (dpFilter == null) {
dpFilter = Filter.containsIgnoreCase(TestEntity.TEST_DP_TAGS, "[" + includeTagsArray[0].trim() + "]");
} else {
dpFilter = Filter.or(dpFilter, Filter.containsIgnoreCase(TestEntity.TEST_DP_TAGS, "[" + includeTagsArray[idx].trim() + "]"));
}
}
}
if (excludedTags != null && excludedTags.trim().length() > 0) {
String[] excludeTagsArray = excludedTags.split(",");
for (int idx = 0; excludeTagsArray.length > 0 && idx < excludeTagsArray.length; idx++) {
if (dpFilter == null) {
dpFilter = Filter.not(Filter.containsIgnoreCase(TestEntity.TEST_DP_TAGS, "[" + excludeTagsArray[idx].trim() + "]"));
} else {
dpFilter = Filter.and(dpFilter, Filter.not(Filter.containsIgnoreCase(TestEntity.TEST_DP_TAGS, "[" + excludeTagsArray[idx].trim() + "]")));
}
}
}
return dpFilter;
}
use of com.seleniumtests.core.Filter in project seleniumRobot by bhecquet.
the class TestFilter method isEqualIgnoreCase.
/**
******* EQUALS_INGORE_CASE ************
* Test if the parameters contain a Filter's name (key)
* EQUALS_INGORE_CASE with the same value, but different case character, then match is true.
*/
@Test(groups = { "ut" })
public void isEqualIgnoreCase() {
Filter f = Filter.isEqualIgnoreCase("isEqualIngoreCase", "WhatEver1");
boolean result = f.match(parameters1);
Assert.assertEquals(result, true);
}
use of com.seleniumtests.core.Filter in project seleniumRobot by bhecquet.
the class TestFilter method orTwo.
/**
******* OR *****************************
* Test if the match result true,
* if the 2 given Filters match true
*/
@Test(groups = { "ut" })
public void orTwo() {
final Filter f1 = Filter.contains("contains", "whatever1");
final Filter f2 = Filter.contains("contains", "whatnut");
Filter fOr = Filter.or(f1, f2);
boolean result = fOr.match(parameters1);
Assert.assertEquals(result, true);
}
use of com.seleniumtests.core.Filter in project seleniumRobot by bhecquet.
the class TestFilter method andOne.
/**
******* AND ****************************
* Test if the match result false,
* if the 1 given Filters match true
*/
@Test(groups = { "ut" })
public void andOne() {
final Filter f1 = Filter.contains("contains", "whatever1");
final Filter f2 = Filter.contains("contains", "whatever2");
Filter fAnd = Filter.and(f1, f2);
boolean result = fAnd.match(parameters1);
Assert.assertEquals(result, false);
}
Aggregations