/* * Copyright 2007 the original author or authors. * * 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 jdave.wicket.selenium; import com.thoughtworks.selenium.Selenium; import jdave.IContextObjectFactory; import jdave.Specification; import jdave.wicket.MultiSelection; import jdave.wicket.Selection; import org.apache.wicket.Component; import org.apache.wicket.MarkupContainer; import org.apache.wicket.model.IModel; /** * @author Janne Hietamäki */ public abstract class SeleniumSpecification extends Specification { SeleniumManager lifecycleListener = new SeleniumManager(this); protected Selenium selenium; public WicketState wicket = new WicketState(); @Override public boolean needsThreadLocalIsolation() { return true; } public SeleniumSpecification() { addListener(lifecycleListener); } @Override public IContextObjectFactory getContextObjectFactory() { return lifecycleListener; } @Override public final void create() { lifecycleListener.start(); } public void onCreate() throws Exception { } /** * Create a new instance of a Wicket component to be specified. *

* The component must get given id. If the component is a Page, * the id is null. * * @param id * The id of a component, null if the component is a * Page, * @param model * A model for the component which was passed in * startComponent method. * @see #startComponent(IModel) */ protected abstract T newComponent(String id, IModel model); public T startComponent(final IModel model) { return newComponent(SeleniumTestWebPage.COMPONENT_ID, model); } public T startComponent() { return startComponent(null); } /** * Select first component whose model object matches given Hamcrest matcher: * *

* * Item item = selectFirst(Item.class).which(is(0)).from(context); * *
* *
*/ public Selection selectFirst(Class type) { return new Selection(type); } /** * Select all components whose model objects match given Hamcrest matcher: * *
* * List
* *
*/ public MultiSelection selectAll(Class type) { return new MultiSelection(type); } /** * Select first component whose Wicket id is given String: * *
* * Label itemName = selectFirst(Label.class, "name").from(context); * *
* *
*/ public Selection selectFirst(Class type, String wicketId) { return new Selection(type, wicketId); } /** * Select all components whose ids are given Wicket id: * *
* * List
* *
*/ public MultiSelection selectAll(Class type, String wicketId) { return new MultiSelection(type, wicketId); } }