Skip to content

Commit

Permalink
Merge pull request #5 from Vertispan/smallrefactor
Browse files Browse the repository at this point in the history
Misc updates
  • Loading branch information
jhickman authored Jan 14, 2022
2 parents 3c40b4d + 56fffcf commit 36bc12c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
import java.io.PrintWriter;
import java.util.List;

import jsinterop.annotations.JsType;

/**
*
*/
Expand All @@ -57,6 +59,7 @@ public String generate(TreeLogger logger, GeneratorContext context, String typeN
TypeOracle oracle = context.getTypeOracle();

JClassType jso = oracle.findType(Name.getSourceNameForClass(JavaScriptObject.class));
JClassType elementalNode = oracle.findType("elemental2.dom.Node");

JClassType toGenerate = oracle.findType(typeName).isClass();

Expand Down Expand Up @@ -165,16 +168,24 @@ public String generate(TreeLogger logger, GeneratorContext context, String typeN
throw new UnableToCompleteException();
}
} else if (
retType.isClass() != null && retType.getQualifiedSourceName().equals("java.lang.String")
||
((retType.isClass() != null) && retType.isClass().isAssignableTo(jso)) ||
((retType.isInterface() != null) && oracle.getSingleJsoImplInterfaces()
.contains(retType))) {
retType.isClass() != null
&& retType.getQualifiedSourceName().equals("java.lang.String")
|| ((retType.isClass() != null) && retType.isClass().isAssignableTo(jso))
|| ((retType.isInterface() != null) && oracle.getSingleJsoImplInterfaces()
.contains(retType))) {
sw.print("return ");
} else {
methodLogger.log(Type.ERROR,
"Can't return non-jso, non-supported primitive " + retType + " from exported method");
throw new UnableToCompleteException();
// check for @JsType native classes
if (retType.isClass() != null
&& retType.isClass().getAnnotation(JsType.class) != null
&& retType.isClass().getAnnotation(JsType.class).isNative()) {
sw.print(" return ");
} else {
methodLogger.log(Type.ERROR,
"Can't return non-jso, non-supported primitive " + retType
+ " from exported method");
throw new UnableToCompleteException();
}
}
if (m.isStatic()) {
sw.print(exportedType);
Expand All @@ -195,6 +206,11 @@ public String generate(TreeLogger logger, GeneratorContext context, String typeN
} else if (type.isClass() != null && type.isClass().isAssignableTo(jso)) {
//normal array plus cast() trickery
sw.print("args.get(%1$d).<%2$s>cast()", i, type.getQualifiedSourceName());
} else if (type.isClass() != null
&& elementalNode != null
&& type.isClass().isAssignableTo(elementalNode)) {
sw.print("jsinterop.base.Js.cast(args.get(%1$d))", i,
type.getQualifiedSourceName());
} else if (type.isInterface() != null && oracle.getSingleJsoImplInterfaces()
.contains(type.isInterface())) {
//single jso cast thing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
*/
public class ByNearestWidget extends By {
private final WebDriver driver;
private final Class<?> widget;
private final String widgetClassName;

/**
* Finds the nearest containing widget of any type - anything that extends Widget will be found.
Expand All @@ -67,8 +67,21 @@ public ByNearestWidget(WebDriver driver) {
* @param type the type of widget to find
*/
public ByNearestWidget(WebDriver driver, Class<? extends Widget> type) {
this.widget = type;
this(driver, type.getName());
}

/**
* Finds the nearest containing widget of the given type. This will find any subtype of that
* widget, allowing you to pass in {@link ValueBoxBase} and find any {@link TextBox}, {@link
* TextArea}, {@link IntegerBox}, etc, as these are all subclasses of {@code ValueBoxBase}. Note
* that interfaces cannot be used, only base classes, and those classes *must* extend Widget.
*
* @param driver the driver to use to communicate with the browser
* @param widgetClassName the type of widget to find
*/
public ByNearestWidget(WebDriver driver, String widgetClassName) {
this.driver = driver;
this.widgetClassName = widgetClassName;
}

@Override
Expand All @@ -84,7 +97,7 @@ public List<WebElement> findElements(SearchContext context) {
public WebElement findElement(SearchContext context) {
WebElement potentialElement = tryFindElement(context);
if (potentialElement == null) {
throw new NoSuchElementException("Cannot find a " + widget.getName() + " in " + context);
throw new NoSuchElementException("Cannot find a " + widgetClassName + " in " + context);
}
return potentialElement;
}
Expand All @@ -99,13 +112,14 @@ public WebElement findElement(SearchContext context) {
private WebElement tryFindElement(SearchContext context) {
WebElement elt = context.findElement(By.xpath("."));
ExportedMethods m = ClientMethodsFactory.create(ExportedMethods.class, driver);
WebElement potentialElement = m.getContainingWidgetEltOfType(elt, widget.getName());
WebElement potentialElement = m.getContainingWidgetEltOfType(elt, widgetClassName);
return potentialElement;
}

@Override
public String toString() {
return "ByNearestWidget" + (widget == Widget.class ? "" : " " + widget.getName());
return "ByNearestWidget"
+ (Widget.class.getName().equals(widgetClassName) ? "" : " " + widgetClassName);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ public ByWidget(WebDriver driver) {
}

public ByWidget(WebDriver driver, Class<? extends Widget> widgetType) {
this(driver, widgetType.getName());
}

public ByWidget(WebDriver driver, String className) {
this.driver = driver;
this.type = widgetType.getName();
this.type = className;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,9 @@ public W waitFor(long duration, TemporalUnit unit) {
}

public W waitFor(Duration duration) {
return new FluentWait<WebDriver>(driver)
return new FluentWait<>(driver)
.withTimeout(duration)
.ignoring(NotFoundException.class)
.until(new Function<WebDriver, W>() {
@Override
public W apply(WebDriver webDriver) {
return done();
}
});
.until((Function<WebDriver, W>) webDriver -> done());
}
}

0 comments on commit 36bc12c

Please sign in to comment.