win wrote:Hi Phil,
I want to be able to run the generated tests on Linux/Windows this will not be possible if using the XYLocator().
Also With regard to the TPB_UNDER_PROPERTIES workaround
Are you suggesting instead of the XYLocator use the TPB_UNDER_PROPERTIES within the CTabItemLocator
ui.click(new CTabItemLocator(TPB_UNDER_PROPERTIES[1]));
Can you give an example .
Hey there, I'm the one who came up with the workaround. Here's how it works:
I got a public Class with the lables put into a String array in the same order as they are in the property sheet.
- Code: Select all
public class PropertySheetLabels
{
public static final String T_TAB_PROPERTIES = "Properties";
// tabbed properties button labels. Those are on the left on the Properties Sheet
public static final String B_TPB_GENERAL = "General"; // topmost button
public static final String B_TPB_DESCRIPTION = "Description";
public static final String B_TPB_DETAILS = "Details"; // bottommost button
/**
* String array containing the Labels of all the tabbed properties buttons
* under the Properties View
*/
public static final String[] TPB_UNDER_PROPERTIES = new String[] { B_TPB_GENERAL, B_TPB_DESCRIPTION, B_TPB_DETAILS};
}
Then, I made a method for clicking on a given button. You can copy that and the snippet below it (setFocusOnView) and try it out. It's crude, but works well. The offsets and button height are wor Windows (XP with the oldschool gray theme), you might need to adapt those if you're running on a different OS or theme.
- Code: Select all
/**
* Attempts to click the given button in the Properties View. A click on the
* "Properties" Tab is executed here, then the coordinates of the desired
* button a calculated and the button is clicked.
*
* This is a workaround because there's no WindowTester Locator for the
* vertical sub-tabs like General, Description, Details, etc...
* Those sub-tabs are not declared in source code, but in the properties of
* an Eclipse application...
*
* TODO Find a better way to do this so it doesn't break if buttons are
* resized
*
* @see http://www.eclipse.org/articles/Article-Tabbed-Properties/tabbed_properties_view.html
*
* @param buttonName
* examples: "General", "Description", "Details"
*/
protected void clickOnButtonInPropertiesView(String buttonName) throws Exception
{
IWidgetLocator propertiesTab = new CTabItemLocator(PropertySheetLabels.T_TAB_PROPERTIES);
// click on Properties Tab
setFocusOnView(propertiesTab);
/*
* offset coordinates of the topmost tabbed property button (relative to
* the top left corner of the Properties View)
*/
int xOffset = 45;
int yOffset = 45;
int buttonHeight = 20; // one button is 20 pixels high
boolean givenButtonNameIsValid = false;
// check if the given buttonName is valid
int lastButtonIndex = PropertySheetLabels.TPB_UNDER_PROPERTIES.length;
for (int i = 0; i < lastButtonIndex; i++)
{
if (PropertySheetLabels.TPB_UNDER_PROPERTIES[i].equals(buttonName))
{
yOffset += buttonHeight * i; // the new relative y coordinate
givenButtonNameIsValid = true;
break;
}
}
- Code: Select all
/**
* Activates (i.e. clicks on the tab of) the given View
*
* @param tabNameAsIWidgetLocator
* @throws Exception
*/
protected void setFocusOnView(IWidgetLocator tabNameAsIWidgetLocator) throws Exception
{
// TODO Add try catch around ui.click?
ui.click(tabNameAsIWidgetLocator);
System.out.println("Clicked on the tab named " + tabNameAsIWidgetLocator);
waitForJobsComplete();
}