Skip to content

Commit

Permalink
#1894 restore Driver parameter in SelenidePageFactory.findSelector() …
Browse files Browse the repository at this point in the history
…- it's used by `selenide-appium`.
  • Loading branch information
asolntsev committed Aug 7, 2022
1 parent 67f5bf5 commit 26fa990
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog

## 6.7.1 (released 08.08.2022)

* #1894 restore Driver parameter in SelenidePageFactory.findSelector() - it's used by `selenide-appium`.

## 6.7.0 (released 04.08.2022)

* #1780 verify the whole text in `$.shouldHave(text)`, not a substring -- see PR #1783
* #1799 implement full-size screenshots as a separate Selenide plugin -- see PR #1858; thanks to Aliaksandr Rasolka for PR #1800
* #1894 add @CacheLookup annotation support -- thanks to [Ilya Koshaleu](https://github.com/groov1kk)
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {

allprojects {
group = 'com.codeborne'
version = '6.7.0'
version = '6.7.1'
}

subprojects {
Expand Down
41 changes: 27 additions & 14 deletions src/main/java/com/codeborne/selenide/impl/SelenidePageFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
Expand All @@ -25,10 +29,6 @@
import java.lang.reflect.TypeVariable;
import java.util.Arrays;
import java.util.List;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;

/**
* Factory class to make using Page Objects simpler and easier.
Expand All @@ -47,7 +47,8 @@ public <PageObjectClass> PageObjectClass page(Driver driver, Class<PageObjectCla
Constructor<PageObjectClass> constructor = pageObjectClass.getDeclaredConstructor();
constructor.setAccessible(true);
return page(driver, constructor.newInstance());
} catch (ReflectiveOperationException e) {
}
catch (ReflectiveOperationException e) {
throw new PageObjectException("Failed to create new instance of " + pageObjectClass, e);
}
}
Expand Down Expand Up @@ -80,7 +81,7 @@ protected void initFields(Driver driver, @Nullable WebElementSource searchContex
Field[] fields = proxyIn.getDeclaredFields();
for (Field field : fields) {
if (!isInitialized(page, field)) {
By selector = findSelector(field);
By selector = findSelector(driver, field);
Object value = decorate(page.getClass().getClassLoader(), driver, searchContext, field, selector, genericTypes);
if (value != null) {
setFieldValue(page, field, value);
Expand All @@ -89,8 +90,13 @@ protected void initFields(Driver driver, @Nullable WebElementSource searchContex
}
}

/**
* @param driver Used by subclasses (e.g. in selenide-appium plugin)
* @param field expected to be an element in a Page Object
* @return {@link By} instance used by webdriver to locate elements
*/
@Nonnull
protected By findSelector(Field field) {
protected By findSelector(@SuppressWarnings("unused") Driver driver, Field field) {
return new Annotations(field).buildBy();
}

Expand All @@ -102,7 +108,8 @@ protected void setFieldValue(Object page, Field field, Object value) {
try {
field.setAccessible(true);
field.set(page, value);
} catch (IllegalAccessException e) {
}
catch (IllegalAccessException e) {
throw new PageObjectException("Failed to assign field " + field + " to value " + value, e);
}
}
Expand All @@ -112,7 +119,8 @@ protected boolean isInitialized(Object page, Field field) {
try {
field.setAccessible(true);
return field.get(page) != null;
} catch (IllegalAccessException e) {
}
catch (IllegalAccessException e) {
throw new PageObjectException("Failed to access field " + field + " in " + page, e);
}
}
Expand All @@ -127,7 +135,8 @@ public ElementsContainer createElementsContainer(Driver driver, @Nullable WebEle
self = new LazyWebElementSnapshot(self);
}
return initElementsContainer(driver, field, self);
} catch (ReflectiveOperationException e) {
}
catch (ReflectiveOperationException e) {
throw new PageObjectException("Failed to create elements container for field " + field.getName(), e);
}
}
Expand Down Expand Up @@ -179,7 +188,8 @@ public Object decorate(ClassLoader loader,
if (ElementsContainer.class.equals(field.getDeclaringClass()) && "self".equals(field.getName())) {
if (searchContext != null) {
return ElementFinder.wrap(SelenideElement.class, searchContext);
} else {
}
else {
logger.warn("Cannot initialize field {}", field);
return null;
}
Expand All @@ -190,9 +200,11 @@ public Object decorate(ClassLoader loader,
if (ElementsCollection.class.isAssignableFrom(field.getType()) ||
isDecoratableList(field, genericTypes, WebElement.class)) {
return createElementsCollection(driver, searchContext, selector, field);
} else if (ElementsContainer.class.isAssignableFrom(field.getType())) {
}
else if (ElementsContainer.class.isAssignableFrom(field.getType())) {
return createElementsContainer(driver, searchContext, field, selector);
} else if (isDecoratableList(field, genericTypes, ElementsContainer.class)) {
}
else if (isDecoratableList(field, genericTypes, ElementsContainer.class)) {
return createElementsContainerList(driver, searchContext, field, genericTypes, selector);
}

Expand Down Expand Up @@ -262,7 +274,8 @@ protected Class<?> getListGenericType(Field field, Type[] genericTypes) {
if (firstType instanceof TypeVariable) {
int indexOfType = indexOf(field.getDeclaringClass(), firstType);
return (Class<?>) genericTypes[indexOfType];
} else if (firstType instanceof Class) {
}
else if (firstType instanceof Class) {
return (Class<?>) firstType;
}
throw new IllegalArgumentException("Cannot detect list type of " + field);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/versions.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Browser: Google Chrome and Chromium - Driver: chromedriver
# Source: http://chromedriver.chromium.org/downloads
chrome104=104.0.5112.29
chrome104=104.0.5112.79
chrome103=103.0.5060.134
chrome102=102.0.5005.61
chrome101=101.0.4951.41
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
* Integration tests for Page Objects support in Selenide
*/
package integration.pageobjects;

0 comments on commit 26fa990

Please sign in to comment.