Search in sources :

Example 11 with WidgetNotFoundException

use of org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException in project linuxtools by eclipse.

the class SWTUtils method hideMenu.

/**
 * Hides the menu for the given <code>tree</code>
 *
 * @param tree
 *            the tree whose {@link Menu} should be hidden
 */
public static void hideMenu(final SWTBotTree tree) {
    try {
        final Menu menu = UIThreadRunnable.syncExec((Result<Menu>) () -> tree.widget.getMenu());
        UIThreadRunnable.syncExec(new VoidResult() {

            @Override
            public void run() {
                hide(menu);
            }

            private void hide(final Menu menu) {
                menu.notifyListeners(SWT.Hide, new Event());
                if (menu.getParentMenu() != null) {
                    hide(menu.getParentMenu());
                }
            }
        });
    } catch (WidgetNotFoundException e) {
    // ignore if widget is not found, that's probably because there's no
    // tree in the
    // Docker Explorer view for the test that just ran.
    }
}
Also used : WidgetNotFoundException(org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException) VoidResult(org.eclipse.swtbot.swt.finder.results.VoidResult) Event(org.eclipse.swt.widgets.Event) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) SWTBotMenu(org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu) Menu(org.eclipse.swt.widgets.Menu)

Example 12 with WidgetNotFoundException

use of org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException in project translationstudio8 by heartsome.

the class ImportToDB method importFile.

/**
	 * @param from
	 *            功能入口,请使用 TSUIConstants 类提供的枚举;
	 */
private void importFile(Entry from) {
    getDataAll();
    openImportDialog(from);
    // 预期结果验证:未选择文件
    if (expectedResult.equals(TsUIConstants.ExpectedResult.NO_FILE)) {
        assertTrue(dialog.txtWLblFile().getText().equals(""));
        dialog.btnFinish().click();
        assertTrue(dialog.msgNoFileToImport().isVisible());
    } else {
        // 无效路径(文件不存在)的预处理
        if (expectedResult.equals(TsUIConstants.ExpectedResult.INVALID_PATH)) {
            File file = new File(filePath);
            if (file.exists()) {
                // 此预期结果分支不应该存在该文件,故需先删除
                file.delete();
            }
        }
        // 浏览文件
        dialog.btnBrowse().click();
        // 用 Mock 的输入对话框代替系统原生对话框来输入文件路径
        InputDialog idlg = new InputDialog(InputDialog.OPEN_FILE);
        idlg.txt().setText(filePath);
        idlg.btnOK().click();
        Waits.shellClosed(idlg);
        HSBot.bot().waitUntil(new IsWidgetTextEquals(dialog.txtWLblFile(), filePath), 10000);
        // 预期结果验证:未选择数据库
        if (expectedResult.equals(TsUIConstants.ExpectedResult.NO_DB)) {
            assertTrue(dialog.txtWLblDatabase().getText().equals(""));
            assertTrue(!dialog.btnFinish().isEnabled());
            assertTrue(dialog.msgNoDBToImport().isVisible());
        } else {
            // 选择库
            dialog.btnSelectDB().click();
            MemoryDBManagement md = new MemoryDBManagement(row);
            md.setFromImportDb(true);
            md.selectDB(dbName);
            //				new DBManagement(row).selectDB(dbName);
            assertTrue("记忆库/术语库未正确选择。", dbName.equals(dialog.txtWLblDatabase().getText()));
            // 选择更新策略
            dialog.btnSetting().click();
            PreferencesDialog dlgPref = new PreferencesDialog();
            selectUpdateMode(dlgPref);
            // 开始导入
            dialog.btnFinish().click();
            // 预期结果验证:成功导入文件
            if (expectedResult.equals(TsUIConstants.ExpectedResult.SUCCESS)) {
                try {
                    // 暂时只设置等待 10 分钟
                    HSBot.bot().waitUntil(new IsWidgetInvisible(dialog.msgImporting()), 600000);
                } catch (WidgetNotFoundException e) {
                    e.printStackTrace();
                }
                assertTrue(dialog.msgImportSuccess().isVisible());
            // 预期结果验证:文件内容有误、无效路径(文件不存在)、错误的文件类型
            } else if (expectedResult.equals(TsUIConstants.ExpectedResult.FILE_ERROR) || expectedResult.equals(TsUIConstants.ExpectedResult.INVALID_PATH) || expectedResult.equals(TsUIConstants.ExpectedResult.WRONG_TYPE)) {
                assertTrue(dialog.msgFileError().isVisible());
            } else {
                assertTrue("无此预期结果:" + expectedResult, false);
            }
        }
    }
    if (dialog.isOpen()) {
        dialog.btnCancel().click();
        Waits.shellClosed(dialog);
    }
}
Also used : WidgetNotFoundException(org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException) InputDialog(net.heartsome.cat.ts.test.ui.dialogs.InputDialog) PreferencesDialog(net.heartsome.cat.ts.test.ui.dialogs.PreferencesDialog) IsWidgetTextEquals(net.heartsome.test.swtbot.waits.IsWidgetTextEquals) File(java.io.File) IsWidgetInvisible(net.heartsome.test.swtbot.waits.IsWidgetInvisible)

