Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 19:54 Go to next message
Joe Luebker is currently offline Joe LuebkerFriend
Messages: 36
Registered: July 2009
Member
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 20:12 Go to previous messageGo to next message
Chris Aniszczyk is currently offline Chris AniszczykFriend
Messages: 674
Registered: July 2009
Senior Member
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 21:07 Go to previous messageGo to next message
Joe Luebker is currently offline Joe LuebkerFriend
Messages: 36
Registered: July 2009
Member
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 23:18 Go to previous messageGo to next message
David Green is currently offline David GreenFriend
Messages: 135
Registered: July 2009
Senior Member
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 07:30 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
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 07:36 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
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 07:43 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
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 22:01 Go to previous messageGo to next message
David Green is currently offline David GreenFriend
Messages: 135
Registered: July 2009
Senior Member
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 16:14 Go to previous messageGo to next message
Joe Luebker is currently offline Joe LuebkerFriend
Messages: 36
Registered: July 2009
Member
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 16:47 Go to previous messageGo to next message
Ketan Padegaonkar is currently offline Ketan PadegaonkarFriend
Messages: 873
Registered: July 2009
Senior Member
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 22:10 Go to previous message
Joe Luebker is currently offline Joe LuebkerFriend
Messages: 36
Registered: July 2009
Member
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: Thu Dec 18 13:47:23 GMT 2014

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

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