AEM Page adapt to experience fragment in test

Avatar

Avatar

JiaJian213

Avatar

JiaJian213

JiaJian213

06-11-2020

Hi, This problem, I've been bugging me around a bit. Whenever I am adapt to ExperienceFragmentVariation, it returns me a NULL. Anyone have some insight on this?

Screen Shot 2020-11-06 at 5.52.11 PM.png

Unit-test

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

sureshd71454102

Avatar

sureshd71454102

sureshd71454102

07-11-2020

 

Is your page resource is Experience Fragment Page?

can you try like get Experience Fragment resource page and then get the variations list of that page resource and then adapto

 

ResourceResolver resourceResolver;
resourceResolver = resourceResolverFactory.getServiceResourceResolver(<<<inputparam>>>);
Resource res=resourceResolver.getResource(<<<<<<Page Path / Resource Path>>>>);
Page page=res.adaptTo(Page.class);
ExperienceFragmentsService expService=experienceFragmentsServiceFactory.getExperienceFragmentsService(<<<resourceResolver>>>);
            /// check if the page is Experience Fragment type or content Fragment type
if(page.getContentResource().isResourceType("cq/experience-fragments/components/experiencefragment")){ 
Iterator<Page> fragmentVariation=page.listChildren(new PageFilter(),false);
while(fragmentVariation.hasNext()){
Page fragmentPage=fragmentVariation.next();
if(null!=fragmentPage){
 ExperienceFragmentVariation fragmentVariation = fragmentPage.adaptTo(ExperienceFragmentVariation.class);
      if (null!=fragmentVariation)  
              <<< LOGIC to implement>>>
      else 
           logger.warn("The page at path cannot be adapted to an experience fragment variation");
}
 

Answers (1)

Answers (1)

Avatar

Avatar

BrianKasingli

MVP

Avatar

BrianKasingli

MVP

BrianKasingli
MVP

08-11-2020

@JiaJian213,

Can you please share the error logs?