Example 13 with WidgetNotFoundException

use of org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException in project translationstudio8 by heartsome.

the class ProjectSetting method setTBDB.

/**
	 * 设置术语库
	 * @param from
	 *            功能入口,请使用 TSUIConstants 类提供的常量;
	 * @param nextAction
	 *            下一步操作,请使用本类提供的常量;
	 */
public void setTBDB(Entry from, NextAction nextAction) {
    if (dlgPrjSetting == null) {
        openPrjSettingDlg(from);
    }
    dlgPrjSetting.treiTbSetting().select();
    if (!dlgPrjSetting.table().containsTextInColumn(tBDBName, dlgPrjSetting.tblColName())) {
        if (isTBDBExist) {
            dlgPrjSetting.btnAdd().click();
            DBManagement dbMgmt = new DBManagement(row);
            dbMgmt.selectDB(tBDBName);
        } else {
            dlgPrjSetting.btnCreate().click();
        // TODO 同上
        }
        try {
            InformationDialog dlgInfo = new InformationDialog(InformationDialog.dlgTitleTips, InformationDialog.msgNoMatchInDB);
            dlgInfo.btnOK().click();
            Waits.shellClosed(dlgInfo);
        } catch (WidgetNotFoundException e) {
            e.printStackTrace();
        }
        assertTrue("未正确选择术语库:" + tBDBName, dlgPrjSetting.table().containsTextInColumn(tBDBName, dlgPrjSetting.tblColName()));
    }
    nextAction(nextAction);
}
Also used : WidgetNotFoundException(org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException) InformationDialog(net.heartsome.cat.ts.test.ui.msgdialogs.InformationDialog) DBManagement(net.heartsome.cat.ts.test.basecase.menu.db.DBManagement)

Example 14 with WidgetNotFoundException

use of org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException in project xtext-xtend by eclipse.

the class SwtBotProjectHelper method clearSourceFolderContents.

