Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » SWTBot » Help in SWTBot(How to test an existing Eclipse based Java application)
Help in SWTBot [message #501186] Tue, 01 December 2009 13:22 Go to next message
Devendra  is currently offline Devendra Friend
Messages: 7
Registered: December 2009
Junior Member
HI All,

I'm new to start with SWTBot. I have installed eclipse 3.4 and SWTBot 2.0. I have never used it before. I have to test one Java based GUI application. Please let me know how to start(how to open this application and test it).

Please let me know the way to test it.
Re: Help in SWTBot [message #501214 is a reply to message #501186] Tue, 01 December 2009 14:34 Go to previous messageGo to next message
Pascal G is currently offline Pascal GFriend
Messages: 157
Registered: July 2009
Senior Member
Devendra wrote:
> HI All,
>
> I'm new to start with SWTBot. I have installed eclipse 3.4 and SWTBot
> 2.0. I have never used it before. I have to test one Java based GUI
> application. Please let me know how to start(how to open this
> application and test it).
>
> Please let me know the way to test it.

The following screencast is a very good starting point:
http://download.eclipse.org/technology/swtbot/docs/videos/be ginners/SWTBotGettingStartedIn5Minutes/

There is also some information on how to get started with the User
Guide[1] on the project website[2].

SWTBot uses JUnit as its base framework. If you don't know about JUnit,
you should start looking on their Getting Started[3].

Hope this helps.

[1] http://wiki.eclipse.org/SWTBot/UsersGuide
[2] http://www.eclipse.org/swtbot/
[3] http://junit.sourceforge.net/#Getting
--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Re: Help in SWTBot [message #501278 is a reply to message #501214] Tue, 01 December 2009 18:02 Go to previous messageGo to next message
Devendra  is currently offline Devendra Friend
Messages: 7
Registered: December 2009
Junior Member
Hi Pascal,

Thnx for a quick response.
But my problem is how to test some existing Java application. I have gone through these links, here examples are given how to create new applications in eclipse. As far as I understood here is that its a kind of testing of Eclipse IDE itself. In the same way I want to test an existing Java application. Plz let me know how to open that application and test it by script or recorder.
Re: Help in SWTBot [message #501291 is a reply to message #501278] Tue, 01 December 2009 18:33 Go to previous messageGo to next message
Pascal G is currently offline Pascal GFriend
Messages: 157
Registered: July 2009
Senior Member
Devendra wrote:
> Thnx for a quick response. But my problem is how to test some existing
> Java application.

By Java application, you mean an Eclipse plug-in? An RCP application? Or
just a plain SWT application?

--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Re: Help in SWTBot [message #501322 is a reply to message #501291] Tue, 01 December 2009 20:38 Go to previous messageGo to next message
Devendra  is currently offline Devendra Friend
Messages: 7
Registered: December 2009
Junior Member
Hi,
not very familier with these words, but that's a Eclipse based Java application. Its an GUI application used to configure soem settings via check boxes...

Can we open it separately just like in examples we have opened new Eclipse instance.
Re: Help in SWTBot [message #501375 is a reply to message #501322] Wed, 02 December 2009 01:05 Go to previous messageGo to next message
Kevin is currently offline KevinFriend
Messages: 2
Registered: December 2009
Junior Member
I'm interested in this answer too.

And I'v got a simular question. I followed the user guide and always got the new application. But what i want is how to open an existing java application (launch eclipse application abc.product under a project in Package Explorer view or click abc.product in drop down toolbar Run if it was launched before) then log in and do furthur test.

It would be appreciated if you can tell me how to do that.

Kevin
Re: Help in SWTBot [message #501386 is a reply to message #501375] Wed, 02 December 2009 04:51 Go to previous messageGo to next message
Devendra  is currently offline Devendra Friend
Messages: 7
Registered: December 2009
Junior Member
Hi Kevin,

I know how to open a existing application using SWTBot script. Even I tried with the same approach. We can open an existing Java project and can execute also. But the problem here is, the running application will open as a different window. As your script is responsible to open one eclipse instance, you hace control over that only. You can not access the new window of your application.
Still you want code, plz let me know I will give you.
Re: Help in SWTBot [message #501397 is a reply to message #501386] Wed, 02 December 2009 07:47 Go to previous messageGo to next message
Kevin is currently offline KevinFriend
Messages: 2
Registered: December 2009
Junior Member
Hi Devendra,

Thanks for your response. It would be great if you can give me the code and i will try to open an existing eclipse application. We can do more discussion later for the problems we have.

Thanks again,

Kevin
Re: Help in SWTBot [message #501606 is a reply to message #501397] Thu, 03 December 2009 05:04 Go to previous messageGo to next message
Devendra  is currently offline Devendra Friend
Messages: 7
Registered: December 2009
Junior Member

Hi Kevin,

I have pasted the code below. Plz add/remove sleep time as per your application need.
When it will open the existing application, it starts building it. It depends on ur system performance and RAM size. Please adapt accordingly. Hopefully this will help you.



package firstproj;

import org.eclipse.swtbot.eclipse.finder.SWTEclipseBot;

import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

@SuppressWarnings("deprecation")
@RunWith(SWTBotJunit4ClassRunner.class)
public class proj {

private static SWTEclipseBot bot;

@BeforeClass
public static void beforeClass() throws Exception {
bot = new SWTEclipseBot();
bot.view("Welcome").close();
}


@Test
public void canCreateANewJavaProject() throws Exception {


//Importing existing application
System.out.println("Get Started");
bot.menu("File").menu("Import...").click();
SWTBotShell shell = bot.shell("Import");

shell.activate(); /* "Enabled import shell" */
bot.tree().select("General").expandNode("General").select( "Existing Projects into Workspace");
bot.button("Next >").click();
bot.text(0).setText("Your project absolute path, e.g c:\\...\\...\\myproject");
bot.button("Browse...").click();
bot.sleep(5000);
bot.button("Finish").click();
System.out.println("imported the existing application");
bot.sleep(60000);
shell.close();

//Building the workspace takes more time
bot.sleep(120000);
System.out.println("building the workspace"); // Just a text to show thw progress in Console view
bot.sleep(120000);

//selecting the package explorer view
bot.view("Hierarchy").setFocus(); // To make sure it is working :Switch between views
bot.sleep(2000);
bot.view("Package Explorer").setFocus();
bot.sleep(10000);
System.out.println("selected package explorer view");

//Select your project in tree view and expand it.
bot.viewByTitle("Package Explorer").bot().tree().select("Your project").expandNode("Your Project");

//run your project
bot.menu("Run").menu("Run As").menu("2 Java Application").click();
bot.sleep(30000);

//selecting ur application if asking
bot.sleep(10000);
shell = bot.shell("Select Java Application");
shell.activate();

bot.text(0).setText("Put the application name which you want to open(Incase if many applications are there");
bot.sleep(20000);
bot.button(0).click(); //"clicked ok"
bot.sleep(20000);
shell.close();
}


}


@AfterClass
public static void sleep() {
bot.sleep(20000);
}

}






Re: Help in SWTBot [message #501710 is a reply to message #501606] Thu, 03 December 2009 14:28 Go to previous message
Pascal G is currently offline Pascal GFriend
Messages: 157
Registered: July 2009
Senior Member
Devendra wrote:
>
> Hi Kevin,
>
> I have pasted the code below. Plz add/remove sleep time as per your
> application need.
> When it will open the existing application, it starts building it. It
> depends on ur system performance and RAM size. Please adapt accordingly.
> Hopefully this will help you.
>
>
>
> package firstproj;
>
> import org.eclipse.swtbot.eclipse.finder.SWTEclipseBot;
>
> import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
> import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
> import org.junit.AfterClass;
> import org.junit.BeforeClass;
> import org.junit.Test;
> import org.junit.runner.RunWith;
>
> @SuppressWarnings("deprecation")
> @RunWith(SWTBotJunit4ClassRunner.class)
> public class proj {
>
> private static SWTEclipseBot bot;
>
> @BeforeClass
> public static void beforeClass() throws Exception {
> bot = new SWTEclipseBot();
> bot.view("Welcome").close();
> }
>
>
> @Test
> public void canCreateANewJavaProject() throws Exception {
>
> //Importing existing application
> System.out.println("Get Started");
> bot.menu("File").menu("Import...").click();
> SWTBotShell shell = bot.shell("Import");
>
> shell.activate(); /* "Enabled import shell" */
> bot.tree().select("General").expandNode("General").select(
> "Existing Projects into Workspace");
> bot.button("Next >").click();
> bot.text(0).setText("Your project absolute path, e.g
> c:\\...\\...\\myproject");
> bot.button("Browse...").click();
> bot.sleep(5000);
> bot.button("Finish").click();
> System.out.println("imported the existing application");
> bot.sleep(60000);
> shell.close();
>
> //Building the workspace takes more time
> bot.sleep(120000);
> System.out.println("building the workspace"); // Just a text to
> show thw progress in Console view
> bot.sleep(120000);
> //selecting the package explorer view
> bot.view("Hierarchy").setFocus(); // To make sure it is
> working :Switch between views
> bot.sleep(2000);
> bot.view("Package Explorer").setFocus();
> bot.sleep(10000);
> System.out.println("selected package explorer view");
>
> //Select your project in tree view and expand it.
> bot.viewByTitle("Package Explorer").bot().tree().select("Your
> project").expandNode("Your Project");
> //run your project
> bot.menu("Run").menu("Run As").menu("2 Java Application").click();
> bot.sleep(30000);
>
> //selecting ur application if asking
> bot.sleep(10000);
> shell = bot.shell("Select Java Application");
> shell.activate();
>
> bot.text(0).setText("Put the application name which you want to
> open(Incase if many applications are there");
> bot.sleep(20000);
> bot.button(0).click(); //"clicked ok"
> bot.sleep(20000);
> shell.close();
> } }
>
>
> @AfterClass
> public static void sleep() {
> bot.sleep(20000);
> }
>
> }

.... This works well and all, but you won't be able to test the launched
application. From my understanding, your application is an AWT or Swing
application (or maybe not even a GUI application from what I see) and
SWTBot can't test that.

By AWT or Swing, I mean your classes use java.awt or javax.swing
packages. SWTBot is for SWT application only (org.eclipse.swt packages)
--
Pascal Gélinas | Software Developer
*Nu Echo Inc.*
http://www.nuecho.com/ | http://blog.nuecho.com/

*Because performance matters.*
Previous Topic:findControls()
Next Topic:Proposed Additional Finders
Goto Forum:
  


Current Time: Sun Dec 21 20:52:45 GMT 2014

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

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