Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to use tooltiptext as identifier #70

Merged
merged 1 commit into from
Jul 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@
public class ByNameOrTextComponentChooser implements ComponentChooser {
private ComponentChooser byNameComponentChooser;
private ComponentChooser byTextComponentChooser;
private ComponentChooser byTooltipComponentChooser;

public ByNameOrTextComponentChooser(String expectedNameOrText) {
byNameComponentChooser = new ByNameComponentChooser(expectedNameOrText);
byTextComponentChooser = new ByTextComponentChooser(expectedNameOrText);
byTooltipComponentChooser = new ByTooltipComponentChooser(expectedNameOrText);
}

public boolean checkComponent(Component component) {
return byNameComponentChooser.checkComponent(component) ||
byTextComponentChooser.checkComponent(component);
return byNameComponentChooser.checkComponent(component)
|| byTextComponentChooser.checkComponent(component)
|| byTooltipComponentChooser.checkComponent(component);
}

public String getDescription() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public ByTextComponentChooser(String expectedText) {
}

@Override
public boolean checkComponent(Component component) {
public boolean checkComponent(Component component)
{
WithText withText = (WithText) Retrofit.partial(component,
WithText.class);
return ObjectUtils.nullSafeEquals(expectedText, withText.getText());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2008-2011 Nokia Siemens Networks Oyj
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.robotframework.swing.chooser;

import org.laughingpanda.jretrofit.Retrofit;
import org.netbeans.jemmy.ComponentChooser;
import org.robotframework.swing.util.ObjectUtils;

import java.awt.*;
import java.io.PrintWriter;

public class ByTooltipComponentChooser implements ComponentChooser {
private final String expectedText;

public ByTooltipComponentChooser(String expectedText) {
this.expectedText = expectedText;
}

@Override
public boolean checkComponent(Component component)
{
WithTooltip withTooltip = (WithTooltip) Retrofit.partial(component,
WithTooltip.class);
return ObjectUtils.nullSafeEquals(expectedText, withTooltip.getToolTipText());
}

@Override
public String getDescription() {
return expectedText;
}
}
21 changes: 21 additions & 0 deletions src/main/java/org/robotframework/swing/chooser/WithTooltip.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2008-2011 Nokia Siemens Networks Oyj
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.robotframework.swing.chooser;

public interface WithTooltip {
String getToolTipText();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class TestButton extends JButton {
public TestButton() {
super(INITIAL_TEXT);
setName("testButton");
setToolTipText("testToolTip");
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public void doesntThrowExceptionForNullNamesOrTexts() {
checking(new Expectations() {{
one(component).getName(); will(returnValue(null));
one(component).getText(); will(returnValue(null));
one(component).getToolTipText(); will(returnValue(null));
}});

specify(context.checkComponent(component), must.equal(false));
Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/robot-tests/buttonkeywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Library TestSwingLibrary
*** Variables ***
${buttonName} testButton
${buttonText} Test Button
${toolTipText} testToolTip
${buttonTextAfterPush} Button Was Pushed1
${buttonIndex} 0

Expand All @@ -24,6 +25,9 @@ Button Should Exist By Internal Name
Button Should Exist By Text
buttonShouldExist ${buttonText}

Button Should Exist By ToolTip
buttonShouldExist ${toolTipText}

Button Should Exist Index
buttonShouldExist ${buttonIndex}

Expand Down