public static void clearSourceFolderContents(final SWTWorkbenchBot it, final String project) {
    try {
        try {
            SWTBotTree packageExplorerTree = it.tree();
            boolean _hasItems = it.tree().hasItems();
            boolean _not = (!_hasItems);
            if (_not) {
                packageExplorerTree = it.viewByTitle("Package Explorer").bot().tree();
            }
            final SWTBotTreeItem srcNode = SwtBotProjectHelper.expandNode(SwtBotProjectHelper.expandNode(packageExplorerTree, project), "src");
            SWTBotTreeItem[] _items = srcNode.getItems();
            for (final SWTBotTreeItem source : _items) {
                boolean _isDisposed = source.widget.isDisposed();
                boolean _not_1 = (!_isDisposed);
                if (_not_1) {
                    InputOutput.<SWTBotText>println(it.text());
                    srcNode.select(source.getText());
                    source.contextMenu("Delete").click();
                    it.shell("Delete").activate();
                    it.button("OK").click();
                }
            }
        } catch (final Throwable _t) {
            if (_t instanceof WidgetNotFoundException) {
                final Consumer<IResource> _function = (IResource it_1) -> {
                    try {
                        it_1.delete(true, null);
                    } catch (Throwable _e) {
                        throw Exceptions.sneakyThrow(_e);
                    }
                };
                ((List<IResource>) Conversions.doWrapArray(ResourcesPlugin.getWorkspace().getRoot().getProject(project).getFolder("src").members())).forEach(_function);
            } else {
                throw Exceptions.sneakyThrow(_t);
            }
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : WidgetNotFoundException(org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException) Consumer(java.util.function.Consumer) SWTBotTree(org.eclipse.swtbot.swt.finder.widgets.SWTBotTree) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) SWTBotText(org.eclipse.swtbot.swt.finder.widgets.SWTBotText) IResource(org.eclipse.core.resources.IResource)

Example 15 with WidgetNotFoundException

use of org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException in project xtext-xtend by eclipse.

the class SwtBotProjectHelper method newXtendEditor.

public static SWTBotEclipseEditor newXtendEditor(final SWTWorkbenchBot it, final String typeName, final String packageName, final String sourceFolderPath) {
    SWTBotEclipseEditor _xblockexpression = null;
    {
        try {
            SwtBotProjectHelper.fileNew(it, "Xtend Class");
        } catch (final Throwable _t) {
            if (_t instanceof WidgetNotFoundException) {
                final WidgetNotFoundException e = (WidgetNotFoundException) _t;
                final Consumer<SWTBotShell> _function = (SWTBotShell it_1) -> {
                    StringConcatenation _builder = new StringConcatenation();
                    _builder.append("Shell: \'");
                    String _text = it_1.getText();
                    _builder.append(_text);
                    _builder.append("\', active: ");
                    boolean _isActive = it_1.isActive();
                    _builder.append(_isActive);
                    InputOutput.<String>println(_builder.toString());
                };
                ((List<SWTBotShell>) Conversions.doWrapArray(it.shells())).forEach(_function);
                StringConcatenation _builder = new StringConcatenation();
                _builder.append(SWTBotPreferences.SCREENSHOTS_DIR);
                _builder.append("/MenuFileNotFound");
                long _currentTimeMillis = System.currentTimeMillis();
                _builder.append(_currentTimeMillis);
                _builder.append(".");
                _builder.append(SWTBotPreferences.SCREENSHOT_FORMAT);
                final Function1<SWTBotShell, Boolean> _function_1 = (SWTBotShell it_1) -> {
                    return Boolean.valueOf(it_1.isActive());
                };
                SWTUtils.captureScreenshot(_builder.toString(), IterableExtensions.<SWTBotShell>head(IterableExtensions.<SWTBotShell>filter(((Iterable<SWTBotShell>) Conversions.doWrapArray(it.shells())), _function_1)).widget);
                throw e;
            } else {
                throw Exceptions.sneakyThrow(_t);
            }
        }
        it.shell("Xtend Class").activate();
        SWTBotText _textWithLabel = it.textWithLabel("Source folder:");
        _textWithLabel.setText(sourceFolderPath);
        SWTBotText _textWithLabel_1 = it.textWithLabel("Package:");
        _textWithLabel_1.setText(packageName);
        SWTBotText _textWithLabel_2 = it.textWithLabel("Name:");
        _textWithLabel_2.setText(typeName);
        it.button("Finish").click();
        _xblockexpression = it.editorByTitle((typeName + ".xtend")).toTextEditor();
    }
    return _xblockexpression;
}
Also used : WidgetNotFoundException(org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException) SWTBotEclipseEditor(org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEclipseEditor) SWTBotText(org.eclipse.swtbot.swt.finder.widgets.SWTBotText) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) List(java.util.List) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell)

Aggregations

WidgetNotFoundException (org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException)24 SWTWorkbenchBot (org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot)12 BeforeClass (org.junit.BeforeClass)12 SWTBotShell (org.eclipse.swtbot.swt.finder.widgets.SWTBotShell)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 TestCreaterepoProject (org.eclipse.linuxtools.internal.rpm.createrepo.form.tests.TestCreaterepoProject)3 DBManagement (net.heartsome.cat.ts.test.basecase.menu.db.DBManagement)2 InformationDialog (net.heartsome.cat.ts.test.ui.msgdialogs.InformationDialog)2 IWorkspace (org.eclipse.core.resources.IWorkspace)2 IWorkspaceDescription (org.eclipse.core.resources.IWorkspaceDescription)2 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)2 SWTBotText (org.eclipse.swtbot.swt.finder.widgets.SWTBotText)2 After (org.junit.After)2 File (java.io.File)1 List (java.util.List)1 Consumer (java.util.function.Consumer)1 InputDialog (net.heartsome.cat.ts.test.ui.dialogs.InputDialog)1 PreTranslateResultDialog (net.heartsome.cat.ts.test.ui.dialogs.PreTranslateResultDialog)1 PreferencesDialog (net.heartsome.cat.ts.test.ui.dialogs.PreferencesDialog)1 IsWidgetInvisible (net.heartsome.test.swtbot.waits.IsWidgetInvisible)1