1

I am writing automated testing using swtBot in eclipse Juno Service Release 2.Below My code

@BeforeClass
public static void beforeClass() {
    SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
    bot = new SWTWorkbenchBot();
    try {
        bot.viewByTitle("Welcome").close();
    } catch (WidgetNotFoundException e) {
        // ignore
    }
    bot.menu("Window").menu("Preferences").click();
    SWTBotShell shell = bot.shell("Preferences");
    shell.activate();
    SWTBotView view = bot.viewByTitle("Preferences");

    bot.tree().expandNode("General").select("Workspace");
    SWTBotCheckBox buildAuto = bot.checkBox("Build automatically");
    if (buildAuto != null && buildAuto.isChecked())
        buildAuto.click();
    bot.button("Apply").click();
    bot.tree().expandNode("General").select("Perspectives");
    SWTBotRadio radio = bot.radio("Always open");
    if (radio != null && !radio.isSelected())
        radio.click();
    bot.button("OK").click();
}

I am getting following exception:

org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException: Could not find shell matching: with text 'Preferences' at org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntilWidgetAppears(SWTBotFactory.java:387) at org.eclipse.swtbot.swt.finder.SWTBotFactory.shells(SWTBotFactory.java:114) at org.eclipse.swtbot.swt.finder.SWTBotFactory.shell(SWTBotFactory.java:104) at org.eclipse.swtbot.swt.finder.SWTBotFactory.shell(SWTBotFactory.java:95) at com.packtpub.e4.junit.plugin.UITest.beforeClass(UITest.java:49) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source)

ArK
  • 20,698
  • 67
  • 109
  • 136

1 Answers1

1

Don't put your test code in the method annotated with @BeforeClass. At this point the test class isn't even instantiated. Cf. this answer here for an explanation of the annotations.

If you have moved the relevant code to a @Test annotated method and the code still doesn't work, check spelling, etc.

Community
  • 1
  • 1
s.d
  • 4,017
  • 5
  • 35
  • 65