Skip to main content



      Home
Home » Eclipse Projects » SWTBot » An example of opening an Eclipse perspective using SWTBot
An example of opening an Eclipse perspective using SWTBot [message #13002] Fri, 09 January 2009 14:54 Go to next message
Eclipse UserFriend
Hello,

I just went through a trial an error session trying to figure out how I
could manipulate the Eclipse UI with SWTBot to open a perspective. Below
is a simple example of how to open the "Debug" perspective. I thought it
may be useful to others that may be getting started with creating tests
for Eclipse based products with SWTBot.

// Change the perspective via the Open Perspective dialog
bot.menu("Window").menu("Open Perspective").menu("Other...").click();
SWTBotShell openPerspectiveShell = bot.shell("Open Perspective");

SWTBotTable table = new SWTBotTable((Table)
bot.widget(widgetOfType(Table.class), openPerspectiveShell.widget));
table.select("Debug");

SWTBotButton OkButton = new SWTBotButton((Button)
bot.widget(widgetOfType(Button.class), openPerspectiveShell.widget));
OkButton.click();

I think it would be very useful to other test developers trying to use
SWTBot to test part various pieces of their Eclipse product if some
tutorials/guides were created that showed some real world examples.

Thanks,
Joe
Re: An example of opening an Eclipse perspective using SWTBot [message #13033 is a reply to message #13002] Fri, 09 January 2009 15:12 Go to previous messageGo to next message
Eclipse UserFriend
Joe Luebker wrote:
> Hello,
>
> I just went through a trial an error session trying to figure out how I
> could manipulate the Eclipse UI with SWTBot to open a perspective. Below
> is a simple example of how to open the "Debug" perspective. I thought it
> may be useful to others that may be getting started with creating tests
> for Eclipse based products with SWTBot.
>
> // Change the perspective via the Open Perspective dialog
> bot.menu("Window").menu("Open Perspective").menu("Other...").click();
> SWTBotShell openPerspectiveShell = bot.shell("Open Perspective");
>
> SWTBotTable table = new SWTBotTable((Table)
> bot.widget(widgetOfType(Table.class), openPerspectiveShell.widget));
> table.select("Debug");
>
> SWTBotButton OkButton = new SWTBotButton((Button)
> bot.widget(widgetOfType(Button.class), openPerspectiveShell.widget));
> OkButton.click();
>
> I think it would be very useful to other test developers trying to use
> SWTBot to test part various pieces of their Eclipse product if some
> tutorials/guides were created that showed some real world examples.

Thanks Joe. I plan to discuss SWTBot in the upcoming 2nd edition of the
RCP Book. There will be a chapter about UI Testing and includes
discussion about SWTBot.

Cheers,

~ Chris
Re: An example of opening an Eclipse perspective using SWTBot [message #13091 is a reply to message #13033] Fri, 09 January 2009 16:07 Go to previous messageGo to next message
Eclipse UserFriend
Thanks Chris. Please post a message when the book is ready. Any idea as
to when you think the book will be published?

- Joe

Chris Aniszczyk wrote:
> Joe Luebker wrote:
>> Hello,
>>
>> I just went through a trial an error session trying to figure out how
>> I could manipulate the Eclipse UI with SWTBot to open a perspective.
>> Below is a simple example of how to open the "Debug" perspective. I
>> thought it may be useful to others that may be getting started with
>> creating tests for Eclipse based products with SWTBot.
>>
>> // Change the perspective via the Open Perspective dialog
>> bot.menu("Window").menu("Open Perspective").menu("Other...").click();
>> SWTBotShell openPerspectiveShell = bot.shell("Open Perspective");
>> SWTBotTable table = new SWTBotTable((Table)
>> bot.widget(widgetOfType(Table.class), openPerspectiveShell.widget));
>> table.select("Debug");
>> SWTBotButton OkButton = new SWTBotButton((Button)
>> bot.widget(widgetOfType(Button.class), openPerspectiveShell.widget));
>> OkButton.click();
>>
>> I think it would be very useful to other test developers trying to use
>> SWTBot to test part various pieces of their Eclipse product if some
>> tutorials/guides were created that showed some real world examples.
>
> Thanks Joe. I plan to discuss SWTBot in the upcoming 2nd edition of the
> RCP Book. There will be a chapter about UI Testing and includes
> discussion about SWTBot.
>
> Cheers,
>
> ~ Chris
Re: An example of opening an Eclipse perspective using SWTBot [message #13119 is a reply to message #13002] Fri, 09 January 2009 18:18 Go to previous messageGo to next message
Eclipse UserFriend
Joe Luebker wrote:
> I think it would be very useful to other test developers trying to use
> SWTBot to test part various pieces of their Eclipse product if some
> tutorials/guides were created that showed some real world examples.
>
> Thanks,
> Joe

Joe,

Thanks for the tip! You're right that propagating this type of
information would be extremely useful. Perhaps an area on the SWTBot
wiki (http://wiki.eclipse.org/SWTBot) would be appropriate?

To me even more useful than documentation would be a DSL specific to
Eclipse. Something like this:

EclipseIDE.workbench().switchPerspective("Debug")

In fact, that is something that we've done. Other DSLs would be useful
too, for manipulating things like the Package Explorer, Problems view,
etc. These DSLs might have different incarnations depending on
differences in versions of the Eclipse UI.

You can read more about how we use DSLs with SWTBot in my blog:
http://greensopinion.blogspot.com/2008/09/eclipse-gui-testin g-is-viable-with.html

Regards,

David
Re: An example of opening an Eclipse perspective using SWTBot [message #13177 is a reply to message #13002] Sat, 10 January 2009 02:30 Go to previous messageGo to next message
Eclipse UserFriend
Hi Joe,

Snippets like these would be really useful for everyone. Thanks for
sharing this tip.

I've created a snippets page on the wiki as recommended by David, and
posted your snippet there.

It also probably makes sense to start off a community project that can
contain such common convenience API that's useful for others. So in this
case you could do something like:

eclipse.openPerspective("Problems View")

instead of having to type this code this all over the place.

-- Ketan

On 10/1/09 01:24, Joe Luebker wrote:
> Hello,
>
> I just went through a trial an error session trying to figure out how I
> could manipulate the Eclipse UI with SWTBot to open a perspective. Below
> is a simple example of how to open the "Debug" perspective. I thought it
> may be useful to others that may be getting started with creating tests
> for Eclipse based products with SWTBot.
>
> // Change the perspective via the Open Perspective dialog
> bot.menu("Window").menu("Open Perspective").menu("Other...").click();
> SWTBotShell openPerspectiveShell = bot.shell("Open Perspective");
>
> SWTBotTable table = new SWTBotTable((Table)
> bot.widget(widgetOfType(Table.class), openPerspectiveShell.widget));
> table.select("Debug");
>
> SWTBotButton OkButton = new SWTBotButton((Button)
> bot.widget(widgetOfType(Button.class), openPerspectiveShell.widget));
> OkButton.click();
>
> I think it would be very useful to other test developers trying to use
> SWTBot to test part various pieces of their Eclipse product if some
> tutorials/guides were created that showed some real world examples.
>
> Thanks,
> Joe
Re: An example of opening an Eclipse perspective using SWTBot [message #13204 is a reply to message #13177] Sat, 10 January 2009 02:36 Go to previous messageGo to next message
Eclipse UserFriend
Forgot to share the link: http://wiki.eclipse.org/SWTBot/Snippets

-- Ketan

On 10/1/09 13:00, Ketan Padegaonkar wrote:
> Hi Joe,
>
> Snippets like these would be really useful for everyone. Thanks for
> sharing this tip.
>
> I've created a snippets page on the wiki as recommended by David, and
> posted your snippet there.
>
> It also probably makes sense to start off a community project that can
> contain such common convenience API that's useful for others. So in this
> case you could do something like:
>
> eclipse.openPerspective("Problems View")
>
> instead of having to type this code this all over the place.
>
> -- Ketan
>
> On 10/1/09 01:24, Joe Luebker wrote:
>> Hello,
>>
>> I just went through a trial an error session trying to figure out how I
>> could manipulate the Eclipse UI with SWTBot to open a perspective. Below
>> is a simple example of how to open the "Debug" perspective. I thought it
>> may be useful to others that may be getting started with creating tests
>> for Eclipse based products with SWTBot.
>>
>> // Change the perspective via the Open Perspective dialog
>> bot.menu("Window").menu("Open Perspective").menu("Other...").click();
>> SWTBotShell openPerspectiveShell = bot.shell("Open Perspective");
>>
>> SWTBotTable table = new SWTBotTable((Table)
>> bot.widget(widgetOfType(Table.class), openPerspectiveShell.widget));
>> table.select("Debug");
>>
>> SWTBotButton OkButton = new SWTBotButton((Button)
>> bot.widget(widgetOfType(Button.class), openPerspectiveShell.widget));
>> OkButton.click();
>>
>> I think it would be very useful to other test developers trying to use
>> SWTBot to test part various pieces of their Eclipse product if some
>> tutorials/guides were created that showed some real world examples.
>>
>> Thanks,
>> Joe
>
Re: An example of opening an Eclipse perspective using SWTBot [message #13231 is a reply to message #13002] Sat, 10 January 2009 02:43 Go to previous messageGo to next message
Eclipse UserFriend
Also realized that you wrote a bit too much of code, you should never
have to do a bot.widget, unless it's finding a widget that SWTBot does
not support, or using a matcher that SWTBot does not have.

// Change the perspective via the Open Perspective dialog
bot.menu("Window").menu("Open Perspective").menu("Other...").click();
SWTBotShell openPerspectiveShell = bot.shell("Open Perspective");
openPerspectiveShell.activate();

bot.table().select("Debug");
bot.button("OK").click();

-- Ketan

On 10/1/09 01:24, Joe Luebker wrote:
> Hello,
>
> I just went through a trial an error session trying to figure out how I
> could manipulate the Eclipse UI with SWTBot to open a perspective. Below
> is a simple example of how to open the "Debug" perspective. I thought it
> may be useful to others that may be getting started with creating tests
> for Eclipse based products with SWTBot.
>
> // Change the perspective via the Open Perspective dialog
> bot.menu("Window").menu("Open Perspective").menu("Other...").click();
> SWTBotShell openPerspectiveShell = bot.shell("Open Perspective");
>
> SWTBotTable table = new SWTBotTable((Table)
> bot.widget(widgetOfType(Table.class), openPerspectiveShell.widget));
> table.select("Debug");
>
> SWTBotButton OkButton = new SWTBotButton((Button)
> bot.widget(widgetOfType(Button.class), openPerspectiveShell.widget));
> OkButton.click();
>
> I think it would be very useful to other test developers trying to use
> SWTBot to test part various pieces of their Eclipse product if some
> tutorials/guides were created that showed some real world examples.
>
> Thanks,
> Joe
Re: An example of opening an Eclipse perspective using SWTBot [message #13316 is a reply to message #13119] Sat, 10 January 2009 17:01 Go to previous messageGo to next message
Eclipse UserFriend
David Green wrote:
> To me even more useful than documentation would be a DSL specific to
> Eclipse. Something like this:
>
> EclipseIDE.workbench().switchPerspective("Debug")
>


I've posted 260623 with an attachment. It's a start for a DSL which I
wrote, with some basics.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=260623
Re: An example of opening an Eclipse perspective using SWTBot [message #14084 is a reply to message #13231] Tue, 13 January 2009 11:14 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for the tip, that results in a cleaner looking test.

Joe

Ketan Padegaonkar wrote:
> Also realized that you wrote a bit too much of code, you should never
> have to do a bot.widget, unless it's finding a widget that SWTBot does
> not support, or using a matcher that SWTBot does not have.
>
> // Change the perspective via the Open Perspective dialog
> bot.menu("Window").menu("Open Perspective").menu("Other...").click();
> SWTBotShell openPerspectiveShell = bot.shell("Open Perspective");
> openPerspectiveShell.activate();
>
> bot.table().select("Debug");
> bot.button("OK").click();
>
> -- Ketan
>
> On 10/1/09 01:24, Joe Luebker wrote:
>> Hello,
>>
>> I just went through a trial an error session trying to figure out how I
>> could manipulate the Eclipse UI with SWTBot to open a perspective. Below
>> is a simple example of how to open the "Debug" perspective. I thought it
>> may be useful to others that may be getting started with creating tests
>> for Eclipse based products with SWTBot.
>>
>> // Change the perspective via the Open Perspective dialog
>> bot.menu("Window").menu("Open Perspective").menu("Other...").click();
>> SWTBotShell openPerspectiveShell = bot.shell("Open Perspective");
>>
>> SWTBotTable table = new SWTBotTable((Table)
>> bot.widget(widgetOfType(Table.class), openPerspectiveShell.widget));
>> table.select("Debug");
>>
>> SWTBotButton OkButton = new SWTBotButton((Button)
>> bot.widget(widgetOfType(Button.class), openPerspectiveShell.widget));
>> OkButton.click();
>>
>> I think it would be very useful to other test developers trying to use
>> SWTBot to test part various pieces of their Eclipse product if some
>> tutorials/guides were created that showed some real world examples.
>>
>> Thanks,
>> Joe
>
Re: An example of opening an Eclipse perspective using SWTBot [message #14101 is a reply to message #14084] Tue, 13 January 2009 11:47 Go to previous messageGo to next message
Eclipse UserFriend
You may be interested in the patch that David filed
(https://bugs.eclipse.org/bugs/show_bug.cgi?id=260623)

It will make your code a one liner:

Eclipse.workbench().switchToPerspective("Debug");

Expect this api to evolve and stabilize over a few weeks, and any inputs
are always welcome.

-- Ketan


On 13/1/09 21:44, Joe Luebker wrote:
> Thanks for the tip, that results in a cleaner looking test.
>
> Joe
>
> Ketan Padegaonkar wrote:
>> Also realized that you wrote a bit too much of code, you should never
>> have to do a bot.widget, unless it's finding a widget that SWTBot does
>> not support, or using a matcher that SWTBot does not have.
>>
>> // Change the perspective via the Open Perspective dialog
>> bot.menu("Window").menu("Open Perspective").menu("Other...").click();
>> SWTBotShell openPerspectiveShell = bot.shell("Open Perspective");
>> openPerspectiveShell.activate();
>>
>> bot.table().select("Debug");
>> bot.button("OK").click();
>>
>> -- Ketan
>>
>> On 10/1/09 01:24, Joe Luebker wrote:
>>> Hello,
>>>
>>> I just went through a trial an error session trying to figure out how I
>>> could manipulate the Eclipse UI with SWTBot to open a perspective. Below
>>> is a simple example of how to open the "Debug" perspective. I thought it
>>> may be useful to others that may be getting started with creating tests
>>> for Eclipse based products with SWTBot.
>>>
>>> // Change the perspective via the Open Perspective dialog
>>> bot.menu("Window").menu("Open Perspective").menu("Other...").click();
>>> SWTBotShell openPerspectiveShell = bot.shell("Open Perspective");
>>>
>>> SWTBotTable table = new SWTBotTable((Table)
>>> bot.widget(widgetOfType(Table.class), openPerspectiveShell.widget));
>>> table.select("Debug");
>>>
>>> SWTBotButton OkButton = new SWTBotButton((Button)
>>> bot.widget(widgetOfType(Button.class), openPerspectiveShell.widget));
>>> OkButton.click();
>>>
>>> I think it would be very useful to other test developers trying to use
>>> SWTBot to test part various pieces of their Eclipse product if some
>>> tutorials/guides were created that showed some real world examples.
>>>
>>> Thanks,
>>> Joe
>>
Re: An example of opening an Eclipse perspective using SWTBot [message #14135 is a reply to message #14101] Tue, 13 January 2009 17:10 Go to previous message
Eclipse UserFriend
Very nice. I created a utility class in my development project to do
just that. I can switch to using the convenience APIs added as a fix for
that bug once they are complete. Looks like the bug is fairly active and
the changes will be quite large. Maybe once the work is complete a
summary of the added APIs should be posted somewhere since they should
make it even easier to create tests for Eclipse based projects.

Joe

Ketan Padegaonkar wrote:
> You may be interested in the patch that David filed
> (https://bugs.eclipse.org/bugs/show_bug.cgi?id=260623)
>
> It will make your code a one liner:
>
> Eclipse.workbench().switchToPerspective("Debug");
>
> Expect this api to evolve and stabilize over a few weeks, and any inputs
> are always welcome.
>
> -- Ketan
>
>
> On 13/1/09 21:44, Joe Luebker wrote:
>> Thanks for the tip, that results in a cleaner looking test.
>>
>> Joe
>>
>> Ketan Padegaonkar wrote:
>>> Also realized that you wrote a bit too much of code, you should never
>>> have to do a bot.widget, unless it's finding a widget that SWTBot does
>>> not support, or using a matcher that SWTBot does not have.
>>>
>>> // Change the perspective via the Open Perspective dialog
>>> bot.menu("Window").menu("Open Perspective").menu("Other...").click();
>>> SWTBotShell openPerspectiveShell = bot.shell("Open Perspective");
>>> openPerspectiveShell.activate();
>>>
>>> bot.table().select("Debug");
>>> bot.button("OK").click();
>>>
>>> -- Ketan
>>>
>>> On 10/1/09 01:24, Joe Luebker wrote:
>>>> Hello,
>>>>
>>>> I just went through a trial an error session trying to figure out how I
>>>> could manipulate the Eclipse UI with SWTBot to open a perspective.
>>>> Below
>>>> is a simple example of how to open the "Debug" perspective. I
>>>> thought it
>>>> may be useful to others that may be getting started with creating tests
>>>> for Eclipse based products with SWTBot.
>>>>
>>>> // Change the perspective via the Open Perspective dialog
>>>> bot.menu("Window").menu("Open Perspective").menu("Other...").click();
>>>> SWTBotShell openPerspectiveShell = bot.shell("Open Perspective");
>>>>
>>>> SWTBotTable table = new SWTBotTable((Table)
>>>> bot.widget(widgetOfType(Table.class), openPerspectiveShell.widget));
>>>> table.select("Debug");
>>>>
>>>> SWTBotButton OkButton = new SWTBotButton((Button)
>>>> bot.widget(widgetOfType(Button.class), openPerspectiveShell.widget));
>>>> OkButton.click();
>>>>
>>>> I think it would be very useful to other test developers trying to use
>>>> SWTBot to test part various pieces of their Eclipse product if some
>>>> tutorials/guides were created that showed some real world examples.
>>>>
>>>> Thanks,
>>>> Joe
>>>
>
Previous Topic:How to show an Eclipse view that hasn't been shown previously?
Next Topic:GEF and SWTBot
Goto Forum:
  


Current Time: Wed Apr 30 16:34:06 EDT 2025

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

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

Back to the top