Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ComboBox changes, created its own GwtWidgetFinder. #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,24 @@
* #L%
*/

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.senchalabs.gwt.gwtdriver.by.ByNearestWidget;
import org.senchalabs.gwt.gwtdriver.by.ByWidget;
import org.senchalabs.gwt.gwtdriver.by.FasterByChained;
import org.senchalabs.gwt.gwtdriver.gxt.models.ComboBox.ComboBoxFinder;
import org.senchalabs.gwt.gwtdriver.invoke.ClientMethods;
import org.senchalabs.gwt.gwtdriver.invoke.ClientMethodsFactory;
import org.senchalabs.gwt.gwtdriver.models.GwtWidget;
import org.senchalabs.gwt.gwtdriver.models.GwtWidget.ForWidget;
import org.senchalabs.gwt.gwtdriver.models.GwtWidgetFinder;

import com.sencha.gxt.widget.core.client.form.FieldLabel;

@ForWidget(com.sencha.gxt.widget.core.client.form.ComboBox.class)
public class ComboBox extends Field {
public class ComboBox extends GwtWidget<ComboBoxFinder> {

private final ComboBoxMethods methods = ClientMethodsFactory.create(ComboBoxMethods.class, getDriver());

public ComboBox(WebDriver driver, WebElement element) {
Expand All @@ -38,8 +48,8 @@ public void clickTrigger() {
methods.clickTrigger(getElement());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed how this works now, so I'll rewrite the model stuff now that I saw how this works.

}

public ListView getListView() {
return null;
public void sendKeys(CharSequence... keys) {
getElement().findElement(By.tagName("input")).sendKeys(keys);
}

public interface ComboBoxMethods extends ClientMethods {
Expand All @@ -50,4 +60,46 @@ public interface ComboBoxMethods extends ClientMethods {
void clickTrigger(WebElement parent);
}

public static class ComboBoxFinder extends GwtWidgetFinder<ComboBox> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternate idea: what if instead of done() or waitFor(...) we did a as(Class) in the GwtWidgetFinder type to make it easier to say just .as(ComboBox.class) instead of .done().as(ComboBox.class).

Or another attempt at generics trickery to make the FieldFinder hand us a ComboBox instead? Did those go anywhere?

private String text;
public ComboBoxFinder withText(String text) {
this.text = text;
return this;
}

private String fieldLabel;
public ComboBoxFinder withLabel(String label) {
this.fieldLabel = label;
return this;
}
@Override
public ComboBoxFinder withDriver(WebDriver driver) {
return (ComboBoxFinder) super.withDriver(driver);
}
@Override
public ComboBox done() {
WebElement elt = this.elt;
if (fieldLabel != null) {
String escaped = escapeToString(fieldLabel);
elt = elt.findElement(new FasterByChained(By.xpath(".|.//*[contains(text(), "+escaped+")]"),
new ByNearestWidget(driver, FieldLabel.class),
new FasterByChained(
By.xpath("*|*/*"),
new ByWidget(driver, com.sencha.gxt.widget.core.client.form.ComboBox.class)
)));
return new ComboBox(driver, elt);
} else if (text != null) {
String escaped = escapeToString(text);
return new ComboBox(driver, elt.findElement(new FasterByChained(
By.xpath(".|.//*[contains(text(), "+escaped+")]"),
new ByNearestWidget(driver, com.sencha.gxt.widget.core.client.form.ComboBox.class)
)));
} else {
WebElement foundElement = elt.findElement(new FasterByChained(By.xpath(".//*"),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed the search, so no with has to be used

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The basic problem I have with this is that it just finds the first ComboBox in the dom, not necessarily the first one the user sees. Could be invisible (not totally sure of this) could be on the main page (i.e. when the user is in a modal window - technically the one on the main page will come first), or they could be reordered on the page.

Helpful for testing individual components, but less good for describing the relationship of the elements in a full application.

If we were to go this route, I'd want to make it configurable globally, and off by default, to avoid possible confusion. Or, since the point here is to just find the first thing that matches, a GwtWidget.findFirst(Class<T extends GwtWidget) that returns T rather than a finder<T>. That could key off of @ForWidget and find the first (visible?) instance in the dom.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind which way you want to go. I tried searching for the combo by field in its latest config and it doesn't find it, so I thought I'd see what you thought. I think the last else should probably just say use a with* in the builder, otherwise it seems that I can't find a widget at all, and no such element is found, but maybe its operator error.

I was picturing something like this:
ComboBox combo = myFormWithOneCombo.find(ComboBox.class, driver).done();

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thought,

List<ComboBox> combo = window.findWidgets(ComboBox.class, driver).done();

new ByWidget(driver, com.sencha.gxt.widget.core.client.form.ComboBox.class)));
return new ComboBox(driver, foundElement);
}
}
}

}