Skip to main content



      Home
Home » Eclipse Projects » SWTBot » example for modifying a preference setting
example for modifying a preference setting [message #389399] Wed, 29 July 2009 20:33 Go to next message
Eclipse UserFriend
I've run your webcast swtbot example sucessfully, and have looked at your
other current examples, but I'm having difficulty applying those to a more
complicated case.

I'd like to uncheck a checkbox in the Preference Settings in the Advanced
Capabilities Settings using the swtbot playback. This would have to
select Window->Preferences, then go to the Preferences shell and select
tree node General->Capabilities, then click button Advanced... in the
Capabilities panel, then switch to the Advanced Capabilities Settings
shell and select the Development->Java Development node in that tree, and
then uncheck its associated checkbox. Is this possible with swtbot?

I've tried several versions of code and, amazingly enough, this gets down
to the bot.checkbox().isChecked() test before it fails. Do you have some
way of selecting that checkbox that is associated with the tree node? I
was assuming that the node being selected would provide the context for
the bot at that point.

// bot is SWTWorkbenchBot
bot.menu("Window").menu("Preferences").click();
SWTBotShell prefsShell = bot.shell("Preferences");
prefsShell.activate();
// now bot is acting on prefsShell?
SWTBotTreeItem treeItem =
bot.tree().getTreeItem("General").select().expand().click();
SWTBotTreeItem treeNode =
treeItem.getNode("Capabilities").select().expand().click();

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

SWTBotShell advancedCapabilitiesShell = bot.shell("Advanced Capabilities
Settings");
advancedCapabilitiesShell.activate();
// now General->Capabilities->Advanced Capabilities Settings should be
open
SWTBotTreeItem devItem =
bot.tree().getTreeItem("Development").select().expand().click();
SWTBotTreeItem javaNode = devItem.getNode("Java
Development").select().expand().click();

if (bot.checkBox().isChecked()){
bot.checkBox().click();
}
bot.button("OK").click();
prefsShell.activate();
bot.button("OK").click();
Re: example for modifying a preference setting [message #403549 is a reply to message #389399] Thu, 30 July 2009 01:28 Go to previous messageGo to next message
Eclipse UserFriend
On 30/7/09 06:03, Jay Norwood wrote:
>
> I'd like to uncheck a checkbox in the Preference Settings in the
> Advanced Capabilities Settings using the swtbot playback. This would
> have to select Window->Preferences, then go to the Preferences shell and
> select tree node General->Capabilities, then click button Advanced... in
> the Capabilities panel, then switch to the Advanced Capabilities
> Settings shell and select the Development->Java Development node in that
> tree, and then uncheck its associated checkbox. Is this possible with
> swtbot?

Yes :)

> I've tried several versions of code and, amazingly enough, this gets
> down to the bot.checkbox().isChecked() test before it fails. Do you
> have some way of selecting that checkbox that is associated with the
> tree node? I was assuming that the node being selected would provide
> the context for the bot at that point

A checkbox is different from a checkbox in a tree. You need to use
SWTBotTreeItem#click and SWTBotTreeItem#isChecked instead
SWTBotCheckbox#click and SWTBotCheckbox#isChecked

--
Ketan
http://studios.thoughtworks.com/twist | http://twitter.com/ketanpkr
Re: example for modifying a preference setting [message #404037 is a reply to message #403549] Thu, 30 July 2009 01:47 Go to previous messageGo to next message
Eclipse UserFriend
Yeah, thanks for the reply. I had just solved the problem and my solution
that runs without error is below. I also fixed the couple of statements
after that. I'm still foggy on how the context is seemingly updated for
the bot, and it also isn't clear to me which of select(), expand(),
click() are really needed.

bot.menu("Window").menu("Preferences").click();
SWTBotShell prefsShell = bot.shell("Preferences");
prefsShell.activate();
// now bot is acting on prefsShell?
SWTBotTreeItem treeItem =
bot.tree().getTreeItem("General").select().expand().click();
SWTBotTreeItem treeNode =
treeItem.getNode("Capabilities").select().expand().click();

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

SWTBotShell advancedCapabilitiesShell = bot.shell("Advanced Capabilities
Settings");
advancedCapabilitiesShell.activate();
// now General->Capabilities->Advanced Capabilities Settings should be
open
SWTBotTreeItem devItem =
bot.tree().getTreeItem("Development").select().expand().click();
SWTBotTreeItem javaNode = devItem.getNode("Java
Development").select().expand().click();

boolean checked = javaNode.isChecked();
if (checked){
javaNode.toggleCheck();
}
bot.button("OK").click();
bot.waitUntil(shellCloses(advancedCapabilitiesShell));

prefsShell.activate();
bot.button("OK").click();
bot.waitUntil(shellCloses(prefsShell));
Re: example for modifying a preference setting [message #406324 is a reply to message #404037] Thu, 30 July 2009 02:26 Go to previous messageGo to next message
Eclipse UserFriend
I also see there are
SWTBotTreeItem.check(), SWTBotTreeItem.uncheck(), so I don't have to use
the toggle in that code.
Re: example for modifying a preference setting [message #406325 is a reply to message #403549] Thu, 30 July 2009 02:29 Go to previous messageGo to next message
Eclipse UserFriend
It isn't clear to me from the code that SWTBotTreeItem.click() is intended
to do anything to the checkbox, and in my testing it didn't alter the
checkbox, but SWTBotTreeItem.check() and SWTBotTreeItem.uncheck() worked
fine.
Re: example for modifying a preference setting [message #411694 is a reply to message #404037] Thu, 30 July 2009 04:39 Go to previous message
Eclipse UserFriend
On 30/7/09 11:17, Jay Norwood wrote:
> I'm still foggy on how the context is seemingly
> updated for the bot

There is no context, you always tell it what to find by passing in a
matcher. Look at the SWTBot for how that works.

, and it also isn't clear to me which of select(),
> expand(), click() are really needed.

These depend on the context of what widget you're working with. Select
selects a tree node, and returns the same node. Expand and click do similar.

The reason the nodes return itself is so you can chain them together:

tree.expand("MyProject").expand("src").select("MyClass.java ") seems more
natural than:

p = tree.get("MyProject")
p.expand();
s = p.get("src")
s.expand();
....
a few more lines
....

--
Ketan
http://studios.thoughtworks.com/twist | http://twitter.com/ketanpkr
Previous Topic:Cannot automate login
Next Topic:cannot find plugin error when running headless ant
Goto Forum:
  


Current Time: Mon Jun 23 08:22:27 EDT 2025

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

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

Back to the top