How to write JellyTools functional tests? - java

I managed to set up JellyTools in my Java project in Netbeans Platform. Now I would like to write some functional tests with it but I can't find any tutorials about JellyTools apart from this:
http://wiki.netbeans.org/JellyTools
Can anyone give me some tips about it or post some other tutorials?
I would like to write a text in a textfield for example and then press the button "Next" in a wizard but I couldn't manage to do it with the tutorial above.

I resolved my own question about writing a text in a wizard and then press "Next". This way I can create a project automaticaly in my application:
Action action = new Action("File|New Project", null);
action.perform();
WizardOperator wo = new WizardOperator("New Project");
wo.next();
JTextFieldOperator txtName = new JTextFieldOperator(
(JTextField) new JLabelOperator(wo, "Project Name:").getLabelFor());
txtName.clearText();
txtName.typeText("MyProject");
wo.finish();

Adrian,
Jelly tools is intended to create UI tests for Netbeans IDE itself, so it is not expected to use it for test Your UI. You can try Jemmy module which is also base layer for Jelly.
You can see some Jemmy tutorials there: https://jemmy.java.net/tutorial.html
Hope this helps.

Related

Does Eclipse RCP include a built in cut/copy/paste handler?

As the title says I'm wondering whether Eclipse RCP 4 provides any built in cut/copy/paste handlers which can be linked to the org.eclipse.ui.edit.cut, org.eclipse.ui.edit.copy and org.eclipse.ui.edit.paste commands?
I appreciate that that a custom handler may be needed for some SWT widgets or more complex use cases with cut/copy/paste operations, but I can't help but feel I'm trying to re-invent the wheel to copy some text from one component and paste in into another.
If there aren't any built in cut/copy/paste handlers, are there any well documented examples of how to do this? I understand how to use the clipboard.getContents and clipboard.setContents methods, but have found this starts to become non-trivial when trying to find out what text was selected when the copy command is invoked and which component has focus and whether its read only when the paste command is invoked.
I've looked at this StackOverflow question but it doesn't explain whether there any built in handlers or offer any guidance on writing my own handlers.
For a 3.x compatibilty mode Eclipse 4 application these commands are defined as:
<command
name="%command.cut.name"
description="%command.cut.description"
categoryId="org.eclipse.ui.category.edit"
id="org.eclipse.ui.edit.cut"
defaultHandler="org.eclipse.ui.internal.handlers.WidgetMethodHandler:cut" />
<command
name="%command.copy.name"
description="%command.copy.description"
categoryId="org.eclipse.ui.category.edit"
id="org.eclipse.ui.edit.copy"
defaultHandler="org.eclipse.ui.internal.handlers.WidgetMethodHandler:copy" />
<command
name="%command.paste.name"
description="%command.paste.description"
categoryId="org.eclipse.ui.category.edit"
id="org.eclipse.ui.edit.paste"
defaultHandler="org.eclipse.ui.internal.handlers.WidgetMethodHandler:paste" />
So they all use org.eclipse.ui.internal.handlers.WidgetMethodHandler as the default handler which is used when no other handler is active.
This handler uses reflection to look for the method name cut, copy or paste in the currently focussed SWT Widget and calls that method if it is found.
For a pure e4 application there is no default definition of cut/copy/paste commands and the WidgetMethodHandler is not available. SWT controls will continue to support cut/copy/paste but there is no other support.
You can put text in the clipboard using something like:
Clipboard clipboard = new Clipboard(Display.getCurrent());
clipboard.setContents(new Object [] {"Text for clipboard"},
new Transfer [] {TextTransfer.getInstance()});
clipboard.dispose()
and get text from the clipboard with:
Clipboard clipboard = new Clipboard(Display.getCurrent());
String text = (String)clipboard.getContents(TextTransfer.getInstance());
clipboard.dispose()

Winium - how to access tool bar item if that bar doesn't have child

