Skip to content

Commit 38ab146

Browse files
committed
Enabled Actions and Traverses to PageObjects from DataObjects. It's also possible to self reference the DataObjects in action methods
1 parent d33748e commit 38ab146

File tree

28 files changed

+323
-46
lines changed

28 files changed

+323
-46
lines changed

pogen4selenium-api/src/main/java/io/toolisticon/pogen4selenium/api/Action.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@
2727
*/
2828
Class<? extends ActionImpl> value();
2929

30-
30+
String[] attributeNameToConstructorMapping () default {};
3131
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package io.toolisticon.pogen4selenium.api;
2+
3+
public @interface ActionFileUpload {
4+
5+
}

pogen4selenium-api/src/main/java/io/toolisticon/pogen4selenium/runtime/CommonByLocators.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package io.toolisticon.pogen4selenium.runtime;
22

33
import org.openqa.selenium.By;
4+
import org.openqa.selenium.SearchContext;
45
import org.openqa.selenium.WebElement;
56

67
/**
78
* These are the locators which should be used by actions, that are both available in {@link DataObjectParentImpl} and {@link PageObjectParentImpl}.
89
*/
910
public interface CommonByLocators {
11+
12+
SearchContext getSearchContext();
1013

1114
WebElement waitForElementToBeInteractable(By by);
1215

pogen4selenium-api/src/main/java/io/toolisticon/pogen4selenium/runtime/DataObjectParentImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.openqa.selenium.By;
66
import org.openqa.selenium.ElementNotInteractableException;
77
import org.openqa.selenium.NoSuchElementException;
8+
import org.openqa.selenium.SearchContext;
89
import org.openqa.selenium.WebDriver;
910
import org.openqa.selenium.WebElement;
1011
import org.openqa.selenium.interactions.Actions;
@@ -110,6 +111,13 @@ public WebElement waitForElementToBePresent(By by) {
110111

111112
}
112113

114+
115+
116+
@Override
117+
public SearchContext getSearchContext() {
118+
return this.relativeParentWebElement;
119+
}
120+
113121
public void pause(Duration duration) {
114122
new Actions(driver).pause(duration).perform();
115123
}

pogen4selenium-api/src/main/java/io/toolisticon/pogen4selenium/runtime/PageObjectParentImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.openqa.selenium.ElementNotInteractableException;
1010
import org.openqa.selenium.Keys;
1111
import org.openqa.selenium.NoSuchElementException;
12+
import org.openqa.selenium.SearchContext;
1213
import org.openqa.selenium.WebDriver;
1314
import org.openqa.selenium.WebElement;
1415
import org.openqa.selenium.interactions.Actions;
@@ -155,6 +156,10 @@ public WebElement waitForElementToBePresent(ExpectedCondition<WebElement> expect
155156
}
156157

157158

159+
@Override
160+
public SearchContext getSearchContext() {
161+
return this.driver;
162+
}
158163

159164

160165

pogen4selenium-api/src/main/java/io/toolisticon/pogen4selenium/runtime/actions/ActionClickImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
import java.util.Collection;
55

66
import org.openqa.selenium.NoSuchElementException;
7+
import org.openqa.selenium.SearchContext;
78
import org.openqa.selenium.WebDriver;
89
import org.openqa.selenium.WebElement;
9-
import org.openqa.selenium.support.ui.ExpectedConditions;
1010

1111
import io.toolisticon.pogen4selenium.runtime.LocatorCondition;
1212

1313
public class ActionClickImpl extends BaseAction {
1414

15-
public ActionClickImpl(WebDriver driver, LocatorCondition sideCondition) {
16-
super(driver, sideCondition);
15+
public ActionClickImpl(WebDriver driver, SearchContext searchContext, LocatorCondition sideCondition) {
16+
super(driver, searchContext, sideCondition);
1717

1818
}
1919

pogen4selenium-api/src/main/java/io/toolisticon/pogen4selenium/runtime/actions/ActionMoveToAndClickImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.Collection;
55

66
import org.openqa.selenium.NoSuchElementException;
7+
import org.openqa.selenium.SearchContext;
78
import org.openqa.selenium.WebDriver;
89
import org.openqa.selenium.WebElement;
910
import org.openqa.selenium.interactions.Actions;
@@ -13,8 +14,8 @@
1314
public class ActionMoveToAndClickImpl extends BaseAction {
1415

1516

16-
public ActionMoveToAndClickImpl(WebDriver driver, LocatorCondition sideCondition) {
17-
super(driver, sideCondition);
17+
public ActionMoveToAndClickImpl(WebDriver driver, SearchContext searchContext, LocatorCondition sideCondition) {
18+
super(driver, searchContext, sideCondition);
1819
}
1920

2021
@Override

pogen4selenium-api/src/main/java/io/toolisticon/pogen4selenium/runtime/actions/ActionWriteImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import org.openqa.selenium.Keys;
77
import org.openqa.selenium.NoSuchElementException;
8+
import org.openqa.selenium.SearchContext;
89
import org.openqa.selenium.WebDriver;
910
import org.openqa.selenium.WebElement;
1011

@@ -15,8 +16,8 @@ public class ActionWriteImpl extends BaseAction {
1516

1617
private final String toSet;
1718

18-
public ActionWriteImpl(WebDriver driver, LocatorCondition sideCondition, String toSet) {
19-
super(driver, sideCondition);
19+
public ActionWriteImpl(WebDriver driver, SearchContext searchContext, LocatorCondition sideCondition, String toSet) {
20+
super(driver, searchContext, sideCondition);
2021

2122
this.toSet = toSet;
2223
}

pogen4selenium-api/src/main/java/io/toolisticon/pogen4selenium/runtime/actions/BaseAction.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import java.time.Duration;
44
import java.util.Collection;
5-
import java.util.function.Supplier;
65
import java.util.stream.Collectors;
76
import java.util.stream.Stream;
87

98
import org.openqa.selenium.By;
109
import org.openqa.selenium.NoSuchElementException;
10+
import org.openqa.selenium.SearchContext;
1111
import org.openqa.selenium.StaleElementReferenceException;
1212
import org.openqa.selenium.WebDriver;
1313
import org.openqa.selenium.WebElement;
@@ -22,10 +22,12 @@ public abstract class BaseAction implements LocatorCondition, ActionImpl{
2222

2323

2424
protected final WebDriver driver;
25+
protected final SearchContext searchContext;
2526
private final LocatorCondition sideCondition;
2627

27-
protected BaseAction(WebDriver driver, LocatorCondition sideCondition) {
28+
protected BaseAction(WebDriver driver, SearchContext searchContext, LocatorCondition sideCondition) {
2829
this.driver = driver;
30+
this.searchContext = searchContext;
2931
this.sideCondition = sideCondition;
3032
}
3133

@@ -57,7 +59,7 @@ public void executeAction(By locator) {
5759
.withMessage("Locator '" + locator.toString() + "' based action '" + this.getClass().getCanonicalName() + "' with side condition '" + this.sideCondition.getClass().getCanonicalName() + "'")
5860
.ignoreAll(getExceptionsToIgnore());
5961

60-
applyAction(wait.until(new WithLocatorCondition(locator)));
62+
applyAction(wait.until(new WithLocatorCondition(this.searchContext, locator)));
6163

6264
}
6365

@@ -73,7 +75,7 @@ class OnElementCondition implements ExpectedCondition<WebElement> {
7375
private OnElementCondition(
7476
WebElement webElement) {
7577

76-
this.webElement = webElement;
78+
this.webElement = webElement;
7779

7880
}
7981

@@ -90,10 +92,12 @@ public WebElement apply(WebDriver input) {
9092

9193
class WithLocatorCondition implements ExpectedCondition<WebElement> {
9294

95+
private final SearchContext searchContext;
9396
private final By locator;
9497

95-
private WithLocatorCondition(By locator) {
98+
private WithLocatorCondition(SearchContext searchContext, By locator) {
9699

100+
this.searchContext = searchContext;
97101
this.locator = locator;
98102

99103
}
@@ -103,7 +107,7 @@ public WebElement apply(WebDriver input) {
103107

104108
try {
105109

106-
WebElement element = input.findElement(locator);
110+
WebElement element = searchContext.findElement(locator);
107111
return new OnElementCondition(element).apply(input);
108112

109113
} catch (NoSuchElementException | StaleElementReferenceException e) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.toolisticon.pogen4selenium.example.withoutpagefactory;
2+
3+
import io.toolisticon.pogen4selenium.api.PageObject;
4+
import io.toolisticon.pogen4selenium.api.PageObjectParent;
5+
6+
@PageObject
7+
public interface ExternalPage extends PageObjectParent<ExternalPage>{
8+
9+
}

0 commit comments

Comments
 (0)