Skip to content

Commit

Permalink
Merge pull request #115 from Umutayb/ElementAcquisition-logic-update
Browse files Browse the repository at this point in the history
Update ElementAcquisition.java
  • Loading branch information
Umutayb authored May 23, 2024
2 parents 4bc9b32 + 7ad74e9 commit 5bf5b40
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
import collections.Pair;
import utils.Printer;
import utils.StringUtilities;
import utils.arrays.lambda.Collectors;
import utils.reflection.ReflectionUtilities;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.*;

Expand Down Expand Up @@ -874,9 +877,14 @@ public Reflections(Class<ObjectRepository> pageRepository) {
this.pageRepositoryClass = pageRepository;
}

protected ObjectRepository getObjectRepository(){
protected Object getPageObject(String pageName){
try {
return pageRepositoryClass.getConstructor().newInstance();
return Arrays.stream(pageRepositoryClass.getDeclaredFields())
.filter(field -> field.getName().equalsIgnoreCase(pageName))
.collect(Collectors.toSingleton())
.getType()
.getDeclaredConstructor()
.newInstance();
}
catch (
InstantiationException |
Expand All @@ -898,7 +906,7 @@ protected ObjectRepository getObjectRepository(){
public WebElement getElementFromPage(String elementFieldName, String pageName){
pageName = StringUtilities.firstLetterDeCapped(pageName);
Map<String, Object> pageFields;
Object pageObject = getFields(getObjectRepository()).get(pageName);
Object pageObject = getPageObject(pageName);
if (pageObject != null) pageFields = getFields(pageObject);
else throw new PickleibException("ObjectRepository does not contain an instance of " + pageName + " object!");
if (pageFields.get(elementFieldName) == null)
Expand All @@ -917,7 +925,7 @@ public WebElement getElementFromPage(String elementFieldName, String pageName){
public List<WebElement> getElementsFromPage(String elementListFieldName, String pageName){
Map<String, Object> pageFields;
pageName = firstLetterDeCapped(pageName);
Object pageObject = getFields(getObjectRepository()).get(pageName);
Object pageObject = getPageObject(pageName);
if (pageObject != null) pageFields = getFields(pageObject);
else throw new PickleibException("ObjectRepository does not contain an instance of " + pageName + " object!");
if (pageFields.get(elementListFieldName) == null)
Expand Down Expand Up @@ -1013,7 +1021,7 @@ public <Component extends WebElement> List<WebElement> getElementsAmongstNamedCo
public Map<String, Object> getComponentFieldsFromPage(String componentName, String pageName){
Map<String, Object> pageFields;
pageName = firstLetterDeCapped(pageName);
Object pageObject = getFields(getObjectRepository()).get(pageName);
Object pageObject = getPageObject(pageName);
if (pageObject != null) pageFields = getFields(pageObject);
else throw new PickleibException("ObjectRepository does not contain an instance of " + pageName + " object!");
if (pageFields.containsKey(componentName)) return getFields(pageFields.get(componentName));
Expand All @@ -1032,7 +1040,7 @@ public <Component extends WebElement> List<Component> getComponentsFromPage(Stri
Map<String, Object> pageFields;
Map<String, Object> componentFields;
pageName = firstLetterDeCapped(pageName);
Object pageObject = getFields(getObjectRepository()).get(pageName);
Object pageObject = getPageObject(pageName);
if (pageObject != null) pageFields = getFields(pageObject);
else throw new PickleibException("ObjectRepository does not contain an instance of " + pageName + " object!");
return (List<Component>) pageFields.get(componentListName);
Expand Down

0 comments on commit 5bf5b40

Please sign in to comment.