I am using Winium + Java for automation testing of Windows application, and trying to access tool bar menu.
When I tried to detect elements using UI Automation Verify, I couldn't see child elements under tool bar element like below screenshot.
enter image description here
But my tool bar definitely has sub menu items like screenshot and I need to access them.
enter image description here
I tried below java code, but it didn't work
WebElement el = driver.findElement(By.id('59398'));
el.click();
WebElement child = el.findElement(By.name('Start'));
child.click();
when I tried
driver.findElement(By.name"Start').click();
it clicked my windows start menu, not my application's menu.
Is there any way to access items under this tool bar?
You can try use another UI Inspector
eg. UI SPY or Inspector.exe
Probably your ID is not a AutomationID (process id?)
You should find a main window (parent of your app) (Example for calc) and get a parameter like AutomationId, ClassName or Name
I see this is MFC application, and this is an app side MFC library problem. If you hover mouse over toolbar button using Inspect.exe, the info is available but you can't reach this button from the hierarchy (the buttons have no parent somehow). Possible workaround involves combined Win32 API and UI Automation approach:
get button rectangle using Win32 API (but there is no text).
use ElementFromPoint method of UI Automation API and get actual texts to choose the right button.
P.S. My suggestion is applicable for Java + Winium in theory. But I can't estimate the complexity because I'm not a Java expert. So below is Python solution.
We have plans to implemented this mixed way in pywinauto. See issue #413. It contains Python code sample how to do that. We've had no chance to integrate it yet.
from ctypes.wintypes import tagPOINT
import pywinauto
app = pywinauto.Application().start(r'.\apps\MFC_samples\RebarTest.exe')
menu_bar = app.RebarTest.MenuBar.wrapper_object()
point = menu_bar.button(0).rectangle().mid_point()
point = menu_bar.client_to_screen(point)
elem = pywinauto.uia_defines.IUIA().iuia.ElementFromPoint(tagPOINT(point[0], point[1]))
element = pywinauto.uia_element_info.UIAElementInfo(elem)
print(element.name)

How to rename the eclipse plugin menu programmatically

I am developing an eclipse plugin.I have given my menu,sub menu names and plugin id in plugin.xml.
I want to dynamically rename my plugin id as well my menu and sub menu name.I came across this SOF link.I am using the below code.
MenuManager menuManager = ((WorkbenchWindow)window).getMenuManager();
Menu menu = menuManager.getMenu();
String itemId = "plugin_menu_id";
IContributionItem item = menuManager.find(itemId);
System.out.println("item.getId() --> " + item.getId());
//gives the plugin_menu_id
System.out.println( "menu.getItemCount() ==> "+ menu.getItemCount());
//gives no of menus in eclipse
But unfortunately I am unable to find an option to rename the menu from IContributionItem.
So is there any other way to modify things in eclipse plugin?
I found a temporary solution .Instead of using a MenuManager,I created a dynamic menu using Actions Framework instead of Command Framework though the former is deprecated.
So each time , I create a Menu,I am able to change the Menu name,icon etc.
I am searching for an equivalent in the Command Framework and will post as soon as I found that.

Eclipse RCP 4.x - Defining workspace location

I know that this question was asked many times, but I didn't find an exact answer which would fulfill my desires :)
Long story short:
I've got simple E4 application, product project, feature and main plugin with simple trim window.
Works, after exporting works too.
Now. I add lifeCycleURI property, create bundleclass for it and create simple dialog with Text area and a Button. Run it\export it and it works, before running main Trim Window dialog is shown. Fine.. Cool etc.
But I want to enter location eg. C:\TEST and after clicking button I want it to be my workspace area for the application (with .metedata and so on). HOW ???
Of course I've tried with :
Location instanceLocation = Platform.getInstanceLocation();
instanceLocation.set(new URL("file", null, "C:\TEST"), false);
But... It says that I can't change location cause it is already set... Tried to use above in Activator. The same. Tried to add
-data #noDefault in products Launching Arguments ... The same...
I always try to accomplish my tasks by myself but this.... this... ehh... Help ?
You should be able to do this in the #PostContextCreate method of the life cycle class. Don't specify the '-data' argument
#PostContextCreate
public void postContextCreate()
{
Location instanceLoc = Platform.getInstanceLocation();
// Stop if location is set
if (instanceLoc.isSet())
return;
File file = new File("C:\\TEST");
instanceLocation.set(file.toURL(), false);
}
Note: You need '\\' in your file path.
This is adapted from code which I use in my e4 RCP.
If you are currently testing the application from within Eclipse you will need to clear the workspace location in the 'Run Configuration' for the application. Open 'Run > Run Configurations', find your application and clear the 'Location' field on the 'Main' tab.

EXT-GWT Portal: How to get all Portlets?

Hi all this is my first Question here!
Im just making my first steps with (Ext-) GWT. I´m testing the Ext-GWT libraries and really: These are absolute great!
Now my question:
Is it possible to make a kind of "clear-Portal" or "hide all portles" for a defined Portal?
Or have i always manually clear the portal like in my example code above?
My sample code looks like this:
//define the Portal, 2 columns, each 50% auf width, with borders and Backgroundcolor
portal = new Portal(2);
portal.setBorders(true);
portal.setStyleAttribute("backgroundColor", "white");
portal.setColumnWidth(0, .50);
portal.setColumnWidth(1, .50);
//define a Portlet for showing all Users
portletUser = new Portlet();
portletUser.setHeading("Benutzer");
configPanel(portletUser);
portletUser.setLayout(new FitLayout());
CompUserList compUserList = new CompUserList();
portletUser.add(compUserList);
portletUser.setHeight(250);
//define a Portlet for showing all Vehicles
portletVehicles = new Portlet();
portletVehicles.setHeading("Fahrzeuge");
configPanel(portletVehicles);
portletVehicles.setLayout(new FitLayout());
CompVehicleList compVehicleList = new CompVehicleList();
portletVehicles.add(compVehicleList);
portletVehicles.setHeight(250);
//define a portlet for showing all countries
portletCountries = new Portlet();
portletCountries.setHeading("Länder");
configPanel(portletCountries);
portletCountries.setLayout(new FitLayout());
CompCountryList compCountryList = new CompCountryList();
portletCountries.add(compCountryList);
portletCountries.setHeight(250);
//add both Portlets to Portal
portal.add(portletUser, 0);
portal.add(portletVehicles, 1);
So first of all this works fine and looks great :-)
Now i have a a button in a accordeon menu. The Listener on this button should hide all portlets in the portal (at this time its the portletUser and portletVehicles) and then add another portlet (for example the portletCountries):
portletUser.hide();
portletVehicles.hide();
portal.add(portletCountries, 0)
Question from above again ;-)
Is it possible to make a kind of "clear-Portal" or "hide all portles" for a defined Portal?
Or have i always manually clear the portal like in my example code above?
What is the best practice for this functionallity?
Thanks all for your tips!
Lars.
I haven't used Ext-GWT -- but looking at the Javadoc for Portal there are two things I would try:
for (LayoutContainer c : portal.getItems()) {
c.hide();
}
or, more generally, wrap a Portal in your own class which records the Portlets which are in the Portal -- then you can get a List rather than List.

Categories

Resources