-
-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
In case of Collection of Qurey fields ex.
List links = IntStream.range(1, 6)
.mapToObj(i -> new Query().defaultLocator(By.cssSelector("table > tbody > tr:nth-child(" + i + ") a")))
.collect(Collectors.toList());
the initQueryObjects method unable to set Driver object.
In this case we can change initQueryObjects method```
private static void initQueryObject(Object object, Field field, RemoteWebDriver driver) {
try {
field.setAccessible(true);
Query queryObject = (Query) field.get(object);
if (null != queryObject) {
queryObject.usingDriver(driver);
}
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}private static void initQueryCollection(Object object, Field field, RemoteWebDriver driver) { try { field.setAccessible(true); @SuppressWarnings("unchecked") Collection<?> unsafeCollection = (Collection) field.get(object); unsafeCollection .stream() // making this collection safe .filter(Query.class::isInstance) .map(Query.class::cast) .filter(Objects::nonNull) .forEach(query -> query.usingDriver(driver)); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } public static void initQueryObjects(Object object, RemoteWebDriver driver) { Arrays.stream(object.getClass().getDeclaredFields()) .forEach( field -> { if (field.getType() == Query.class) { initQueryObject(object, field, driver); } else if (Collection.class.isAssignableFrom(field.getType())) { initQueryCollection(object, field, driver); } } ); }
Metadata
Metadata
Assignees
Labels
No labels