-
Notifications
You must be signed in to change notification settings - Fork 7
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
|
@@ -38,8 +48,8 @@ public void clickTrigger() { | |
methods.clickTrigger(getElement()); | ||
} | ||
|
||
public ListView getListView() { | ||
return null; | ||
public void sendKeys(CharSequence... keys) { | ||
getElement().findElement(By.tagName("input")).sendKeys(keys); | ||
} | ||
|
||
public interface ComboBoxMethods extends ClientMethods { | ||
|
@@ -50,4 +60,46 @@ public interface ComboBoxMethods extends ClientMethods { | |
void clickTrigger(WebElement parent); | ||
} | ||
|
||
public static class ComboBoxFinder extends GwtWidgetFinder<ComboBox> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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(".//*"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed the search, so no with has to be used There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a thought,
|
||
new ByWidget(driver, com.sencha.gxt.widget.core.client.form.ComboBox.class))); | ||
return new ComboBox(driver, foundElement); | ||
} | ||
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
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.