private <T extends PageObject> void initializeWebElement(T pageInstance, WebElement webElement) { try { Field field = PageObject.class.getDeclaredField(FIELD_NAME_WEB_ELEMENT); ReflectionUtils.forceSetField(field, pageInstance, webElement); } catch (Exception e) { throw exception(pageInstance, e).inWebElementFieldInjection(); } }
private <T extends PageObject> void initializeModel(T pageInstance, PageObjectModel model) { try { Field field = PageObject.class.getDeclaredField(FIELD_NAME_MODEL); ReflectionUtils.forceSetField(field, pageInstance, model); } catch (Exception e) { throw exception(pageInstance, e).inModelFieldInjection(); } }
private <T extends PageObject> void initializeFieldAsPageObject( Field field, T pageInstance, Browser browser) { Identification identification = getIdentificationForField(field); PageObjectModel metaData = PageObjectModel.forPageFragment(browser, identification, pageInstance); metaData.setCaching(getCachingForField(field)); metaData.setName(getNameForField(field)); try { PageObject pageObject = create((Class<? extends PageObject>) field.getType(), metaData); ReflectionUtils.forceSetField(field, pageInstance, pageObject); } catch (Exception e) { throw exception(pageInstance, e).inPageObjectFieldInjection(field); } }
@SuppressWarnings("rawtypes") private <T extends PageObject> void initializeFieldAsPageObjectList( Field field, T pageInstance, Browser browser) { Identification identification = getIdentificationForField(field); Class<? extends PageObject> listType = getPageObjectClassFromListField(pageInstance, field); PageObjectModel listMetaData = PageObjectModel.forPageFragment(browser, identification, pageInstance); listMetaData.setCaching(getCachingForField(field)); listMetaData.setName(getNameForField(field)); try { PageObjectList<? extends PageObject> pageObjectList = new LazyLoadingPageObjectList(listType, listMetaData); ReflectionUtils.forceSetField(field, pageInstance, pageObjectList); } catch (Exception e) { throw exception(pageInstance, e).inPageObjectFieldInjection(field); } }
@Internal public static void forceSetField(String fieldName, Object objectInstance, Object fieldValue) throws ReflectiveOperationException { Field field = objectInstance.getClass().getDeclaredField(fieldName); forceSetField(field, objectInstance, fieldValue); }
@Internal public static void forceSetField(Class<?> clazz, String fieldName, Object fieldValue) throws ReflectiveOperationException { Field field = clazz.getDeclaredField(fieldName); forceSetField(field, null, fieldValue); }