> + /** > + * Haven't figured out how to get Selenium to click the actual elements, > never mine > + * coordinate the wait for the Ajax. So far its just been manual testing. > + */
It's hard to do with basic selenium functions because the label isn't clickable (that's probably a defect). At the first level you can just call click "tree" click "tree_0" etc... but that breaks down once you start pulling in nodes with random ids. Here is a solution that works based on labels. It has to use the contains function because the labels have extra whitespace so text()='Games' is false. click "//span[contains(text(),'Games')]/preceding-sibling::span[contains(@class, 't-tree-icon')]" waitForCondition "selenium.isElementPresent(\"//span[contains(text(),'Board Games')]\")", "10000" click "//span[contains(text(),'Board Games')]/preceding-sibling::span[contains(@class, 't-tree-icon')]" waitForCondition "selenium.isElementPresent(\"//span[contains(text(),'Agricola')]\") != null", "10000" Josh On Tue, Jun 14, 2011 at 4:10 PM, <[email protected]> wrote: > Author: hlship > Date: Tue Jun 14 23:10:46 2011 > New Revision: 1135841 > > URL: http://svn.apache.org/viewvc?rev=1135841&view=rev > Log: > Add partially functional tests for the Tree component > > Added: > > tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/TreeTests.groovy > > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/Stuff.java > > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/StuffTreeModelAdapter.java > - copied, changed from r1135708, > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/TreeDemo.java > Removed: > > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/FileSystemTreeModel.java > Modified: > > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/TreeDemo.java > > tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/TreeDemo.tml > > Added: > tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/TreeTests.groovy > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/TreeTests.groovy?rev=1135841&view=auto > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/TreeTests.groovy > (added) > +++ > tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/TreeTests.groovy > Tue Jun 14 23:10:46 2011 > @@ -0,0 +1,51 @@ > +// Copyright 2011 The Apache Software Foundation > +// > +// Licensed under the Apache License, Version 2.0 (the "License"); > +// you may not use this file except in compliance with the License. > +// You may obtain a copy of the License at > +// > +// http://www.apache.org/licenses/LICENSE-2.0 > +// > +// Unless required by applicable law or agreed to in writing, software > +// distributed under the License is distributed on an "AS IS" BASIS, > +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > +// See the License for the specific language governing permissions and > +// limitations under the License. > + > +package org.apache.tapestry5.integration.app1 > + > +import org.apache.tapestry5.test.SeleniumTestCase > +import org.testng.annotations.Test > + > +class TreeTests extends SeleniumTestCase > +{ > + /** > + * Haven't figured out how to get Selenium to click the actual elements, > never mine > + * coordinate the wait for the Ajax. So far its just been manual testing. > + */ > + @Test > + void basics() { > + > + openBaseURL() > + > + clickAndWait "link=Tree Component Demo" > + > + clickAndWait "link=clear expansions" > + > + if (false) { > + click "//span[@class='t-tree-icon'][2]" > + > + sleep 100 > + > + click "//span[@class='t-tree-icon'][3]" > + > + sleep 100 > + > + assertTextPresent "Agricola" > + > + clickAndWait "link=Redraw" > + > + assertTextPresent "Agricola" > + } > + } > +} > > Added: > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/Stuff.java > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/Stuff.java?rev=1135841&view=auto > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/Stuff.java > (added) > +++ > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/Stuff.java > Tue Jun 14 23:10:46 2011 > @@ -0,0 +1,67 @@ > +// Copyright 2011 The Apache Software Foundation > +// > +// Licensed under the Apache License, Version 2.0 (the "License"); > +// you may not use this file except in compliance with the License. > +// You may obtain a copy of the License at > +// > +// http://www.apache.org/licenses/LICENSE-2.0 > +// > +// Unless required by applicable law or agreed to in writing, software > +// distributed under the License is distributed on an "AS IS" BASIS, > +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. > +// See the License for the specific language governing permissions and > +// limitations under the License. > + > +package org.apache.tapestry5.integration.app1; > + > +import java.util.List; > +import java.util.UUID; > + > +import org.apache.tapestry5.ioc.internal.util.CollectionFactory; > + > +public class Stuff > +{ > + public final String uuid = UUID.randomUUID().toString(); > + > + public final String name; > + > + public final List<Stuff> children = CollectionFactory.newList(); > + > + public Stuff(String name) > + { > + this.name = name; > + } > + > + public Stuff addChildrenNamed(String... names) > + { > + for (String name : names) > + { > + children.add(new Stuff(name)); > + } > + > + return this; > + } > + > + public Stuff addChild(Stuff child) > + { > + children.add(child); > + > + return this; > + } > + > + public Stuff seek(String uuid) > + { > + if (this.uuid.equals(uuid)) > + return this; > + > + for (Stuff child : children) > + { > + Stuff match = child.seek(uuid); > + > + if (match != null) > + return match; > + } > + > + return null; > + } > +} > > Copied: > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/StuffTreeModelAdapter.java > (from r1135708, > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/TreeDemo.java) > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/StuffTreeModelAdapter.java?p2=tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/StuffTreeModelAdapter.java&p1=tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/TreeDemo.java&r1=1135708&r2=1135841&rev=1135841&view=diff > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/TreeDemo.java > (original) > +++ > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/StuffTreeModelAdapter.java > Tue Jun 14 23:10:46 2011 > @@ -12,27 +12,31 @@ > // See the License for the specific language governing permissions and > // limitations under the License. > > -package org.apache.tapestry5.integration.app1.pages; > +package org.apache.tapestry5.integration.app1; > > -import java.io.File; > +import java.util.List; > > -import org.apache.tapestry5.annotations.InjectComponent; > -import org.apache.tapestry5.corelib.components.Tree; > -import org.apache.tapestry5.integration.app1.FileSystemTreeModel; > -import org.apache.tapestry5.tree.TreeModel; > +import org.apache.tapestry5.tree.TreeModelAdapter; > > -public class TreeDemo > +public class StuffTreeModelAdapter implements TreeModelAdapter<Stuff> > { > - @InjectComponent > - private Tree fs; > + public boolean isLeaf(Stuff value) > + { > + return value.children.isEmpty(); > + } > + > + public boolean hasChildren(Stuff value) > + { > + return !value.children.isEmpty(); > + } > > - public TreeModel<File> getFileSystemTreeModel() > + public List<Stuff> getChildren(Stuff value) > { > - return new FileSystemTreeModel(); > + return value.children; > } > > - void onActionFromClear() > + public String getLabel(Stuff value) > { > - fs.clearExpansions(); > + return value.name; > } > } > > Modified: > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/TreeDemo.java > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/TreeDemo.java?rev=1135841&r1=1135840&r2=1135841&view=diff > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/TreeDemo.java > (original) > +++ > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/TreeDemo.java > Tue Jun 14 23:10:46 2011 > @@ -14,25 +14,58 @@ > > package org.apache.tapestry5.integration.app1.pages; > > -import java.io.File; > - > +import org.apache.tapestry5.ValueEncoder; > import org.apache.tapestry5.annotations.InjectComponent; > import org.apache.tapestry5.corelib.components.Tree; > -import org.apache.tapestry5.integration.app1.FileSystemTreeModel; > +import org.apache.tapestry5.integration.app1.Stuff; > +import org.apache.tapestry5.integration.app1.StuffTreeModelAdapter; > +import org.apache.tapestry5.tree.DefaultTreeModel; > import org.apache.tapestry5.tree.TreeModel; > > public class TreeDemo > { > @InjectComponent > - private Tree fs; > + private Tree tree; > + > + private static final Stuff rootStuff = new Stuff("<root>"); > > - public TreeModel<File> getFileSystemTreeModel() > + static > { > - return new FileSystemTreeModel(); > + rootStuff.addChild(new Stuff("Pets").addChildrenNamed("Oscar", > "Gromit", "Max", "Roger", "Cooper")); > + rootStuff.addChild(new Stuff("Games").addChild( > + new Stuff("Board Games").addChildrenNamed("Settlers of > Catan", "Agricola", "Ra", "Risk", "Dvonn")) > + .addChild(new Stuff("Card Games").addChildrenNamed("Magic > the Gathering", "Dominion", "Mu"))); > + > + Stuff numbers = new Stuff("Numbers"); > + > + for (int i = 0; i < 10000; i++) > + { > + numbers.addChild(new Stuff(Integer.toString(i))); > + } > + > + rootStuff.addChild(numbers); > + } > + > + public TreeModel<Stuff> getStuffModel() > + { > + ValueEncoder<Stuff> encoder = new ValueEncoder<Stuff>() > + { > + public String toClient(Stuff value) > + { > + return value.uuid; > + } > + > + public Stuff toValue(String clientValue) > + { > + return rootStuff.seek(clientValue); > + } > + }; > + > + return new DefaultTreeModel<Stuff>(encoder, new > StuffTreeModelAdapter(), rootStuff.children); > } > > void onActionFromClear() > { > - fs.clearExpansions(); > + tree.clearExpansions(); > } > } > > Modified: > tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/TreeDemo.tml > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/TreeDemo.tml?rev=1135841&r1=1135840&r2=1135841&view=diff > ============================================================================== > --- > tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/TreeDemo.tml > (original) > +++ > tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/TreeDemo.tml > Tue Jun 14 23:10:46 2011 > @@ -2,7 +2,7 @@ > > <h1>Tree Demo</h1> > > - <t:tree t:id="fs" model="fileSystemTreeModel"/> > + <t:tree class="test-hook" t:id="tree" model="stuffModel"/> > > <p> > [ > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
