Skip to content

Commit

Permalink
Fixed UI Wizard Tests for combo
Browse files Browse the repository at this point in the history
Linux uses CCombo instead of Combo, so encapsulate bot combo matching in
tests

Change-Id: I420470a1891b0157bccc7e3a4431be0736d83b6c
Signed-off-by: Carsten Reckord <reckord@yatta.de>
  • Loading branch information
creckord committed Sep 3, 2020
1 parent f99217c commit db77ab9
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 11 deletions.
Expand Up @@ -54,6 +54,7 @@
import org.eclipse.epp.mpc.core.model.INode;
import org.eclipse.epp.mpc.core.service.QueryHelper;
import org.eclipse.epp.mpc.tests.ui.wizard.matcher.NodeMatcher;
import org.eclipse.epp.mpc.tests.util.SWTBotComboAdapter;
import org.eclipse.equinox.internal.p2.discovery.model.Tag;
import org.eclipse.equinox.internal.p2.ui.discovery.wizards.CatalogFilter;
import org.eclipse.osgi.util.NLS;
Expand Down Expand Up @@ -86,7 +87,6 @@
import org.eclipse.swtbot.swt.finder.widgets.SWTBotBrowser;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCTabItem;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotLabel;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotLink;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
Expand Down Expand Up @@ -440,21 +440,21 @@ protected void checkSelectedTab(String tabLabel) {
}

protected void filterMarket(String term) {
SWTBotCombo comboBox = marketCombo();
SWTBotComboAdapter comboBox = marketCombo();
select(comboBox, IMarket.class, term);
}

protected SWTBotCombo marketCombo() {
return bot.comboBox(0);
protected SWTBotComboAdapter marketCombo() {
return SWTBotComboAdapter.comboBox(bot, 0);
}

protected void filterCategory(String term) {
SWTBotCombo comboBox = categoryCombo();
SWTBotComboAdapter comboBox = categoryCombo();
select(comboBox, ICategory.class, term);
}

protected SWTBotCombo categoryCombo() {
return bot.comboBox(1);
protected SWTBotComboAdapter categoryCombo() {
return SWTBotComboAdapter.comboBox(bot, 1);
}

protected void search(String term) {
Expand Down Expand Up @@ -523,7 +523,7 @@ protected String getText(StyleRange range, SWTBotStyledText styledText) {
return text.substring(range.start, range.start + range.length);
}

protected void select(SWTBotCombo comboBox, Class<?> classifier, String choice) {
protected void select(SWTBotComboAdapter comboBox, Class<?> classifier, String choice) {
AbstractTagFilter filter = findFilter(classifier);
String choiceText = choice != null ? choice : ((ComboTagFilter) filter).getNoSelectionLabel();

Expand Down
Expand Up @@ -26,13 +26,13 @@
import org.eclipse.epp.mpc.tests.Categories.RemoteTests;
import org.eclipse.epp.mpc.tests.Categories.UITests;
import org.eclipse.epp.mpc.tests.ui.wizard.matcher.NodeMatcher;
import org.eclipse.epp.mpc.tests.util.SWTBotComboAdapter;
import org.eclipse.epp.mpc.ui.IMarketplaceClientConfiguration;
import org.eclipse.epp.mpc.ui.IMarketplaceClientService;
import org.eclipse.epp.mpc.ui.MarketplaceClient;
import org.eclipse.epp.mpc.ui.Operation;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.eclipse.ui.PlatformUI;
Expand Down Expand Up @@ -108,8 +108,8 @@ public void testOpenSearch() throws Exception {
initWizardBot();
checkSelectedTab("Search");

SWTBotCombo marketCombo = bot.comboBox(0);
SWTBotCombo categoryCombo = bot.comboBox(1);
SWTBotComboAdapter marketCombo = SWTBotComboAdapter.comboBox(bot, 0);
SWTBotComboAdapter categoryCombo = SWTBotComboAdapter.comboBox(bot, 1);
assertEquals("Tools", marketCombo.getText());
assertEquals("Editor", categoryCombo.getText());

Expand Down
@@ -0,0 +1,105 @@
/*******************************************************************************
* Copyright (c) 2018 The Eclipse Foundation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* The Eclipse Foundation - initial API and implementation
*******************************************************************************/
package org.eclipse.epp.mpc.tests.util;

import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.anyOf;
import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.widgetOfType;

import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCCombo;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo;
import org.hamcrest.Matcher;
import org.hamcrest.SelfDescribing;

public interface SWTBotComboAdapter {

public void setSelection(String text);

public String selection();

public int selectionIndex();

public void setSelection(int index);

public int itemCount();

public String[] items();

public String getText();

public String getId();

public String getToolTipText();

public boolean isEnabled();

public boolean isVisible();

public boolean isActive();

static class ComboAdapter extends SWTBotCombo implements SWTBotComboAdapter {

public ComboAdapter(Combo w, SelfDescribing description) throws WidgetNotFoundException {
super(w, description);
// ignore
}

public ComboAdapter(Combo w) throws WidgetNotFoundException {
super(w);
// ignore
}

}

static class CComboAdapter extends SWTBotCCombo implements SWTBotComboAdapter {

public CComboAdapter(CCombo w, SelfDescribing description) throws WidgetNotFoundException {
super(w, description);
}

public CComboAdapter(CCombo w) throws WidgetNotFoundException {
super(w);
}
}

/**
* @return a {@link SWTBotCombo} with the specified <code>none</code>.
* @throws WidgetNotFoundException
* if the widget is not found or is disposed.
*/
public static SWTBotComboAdapter comboBox(SWTBot bot) {
return comboBox(bot, 0);
}

/**
* @param index
* the index of the widget.
* @return a {@link SWTBotCombo} with the specified <code>none</code>.
* @throws WidgetNotFoundException
* if the widget is not found or is disposed.
*/
@SuppressWarnings("unchecked")
public static SWTBotComboAdapter comboBox(SWTBot bot, int index) {
Matcher<Widget> matcher = anyOf(widgetOfType(Combo.class), widgetOfType(CCombo.class));
Widget widget = bot.widget(matcher, index);
if (widget instanceof CCombo) {
return new CComboAdapter((CCombo) widget, matcher);
}
return new ComboAdapter((Combo) widget, matcher);
}

}

0 comments on commit db77ab9

Please sign in to comment.