Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » clearing the workspace in @AfterClass
clearing the workspace in @AfterClass [message #704000] Thu, 28 July 2011 07:08 Go to next message
Lorenzo Bettini is currently offline Lorenzo Bettini
Messages: 1349
Registered: July 2009
Senior Member
Hi

I've just started using SWTBOT; I tried with the example
http://wiki.eclipse.org/SWTBot/UsersGuide which creates a new project

protected void createSimpleProject() {
bot.menu("File").menu("New").menu("Project...").click();

SWTBotShell shell = bot.shell("New Project");
shell.activate();
bot.tree().expandNode("General").select("Project");
bot.button("Next >").click();

bot.textWithLabel("Project name:").setText(MY_TEST_PROJECT);

bot.button("Finish").click();

waitForAutoBuild();
}

after creating the project I'm waiting for the autobuild to finish with
this code

public static void waitForAutoBuild() {
boolean wasInterrupted = false;
do {
try {
Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD,
null);
wasInterrupted = false;
} catch (OperationCanceledException e) {
e.printStackTrace();
} catch (InterruptedException e) {
wasInterrupted = true;
}
} while (wasInterrupted);
}

then, I'd like to clear the whole workspace before the next test, then I
wrote

@AfterClass
public static void clean() throws CoreException {
cleanWorkspace();
bot.sleep(2000);
}

where cleanWorkspace programmatically deletes all the projects in the
workspace.

However, when the second test is executed (for this example I simply
create another project), I get an exception saying that (I guess) the
menu cannot be found

Caused by: org.eclipse.swt.SWTException: Widget is disposed
at org.eclipse.swt.SWT.error(SWT.java:4282)
at org.eclipse.swt.SWT.error(SWT.java:4197)
at org.eclipse.swt.SWT.error(SWT.java:4168)
at org.eclipse.swt.widgets.Widget.error(Widget.java:466)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:403)
at org.eclipse.swt.widgets.Decorations.getMenuBar(Decorations.java:392)
at
org.eclipse.swtbot.swt.finder.finders.MenuFinder$1.run(MenuFinder.java:106)
at
org.eclipse.swtbot.swt.finder.finders.MenuFinder$1.run(MenuFinder.java:1)
at
org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable$2.doRun(UIThreadRunnable.java:140)
at
org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable$1.run(UIThreadRunnable.java:89)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at
org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
... 24 more

am I doing something wrong? Should I clear the workspace using the bot
somehow?

I saw that SWTWorkbenchBot provides resetWorkbench but this does not
seem to remove the projects in the workspace...

thanks in advance
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
Re: clearing the workspace in @AfterClass [message #704017 is a reply to message #704000] Thu, 28 July 2011 07:16 Go to previous message
Lorenzo Bettini is currently offline Lorenzo Bettini
Messages: 1349
Registered: July 2009
Senior Member
Sorry for the noise: since I'm new to Junit4 as well, I wasn't thinking
that @AfterClass does *not* correspond to tearDown (and indeed it's a
static method)!

using

@After
public void runAfterEveryTest() throws CoreException {
cleanWorkspace();
}

fixes the problem :)

cheers
Lorenzo

On 07/28/2011 09:08 AM, Lorenzo Bettini wrote:
> Hi
>
> I've just started using SWTBOT; I tried with the example
> http://wiki.eclipse.org/SWTBot/UsersGuide which creates a new project
>
> protected void createSimpleProject() {
> bot.menu("File").menu("New").menu("Project...").click();
>
> SWTBotShell shell = bot.shell("New Project");
> shell.activate();
> bot.tree().expandNode("General").select("Project");
> bot.button("Next >").click();
>
> bot.textWithLabel("Project name:").setText(MY_TEST_PROJECT);
>
> bot.button("Finish").click();
>
> waitForAutoBuild();
> }
>
> after creating the project I'm waiting for the autobuild to finish with
> this code
>
> public static void waitForAutoBuild() {
> boolean wasInterrupted = false;
> do {
> try {
> Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD,
> null);
> wasInterrupted = false;
> } catch (OperationCanceledException e) {
> e.printStackTrace();
> } catch (InterruptedException e) {
> wasInterrupted = true;
> }
> } while (wasInterrupted);
> }
>
> then, I'd like to clear the whole workspace before the next test, then I
> wrote
>
> @AfterClass
> public static void clean() throws CoreException {
> cleanWorkspace();
> bot.sleep(2000);
> }
>
> where cleanWorkspace programmatically deletes all the projects in the
> workspace.
>
> However, when the second test is executed (for this example I simply
> create another project), I get an exception saying that (I guess) the
> menu cannot be found
>
> Caused by: org.eclipse.swt.SWTException: Widget is disposed
> at org.eclipse.swt.SWT.error(SWT.java:4282)
> at org.eclipse.swt.SWT.error(SWT.java:4197)
> at org.eclipse.swt.SWT.error(SWT.java:4168)
> at org.eclipse.swt.widgets.Widget.error(Widget.java:466)
> at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:403)
> at org.eclipse.swt.widgets.Decorations.getMenuBar(Decorations.java:392)
> at
> org.eclipse.swtbot.swt.finder.finders.MenuFinder$1.run(MenuFinder.java:106)
> at
> org.eclipse.swtbot.swt.finder.finders.MenuFinder$1.run(MenuFinder.java:1)
> at
> org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable$2.doRun(UIThreadRunnable.java:140)
>
> at
> org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable$1.run(UIThreadRunnable.java:89)
>
> at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
> at
> org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
>
> ... 24 more
>
> am I doing something wrong? Should I clear the workspace using the bot
> somehow?
>
> I saw that SWTWorkbenchBot provides resetWorkbench but this does not
> seem to remove the projects in the workspace...
>
> thanks in advance
> Lorenzo
>


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net
Previous Topic:Click on editor with swtbot
Next Topic:Want to access CommandContributionItem through SWTBot
Goto Forum:
  


Current Time: Mon Sep 15 02:09:16 GMT 2014

Powered by FUDForum. Page generated in 0.03526 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software