├── .github └── workflows │ └── CI.yml ├── .gitignore ├── BUILD.rest ├── COPYRIGHT.txt ├── README.rest ├── demo ├── README.txt ├── example.txt └── run_demo.py ├── pom.xml └── src ├── it ├── included_dependencies │ ├── invoker.properties │ ├── pom.xml │ └── src │ │ └── test │ │ └── robotframework │ │ └── acceptance │ │ └── swing_maven_dependency.txt └── maven_dependency │ ├── invoker.properties │ ├── pom.xml │ └── src │ └── test │ └── robotframework │ └── acceptance │ └── swing_maven_dependency.txt ├── main └── java │ ├── SwingLibrary.java │ ├── TestSwingLibrary.java │ ├── com │ └── some │ │ └── own │ │ └── keyword │ │ └── KeywordsInOtherPackage.java │ └── org │ └── robotframework │ └── swing │ ├── SwingLibrary.java │ ├── arguments │ ├── ArgumentHandler.java │ ├── ArgumentParser.java │ ├── IdentifierHandler.java │ └── VoidIdentifierHandler.java │ ├── button │ ├── AbstractButtonOperator.java │ ├── ButtonOperator.java │ └── ButtonOperatorFactory.java │ ├── checkbox │ ├── CheckBoxListOperatorFactory.java │ ├── CheckBoxOperator.java │ └── CheckBoxOperatorFactory.java │ ├── chooser │ ├── ByNameComponentChooser.java │ ├── ByNameOrTextComponentChooser.java │ ├── ByNameOrTitleFrameChooser.java │ ├── ByTextComponentChooser.java │ ├── ByTitleComponentChooser.java │ ├── ByTooltipComponentChooser.java │ ├── ListItemChooser.java │ ├── WithText.java │ ├── WithTitle.java │ └── WithTooltip.java │ ├── combobox │ ├── ComboBoxOperator.java │ ├── ComboBoxOperatorFactory.java │ ├── ComboboxSelectedItemWaitable.java │ └── ItemTextExtractor.java │ ├── common │ ├── Identifier.java │ ├── IdentifierSupport.java │ ├── ProxyHandler.java │ ├── SmoothInvoker.java │ ├── TimeoutCopier.java │ └── TimeoutName.java │ ├── comparator │ └── EqualsStringComparator.java │ ├── component │ ├── ComponentOperator.java │ └── ComponentOperatorFactory.java │ ├── container │ └── ContainerIteratorForListing.java │ ├── context │ ├── AbstractContextVerifier.java │ ├── ContainerOperator.java │ ├── ContainerOperatorFactory.java │ ├── Context.java │ ├── ContextVerifier.java │ └── DefaultContextVerifier.java │ ├── dialog │ ├── DialogOperator.java │ └── DialogOperatorFactory.java │ ├── factory │ ├── ContextBasedOperatorFactory.java │ ├── DefaultContextVerifyingOperatorFactory.java │ ├── IdentifierParsingOperatorFactory.java │ ├── OperatorFactory.java │ └── OperatorsFactory.java │ ├── filechooser │ └── FileChooserOperatorFactory.java │ ├── internalframe │ ├── InternalFrameIteratorForListing.java │ ├── InternalFrameOperator.java │ └── InternalFrameOperatorFactory.java │ ├── keyboard │ ├── KeyEventPresser.java │ └── KeyEventSender.java │ ├── keyword │ ├── button │ │ ├── ButtonKeywords.java │ │ └── ButtonOperatorWrapper.java │ ├── checkbox │ │ ├── CheckBoxKeywords.java │ │ └── CheckBoxListKeywords.java │ ├── combobox │ │ └── ComboBoxKeywords.java │ ├── component │ │ └── ComponentKeywords.java │ ├── concurrent │ │ └── ThreadKeywords.java │ ├── context │ │ └── ContextKeywords.java │ ├── development │ │ ├── ComponentOccurences.java │ │ └── DevelopmentKeywords.java │ ├── dialog │ │ └── DialogKeywords.java │ ├── dispatch │ │ └── DispatchModelKeywords.java │ ├── filechooser │ │ └── FileChooserKeywords.java │ ├── internalframe │ │ └── InternalFrameKeywords.java │ ├── keyboard │ │ └── KeyEventKeywords.java │ ├── label │ │ └── LabelKeywords.java │ ├── launch │ │ └── ApplicationLaunchingKeywords.java │ ├── list │ │ └── ListKeywords.java │ ├── menu │ │ ├── MainMenuKeywords.java │ │ ├── MenuCheckboxKeywords.java │ │ ├── MenuKeywords.java │ │ └── MenuRadioButtonKeywords.java │ ├── radiobutton │ │ └── RadioButtonKeywords.java │ ├── slider │ │ └── SliderKeywords.java │ ├── spinner │ │ └── SpinnerKeywords.java │ ├── tab │ │ └── TabKeywords.java │ ├── table │ │ └── TableKeywords.java │ ├── textcomponent │ │ ├── EditorPaneKeywords.java │ │ └── TextComponentKeywords.java │ ├── timeout │ │ └── TimeoutKeywords.java │ ├── togglebutton │ │ └── ToggleButtonKeywords.java │ ├── tree │ │ ├── TreeNodeExistenceKeywords.java │ │ ├── TreeNodeKeywords.java │ │ ├── TreeNodePopupKeywords.java │ │ ├── TreeNodeSelectionKeywords.java │ │ └── TreeNodeVisibilityKeywords.java │ ├── utils │ │ └── OptionalArgsForTableCellAndComponentClicking.java │ └── window │ │ └── WindowKeywords.java │ ├── label │ ├── LabelOperator.java │ └── LabelOperatorFactory.java │ ├── list │ ├── CellTextExtractor.java │ ├── ListFindItemIndexWaitable.java │ ├── ListOperator.java │ └── ListOperatorFactory.java │ ├── menu │ └── MenuSupport.java │ ├── operator │ └── ComponentWrapper.java │ ├── popup │ ├── PopupCaller.java │ └── PopupMenuOperatorFactory.java │ ├── radiobutton │ └── RadioButtonOperatorFactory.java │ ├── slider │ ├── DefaultSliderOperator.java │ ├── SliderOperator.java │ └── SliderOperatorFactory.java │ ├── spinner │ ├── DefaultSpinnerOperator.java │ ├── SpinnerOperator.java │ └── SpinnerOperatorFactory.java │ ├── tab │ ├── TabOperator.java │ ├── TabPaneOperatorFactory.java │ └── TabbedPaneOperator.java │ ├── table │ ├── AbstractTableCellChooser.java │ ├── CellValueExtractor.java │ ├── ColumnIndexTableCellChooser.java │ ├── ColumnNameTableCellChooser.java │ ├── InvalidCellException.java │ ├── TableHeaderOperator.java │ ├── TableOperator.java │ └── TableOperatorFactory.java │ ├── testapp │ ├── ContextMenu.java │ ├── Delay.java │ ├── MenuItemWithCommand.java │ ├── Operation.java │ ├── TestApplication.java │ ├── TestButton.java │ ├── TestCheckBox.java │ ├── TestComboBox.java │ ├── TestDesktopPane.java │ ├── TestEditorPane.java │ ├── TestFastUpdatingPane.java │ ├── TestFileChooser.java │ ├── TestLabel.java │ ├── TestList.java │ ├── TestListResults.java │ ├── TestMenuBar.java │ ├── TestNonModalDialog.java │ ├── TestRadioButton.java │ ├── TestScrollPane.java │ ├── TestSpinnerButton.java │ ├── TestTabbedPane.java │ ├── TestTable.java │ ├── TestTextArea.java │ ├── TestTextField.java │ ├── TestToggleButton.java │ ├── TestTree.java │ ├── TestTreeResults.java │ ├── TreeWithoutTreeNode.java │ ├── WithPopup.java │ ├── examplesut │ │ └── TodoListApplication.java │ ├── extension │ │ ├── ExtendedSwingLibrary.java │ │ └── ExtendedSwingLibrary2.java │ └── keyword │ │ └── testapp │ │ └── SomeApplication.java │ ├── testkeyword │ ├── ApplicationLaunchingTestingKeywords.java │ ├── ButtonTestingKeywords.java │ ├── CheckboxTestingKeywords.java │ ├── ComboBoxTestingKeywords.java │ ├── EditorPaneTestingKeywords.java │ ├── FileChooserTestingKeywords.java │ ├── ListTestingKeywords.java │ ├── RadioButtonTestingKeywords.java │ ├── RecordStdOut.java │ ├── RunnerKeyword.java │ ├── TestingKeywords.java │ ├── TextfieldTestingKeywords.java │ ├── ThreadTestingKeywords.java │ ├── ToggleButtonTestingKeywords.java │ └── TreeTestingKeywords.java │ ├── textcomponent │ ├── AWTTextComponentOperator.java │ ├── EditorPaneOperator.java │ ├── EditorPaneOperatorFactory.java │ ├── HtmlElement.java │ ├── HyperlinkEventFactory.java │ ├── LinkNotFoundException.java │ ├── SwingTextComponentOperator.java │ ├── TextComponentOperator.java │ └── TextComponentOperatorFactory.java │ ├── togglebutton │ └── ToggleButtonOperatorFactory.java │ ├── tree │ ├── JTreeLocationFactory.java │ ├── NodeTextExtractor.java │ ├── TreeIterator.java │ ├── TreeNodeExistenceResolver.java │ ├── TreeOperator.java │ ├── TreeOperatorFactory.java │ ├── TreePathAction.java │ ├── TreePathFactory.java │ ├── TreePathWaitable.java │ ├── TreePopupMenuOperatorFactory.java │ └── TreeSupport.java │ ├── util │ ├── ComponentExistenceResolver.java │ ├── ComponentUtils.java │ ├── IComponentConditionResolver.java │ ├── ObjectUtils.java │ ├── PropertyExtractor.java │ ├── StandardOutOutput.java │ ├── SwingInvoker.java │ └── SwingWaiter.java │ └── window │ ├── FrameOperator.java │ └── FrameOperatorFactory.java └── test ├── java └── org │ └── robotframework │ ├── somepackage │ └── KeywordsOutsidePathPattern.java │ └── swing │ ├── SwingLibrarySpec.java │ ├── arguments │ └── ArgumentParserSpec.java │ ├── button │ └── ButtonOperatorFactorySpec.java │ ├── checkbox │ └── CheckBoxOperatorFactorySpec.java │ ├── chooser │ ├── ByNameComponentChooserSpec.java │ ├── ByNameOrTextComponentChooserSpec.java │ ├── ByTextComponentChooserSpec.java │ ├── ByTitleComponentChooserSpec.java │ └── ListItemChooserSpec.java │ ├── combobox │ ├── ComboBoxOperatorFactorySpec.java │ ├── ComboBoxOperatorSpec.java │ └── ItemTextExtractorSpec.java │ ├── common │ ├── IdentifierSupportSpec.java │ └── IdentifierTest.java │ ├── comparator │ └── EqualsStringComparatorSpec.java │ ├── component │ └── ComponentOperatorSpec.java │ ├── context │ ├── ContainerOperatorFactorySpec.java │ ├── ContextVerifierSpecification.java │ └── DefaultContextVerifierSpec.java │ ├── factory │ ├── DefaultContextVerifyingOperatorFactorySpec.java │ ├── IdentifierParsingOperatorFactorySpec.java │ ├── OperatorFactorySpecification.java │ └── OperatorsFactorySpec.java │ ├── internalframe │ └── InternalFrameOperatorFactorySpec.java │ ├── keyboard │ └── KeyEventSenderSpec.java │ ├── keyword │ ├── button │ │ └── ButtonKeywordsSpec.java │ ├── checkbox │ │ ├── CheckBoxKeywordsSpec.java │ │ └── CheckBoxListKeywordsSpec.java │ ├── combobox │ │ └── ComboBoxKeywordsSpec.java │ ├── component │ │ └── ComponentKeywordsSpec.java │ ├── concurrent │ │ └── ThreadKeywordsSpec.java │ ├── context │ │ └── ContextKeywordsSpec.java │ ├── dialog │ │ └── DialogKeywordsSpec.java │ ├── filechooser │ │ └── FileChooserKeywordsSpec.java │ ├── internalframe │ │ └── InternalFrameKeywordsSpec.java │ ├── keyboard │ │ └── KeyEventKeywordsSpec.java │ ├── label │ │ └── LabelKeywordsSpec.java │ ├── launch │ │ └── ApplicationLaunchingKeywordsSpec.java │ ├── list │ │ └── ListKeywordsSpec.java │ ├── menu │ │ ├── MainMenuKeywordsSpec.java │ │ ├── MenuCheckboxKeywordsSpec.java │ │ └── MenuKeywordsSpec.java │ ├── radiobutton │ │ └── RadioButtonKeywordsSpec.java │ ├── spinner │ │ └── SpinnerKeywordsSpec.java │ ├── tab │ │ └── TabKeywordsSpec.java │ ├── table │ │ └── TableKeywordsSpec.java │ ├── testapp │ │ └── SomeApplication.java │ ├── textcomponent │ │ ├── EditorPaneKeywordsSpec.java │ │ └── TextComponentKeywordsSpec.java │ ├── timeout │ │ └── TimeoutKeywordsSpec.java │ ├── togglebutton │ │ └── ToggleButtonKeywordsSpec.java │ ├── tree │ │ ├── TreeNodeExistenceKeywordsSpec.java │ │ ├── TreeNodeKeywordsSpec.java │ │ ├── TreeNodePopupKeywordsSpec.java │ │ ├── TreeNodeSelectionKeywordsSpec.java │ │ ├── TreeNodeVisibilityKeywordsSpec.java │ │ └── TreeSpecification.java │ └── window │ │ └── WindowKeywordsSpec.java │ ├── label │ └── LabelOperatorFactorySpec.java │ ├── list │ ├── ListOperatorFactorySpec.java │ └── ListOperatorSpec.java │ ├── menu │ └── MenuSupportSpec.java │ ├── popup │ └── PopupMenuOperatorFactorySpec.java │ ├── radiobutton │ └── RadioButtonOperatorFactorySpec.java │ ├── spinner │ ├── DefaultSpinnerOperatorSpec.java │ └── SpinnerOperatorFactorySpec.java │ ├── tab │ └── TabPaneOperatorFactorySpec.java │ ├── table │ ├── AbstractTableCellChooserSpec.java │ ├── InvalidCellExceptionSpec.java │ ├── TableContextVerifierSpec.java │ └── TableOperatorSpec.java │ ├── textcomponent │ ├── EditorPaneOperatorSpec.java │ ├── HtmlElementSpec.java │ └── HyperlinkEventFactorySpec.java │ ├── togglebutton │ └── ToggleButtonOperatorFactorySpec.java │ ├── tree │ ├── JTreeLocationFactorySpec.java │ ├── TreeIteratorSpec.java │ ├── TreeNodeExistenceResolverSpec.java │ ├── TreeOperatorFactorySpec.java │ ├── TreeOperatorSpec.java │ ├── TreePathFactorySpec.java │ ├── TreePopupMenuOperatorFactorySpec.java │ └── TreeSupportSpec.java │ └── util │ ├── ComponentExistenceResolverSpec.java │ └── PropertyExtractorSpec.java └── resources └── robot-tests ├── __init__.robot ├── applicationlaunching.robot ├── awtcomponent.robot ├── button.robot ├── checkbox.robot ├── combobox.robot ├── component.robot ├── context.robot ├── development.robot ├── dialog.robot ├── dispatchmodel.robot ├── editorpane.robot ├── extending.robot ├── filechooser.robot ├── internalframe.robot ├── keyboardevent.robot ├── label.robot ├── list.robot ├── menu.robot ├── platform_info.py ├── radiobutton.robot ├── run.py ├── scroll.robot ├── slider.robot ├── spinner.robot ├── tab.robot ├── table.robot ├── textcomponent.robot ├── thread.robot ├── timeout.robot ├── togglebutton.robot ├── tree.robot └── window.robot /.github/workflows/CI.yml: -------------------------------------------------------------------------------- 1 | name: SwingLibrary CI 2 | 3 | on: [ push, pull_request ] 4 | 5 | jobs: 6 | build: 7 | runs-on: ${{ matrix.os }} 8 | strategy: 9 | fail-fast: false 10 | matrix: 11 | os: [ 'ubuntu-latest', 'windows-latest', 'macos-latest' ] 12 | include: 13 | - os: ubuntu-latest 14 | set_display: export DISPLAY=:99; Xvfb :99 -screen 0 1920x1080x24 -ac -noreset & sleep 3 15 | 16 | steps: 17 | - uses: actions/checkout@v2 18 | - name: Set up Java 8 19 | uses: actions/setup-java@v1 20 | with: 21 | java-version: 8 22 | - name: maven-settings-xml-action 23 | uses: whelk-io/maven-settings-xml-action@v20 24 | with: 25 | mirrors: '[{ "id": "maven-default-http-blocker", "mirrorOf": "dummy", "url": "http://0.0.0.0/" }]' 26 | - name: Run tests on Linux 27 | if: runner.os == 'Linux' 28 | run: | 29 | ${{ matrix.set_display }} 30 | mvn clean verify 31 | - name: Run tests on Windows 32 | if: runner.os == 'Windows' 33 | run: Set-DisplayResolution -Width 1920 -Height 1080 -Force; mvn clean verify 34 | shell: powershell 35 | - name: Run tests MacOS 36 | if: runner.os == 'macOS' 37 | run: mvn clean verify 38 | - uses: actions/upload-artifact@v1 39 | if: success() || failure() 40 | with: 41 | name: Test Results - ${{ runner.os }} 42 | path: "target with spaces/robotframework-reports/" 43 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .classpath 3 | .project 4 | *py.class 5 | swinglibrary.iml 6 | target with spaces 7 | reports 8 | tmp 9 | .DS_Store -------------------------------------------------------------------------------- /COPYRIGHT.txt: -------------------------------------------------------------------------------- 1 | Copyright 2008-2011 Nokia Siemens Networks Oyj 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /README.rest: -------------------------------------------------------------------------------- 1 | SwingLibrary 2 | ============ 3 | 4 | Swing Library is a Robot Framework library for testing Java Swing 5 | applications. Usage instructions are in the Wiki__. 6 | 7 | __ https://github.com/MarketSquare/SwingLibrary/wiki 8 | 9 | Downloads are available at `Releases 2.3.0`__ 10 | 11 | __ https://github.com/MarketSquare/SwingLibrary/releases/tag/2.3.0 12 | 13 | Keyword documentation for the latest version (2.3.0) are available `here`__ 14 | 15 | __ https://marketsquare.github.io/SwingLibrary/SwingLibrary-2.3.0.html 16 | 17 | This project was originally hosted in `Google Code`__ 18 | 19 | __ http://code.google.com/p/robotframework-swinglibrary/ 20 | 21 | and later on `robotframework github`__ 22 | 23 | __ https://github.com/robotframework/SwingLibrary/ 24 | 25 | 26 | Building SwingLibrary 27 | --------------------- 28 | 29 | See `BUILD.rest`__ for development, build and release instructions. 30 | 31 | __ https://github.com/MarketSquare/SwingLibrary/blob/master/BUILD.rest 32 | -------------------------------------------------------------------------------- /demo/README.txt: -------------------------------------------------------------------------------- 1 | Robot Framework SwingLibrary Demo 2 | --------------------------------- 3 | 4 | This directory contains an easily executable demo for Robot Framework 5 | using SwingLibrary. The tests can be executed using the `run_demo.py` 6 | script. Full usage instructions are available online at 7 | http://code.google.com/p/robotframework-swinglibrary/wiki/SwingLibraryDemo 8 | 9 | -------------------------------------------------------------------------------- /demo/example.txt: -------------------------------------------------------------------------------- 1 | *** Settings *** 2 | Library SwingLibrary 3 | Suite Setup Start Test Application 4 | 5 | *** Test Cases *** 6 | Test Add Todo Item 7 | Insert Todo Item buy milk 8 | Select From List todolist 0 9 | ${item}= Get Selected Value From List todolist 10 | Should Be Equal ${item} buy milk 11 | Push Button delete 12 | 13 | Test Delete Todo Item 14 | Insert Todo Item to be deleted 15 | Select From List todolist 0 16 | Push Button delete 17 | ${items}= Get List Item Count todolist 18 | Should Be Equal As Numbers ${items} 0 19 | 20 | *** Keywords *** 21 | Start Test Application 22 | Start Application org.robotframework.swing.testapp.examplesut.TodoListApplication 23 | Select Window Todo List 24 | 25 | Insert Todo Item ${arg} 26 | Insert Into Text Field description ${arg} 27 | Push Button add 28 | -------------------------------------------------------------------------------- /demo/run_demo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | import sys 5 | from subprocess import call 6 | from glob import glob 7 | 8 | TESTAPP = 'org.robotframework.swing.testapp.examplesut.TodoListApplication' 9 | 10 | def _get_jars(): 11 | dir = os.path.dirname(__file__) 12 | return glob(os.path.join(dir, 'lib', 13 | 'swinglibrary-*.jar')) 14 | 15 | def _set_classpath(): 16 | os.environ['CLASSPATH'] = os.pathsep.join(_get_jars()) 17 | 18 | def _parse_command(): 19 | if sys.argv[1] == 'startapp': 20 | return ['java', TESTAPP] 21 | return ['jybot', '--outputdir', 'results'] + sys.argv[1:] 22 | 23 | if __name__ == '__main__': 24 | if len(sys.argv) == 1: 25 | print 'Usage: run_demo.py [startapp|path_to_tests]' 26 | sys.exit(1) 27 | _set_classpath() 28 | call(_parse_command(), shell=os.name=='nt') 29 | -------------------------------------------------------------------------------- /src/it/included_dependencies/invoker.properties: -------------------------------------------------------------------------------- 1 | invoker.goals = verify -------------------------------------------------------------------------------- /src/it/included_dependencies/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | org.robotframework.test 6 | test-maven-dependency 7 | 1.0-SNAPSHOT 8 | jar 9 | 10 | mytest 11 | http://maven.apache.org 12 | 13 | 14 | this.does.not.matter 15 | ThisAlsoIsIgnored 16 | 42 17 | system 18 | @project.build.directory@/with-dependencies/swinglibrary-@project.version@.jar 19 | 20 | 21 | 22 | 23 | 24 | org.robotframework 25 | robotframework-maven-plugin 26 | 1.4.5 27 | 28 | 29 | 30 | run 31 | verify 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/it/included_dependencies/src/test/robotframework/acceptance/swing_maven_dependency.txt: -------------------------------------------------------------------------------- 1 | *** Settings *** 2 | Library SwingLibrary 3 | 4 | 5 | *** Test Cases *** 6 | Start app and close it 7 | Launch application org.robotframework.swing.testapp.TestApplication 8 | Select window Test App 9 | Close window Test App 10 | -------------------------------------------------------------------------------- /src/it/maven_dependency/invoker.properties: -------------------------------------------------------------------------------- 1 | invoker.goals = verify -------------------------------------------------------------------------------- /src/it/maven_dependency/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | org.robotframework.test 6 | test-maven-dependency 7 | 1.0-SNAPSHOT 8 | jar 9 | 10 | mytest 11 | http://maven.apache.org 12 | 13 | 14 | 15 | org.robotframework 16 | swinglibrary 17 | @project.version@ 18 | 19 | 20 | 21 | 22 | 23 | org.robotframework 24 | robotframework-maven-plugin 25 | 1.4.5 26 | 27 | 28 | 29 | run 30 | verify 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/it/maven_dependency/src/test/robotframework/acceptance/swing_maven_dependency.txt: -------------------------------------------------------------------------------- 1 | *** Settings *** 2 | Library SwingLibrary 3 | 4 | 5 | *** Test Cases *** 6 | Start app and close it 7 | Launch application org.robotframework.swing.testapp.TestApplication 8 | Select window Test App 9 | Close window Test App 10 | -------------------------------------------------------------------------------- /src/main/java/SwingLibrary.java: -------------------------------------------------------------------------------- 1 | import java.util.Collection; 2 | import java.util.Collections; 3 | 4 | /* 5 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | public class SwingLibrary extends org.robotframework.swing.SwingLibrary { 21 | public SwingLibrary() { 22 | this(Collections.emptyList()); 23 | } 24 | 25 | protected SwingLibrary(Collection keywordPatterns) { 26 | super(keywordPatterns); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/TestSwingLibrary.java: -------------------------------------------------------------------------------- 1 | 2 | public class TestSwingLibrary extends org.robotframework.swing.SwingLibrary { 3 | 4 | public TestSwingLibrary() { 5 | super("org/robotframework/swing/testkeyword/**/*.class"); 6 | } 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/some/own/keyword/KeywordsInOtherPackage.java: -------------------------------------------------------------------------------- 1 | package com.some.own.keyword; 2 | 3 | import org.robotframework.javalib.annotation.ArgumentNames; 4 | import org.robotframework.javalib.annotation.RobotKeyword; 5 | import org.robotframework.javalib.annotation.RobotKeywords; 6 | 7 | 8 | @RobotKeywords 9 | public class KeywordsInOtherPackage { 10 | @RobotKeyword 11 | @ArgumentNames({"arg"}) 12 | public String keywordInOtherPackage(String arg) { 13 | return arg; 14 | } 15 | 16 | @RobotKeyword 17 | @ArgumentNames({"*args"}) 18 | public String keywordwithoutArgumentNames(String... args) { 19 | return args[0]; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/arguments/ArgumentHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.arguments; 18 | 19 | public interface ArgumentHandler { 20 | T indexArgument(int index); 21 | T nameArgument(String name); 22 | T indexAWTArgument(int index); 23 | T nameAWTArgument(String name); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/arguments/IdentifierHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.arguments; 18 | 19 | public abstract class IdentifierHandler extends ArgumentParser implements ArgumentHandler { 20 | public IdentifierHandler() { 21 | setArgumentHandler(this); 22 | } 23 | 24 | public abstract T indexArgument(int index); 25 | public abstract T nameArgument(String name); 26 | public T indexAWTArgument(int index) { 27 | // TODO: Smarter exception type 28 | throw new RuntimeException("AWT components are not supported by this keyword."); 29 | } 30 | public T nameAWTArgument(String name) { 31 | throw new RuntimeException("AWT components are not supported by this keyword."); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/arguments/VoidIdentifierHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.arguments; 18 | 19 | public abstract class VoidIdentifierHandler extends IdentifierHandler { 20 | @Override 21 | public Boolean indexArgument(int index) { 22 | handleIndexArgument(index); 23 | return Boolean.TRUE; 24 | } 25 | 26 | @Override 27 | public Boolean nameArgument(String name) { 28 | handleNameArgument(name); 29 | return Boolean.TRUE; 30 | } 31 | 32 | protected abstract void handleNameArgument(String name); 33 | protected abstract void handleIndexArgument(int index); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/button/AbstractButtonOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.button; 18 | 19 | import org.robotframework.swing.operator.ComponentWrapper; 20 | 21 | public interface AbstractButtonOperator extends ComponentWrapper { 22 | void push(); 23 | boolean isSelected(); 24 | boolean isEnabled(); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/button/ButtonOperator.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.button; 2 | 3 | import org.netbeans.jemmy.ComponentChooser; 4 | import org.netbeans.jemmy.operators.ContainerOperator; 5 | import org.netbeans.jemmy.operators.JButtonOperator; 6 | 7 | public class ButtonOperator extends JButtonOperator implements AbstractButtonOperator { 8 | public ButtonOperator(ContainerOperator container, int index) { 9 | super(container, index); 10 | } 11 | 12 | public ButtonOperator(ContainerOperator container, ComponentChooser chooser) { 13 | super(container, chooser); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/button/ButtonOperatorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.button; 18 | 19 | import org.netbeans.jemmy.operators.ContainerOperator; 20 | import org.robotframework.swing.chooser.ByNameOrTextComponentChooser; 21 | import org.robotframework.swing.context.Context; 22 | import org.robotframework.swing.factory.DefaultContextVerifyingOperatorFactory; 23 | 24 | public class ButtonOperatorFactory extends DefaultContextVerifyingOperatorFactory { 25 | @Override 26 | public ButtonOperator createOperatorByIndex(int index) { 27 | return new ButtonOperator((ContainerOperator) Context.getContext(), index); 28 | } 29 | 30 | @Override 31 | public ButtonOperator createOperatorByName(String name) { 32 | return new ButtonOperator((ContainerOperator) Context.getContext(), new ByNameOrTextComponentChooser(name)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/checkbox/CheckBoxListOperatorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.checkbox; 18 | 19 | import java.awt.Component; 20 | 21 | import javax.swing.JCheckBox; 22 | 23 | import org.netbeans.jemmy.operators.Operator.Finder; 24 | import org.robotframework.swing.factory.OperatorsFactory; 25 | 26 | public class CheckBoxListOperatorFactory extends OperatorsFactory { 27 | public CheckBoxListOperatorFactory() { 28 | super(new Finder(JCheckBox.class), new CheckBoxOperatorFactory()); 29 | } 30 | 31 | private static class CheckBoxOperatorFactory implements ComponentBasedOperatorFactory { 32 | public CheckBoxOperator createOperator(Component component) { 33 | return new CheckBoxOperator((JCheckBox) component); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/checkbox/CheckBoxOperator.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.checkbox; 2 | 3 | import javax.swing.JCheckBox; 4 | 5 | import org.netbeans.jemmy.ComponentChooser; 6 | import org.netbeans.jemmy.operators.ContainerOperator; 7 | import org.netbeans.jemmy.operators.JCheckBoxOperator; 8 | import org.robotframework.swing.operator.ComponentWrapper; 9 | 10 | public class CheckBoxOperator extends JCheckBoxOperator implements ComponentWrapper { 11 | public CheckBoxOperator(ContainerOperator container, int index) { 12 | super(container, index); 13 | } 14 | 15 | public CheckBoxOperator(ContainerOperator container, ComponentChooser chooser) { 16 | super(container, chooser); 17 | } 18 | 19 | public CheckBoxOperator(JCheckBox source) { 20 | super(source); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/checkbox/CheckBoxOperatorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.checkbox; 18 | 19 | import org.netbeans.jemmy.operators.ContainerOperator; 20 | import org.robotframework.swing.chooser.ByNameOrTextComponentChooser; 21 | import org.robotframework.swing.context.Context; 22 | import org.robotframework.swing.factory.DefaultContextVerifyingOperatorFactory; 23 | 24 | public class CheckBoxOperatorFactory extends DefaultContextVerifyingOperatorFactory { 25 | public CheckBoxOperator createOperatorByIndex(int index) { 26 | return new CheckBoxOperator((ContainerOperator) Context.getContext(), index); 27 | } 28 | 29 | public CheckBoxOperator createOperatorByName(final String name) { 30 | return new CheckBoxOperator((ContainerOperator) Context.getContext(), new ByNameOrTextComponentChooser(name)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/chooser/ByNameComponentChooser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.chooser; 18 | 19 | import java.awt.Component; 20 | 21 | import org.netbeans.jemmy.ComponentChooser; 22 | import org.robotframework.swing.util.ObjectUtils; 23 | 24 | public class ByNameComponentChooser implements ComponentChooser { 25 | private final String componentName; 26 | 27 | public ByNameComponentChooser(String componentName) { 28 | this.componentName = componentName; 29 | } 30 | 31 | @Override 32 | public boolean checkComponent(Component comp) { 33 | return ObjectUtils.nullSafeEquals(comp.getName(), componentName); 34 | } 35 | 36 | @Override 37 | public String getDescription() { 38 | return componentName; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/chooser/ByNameOrTextComponentChooser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.chooser; 18 | 19 | import java.awt.Component; 20 | 21 | import org.netbeans.jemmy.ComponentChooser; 22 | 23 | public class ByNameOrTextComponentChooser implements ComponentChooser { 24 | private ComponentChooser byNameComponentChooser; 25 | private ComponentChooser byTextComponentChooser; 26 | private ComponentChooser byTooltipComponentChooser; 27 | 28 | public ByNameOrTextComponentChooser(String expectedNameOrText) { 29 | byNameComponentChooser = new ByNameComponentChooser(expectedNameOrText); 30 | byTextComponentChooser = new ByTextComponentChooser(expectedNameOrText); 31 | byTooltipComponentChooser = new ByTooltipComponentChooser(expectedNameOrText); 32 | } 33 | 34 | public boolean checkComponent(Component component) { 35 | return byNameComponentChooser.checkComponent(component) 36 | || byTextComponentChooser.checkComponent(component) 37 | || byTooltipComponentChooser.checkComponent(component); 38 | } 39 | 40 | public String getDescription() { 41 | return byNameComponentChooser.getDescription(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/chooser/ByTextComponentChooser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.chooser; 18 | 19 | import java.awt.Component; 20 | 21 | import org.jretrofit.Retrofit; 22 | import org.netbeans.jemmy.ComponentChooser; 23 | import org.robotframework.swing.util.ObjectUtils; 24 | 25 | public class ByTextComponentChooser implements ComponentChooser { 26 | private final String expectedText; 27 | 28 | public ByTextComponentChooser(String expectedText) { 29 | this.expectedText = expectedText; 30 | } 31 | 32 | @Override 33 | public boolean checkComponent(Component component) { 34 | WithText withText = (WithText) Retrofit.partial(component, 35 | WithText.class); 36 | return ObjectUtils.nullSafeEquals(expectedText, withText.getText()); 37 | } 38 | 39 | @Override 40 | public String getDescription() { 41 | return expectedText; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/chooser/ByTitleComponentChooser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.chooser; 18 | 19 | import java.awt.Component; 20 | 21 | import org.jretrofit.Retrofit; 22 | import org.netbeans.jemmy.ComponentChooser; 23 | import org.robotframework.swing.util.ObjectUtils; 24 | 25 | public class ByTitleComponentChooser implements ComponentChooser { 26 | private final String expectedTitle; 27 | 28 | public ByTitleComponentChooser(String expectedTitle) { 29 | this.expectedTitle = expectedTitle; 30 | } 31 | 32 | @Override 33 | public boolean checkComponent(Component component) { 34 | WithTitle withTitle = (WithTitle) Retrofit.partial(component, 35 | WithTitle.class); 36 | return ObjectUtils.nullSafeEquals(expectedTitle, withTitle.getTitle()); 37 | } 38 | 39 | @Override 40 | public String getDescription() { 41 | return expectedTitle; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/chooser/ByTooltipComponentChooser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.chooser; 18 | 19 | import org.jretrofit.Retrofit; 20 | import org.netbeans.jemmy.ComponentChooser; 21 | import org.robotframework.swing.util.ObjectUtils; 22 | 23 | import java.awt.*; 24 | 25 | public class ByTooltipComponentChooser implements ComponentChooser { 26 | private final String expectedText; 27 | 28 | public ByTooltipComponentChooser(String expectedText) { 29 | this.expectedText = expectedText; 30 | } 31 | 32 | @Override 33 | public boolean checkComponent(Component component) { 34 | WithTooltip withTooltip = (WithTooltip) Retrofit.partial(component, 35 | WithTooltip.class); 36 | return ObjectUtils.nullSafeEquals(expectedText, withTooltip.getToolTipText()); 37 | } 38 | 39 | @Override 40 | public String getDescription() { 41 | return expectedText; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/chooser/ListItemChooser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.chooser; 18 | 19 | import org.netbeans.jemmy.operators.JListOperator; 20 | import org.robotframework.swing.util.ObjectUtils; 21 | 22 | public class ListItemChooser implements 23 | org.netbeans.jemmy.operators.JListOperator.ListItemChooser { 24 | private final String name; 25 | 26 | public ListItemChooser(String itemIdentifier) { 27 | this.name = itemIdentifier; 28 | } 29 | 30 | @Override 31 | public boolean checkItem(JListOperator operator, int index) { 32 | String item = operator.getModel().getElementAt(index).toString(); 33 | return ObjectUtils.nullSafeEquals(name, item); 34 | } 35 | 36 | @Override 37 | public String getDescription() { 38 | return name; 39 | } 40 | } -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/chooser/WithText.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.chooser; 18 | 19 | public interface WithText { 20 | String getText(); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/chooser/WithTitle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.chooser; 18 | 19 | public interface WithTitle { 20 | String getTitle(); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/chooser/WithTooltip.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.chooser; 18 | 19 | public interface WithTooltip { 20 | String getToolTipText(); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/combobox/ComboBoxOperatorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.combobox; 18 | 19 | import org.netbeans.jemmy.operators.ContainerOperator; 20 | import org.netbeans.jemmy.operators.JComboBoxOperator; 21 | import org.robotframework.swing.chooser.ByNameComponentChooser; 22 | import org.robotframework.swing.context.Context; 23 | import org.robotframework.swing.factory.DefaultContextVerifyingOperatorFactory; 24 | 25 | public class ComboBoxOperatorFactory extends DefaultContextVerifyingOperatorFactory { 26 | public ComboBoxOperator createOperatorByIndex(int index) { 27 | JComboBoxOperator jComboboxOperator = new JComboBoxOperator((ContainerOperator) Context.getContext(), index); 28 | return new ComboBoxOperator(jComboboxOperator); 29 | } 30 | 31 | public ComboBoxOperator createOperatorByName(String name) { 32 | JComboBoxOperator jComboboxOperator = new JComboBoxOperator((ContainerOperator) Context.getContext(), new ByNameComponentChooser(name)); 33 | return new ComboBoxOperator(jComboboxOperator); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/combobox/ComboboxSelectedItemWaitable.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.combobox; 2 | 3 | import org.netbeans.jemmy.Waitable; 4 | import org.robotframework.swing.common.Identifier; 5 | 6 | public class ComboboxSelectedItemWaitable implements Waitable { 7 | 8 | private ComboBoxOperator comboboxOperator; 9 | private Identifier itemIdentifier; 10 | 11 | public ComboboxSelectedItemWaitable(ComboBoxOperator comboboxOperator, String itemIdentifier) { 12 | this.comboboxOperator = comboboxOperator; 13 | this.itemIdentifier = new Identifier(itemIdentifier); 14 | } 15 | 16 | /**@return The selected item or selected index, depending on the itemIdentifier.*/ 17 | public Object actionProduced(Object obj) { 18 | if (itemIdentifier.isIndex()) 19 | return new Integer(comboboxOperator.getComboboxOperator() 20 | .getSelectedIndex()); 21 | return comboboxOperator.getSelectedItem(); 22 | } 23 | 24 | public String getDescription() { 25 | return "Couldn't get the selected item from the combobox."; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/common/IdentifierSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.common; 18 | 19 | 20 | public class IdentifierSupport { 21 | 22 | public int asIndex(String identifier) { 23 | return Integer.parseInt(identifier); 24 | } 25 | 26 | public boolean isIndex(String identifier) { 27 | try { 28 | Integer.parseInt(identifier); 29 | } catch (NumberFormatException e) { 30 | return false; 31 | } 32 | return true; 33 | } 34 | 35 | public int extractIntArgument(String[] args) { 36 | return extractIntArgument(args, 1); 37 | } 38 | 39 | public int extractIntArgument(String[] args, int defaultValue) { 40 | if (args.length == 0) 41 | return defaultValue; 42 | return Integer.parseInt(args[0]); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/common/SmoothInvoker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | package org.robotframework.swing.common; 19 | 20 | import org.netbeans.jemmy.QueueTool; 21 | 22 | public abstract class SmoothInvoker { 23 | @SuppressWarnings("unchecked") 24 | public T invoke() { 25 | return (T) new QueueTool().invokeSmoothly(new QueueTool.QueueAction("Invoking smoothly") { 26 | public Object launch() throws Exception { 27 | return work(); 28 | } 29 | }); 30 | } 31 | 32 | public abstract Object work(); 33 | } -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/common/TimeoutCopier.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.common; 2 | 3 | import org.netbeans.jemmy.Timeouts; 4 | import org.netbeans.jemmy.operators.JComponentOperator; 5 | 6 | public class TimeoutCopier { 7 | 8 | private JComponentOperator operator; 9 | private String timeout; 10 | 11 | public TimeoutCopier(JComponentOperator operator, String timeout) { 12 | this.operator = operator; 13 | this.timeout = timeout; 14 | } 15 | 16 | public Timeouts getTimeouts() { 17 | Timeouts timeouts = operator.getTimeouts(); 18 | Timeouts times = timeouts.cloneThis(); 19 | times.setTimeout("Waiter.WaitingTime", timeouts.getTimeout(timeout)); 20 | return times; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/common/TimeoutName.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.common; 2 | 3 | public class TimeoutName { 4 | public static final String J_COMBOBOX_OPERATOR_WAIT_GET_SELECTED_ITEM_TIMEOUT = "JComboboxOperator.WaitGetSelectedItemTimeout"; 5 | public static final String J_LIST_OPERATOR_WAIT_FIND_ITEM_INDEX_TIMEOUT = "JListOperator.WaitFindItemIndexTimeout"; 6 | public static final String COMPONENT_OPERATOR_WAIT_STATE_TIMEOUT = "ComponentOperator.WaitStateTimeout"; 7 | public static final String COMPONENT_OPERATOR_WAIT_COMPONENT_ENABLED_TIMEOUT = "ComponentOperator.WaitComponentEnabledTimeout"; 8 | public static final String J_TREE_OPERATOR_WAIT_NODE_VISIBLE_TIMEOUT = "JTreeOperator.WaitNodeVisibleTimeout"; 9 | public static final String J_TREE_OPERATOR_WAIT_NEXT_NODE_TIMEOUT = "JTreeOperator.WaitNextNodeTimeout"; 10 | public static final String J_TREE_OPERATOR_WAIT_NODE_EXPANDED_TIMEOUT = "JTreeOperator.WaitNodeExpandedTimeout"; 11 | public static final String J_MENU_OPERATOR_WAIT_POPUP_TIMEOUT = "JMenuOperator.WaitPopupTimeout"; 12 | public static final String COMPONENT_OPERATOR_WAIT_COMPONENT_TIMEOUT = "ComponentOperator.WaitComponentTimeout"; 13 | public static final String WINDOW_WAITER_WAIT_WINDOW_TIMEOUT = "WindowWaiter.WaitWindowTimeout"; 14 | public static final String FRAME_WAITER_WAIT_FRAME_TIMEOUT = "FrameWaiter.WaitFrameTimeout"; 15 | public static final String DIALOG_WAITER_WAIT_DIALOG_TIMEOUT = "DialogWaiter.WaitDialogTimeout"; 16 | public static final String J_COMBO_BOX_OPERATOR_WAIT_LIST_TIMEOUT = "JComboBoxOperator.WaitListTimeout"; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/comparator/EqualsStringComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.comparator; 18 | 19 | import org.netbeans.jemmy.operators.Operator.DefaultStringComparator; 20 | import org.netbeans.jemmy.operators.Operator.StringComparator; 21 | 22 | public class EqualsStringComparator implements StringComparator { 23 | private DefaultStringComparator defaultStringComparator = new DefaultStringComparator(true, true); 24 | 25 | public boolean equals(String caption, String match) { 26 | return defaultStringComparator.equals(caption, match); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/component/ComponentOperatorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.component; 18 | 19 | import org.netbeans.jemmy.operators.ContainerOperator; 20 | import org.robotframework.swing.chooser.ByNameComponentChooser; 21 | import org.robotframework.swing.context.Context; 22 | import org.robotframework.swing.factory.DefaultContextVerifyingOperatorFactory; 23 | 24 | public class ComponentOperatorFactory extends DefaultContextVerifyingOperatorFactory { 25 | @Override 26 | public ComponentOperator createOperatorByIndex(int index) { 27 | return ComponentOperator.newOperatorFor(index); 28 | } 29 | 30 | @Override 31 | public ComponentOperator createOperatorByName(String name) { 32 | return ComponentOperator.newOperatorFor(name); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/context/AbstractContextVerifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.context; 18 | 19 | import java.awt.Component; 20 | 21 | import org.junit.Assert; 22 | 23 | public abstract class AbstractContextVerifier implements ContextVerifier { 24 | private final String errorMessage; 25 | 26 | public AbstractContextVerifier(String errorMessage) { 27 | this.errorMessage = errorMessage; 28 | } 29 | 30 | public void verifyContext() { 31 | Class[] expectedClasses = getExpectedClasses(); 32 | for (Class expectedClass : expectedClasses) { 33 | if (expectedClass.isAssignableFrom(contextClass())) { 34 | return; 35 | } 36 | } 37 | Assert.fail(errorMessage + " Current context is " + contextClass().getName()); 38 | } 39 | 40 | protected abstract Class[] getExpectedClasses(); 41 | 42 | private Class contextClass() { 43 | return Context.getContext().getSource().getClass(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/context/ContainerOperator.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.context; 2 | 3 | import org.netbeans.jemmy.ComponentChooser; 4 | import org.robotframework.swing.operator.ComponentWrapper; 5 | 6 | public class ContainerOperator extends org.netbeans.jemmy.operators.ContainerOperator implements ComponentWrapper { 7 | public ContainerOperator(org.netbeans.jemmy.operators.ContainerOperator container, int index) { 8 | super(container, index); 9 | } 10 | 11 | public ContainerOperator(org.netbeans.jemmy.operators.ContainerOperator container, ComponentChooser chooser) { 12 | super(container, chooser); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/context/ContainerOperatorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.context; 18 | 19 | import org.robotframework.swing.chooser.ByNameComponentChooser; 20 | import org.robotframework.swing.factory.IdentifierParsingOperatorFactory; 21 | 22 | public class ContainerOperatorFactory extends IdentifierParsingOperatorFactory { 23 | @Override 24 | public ContainerOperator createOperatorByIndex(int index) { 25 | return new ContainerOperator((org.netbeans.jemmy.operators.ContainerOperator) Context.getContext(), index); 26 | } 27 | 28 | @Override 29 | public ContainerOperator createOperatorByName(String name) { 30 | return new ContainerOperator((org.netbeans.jemmy.operators.ContainerOperator) Context.getContext(), new ByNameComponentChooser(name)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/context/Context.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.context; 18 | 19 | import org.robotframework.swing.operator.ComponentWrapper; 20 | 21 | public class Context { 22 | private static ComponentWrapper context; 23 | 24 | public static void setContext(ComponentWrapper operator) { 25 | context = operator; 26 | } 27 | 28 | public static ComponentWrapper getContext() { 29 | if (context == null) { 30 | throw new IllegalStateException("Context is not selected. Please select a context using 'Select Window' or 'Select Dialog' keyword."); 31 | } 32 | return context; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/context/ContextVerifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.context; 18 | 19 | public interface ContextVerifier { 20 | void verifyContext(); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/context/DefaultContextVerifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.context; 18 | 19 | import java.awt.Component; 20 | import java.awt.Panel; 21 | import java.awt.Window; 22 | 23 | import javax.swing.JInternalFrame; 24 | import javax.swing.JPanel; 25 | import javax.swing.JLayer; 26 | 27 | public class DefaultContextVerifier extends AbstractContextVerifier { 28 | static final String ERROR_MESSAGE = "To use this keyword you must first select a correct context. Please see e.g. \"Select Dialog\" -keyword."; 29 | 30 | public DefaultContextVerifier() { 31 | super(ERROR_MESSAGE); 32 | } 33 | 34 | @SuppressWarnings("unchecked") 35 | @Override 36 | protected Class[] getExpectedClasses() { 37 | return new Class[] { Window.class, JPanel.class, Panel.class, JInternalFrame.class, JLayer.class }; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/dialog/DialogOperatorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.dialog; 18 | 19 | import org.robotframework.swing.factory.IdentifierParsingOperatorFactory; 20 | 21 | public class DialogOperatorFactory extends IdentifierParsingOperatorFactory { 22 | public DialogOperator createOperatorByIndex(int index) { 23 | return DialogOperator.newOperatorFor(index); 24 | } 25 | 26 | public DialogOperator createOperatorByName(String name) { 27 | return DialogOperator.newOperatorFor(name); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/factory/ContextBasedOperatorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.factory; 18 | 19 | import org.netbeans.jemmy.operators.Operator; 20 | 21 | public interface ContextBasedOperatorFactory { 22 | T createOperatorFromContext(); 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/factory/DefaultContextVerifyingOperatorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.robotframework.swing.factory; 17 | 18 | import org.robotframework.swing.context.ContextVerifier; 19 | import org.robotframework.swing.context.DefaultContextVerifier; 20 | 21 | public abstract class DefaultContextVerifyingOperatorFactory extends IdentifierParsingOperatorFactory { 22 | private ContextVerifier contextVerifier = new DefaultContextVerifier(); 23 | 24 | @Override 25 | public T parseArgument(String argument) { 26 | contextVerifier.verifyContext(); 27 | return super.parseArgument(argument); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/factory/IdentifierParsingOperatorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.factory; 18 | 19 | import org.robotframework.swing.arguments.IdentifierHandler; 20 | 21 | public abstract class IdentifierParsingOperatorFactory 22 | extends IdentifierHandler implements OperatorFactory { 23 | 24 | public T createOperator(String identifier) { 25 | return parseArgument(identifier); 26 | } 27 | 28 | public T indexArgument(int index) { 29 | return createOperatorByIndex(index); 30 | } 31 | 32 | public T nameArgument(String name) { 33 | return createOperatorByName(name); 34 | } 35 | 36 | public abstract T createOperatorByName(String name); 37 | public abstract T createOperatorByIndex(int index); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/factory/OperatorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.factory; 18 | 19 | 20 | public interface OperatorFactory { 21 | T createOperator(String identifier); 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/filechooser/FileChooserOperatorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.robotframework.swing.filechooser; 17 | 18 | import org.netbeans.jemmy.operators.JFileChooserOperator; 19 | 20 | public class FileChooserOperatorFactory { 21 | public JFileChooserOperator createFileChooserOperator() { 22 | return new JFileChooserOperator(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/internalframe/InternalFrameOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.internalframe; 18 | 19 | import org.netbeans.jemmy.ComponentChooser; 20 | import org.netbeans.jemmy.operators.ContainerOperator; 21 | import org.netbeans.jemmy.operators.JInternalFrameOperator; 22 | import org.robotframework.swing.operator.ComponentWrapper; 23 | 24 | public class InternalFrameOperator extends JInternalFrameOperator implements ComponentWrapper { 25 | public InternalFrameOperator(ContainerOperator container, int index) { 26 | super(container, index); 27 | } 28 | 29 | public InternalFrameOperator(ContainerOperator container, ComponentChooser chooser) { 30 | super(container, chooser); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/internalframe/InternalFrameOperatorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | package org.robotframework.swing.internalframe; 19 | 20 | import org.netbeans.jemmy.operators.ContainerOperator; 21 | import org.robotframework.swing.chooser.ByTitleComponentChooser; 22 | import org.robotframework.swing.context.Context; 23 | import org.robotframework.swing.factory.DefaultContextVerifyingOperatorFactory; 24 | 25 | public class InternalFrameOperatorFactory extends DefaultContextVerifyingOperatorFactory { 26 | @Override 27 | public InternalFrameOperator createOperatorByIndex(int index) { 28 | return new InternalFrameOperator((ContainerOperator) Context.getContext(), index); 29 | } 30 | 31 | @Override 32 | public InternalFrameOperator createOperatorByName(String title) { 33 | return new InternalFrameOperator((ContainerOperator) Context.getContext(), new ByTitleComponentChooser(title)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/keyword/button/ButtonOperatorWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.keyword.button; 18 | 19 | import org.netbeans.jemmy.drivers.DriverManager; 20 | import org.robotframework.swing.button.ButtonOperator; 21 | 22 | public class ButtonOperatorWrapper { 23 | private final ButtonOperator buttonOperator; 24 | 25 | public ButtonOperatorWrapper(ButtonOperator buttonOperator) { 26 | this.buttonOperator = buttonOperator; 27 | } 28 | 29 | public void push() { 30 | waitButtonToBeEnabled(); 31 | pushButton(); 32 | } 33 | 34 | private void waitButtonToBeEnabled() { 35 | try { 36 | buttonOperator.waitComponentEnabled(); 37 | } catch (InterruptedException e) { 38 | throw new RuntimeException("Wait for buttion interrupted", e); 39 | } 40 | } 41 | 42 | private void pushButton() { 43 | DriverManager.getButtonDriver(buttonOperator).push(buttonOperator); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/keyword/textcomponent/EditorPaneKeywords.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | package org.robotframework.swing.keyword.textcomponent; 19 | 20 | import org.robotframework.javalib.annotation.ArgumentNames; 21 | import org.robotframework.javalib.annotation.RobotKeyword; 22 | import org.robotframework.javalib.annotation.RobotKeywords; 23 | import org.robotframework.swing.factory.OperatorFactory; 24 | import org.robotframework.swing.textcomponent.EditorPaneOperator; 25 | import org.robotframework.swing.textcomponent.EditorPaneOperatorFactory; 26 | 27 | @RobotKeywords 28 | public class EditorPaneKeywords { 29 | private OperatorFactory operatorFactory = new EditorPaneOperatorFactory(); 30 | 31 | @RobotKeyword("Clicks on a hyperlink in a JEditorPane.\n" 32 | + "Fails if the link is not found.\n\n" 33 | + "Example:\n" 34 | + "| `Click Hyperlink` | myEditor | Network Elements |\n") 35 | @ArgumentNames({"identifier", "linkText"}) 36 | public void clickHyperLink(String identifier, String linkText) { 37 | operatorFactory.createOperator(identifier).activateHyperLink(linkText); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/label/LabelOperator.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.label; 2 | 3 | import org.netbeans.jemmy.ComponentChooser; 4 | import org.netbeans.jemmy.operators.ContainerOperator; 5 | import org.netbeans.jemmy.operators.JLabelOperator; 6 | import org.robotframework.swing.operator.ComponentWrapper; 7 | 8 | public class LabelOperator extends JLabelOperator implements ComponentWrapper { 9 | public LabelOperator(ContainerOperator container, ComponentChooser chooser) { 10 | super(container, chooser); 11 | } 12 | 13 | public LabelOperator(ContainerOperator container, int index) { 14 | super(container, index); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/label/LabelOperatorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.label; 18 | 19 | import org.netbeans.jemmy.operators.ContainerOperator; 20 | import org.robotframework.swing.chooser.ByNameOrTextComponentChooser; 21 | import org.robotframework.swing.context.Context; 22 | import org.robotframework.swing.factory.DefaultContextVerifyingOperatorFactory; 23 | 24 | public class LabelOperatorFactory extends DefaultContextVerifyingOperatorFactory { 25 | public LabelOperator createOperatorByIndex(int index) { 26 | return new LabelOperator((ContainerOperator) Context.getContext(), index); 27 | } 28 | 29 | public LabelOperator createOperatorByName(String name) { 30 | return new LabelOperator((ContainerOperator) Context.getContext(), new ByNameOrTextComponentChooser(name)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/list/ListFindItemIndexWaitable.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.list; 2 | 3 | import org.netbeans.jemmy.Waitable; 4 | 5 | public class ListFindItemIndexWaitable implements Waitable { 6 | 7 | private String itemIdentifier; 8 | private CellTextExtractor itemTextExtractor; 9 | 10 | public ListFindItemIndexWaitable(CellTextExtractor itemTextExtractor, String itemIdentifier) { 11 | this.itemTextExtractor = itemTextExtractor; 12 | this.itemIdentifier = itemIdentifier; 13 | } 14 | 15 | public Object actionProduced(Object obj) { 16 | int index = findItemIndexWithRenderer(itemIdentifier); 17 | if (index == -1) 18 | return null; 19 | return new Integer(index); 20 | } 21 | 22 | private int findItemIndexWithRenderer(String expectedText) { 23 | for (int itemIndex = 0, itemCount = itemTextExtractor.itemCount(); itemIndex < itemCount; itemIndex++) { 24 | String text = itemTextExtractor.getTextFromRenderedComponent(itemIndex); 25 | if (expectedText.equals(text)) 26 | return itemIndex; 27 | } 28 | throw new RuntimeException("Couldn't find text '" + expectedText + "'"); 29 | } 30 | 31 | public String getDescription() { 32 | return "Couldn't find item: '"+itemIdentifier+"' from the list."; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/list/ListOperatorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.list; 18 | 19 | import org.netbeans.jemmy.operators.ContainerOperator; 20 | import org.robotframework.swing.chooser.ByNameComponentChooser; 21 | import org.robotframework.swing.context.Context; 22 | import org.robotframework.swing.factory.DefaultContextVerifyingOperatorFactory; 23 | 24 | public class ListOperatorFactory extends DefaultContextVerifyingOperatorFactory { 25 | @Override 26 | public ListOperator createOperatorByIndex(int index) { 27 | return new ListOperator((ContainerOperator) Context.getContext(), index); 28 | } 29 | 30 | @Override 31 | public ListOperator createOperatorByName(String name) { 32 | return new ListOperator((ContainerOperator) Context.getContext(), new ByNameComponentChooser(name)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/operator/ComponentWrapper.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.operator; 2 | 3 | import java.awt.Component; 4 | 5 | public interface ComponentWrapper { 6 | Component getSource(); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/popup/PopupCaller.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.popup; 18 | 19 | import java.awt.Point; 20 | 21 | import javax.swing.JPopupMenu; 22 | 23 | import org.netbeans.jemmy.operators.ComponentOperator; 24 | import org.netbeans.jemmy.operators.JPopupMenuOperator; 25 | import org.netbeans.jemmy.operators.Operator; 26 | 27 | public class PopupCaller { 28 | public JPopupMenu callPopupOnComponent(ComponentOperator componentOperator, Point pointToClick) { 29 | return JPopupMenuOperator.callPopup(componentOperator, pointToClick.x, pointToClick.y, Operator 30 | .getPopupMouseButton()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/slider/DefaultSliderOperator.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.slider; 2 | 3 | import org.netbeans.jemmy.operators.JSliderOperator; 4 | 5 | public class DefaultSliderOperator implements SliderOperator { 6 | 7 | private JSliderOperator sliderOperator; 8 | 9 | public DefaultSliderOperator(JSliderOperator sliderOperator) { 10 | this.sliderOperator = sliderOperator; 11 | } 12 | 13 | public int getValue() { 14 | return sliderOperator.getValue(); 15 | } 16 | 17 | public void setValue(int value) { 18 | sliderOperator.setValue(value); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/slider/SliderOperator.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.slider; 2 | 3 | public interface SliderOperator { 4 | int getValue(); 5 | void setValue(int value); 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/slider/SliderOperatorFactory.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.slider; 2 | 3 | import org.netbeans.jemmy.operators.ContainerOperator; 4 | import org.netbeans.jemmy.operators.JSliderOperator; 5 | import org.robotframework.swing.chooser.ByNameComponentChooser; 6 | import org.robotframework.swing.context.Context; 7 | import org.robotframework.swing.factory.DefaultContextVerifyingOperatorFactory; 8 | 9 | public class SliderOperatorFactory extends DefaultContextVerifyingOperatorFactory { 10 | 11 | @Override 12 | public SliderOperator createOperatorByIndex(int index) { 13 | return new DefaultSliderOperator(new JSliderOperator((ContainerOperator) Context.getContext(), index)); 14 | } 15 | 16 | @Override 17 | public SliderOperator createOperatorByName(String name) { 18 | return new DefaultSliderOperator(new JSliderOperator((ContainerOperator) Context.getContext(), new ByNameComponentChooser(name))); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/spinner/DefaultSpinnerOperator.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.spinner; 2 | 3 | import java.awt.Component; 4 | 5 | import org.netbeans.jemmy.operators.JSpinnerOperator; 6 | 7 | public class DefaultSpinnerOperator implements SpinnerOperator { 8 | private final JSpinnerOperator spinnerOperator; 9 | 10 | public DefaultSpinnerOperator(JSpinnerOperator spinnerOperator) { 11 | this.spinnerOperator = spinnerOperator; 12 | } 13 | 14 | public Component getSource() { 15 | return spinnerOperator.getSource(); 16 | } 17 | 18 | public Object getValue() { 19 | return spinnerOperator.getValue(); 20 | } 21 | 22 | public void setValue(Object value) { 23 | spinnerOperator.setValue(value); 24 | } 25 | 26 | public void decrease() { 27 | spinnerOperator.getDecreaseOperator().push(); 28 | } 29 | 30 | public void decreaseToMinimum() { 31 | spinnerOperator.scrollToMinimum(); 32 | } 33 | 34 | public void increase() { 35 | spinnerOperator.getIncreaseOperator().push(); 36 | } 37 | 38 | public void increaseToMaximum() { 39 | spinnerOperator.scrollToMaximum(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/spinner/SpinnerOperator.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.spinner; 2 | 3 | import org.robotframework.swing.operator.ComponentWrapper; 4 | 5 | public interface SpinnerOperator extends ComponentWrapper { 6 | Object getValue(); 7 | void setValue(Object value); 8 | void increase(); 9 | void increaseToMaximum(); 10 | void decrease(); 11 | void decreaseToMinimum(); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/spinner/SpinnerOperatorFactory.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.spinner; 2 | 3 | import org.netbeans.jemmy.operators.ContainerOperator; 4 | import org.netbeans.jemmy.operators.JSpinnerOperator; 5 | import org.robotframework.swing.chooser.ByNameComponentChooser; 6 | import org.robotframework.swing.context.Context; 7 | import org.robotframework.swing.factory.DefaultContextVerifyingOperatorFactory; 8 | 9 | public class SpinnerOperatorFactory extends DefaultContextVerifyingOperatorFactory { 10 | @Override 11 | public SpinnerOperator createOperatorByIndex(int index) { 12 | return new DefaultSpinnerOperator(new JSpinnerOperator((ContainerOperator) Context.getContext(), index)); 13 | } 14 | 15 | @Override 16 | public SpinnerOperator createOperatorByName(String name) { 17 | return new DefaultSpinnerOperator(new JSpinnerOperator((ContainerOperator) Context.getContext(), new ByNameComponentChooser(name))); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/tab/TabOperator.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.tab; 2 | 3 | import java.awt.Container; 4 | 5 | import org.robotframework.swing.operator.ComponentWrapper; 6 | 7 | public class TabOperator extends org.netbeans.jemmy.operators.ContainerOperator implements ComponentWrapper { 8 | public TabOperator(Container container) { 9 | super(container); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/table/AbstractTableCellChooser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.table; 18 | 19 | import org.netbeans.jemmy.operators.JTableOperator; 20 | import org.netbeans.jemmy.operators.JTableOperator.TableCellChooser; 21 | 22 | public abstract class AbstractTableCellChooser implements TableCellChooser { 23 | private final int expectedRow; 24 | 25 | public AbstractTableCellChooser(int row) { 26 | this.expectedRow = row; 27 | } 28 | 29 | public boolean checkCell(JTableOperator tableOperator, int actualRow, int column) { 30 | return expectedRow == actualRow && checkColumn(tableOperator, column); 31 | } 32 | 33 | public String getDescription() { 34 | return "Chooses table cell according to row index and column identifier"; 35 | } 36 | 37 | protected abstract boolean checkColumn(JTableOperator tableOperator, int column); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/table/ColumnIndexTableCellChooser.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.table; 2 | 3 | import org.netbeans.jemmy.operators.JTableOperator; 4 | 5 | 6 | public class ColumnIndexTableCellChooser extends AbstractTableCellChooser { 7 | private final int expectedColumn; 8 | 9 | public ColumnIndexTableCellChooser(int expectedRow, String expectedColumn) { 10 | super(expectedRow); 11 | this.expectedColumn = Integer.parseInt(expectedColumn); 12 | } 13 | 14 | @Override 15 | protected boolean checkColumn(JTableOperator tableOperator, int column) { 16 | return expectedColumn == column; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/table/ColumnNameTableCellChooser.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.table; 2 | 3 | import javax.swing.table.TableColumnModel; 4 | 5 | import org.netbeans.jemmy.operators.JTableOperator; 6 | import org.robotframework.swing.util.ObjectUtils; 7 | 8 | public class ColumnNameTableCellChooser extends AbstractTableCellChooser { 9 | private final String expectedColumnName; 10 | 11 | public ColumnNameTableCellChooser(int row, String expectedColumnName) { 12 | super(row); 13 | this.expectedColumnName = expectedColumnName; 14 | } 15 | 16 | @Override 17 | protected boolean checkColumn(JTableOperator tableOperator, int column) { 18 | TableColumnModel columnModel = tableOperator.getColumnModel(); 19 | Object actualColumnName = columnModel.getColumn(column) 20 | .getHeaderValue(); 21 | return ObjectUtils.nullSafeEquals(expectedColumnName, actualColumnName); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/table/InvalidCellException.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.table; 2 | 3 | public class InvalidCellException extends RuntimeException { 4 | private final int row; 5 | private final String columnIdentifier; 6 | 7 | public InvalidCellException(int row, String columnIdentifier) { 8 | this.row = row; 9 | this.columnIdentifier = columnIdentifier; 10 | } 11 | 12 | @Override 13 | public String getMessage() { 14 | return "The specified table cell (row: " + row + ", column: " + columnIdentifier + ") is invalid."; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/table/TableOperatorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.table; 18 | 19 | import org.netbeans.jemmy.operators.ContainerOperator; 20 | import org.netbeans.jemmy.operators.JTableOperator; 21 | import org.robotframework.swing.chooser.ByNameComponentChooser; 22 | import org.robotframework.swing.context.Context; 23 | import org.robotframework.swing.factory.DefaultContextVerifyingOperatorFactory; 24 | 25 | public class TableOperatorFactory extends DefaultContextVerifyingOperatorFactory { 26 | public TableOperator createOperatorByIndex(int index) { 27 | return new TableOperator(new JTableOperator((ContainerOperator) Context.getContext(), index)); 28 | } 29 | 30 | public TableOperator createOperatorByName(String name) { 31 | return new TableOperator(new JTableOperator((ContainerOperator) Context.getContext(), new ByNameComponentChooser(name))); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testapp/ContextMenu.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.testapp; 2 | 3 | import java.awt.Component; 4 | import java.awt.event.ActionEvent; 5 | import java.awt.event.ActionListener; 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | import javax.swing.JMenuItem; 10 | import javax.swing.JPopupMenu; 11 | 12 | public class ContextMenu extends JPopupMenu implements ActionListener { 13 | private static final Map commands = new HashMap(); 14 | private volatile Component operatedComponent = null; 15 | 16 | public ContextMenu() { 17 | setOpaque(true); 18 | setLightWeightPopupEnabled(true); 19 | setName("contextMenu"); 20 | } 21 | 22 | public ContextMenu add(String text, Operation command) { 23 | add(new ContextMenuItem(text, command)); 24 | return this; 25 | } 26 | 27 | @Override 28 | public void show(Component invoker, int x, int y) { 29 | Delay.delay(); 30 | operatedComponent = invoker; 31 | super.show(invoker, x, y); 32 | } 33 | 34 | public void actionPerformed(ActionEvent e) { 35 | String command = e.getActionCommand(); 36 | commands.get(command).perform(operatedComponent); 37 | } 38 | 39 | private class ContextMenuItem extends JMenuItem { 40 | public ContextMenuItem(String text, Operation command) { 41 | super(text); 42 | setName(text.toUpperCase()); 43 | addActionListener(ContextMenu.this); 44 | setActionCommand(text); 45 | commands.put(text, command); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testapp/Delay.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | package org.robotframework.swing.testapp; 19 | 20 | public class Delay { 21 | public static long delayTimeMillis = 0; 22 | public static boolean randomEnabled = false; 23 | 24 | public static void delay() { 25 | try { 26 | Thread.sleep(getDelay()); 27 | } catch (InterruptedException e) { 28 | throw new RuntimeException(e); 29 | } 30 | } 31 | private static long getDelay() { 32 | return (long) (getRandom() * delayTimeMillis); 33 | } 34 | 35 | private static double getRandom() { 36 | if (randomEnabled) 37 | return Math.random(); 38 | return 1; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testapp/MenuItemWithCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.testapp; 18 | 19 | import java.awt.event.ActionEvent; 20 | import java.awt.event.ActionListener; 21 | 22 | import javax.swing.JMenuItem; 23 | 24 | import org.robotframework.javalib.util.KeywordNameNormalizer; 25 | 26 | public class MenuItemWithCommand extends JMenuItem implements ActionListener { 27 | public MenuItemWithCommand(String text) { 28 | super(text); 29 | setName(new KeywordNameNormalizer().normalize(text)); 30 | addActionListener(this); 31 | } 32 | 33 | public void actionPerformed(ActionEvent e) { 34 | throw new UnsupportedOperationException("Not implemented."); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testapp/Operation.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.testapp; 2 | 3 | import java.awt.Component; 4 | 5 | public interface Operation { 6 | void perform(Component operatedComponent); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testapp/TestButton.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.testapp; 2 | 3 | import java.awt.event.MouseAdapter; 4 | import java.awt.event.MouseEvent; 5 | import java.awt.event.ActionEvent; 6 | 7 | import javax.swing.JButton; 8 | 9 | public class TestButton extends JButton { 10 | private static final String INITIAL_TEXT = "Test Button"; 11 | private static final String BUTTON_PUSHED_TEXT = "Button Was Pushed"; 12 | private static final String RIGHT_CLICKED_TEXT = "Right Clicked"; 13 | private static final String CLICK_SHIFT_TEXT = "Click With Shift"; 14 | 15 | public TestButton() { 16 | super(INITIAL_TEXT); 17 | setName("testButton"); 18 | setToolTipText("testToolTip"); 19 | addMouseListener(new MouseAdapter() { 20 | @Override 21 | public void mouseClicked(MouseEvent e) { 22 | if (e.getButton() == MouseEvent.BUTTON1) 23 | setText(BUTTON_PUSHED_TEXT + e.getClickCount()); 24 | if(e.getButton() == MouseEvent.BUTTON1 && e.isShiftDown()) 25 | setText(CLICK_SHIFT_TEXT); 26 | if (e.getButton() == MouseEvent.BUTTON3) 27 | setText(RIGHT_CLICKED_TEXT); 28 | } 29 | }); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testapp/TestCheckBox.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.testapp; 2 | 3 | import javax.swing.JCheckBox; 4 | 5 | public class TestCheckBox extends JCheckBox { 6 | public TestCheckBox(String text) { 7 | super(text); 8 | setName(withoutSpaces(text)); 9 | } 10 | 11 | private String withoutSpaces(String text) { 12 | StringBuilder textWithoutSpaces = new StringBuilder(); 13 | for (String piece : text.split(" ")) { 14 | textWithoutSpaces.append(piece); 15 | } 16 | return textWithoutSpaces.toString(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testapp/TestComboBox.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.testapp; 2 | 3 | import javax.swing.JComboBox; 4 | 5 | public class TestComboBox extends JComboBox { 6 | private static final String[] ENTRIES = new String[] { "one", "two", "three" }; 7 | 8 | public TestComboBox() { 9 | super(ENTRIES); 10 | setName("testComboBox"); 11 | setEditable(true); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testapp/TestDesktopPane.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | package org.robotframework.swing.testapp; 19 | 20 | import java.awt.Dimension; 21 | 22 | import javax.swing.JDesktopPane; 23 | import javax.swing.JInternalFrame; 24 | 25 | public class TestDesktopPane extends JDesktopPane { 26 | public static final TestDesktopPane INSTANCE = new TestDesktopPane(); 27 | private JInternalFrame internalFrame = new JInternalFrame("Test Internal Frame", 28 | true, true, true, true) {{ 29 | setSize(300, 150); 30 | setName("testInternalFrame"); 31 | setDefaultCloseOperation(HIDE_ON_CLOSE); 32 | }}; 33 | 34 | private TestDesktopPane() { 35 | setName("testDesktopPane"); 36 | add(internalFrame); 37 | } 38 | 39 | public void showInternalFrame() { 40 | internalFrame.setVisible(true); 41 | } 42 | 43 | @Override 44 | public Dimension getPreferredSize() { 45 | return new Dimension(1000, 300); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testapp/TestEditorPane.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.testapp; 2 | 3 | import javax.swing.JEditorPane; 4 | import javax.swing.event.HyperlinkEvent; 5 | import javax.swing.event.HyperlinkListener; 6 | 7 | public class TestEditorPane extends JEditorPane { 8 | public static boolean clicked = false; 9 | public static String eventDescription; 10 | 11 | private static String HTML = "" + 12 | " " + 13 | " " + 14 | " " + 15 | " Apply this rule after an event arrives
       from Network" + 16 | " Elements" + 17 | " " + 18 | ""; 19 | 20 | public TestEditorPane() { 21 | setName("testEditorPane"); 22 | setEditable(false); 23 | setContentType("text/html"); 24 | setText(HTML); 25 | addHyperlinkListener(new HyperlinkListener() { 26 | public void hyperlinkUpdate(HyperlinkEvent e) { 27 | if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { 28 | clicked = true; 29 | eventDescription = e.getDescription(); 30 | } 31 | } 32 | }); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testapp/TestFastUpdatingPane.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.testapp; 2 | 3 | import javax.swing.*; 4 | import javax.swing.Timer; 5 | import java.awt.*; 6 | import java.awt.event.ActionEvent; 7 | import java.awt.event.ActionListener; 8 | 9 | // The point of this class is to spam the event queue constantly. This prevents 10 | // simply waiting forever for the queue to be empty. 11 | public class TestFastUpdatingPane extends JScrollPane { 12 | 13 | public TestFastUpdatingPane() { 14 | super(); 15 | setName("testFastUpdatingPane"); 16 | setPreferredSize(new Dimension(40, 40)); 17 | JPanel content = new JPanel(new GridLayout(0,1)); 18 | // We need some content to replicate problem wait jemmy.EventTool.waitNoEvent( 19 | content.add(new JComboBox(new String[]{"filler", "b", "c"})); 20 | setViewportView(content); 21 | registerUpdater(); 22 | } 23 | 24 | public void increaseTicker() { 25 | Color color = getBackground(); 26 | if (!color.equals(Color.black)) 27 | color = Color.black; 28 | else 29 | color = Color.white; 30 | setBackground(color); 31 | repaint(); 32 | } 33 | 34 | public void registerUpdater() { 35 | ActionListener updateClockAction = new ActionListener() { 36 | public void actionPerformed(ActionEvent e) { 37 | increaseTicker(); 38 | } 39 | }; 40 | Timer t = new Timer(100, updateClockAction); 41 | t.start(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testapp/TestFileChooser.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.testapp; 2 | 3 | import java.io.File; 4 | 5 | import javax.swing.JFileChooser; 6 | 7 | public class TestFileChooser extends JFileChooser { 8 | public static String selectedFilePath; 9 | public static boolean cancelled = false; 10 | 11 | public TestFileChooser() { 12 | super(new File(System.getProperty("java.io.tmpdir"))); 13 | setName("testFileChooser"); 14 | setSelectedFile(new File("someFile.txt")); 15 | } 16 | 17 | @Override 18 | public void approveSelection() { 19 | super.approveSelection(); 20 | cancelled = false; 21 | File selected = super.getSelectedFile(); 22 | if (selected != null) { 23 | selectedFilePath = selected.getAbsolutePath(); 24 | } 25 | } 26 | 27 | @Override 28 | public void cancelSelection() { 29 | super.cancelSelection(); 30 | cancelled = true; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testapp/TestLabel.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.testapp; 2 | 3 | import javax.swing.JLabel; 4 | 5 | public class TestLabel extends JLabel { 6 | public TestLabel() { 7 | super("Test Label"); 8 | setName("testLabel"); 9 | setToolTipText("TEST LABEL"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testapp/TestList.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.testapp; 2 | 3 | import java.awt.Dimension; 4 | import java.awt.event.MouseAdapter; 5 | import java.awt.event.MouseEvent; 6 | 7 | import javax.swing.JList; 8 | 9 | @WithPopup 10 | public class TestList extends JList { 11 | private static Object[] items = new Object[] { "one", "two", "three" }; 12 | 13 | public TestList() { 14 | super(items); 15 | setName("testList"); 16 | setPreferredSize(new Dimension(50, 50)); 17 | addMouseListener(new MouseAdapter() { 18 | public void mouseClicked(MouseEvent e) { 19 | int index = locationToIndex(e.getPoint()); 20 | Object selectedElement = getModel().getElementAt(index); 21 | TestListResults.selectedElement = selectedElement; 22 | TestListResults.clickCount = e.getClickCount(); 23 | } 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testapp/TestListResults.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.robotframework.swing.testapp; 17 | 18 | 19 | public class TestListResults { 20 | public static Object selectedElement; 21 | public static int clickCount; 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testapp/TestNonModalDialog.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.testapp; 2 | 3 | import java.awt.Component; 4 | 5 | import javax.swing.JDialog; 6 | import javax.swing.JOptionPane; 7 | 8 | public class TestNonModalDialog { 9 | 10 | private Component parent; 11 | 12 | public TestNonModalDialog() {} 13 | 14 | public void showDialog() { 15 | JOptionPane pane = new JOptionPane("Push the OK button!", JOptionPane.INFORMATION_MESSAGE); 16 | JDialog dialog = pane.createDialog(parent, "Non-modal Dialog"); 17 | dialog.setModal(false); 18 | dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); 19 | dialog.setVisible(true); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testapp/TestRadioButton.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.testapp; 2 | 3 | import java.util.Enumeration; 4 | 5 | import javax.swing.AbstractButton; 6 | import javax.swing.ButtonGroup; 7 | import javax.swing.JPanel; 8 | import javax.swing.JRadioButton; 9 | 10 | public class TestRadioButton extends JPanel { 11 | public TestRadioButton() { 12 | ButtonGroup buttonGroup = new ButtonGroup() {{ 13 | add(new JRadioButton("One") {{ setName("one"); }}); 14 | add(new JRadioButton("Two") {{ setName("two"); }}); 15 | add(new JRadioButton("Three") {{ setName("three"); }}); 16 | }}; 17 | 18 | Enumeration elements = buttonGroup.getElements(); 19 | while (elements.hasMoreElements()) 20 | add(elements.nextElement()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testapp/TestScrollPane.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.testapp; 2 | 3 | import javax.swing.JComboBox; 4 | import javax.swing.JPanel; 5 | import javax.swing.JScrollPane; 6 | import java.awt.Dimension; 7 | import java.awt.GridLayout; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | public class TestScrollPane extends JScrollPane { 12 | 13 | public TestScrollPane() { 14 | super(); 15 | setName("testList"); 16 | setPreferredSize(new Dimension(100, 100)); 17 | java.util.List comboList = getCombos(10); 18 | JPanel combos = new JPanel(new GridLayout(0,1)); 19 | for (JComboBox combo:comboList) 20 | combos.add(combo); 21 | setViewportView(combos); 22 | setName("ScrollPaneWithComboBoxes"); 23 | } 24 | 25 | private List getCombos(int count) { 26 | List results = new ArrayList(count); 27 | for (int i=0;i nodes = new ArrayList(); 10 | public static int clickCount; 11 | public static void saveNodes(TreePath[] selectionPaths) { 12 | nodes.clear(); 13 | for (TreePath treePath : selectionPaths) { 14 | nodes.add(treePath.getLastPathComponent().toString().toLowerCase()); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testapp/WithPopup.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.testapp; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target(ElementType.TYPE) 10 | public @interface WithPopup { 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testapp/extension/ExtendedSwingLibrary.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | package org.robotframework.swing.testapp.extension; 19 | 20 | import java.util.Arrays; 21 | 22 | import org.robotframework.swing.SwingLibrary; 23 | 24 | public class ExtendedSwingLibrary extends SwingLibrary { 25 | public ExtendedSwingLibrary() { 26 | super(Arrays.asList("com/some/own/keyword/*.class", "org/robotframework/swing/testkeyword/**/*.class")); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testapp/extension/ExtendedSwingLibrary2.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.testapp.extension; 2 | 3 | 4 | public class ExtendedSwingLibrary2 extends ExtendedSwingLibrary { 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testapp/keyword/testapp/SomeApplication.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.testapp.keyword.testapp; 2 | 3 | import org.junit.Assert; 4 | import org.robotframework.javalib.annotation.RobotKeywords; 5 | import org.robotframework.swing.testapp.keyword.testapp.SomeApplication; 6 | 7 | @RobotKeywords 8 | public class SomeApplication { 9 | public static String[] args; 10 | public static boolean wasCalled = false; 11 | 12 | public static String[] getLastUsedArguments() { 13 | return args; 14 | } 15 | 16 | public static void main(String[] args) { 17 | wasCalled = true; 18 | SomeApplication.args = args; 19 | } 20 | 21 | public void assertApplicationWasCalled() { 22 | Assert.assertTrue(wasCalled); 23 | } 24 | 25 | public String[] getReceivedArguments() { 26 | return args; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testkeyword/ApplicationLaunchingTestingKeywords.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | package org.robotframework.swing.testkeyword; 19 | 20 | import org.junit.Assert; 21 | 22 | import org.robotframework.javalib.annotation.RobotKeyword; 23 | import org.robotframework.javalib.annotation.RobotKeywords; 24 | import org.robotframework.swing.testapp.keyword.testapp.SomeApplication; 25 | 26 | @RobotKeywords 27 | public class ApplicationLaunchingTestingKeywords { 28 | @RobotKeyword 29 | public void assertApplicationWasCalled() { 30 | Assert.assertTrue(true); 31 | if (!SomeApplication.wasCalled) { 32 | throw new AssertionError("Application was not called"); 33 | } 34 | } 35 | 36 | @RobotKeyword 37 | public String[] getReceivedArguments() { 38 | return SomeApplication.args; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testkeyword/ButtonTestingKeywords.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.testkeyword; 2 | 3 | import org.robotframework.javalib.annotation.RobotKeyword; 4 | import org.robotframework.javalib.annotation.RobotKeywords; 5 | import org.robotframework.swing.button.ButtonOperatorFactory; 6 | 7 | 8 | @RobotKeywords 9 | public class ButtonTestingKeywords { 10 | private ButtonOperatorFactory operatorFactory = new ButtonOperatorFactory(); 11 | 12 | @RobotKeyword 13 | public void setButtonText(String identifier, String newText) { 14 | operatorFactory.createOperator(identifier).setText(newText); 15 | } 16 | 17 | @RobotKeyword 18 | public void disableButton(String identifier) { 19 | operatorFactory.createOperator(identifier).setEnabled(false); 20 | } 21 | 22 | @RobotKeyword 23 | public void enableButton(String identifier) { 24 | operatorFactory.createOperator(identifier).setEnabled(true); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testkeyword/CheckboxTestingKeywords.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.testkeyword; 18 | 19 | import org.robotframework.javalib.annotation.RobotKeyword; 20 | import org.robotframework.javalib.annotation.RobotKeywords; 21 | import org.robotframework.swing.checkbox.CheckBoxOperator; 22 | import org.robotframework.swing.checkbox.CheckBoxOperatorFactory; 23 | 24 | @RobotKeywords 25 | public class CheckboxTestingKeywords { 26 | @RobotKeyword 27 | public void disableCheckbox(String identifier) { 28 | createOperator(identifier).setEnabled(false); 29 | } 30 | 31 | @RobotKeyword 32 | public void enableCheckbox(String identifier) { 33 | createOperator(identifier).setEnabled(true); 34 | } 35 | 36 | private CheckBoxOperator createOperator(String identifier) { 37 | return new CheckBoxOperatorFactory().createOperator(identifier); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testkeyword/ComboBoxTestingKeywords.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.testkeyword; 2 | 3 | import org.netbeans.jemmy.operators.ContainerOperator; 4 | import org.netbeans.jemmy.operators.JComboBoxOperator; 5 | import org.robotframework.javalib.annotation.RobotKeyword; 6 | import org.robotframework.javalib.annotation.RobotKeywords; 7 | import org.robotframework.swing.chooser.ByNameOrTextComponentChooser; 8 | import org.robotframework.swing.context.Context; 9 | 10 | @RobotKeywords 11 | public class ComboBoxTestingKeywords { 12 | @RobotKeyword 13 | public void disableCombobox(String identifier) { 14 | createOperator(identifier).setEnabled(false); 15 | } 16 | 17 | @RobotKeyword 18 | public void enableCombobox(String identifier) { 19 | createOperator(identifier).setEnabled(true); 20 | } 21 | 22 | @RobotKeyword 23 | public String getComboboxText(String identifier) { 24 | return createOperator(identifier).getTextField().getText(); 25 | } 26 | 27 | private JComboBoxOperator createOperator(String identifier) { 28 | return new JComboBoxOperator((ContainerOperator) Context.getContext(), new ByNameOrTextComponentChooser(identifier)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testkeyword/EditorPaneTestingKeywords.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.testkeyword; 2 | 3 | import org.junit.Assert; 4 | import org.robotframework.javalib.annotation.RobotKeyword; 5 | import org.robotframework.javalib.annotation.RobotKeywords; 6 | import org.robotframework.swing.testapp.TestEditorPane; 7 | 8 | @RobotKeywords 9 | public class EditorPaneTestingKeywords { 10 | @RobotKeyword 11 | public void linkShouldHaveBeenClicked() { 12 | Assert.assertTrue("Link was not clicked", TestEditorPane.clicked); 13 | } 14 | 15 | @RobotKeyword 16 | public void hyperLinkEventDescriptionShouldBe(String expectedDescription) { 17 | Assert.assertEquals(expectedDescription, TestEditorPane.eventDescription); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testkeyword/FileChooserTestingKeywords.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.robotframework.swing.testkeyword; 17 | 18 | import org.junit.Assert; 19 | import java.io.File; 20 | 21 | import org.robotframework.javalib.annotation.RobotKeyword; 22 | import org.robotframework.javalib.annotation.RobotKeywords; 23 | import org.robotframework.swing.testapp.TestFileChooser; 24 | 25 | @RobotKeywords 26 | public class FileChooserTestingKeywords { 27 | @RobotKeyword 28 | public void fileChooserShouldHaveBeenCancelled() { 29 | Assert.assertTrue(TestFileChooser.cancelled); 30 | } 31 | 32 | @RobotKeyword 33 | public void selectedFileShouldBe(String expectedFile) { 34 | File expected = new File(expectedFile); 35 | File selected = new File(TestFileChooser.selectedFilePath); 36 | if (!expected.equals(selected)) 37 | throw new RuntimeException("Paths are not equal "+expected+" != "+selected); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testkeyword/ListTestingKeywords.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.testkeyword; 2 | 3 | import org.netbeans.jemmy.operators.ContainerOperator; 4 | import org.netbeans.jemmy.operators.JListOperator; 5 | import org.robotframework.javalib.annotation.RobotKeyword; 6 | import org.robotframework.javalib.annotation.RobotKeywords; 7 | import org.robotframework.swing.context.Context; 8 | import org.robotframework.swing.testapp.TestListResults; 9 | 10 | @RobotKeywords 11 | public class ListTestingKeywords { 12 | @RobotKeyword 13 | public Object getListSelection() { 14 | return TestListResults.selectedElement; 15 | } 16 | 17 | @RobotKeyword 18 | public int getSelectionClickCount() { 19 | return TestListResults.clickCount; 20 | } 21 | 22 | @RobotKeyword 23 | public Object[] getSelectedValues(String index) { 24 | JListOperator operator = new JListOperator((ContainerOperator) Context.getContext(), Integer.parseInt(index)); 25 | return operator.getSelectedValues(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testkeyword/RadioButtonTestingKeywords.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.testkeyword; 2 | 3 | import org.netbeans.jemmy.operators.ContainerOperator; 4 | import org.netbeans.jemmy.operators.JRadioButtonOperator; 5 | import org.robotframework.javalib.annotation.RobotKeyword; 6 | import org.robotframework.javalib.annotation.RobotKeywords; 7 | import org.robotframework.swing.chooser.ByNameOrTextComponentChooser; 8 | import org.robotframework.swing.context.Context; 9 | 10 | @RobotKeywords 11 | public class RadioButtonTestingKeywords { 12 | @RobotKeyword 13 | public void enableRadioButton(String identifier) { 14 | JRadioButtonOperator operator = createOperator(identifier); 15 | operator.setEnabled(true); 16 | } 17 | 18 | @RobotKeyword 19 | public void disableRadioButton(String identifier) { 20 | JRadioButtonOperator operator = createOperator(identifier); 21 | operator.setEnabled(false); 22 | } 23 | 24 | private JRadioButtonOperator createOperator(String nameOrText) { 25 | return new JRadioButtonOperator((ContainerOperator) Context.getContext(), new ByNameOrTextComponentChooser(nameOrText)); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testkeyword/RecordStdOut.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.testkeyword; 2 | 3 | import org.robotframework.javalib.util.StdStreamRedirecter; 4 | 5 | public class RecordStdOut extends RunnerKeyword { 6 | protected Object executeKeyword() { 7 | StdStreamRedirecter stdStreamRedirecterImpl = new StdStreamRedirecter(); 8 | stdStreamRedirecterImpl.redirectStdStreams(); 9 | 10 | runKeyword(); 11 | 12 | String stdout = stdStreamRedirecterImpl.getStdOutAsString(); 13 | stdStreamRedirecterImpl.resetStdStreams(); 14 | 15 | return stdout; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testkeyword/RunnerKeyword.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.testkeyword; 2 | 3 | import org.robotframework.javalib.keyword.Keyword; 4 | import org.robotframework.javalib.library.AnnotationLibrary; 5 | import org.robotframework.javalib.library.RobotFrameworkDynamicAPI; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | public abstract class RunnerKeyword implements Keyword { 12 | private List arguments; 13 | private Map kwargs; 14 | private RobotFrameworkDynamicAPI library = new AnnotationLibrary() {{ 15 | addKeywordPattern("org/robotframework/**/keyword/**/*.class"); 16 | }}; 17 | 18 | public Object execute(List arguments) { 19 | this.arguments = arguments; 20 | return executeKeyword(); 21 | } 22 | 23 | public Object execute(List arguments, Map kwargs) { 24 | this.arguments = arguments; 25 | this.kwargs = kwargs; 26 | return executeKeyword(); 27 | } 28 | 29 | protected Object runKeyword() { 30 | return library.runKeyword(arguments.get(0), removeFirstArgument(arguments)); 31 | } 32 | 33 | private List removeFirstArgument(List arguments) { 34 | List newArgList = new ArrayList<>(); 35 | newArgList.addAll(arguments); 36 | newArgList.remove(0); 37 | return newArgList; 38 | } 39 | 40 | protected abstract Object executeKeyword(); 41 | 42 | public List getArgumentTypes() { 43 | return null; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testkeyword/TestingKeywords.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.testkeyword; 2 | 3 | import java.awt.Component; 4 | import java.awt.Container; 5 | 6 | import org.netbeans.jemmy.operators.ContainerOperator; 7 | import org.robotframework.javalib.annotation.RobotKeyword; 8 | import org.robotframework.javalib.annotation.RobotKeywords; 9 | import org.robotframework.swing.context.Context; 10 | import org.robotframework.swing.operator.ComponentWrapper; 11 | import org.robotframework.swing.testapp.Delay; 12 | 13 | 14 | @RobotKeywords 15 | public class TestingKeywords { 16 | @RobotKeyword 17 | public void selectEmptyContext() { 18 | final Container container = new Container(); 19 | Context.setContext(new ComponentWrapper() { 20 | public Component getSource() { 21 | return container; 22 | } 23 | }); 24 | } 25 | 26 | @RobotKeyword 27 | public String getCurrentContextSourceAsString() { 28 | return ((ContainerOperator) Context.getContext()).toStringSource(); 29 | } 30 | 31 | @RobotKeyword 32 | public void setDelay(String delayStr) { 33 | Delay.delayTimeMillis = Long.parseLong(delayStr); 34 | } 35 | 36 | @RobotKeyword 37 | public void randomizeDelay() { 38 | Delay.randomEnabled = true; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testkeyword/TextfieldTestingKeywords.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.testkeyword; 2 | 3 | import org.robotframework.javalib.annotation.RobotKeyword; 4 | import org.robotframework.javalib.annotation.RobotKeywords; 5 | import org.robotframework.swing.textcomponent.TextComponentOperator; 6 | import org.robotframework.swing.textcomponent.TextComponentOperatorFactory; 7 | 8 | @RobotKeywords 9 | public class TextfieldTestingKeywords { 10 | @RobotKeyword 11 | public void disableTextField(String identifier) { 12 | createOperator(identifier).setEnabled(false); 13 | } 14 | 15 | @RobotKeyword 16 | public void enableTextField(String identifier) { 17 | createOperator(identifier).setEnabled(true); 18 | } 19 | 20 | @RobotKeyword 21 | public void selectTextFieldContents(String identifier) { 22 | TextComponentOperator textFieldOperator = createOperator(identifier); 23 | textFieldOperator.makeComponentVisible(); 24 | textFieldOperator.selectAll(); 25 | } 26 | 27 | private TextComponentOperator createOperator(String identifier) { 28 | return new TextComponentOperatorFactory().createOperator(identifier); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testkeyword/ThreadTestingKeywords.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.testkeyword; 2 | 3 | import org.junit.Assert; 4 | 5 | import org.robotframework.javalib.annotation.RobotKeyword; 6 | import org.robotframework.javalib.annotation.RobotKeywords; 7 | 8 | @RobotKeywords 9 | public class ThreadTestingKeywords { 10 | private static Thread originalThread = Thread.currentThread(); 11 | private static boolean keywordWasRun = false; 12 | 13 | @RobotKeyword 14 | public Boolean shouldBeRunInSeparateThread() { 15 | keywordWasRun = true; 16 | Assert.assertNotSame(originalThread, Thread.currentThread()); 17 | return Boolean.TRUE; 18 | } 19 | 20 | @RobotKeyword 21 | public void keywordWasRun() { 22 | Assert.assertTrue("Keyword was not run", keywordWasRun); 23 | keywordWasRun = false; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/testkeyword/ToggleButtonTestingKeywords.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.testkeyword; 2 | 3 | import org.netbeans.jemmy.operators.ContainerOperator; 4 | import org.netbeans.jemmy.operators.JToggleButtonOperator; 5 | import org.robotframework.javalib.annotation.RobotKeyword; 6 | import org.robotframework.javalib.annotation.RobotKeywords; 7 | import org.robotframework.swing.chooser.ByNameComponentChooser; 8 | import org.robotframework.swing.context.Context; 9 | 10 | @RobotKeywords 11 | public class ToggleButtonTestingKeywords { 12 | @RobotKeyword 13 | public void selectToggleButton(String identifier) { 14 | createToggleButtonOperator(identifier).changeSelection(true); 15 | } 16 | 17 | @RobotKeyword 18 | public void unSelectToggleButton(String identifier) { 19 | createToggleButtonOperator(identifier).changeSelection(false); 20 | } 21 | 22 | private JToggleButtonOperator createToggleButtonOperator(String identifier) { 23 | return new JToggleButtonOperator((ContainerOperator) Context.getContext(), new ByNameComponentChooser(identifier)); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/textcomponent/AWTTextComponentOperator.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.textcomponent; 2 | 3 | import org.netbeans.jemmy.ComponentChooser; 4 | import org.netbeans.jemmy.operators.ContainerOperator; 5 | import org.robotframework.swing.operator.ComponentWrapper; 6 | 7 | 8 | public class AWTTextComponentOperator extends org.netbeans.jemmy.operators.TextComponentOperator implements ComponentWrapper { 9 | public AWTTextComponentOperator(ContainerOperator container, int index) { 10 | super(container, index); 11 | } 12 | 13 | public AWTTextComponentOperator(ContainerOperator container, ComponentChooser chooser) { 14 | super(container, chooser); 15 | } 16 | 17 | /* 18 | * We want to let the application do whatever it wants with the inputs the textfield receives. 19 | */ 20 | @Override 21 | public boolean getVerification() { 22 | return false; 23 | } 24 | 25 | /** 26 | * For whatever reason clearText fails on AWT component, if the component is not shown on screen. 27 | * This is to work around that problem. 28 | **/ 29 | @Override 30 | public void clearText() { 31 | super.setText(""); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/textcomponent/EditorPaneOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.textcomponent; 18 | 19 | import javax.swing.event.HyperlinkEvent; 20 | 21 | import org.netbeans.jemmy.JemmyException; 22 | import org.netbeans.jemmy.operators.JEditorPaneOperator; 23 | 24 | public class EditorPaneOperator { 25 | private final JEditorPaneOperator editorPaneOperator; 26 | private HyperlinkEventFactory eventFactory; 27 | 28 | public EditorPaneOperator(JEditorPaneOperator editorPaneOperator) { 29 | this.editorPaneOperator = editorPaneOperator; 30 | this.eventFactory = new HyperlinkEventFactory(editorPaneOperator); 31 | } 32 | 33 | public void activateHyperLink(String linkText) { 34 | HyperlinkEvent hyperlinkEvent = eventFactory.createHyperLinkEvent(linkText); 35 | try { 36 | editorPaneOperator.fireHyperlinkUpdate(hyperlinkEvent); 37 | } catch (JemmyException e) { 38 | Throwable innerThrowable = e.getInnerThrowable(); 39 | throw new RuntimeException(innerThrowable); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/textcomponent/EditorPaneOperatorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.textcomponent; 18 | 19 | import org.netbeans.jemmy.operators.ContainerOperator; 20 | import org.netbeans.jemmy.operators.JEditorPaneOperator; 21 | import org.robotframework.swing.chooser.ByNameComponentChooser; 22 | import org.robotframework.swing.context.Context; 23 | import org.robotframework.swing.factory.IdentifierParsingOperatorFactory; 24 | 25 | public class EditorPaneOperatorFactory extends IdentifierParsingOperatorFactory { 26 | @Override 27 | public EditorPaneOperator createOperatorByIndex(int index) { 28 | return new EditorPaneOperator(new JEditorPaneOperator((ContainerOperator) Context.getContext(), index)); 29 | } 30 | 31 | @Override 32 | public EditorPaneOperator createOperatorByName(String name) { 33 | return new EditorPaneOperator(new JEditorPaneOperator((ContainerOperator) Context.getContext(), new ByNameComponentChooser(name))); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/textcomponent/LinkNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.textcomponent; 18 | 19 | public class LinkNotFoundException extends RuntimeException { 20 | public LinkNotFoundException(String message) { 21 | super(message); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/textcomponent/SwingTextComponentOperator.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.textcomponent; 2 | 3 | import org.netbeans.jemmy.ComponentChooser; 4 | import org.netbeans.jemmy.operators.ContainerOperator; 5 | import org.netbeans.jemmy.operators.JTextComponentOperator; 6 | import org.robotframework.swing.operator.ComponentWrapper; 7 | 8 | public class SwingTextComponentOperator extends JTextComponentOperator implements ComponentWrapper { 9 | public SwingTextComponentOperator(ContainerOperator container, int index) { 10 | super(container, index); 11 | } 12 | 13 | public SwingTextComponentOperator(ContainerOperator container, ComponentChooser chooser) { 14 | super(container, chooser); 15 | } 16 | 17 | /* 18 | * We want to let the application do whatever it wants with the inputs the textfield receives. 19 | */ 20 | @Override 21 | public boolean getVerification() { 22 | return false; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/textcomponent/TextComponentOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.robotframework.swing.textcomponent; 17 | 18 | 19 | public interface TextComponentOperator { 20 | 21 | 22 | public void setText(String text); 23 | 24 | public boolean isEditable(); 25 | 26 | public boolean isEnabled(); 27 | 28 | public void setEnabled(boolean enabled); 29 | 30 | public String getText(); 31 | 32 | public void typeText(String text); 33 | 34 | public void clearText(); 35 | 36 | public void makeComponentVisible(); 37 | 38 | public void selectAll(); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/togglebutton/ToggleButtonOperatorFactory.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.togglebutton; 2 | 3 | import org.jretrofit.Retrofit; 4 | import org.netbeans.jemmy.operators.ContainerOperator; 5 | import org.netbeans.jemmy.operators.JToggleButtonOperator; 6 | import org.robotframework.swing.button.AbstractButtonOperator; 7 | import org.robotframework.swing.chooser.ByNameOrTextComponentChooser; 8 | import org.robotframework.swing.context.Context; 9 | import org.robotframework.swing.factory.DefaultContextVerifyingOperatorFactory; 10 | 11 | public class ToggleButtonOperatorFactory extends DefaultContextVerifyingOperatorFactory { 12 | @Override 13 | public AbstractButtonOperator createOperatorByIndex(int index) { 14 | return coerceToAbstractButtonOperator(new JToggleButtonOperator((ContainerOperator) Context.getContext(), index)); 15 | } 16 | 17 | @Override 18 | public AbstractButtonOperator createOperatorByName(String name) { 19 | return coerceToAbstractButtonOperator(new JToggleButtonOperator((ContainerOperator) Context.getContext(), new ByNameOrTextComponentChooser(name))); 20 | } 21 | 22 | private AbstractButtonOperator coerceToAbstractButtonOperator(JToggleButtonOperator toggleButtonOperator) { 23 | return (AbstractButtonOperator) Retrofit.partial(toggleButtonOperator, AbstractButtonOperator.class); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/tree/JTreeLocationFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.tree; 18 | 19 | import javax.swing.tree.TreePath; 20 | 21 | import org.robotframework.swing.arguments.IdentifierHandler; 22 | 23 | import abbot.tester.JTreeLocation; 24 | 25 | public class JTreeLocationFactory extends IdentifierHandler { 26 | @Override 27 | public JTreeLocation indexArgument(int rowIndex) { 28 | return new JTreeLocation(rowIndex); 29 | } 30 | 31 | @Override 32 | public JTreeLocation nameArgument(String pathToNode) { 33 | return new JTreeLocation(new TreePath(pathToNode.split("\\|"))); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/tree/TreeIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.tree; 18 | 19 | import java.util.Enumeration; 20 | 21 | import javax.swing.tree.TreeNode; 22 | import javax.swing.tree.TreePath; 23 | 24 | import org.netbeans.jemmy.operators.JTreeOperator; 25 | 26 | public class TreeIterator { 27 | private final JTreeOperator treeOperator; 28 | 29 | public TreeIterator(JTreeOperator treeOperator) { 30 | this.treeOperator = treeOperator; 31 | } 32 | 33 | public void operateOnAllNodes(TreePathAction treePathAction) { 34 | doOnAll(root(), treePathAction); 35 | } 36 | 37 | TreePath root() { 38 | return new TreePath(treeOperator.getRoot()); 39 | } 40 | 41 | private void doOnAll(TreePath parent, TreePathAction treePathAction) { 42 | TreeNode node = (TreeNode) parent.getLastPathComponent(); 43 | for (@SuppressWarnings("unchecked") 44 | Enumeration e = node.children(); e.hasMoreElements();) { 45 | TreePath path = parent.pathByAddingChild(e.nextElement()); 46 | doOnAll(path, treePathAction); 47 | } 48 | 49 | treePathAction.operate(parent); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/tree/TreeNodeExistenceResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | package org.robotframework.swing.tree; 19 | 20 | import org.robotframework.swing.util.ComponentExistenceResolver; 21 | 22 | public class TreeNodeExistenceResolver { 23 | private TreePathFactory treePathFactory; 24 | 25 | public TreeNodeExistenceResolver(TreeOperator treeOperator) { 26 | treePathFactory = new TreePathFactory(treeOperator); 27 | } 28 | 29 | public boolean treeNodeExists(String nodePath) { 30 | return new ComponentExistenceResolver(treePathFactory).satisfiesCondition(nodePath); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/tree/TreeOperatorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.tree; 18 | 19 | import org.netbeans.jemmy.operators.ContainerOperator; 20 | import org.robotframework.swing.chooser.ByNameComponentChooser; 21 | import org.robotframework.swing.context.Context; 22 | import org.robotframework.swing.factory.DefaultContextVerifyingOperatorFactory; 23 | 24 | public class TreeOperatorFactory extends DefaultContextVerifyingOperatorFactory { 25 | public TreeOperator createOperatorByIndex(int index) { 26 | return new TreeOperator((ContainerOperator) Context.getContext(), index); 27 | } 28 | 29 | public TreeOperator createOperatorByName(String name) { 30 | return new TreeOperator((ContainerOperator) Context.getContext(), new ByNameComponentChooser(name)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/tree/TreePathAction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | package org.robotframework.swing.tree; 19 | 20 | import javax.swing.tree.TreePath; 21 | 22 | public interface TreePathAction { 23 | void operate(TreePath path); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/tree/TreePathFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.tree; 18 | 19 | import javax.swing.tree.TreePath; 20 | 21 | import org.netbeans.jemmy.TimeoutExpiredException; 22 | import org.robotframework.swing.arguments.IdentifierHandler; 23 | 24 | public class TreePathFactory extends IdentifierHandler { 25 | private final TreeOperator treeOperator; 26 | 27 | public TreePathFactory(TreeOperator treeOperator) { 28 | this.treeOperator = treeOperator; 29 | } 30 | 31 | @Override 32 | public TreePath indexArgument(int row) { 33 | TreePath pathForRow = treeOperator.getPathForRow(row); 34 | if (pathForRow == null) { 35 | throw new TimeoutExpiredException("Couldn't find tree path for row '" + row + "'"); 36 | } 37 | return pathForRow; 38 | } 39 | 40 | @Override 41 | public TreePath nameArgument(String nodePath) { 42 | return treeOperator.findPath(nodePath); 43 | } 44 | 45 | public TreePath createTreePath(String nodeIdentifier) { 46 | return parseArgument(nodeIdentifier); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/tree/TreeSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.tree; 18 | 19 | import org.robotframework.swing.common.IdentifierSupport; 20 | import org.robotframework.swing.factory.OperatorFactory; 21 | 22 | public class TreeSupport extends IdentifierSupport { 23 | protected OperatorFactory operatorFactory = new TreeOperatorFactory(); 24 | 25 | public TreeOperator treeOperator(String identifier) { 26 | return operatorFactory.createOperator(identifier); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/util/ComponentExistenceResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.util; 18 | 19 | import org.netbeans.jemmy.TimeoutExpiredException; 20 | import org.robotframework.swing.arguments.ArgumentParser; 21 | 22 | public class ComponentExistenceResolver implements IComponentConditionResolver { 23 | private ArgumentParser identifierParser; 24 | 25 | public ComponentExistenceResolver(ArgumentParser identifierParser) { 26 | this.identifierParser = identifierParser; 27 | } 28 | 29 | public boolean satisfiesCondition(String identifier) { 30 | try { 31 | identifierParser.parseArgument(identifier); 32 | } catch(TimeoutExpiredException e) { 33 | return false; 34 | } 35 | return true; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/util/ComponentUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.util; 18 | 19 | import javax.swing.*; 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | 24 | public class ComponentUtils { 25 | public static List getParsedElements(MenuElement[] elements) { 26 | List returnable = new ArrayList(); 27 | for (MenuElement e : elements) { 28 | if (JMenuItem.class.isAssignableFrom(e.getClass())) { 29 | returnable.add(((JMenuItem) e).getText()); 30 | } 31 | } 32 | return returnable; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/util/IComponentConditionResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.util; 18 | 19 | public interface IComponentConditionResolver { 20 | boolean satisfiesCondition(String componentIdentifier); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/util/ObjectUtils.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.util; 2 | 3 | public class ObjectUtils { 4 | 5 | public static boolean nullSafeEquals(Object first, Object second) { 6 | if (first == null && second == null) 7 | return true; 8 | if (first == null || second == null) 9 | return false; 10 | return first.equals(second); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/util/StandardOutOutput.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.util; 2 | 3 | import org.netbeans.jemmy.TestOut; 4 | 5 | import java.io.InputStream; 6 | import java.io.PrintWriter; 7 | 8 | 9 | public class StandardOutOutput extends TestOut { 10 | 11 | public final long starterThreadId; 12 | 13 | 14 | public StandardOutOutput() { 15 | super((InputStream)null, (PrintWriter)null, (PrintWriter)null); 16 | starterThreadId = Thread.currentThread().getId(); 17 | } 18 | 19 | @Override 20 | public void print(String line) { 21 | log(line); 22 | } 23 | 24 | @Override 25 | public void printLine(String line) { 26 | log(line); 27 | } 28 | 29 | @Override 30 | public void printTrace(String text) { 31 | log(text); 32 | } 33 | 34 | @Override 35 | public void printErrLine(String line) { 36 | log(line); 37 | } 38 | 39 | @Override 40 | public void printError(String text) { 41 | log(text); 42 | } 43 | 44 | @Override 45 | public void printStackTrace(Throwable e) { 46 | log("Error in Jemmy:"); 47 | e.printStackTrace(System.out); 48 | } 49 | 50 | private void log(String msg) { 51 | if (Thread.currentThread().getId() == starterThreadId) 52 | System.out.println("*DEBUG:"+System.currentTimeMillis()+"* Jemmy: "+ msg); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/util/SwingInvoker.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.util; 2 | 3 | import java.awt.AWTEvent; 4 | import java.awt.Toolkit; 5 | import java.lang.reflect.InvocationTargetException; 6 | 7 | import javax.swing.SwingUtilities; 8 | 9 | public class SwingInvoker { 10 | 11 | public static void postEvent(final AWTEvent event) { 12 | invokeAndWait(new Runnable() { 13 | @Override 14 | public void run() { 15 | Toolkit.getDefaultToolkit().getSystemEventQueue() 16 | .postEvent(event); 17 | } 18 | }); 19 | } 20 | 21 | public static void invokeAndWait(final Runnable runnable) { 22 | try { 23 | SwingUtilities.invokeAndWait(runnable); 24 | } catch (InvocationTargetException e) { 25 | Throwable cause = e.getCause(); 26 | throw new RuntimeException(cause != null ? cause.getMessage() : e.getMessage(), e); 27 | } catch (InterruptedException e) { 28 | throw new RuntimeException(e); 29 | } 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/util/SwingWaiter.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.util; 2 | 3 | import org.netbeans.jemmy.EventTool; 4 | import org.netbeans.jemmy.TimeoutExpiredException; 5 | 6 | /** 7 | * This class provides an interface for waiting between swing library events. 8 | * Originally we used EventTool.waitNoEvent from jemmy without any event filter. 9 | * This is bad(tm) because some applications cause events continuously. 10 | * 11 | * Now trying to wait for maximum 600ms second (or given time). 12 | */ 13 | public class SwingWaiter { 14 | 15 | private static EventTool eventTool = new EventTool(); 16 | 17 | public static void waitToAvoidInstability(int time) { 18 | try { 19 | eventTool.getTimeouts().setTimeout("EventTool.WaitNoEventTimeout", Math.max(600, time)); 20 | eventTool.waitNoEvent(time); 21 | } catch (TimeoutExpiredException e) { 22 | // Ignore 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/robotframework/swing/window/FrameOperatorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.robotframework.swing.window; 18 | 19 | import org.robotframework.swing.factory.IdentifierParsingOperatorFactory; 20 | 21 | public class FrameOperatorFactory extends IdentifierParsingOperatorFactory { 22 | public FrameOperator createOperatorByIndex(int index) { 23 | return FrameOperator.newOperatorFor(index); 24 | } 25 | 26 | public FrameOperator createOperatorByName(String name) { 27 | return FrameOperator.newOperatorFor(name); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/somepackage/KeywordsOutsidePathPattern.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.somepackage; 2 | 3 | import org.robotframework.javalib.annotation.RobotKeyword; 4 | import org.robotframework.javalib.annotation.RobotKeywords; 5 | 6 | @RobotKeywords 7 | public class KeywordsOutsidePathPattern { 8 | @RobotKeyword 9 | public void keywordThatShouldNotBeRegistered() { } 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/SwingLibrarySpec.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing; 2 | 3 | import jdave.junit4.JDaveRunner; 4 | 5 | import org.junit.runner.RunWith; 6 | import org.netbeans.jemmy.JemmyProperties; 7 | import org.robotframework.jdave.mock.MockSupportSpecification; 8 | import org.robotframework.swing.keyword.timeout.TimeoutKeywords; 9 | 10 | @RunWith(JDaveRunner.class) 11 | public class SwingLibrarySpec extends MockSupportSpecification { 12 | public class Any { 13 | public SwingLibrary create() { 14 | return new SwingLibrary(); 15 | } 16 | 17 | public void doesntContainKeywordsThatDontMatchDefaultPathPattern() { 18 | specify(context.getKeywordNames(), must.not().contain("keywordThatShouldNotBeRegistered")); 19 | } 20 | 21 | public void outputsAreNull() { 22 | specify(JemmyProperties.getCurrentOutput().getOutput(), must.equal(null)); 23 | specify(JemmyProperties.getCurrentOutput().getErrput(), must.equal(null)); 24 | } 25 | 26 | public void setsTimeoutsTo5Seconds() { 27 | String[] timeouts = TimeoutKeywords.JEMMY_TIMEOUTS; 28 | for (String timeout : timeouts) { 29 | specify(JemmyProperties.getCurrentTimeout(timeout), must.equal(10000)); 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/arguments/ArgumentParserSpec.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.arguments; 2 | 3 | import jdave.Specification; 4 | import jdave.junit4.JDaveRunner; 5 | 6 | import org.jmock.Expectations; 7 | import org.junit.runner.RunWith; 8 | 9 | 10 | @RunWith(JDaveRunner.class) 11 | public class ArgumentParserSpec extends Specification> { 12 | public class WhenParsingArguments { 13 | private ArgumentHandler handler; 14 | 15 | public ArgumentParser create() { 16 | handler = mock(ArgumentHandler.class); 17 | ArgumentParser argumentParser = new ArgumentParser(handler); 18 | return argumentParser; 19 | } 20 | 21 | public void returnsIndexArgumentFromArgumentHandlerIfArgumentConvertibleToInt() { 22 | String argConvertibleToInt = "1"; 23 | final String retValForIntArgument = "returnValueForIntArgument"; 24 | 25 | checking(new Expectations() {{ 26 | one(handler).indexArgument(1); will(returnValue(retValForIntArgument)); 27 | }}); 28 | 29 | specify(context.parseArgument(argConvertibleToInt), does.equal(retValForIntArgument)); 30 | } 31 | 32 | public void returnsStringArgumentFromArgumentHandlerIfArgumentNotConvertibleToInt() { 33 | final String argNotConvertibleToInt = "notConvertibleToInt"; 34 | final String retValForStringArgument = "returnValueForStringArgument"; 35 | 36 | checking(new Expectations() {{ 37 | one(handler).nameArgument(with(equal(argNotConvertibleToInt))); 38 | will(returnValue(retValForStringArgument)); 39 | }}); 40 | 41 | specify(context.parseArgument(argNotConvertibleToInt), does.equal(retValForStringArgument)); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/button/ButtonOperatorFactorySpec.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.button; 2 | 3 | import java.awt.Component; 4 | 5 | import javax.swing.JButton; 6 | 7 | import jdave.junit4.JDaveRunner; 8 | 9 | import org.junit.runner.RunWith; 10 | import org.robotframework.swing.factory.OperatorFactory; 11 | import org.robotframework.swing.factory.OperatorFactorySpecification; 12 | 13 | 14 | @RunWith(JDaveRunner.class) 15 | public class ButtonOperatorFactorySpec extends OperatorFactorySpecification { 16 | public class Any extends AnyIdentifierParsingOperatorFactory { 17 | @Override 18 | protected OperatorFactory createOperatorFactory() { 19 | return new ButtonOperatorFactory(); 20 | } 21 | 22 | @Override 23 | protected Component createComponent() { 24 | return new JButton() { 25 | public boolean isShowing() { 26 | return true; 27 | } 28 | }; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/checkbox/CheckBoxOperatorFactorySpec.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.checkbox; 2 | 3 | import java.awt.Component; 4 | 5 | import javax.swing.JCheckBox; 6 | 7 | import jdave.junit4.JDaveRunner; 8 | 9 | import org.junit.runner.RunWith; 10 | import org.robotframework.swing.factory.OperatorFactory; 11 | import org.robotframework.swing.factory.OperatorFactorySpecification; 12 | 13 | 14 | @RunWith(JDaveRunner.class) 15 | public class CheckBoxOperatorFactorySpec extends OperatorFactorySpecification { 16 | public class Any extends AnyIdentifierParsingOperatorFactory { 17 | @Override 18 | protected OperatorFactory createOperatorFactory() { 19 | return new CheckBoxOperatorFactory(); 20 | } 21 | 22 | @Override 23 | protected Component createComponent() { 24 | return new JCheckBox() { 25 | public boolean isShowing() { 26 | return true; 27 | } 28 | }; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/chooser/ListItemChooserSpec.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.chooser; 2 | 3 | import javax.swing.ListModel; 4 | 5 | import jdave.Specification; 6 | import jdave.junit4.JDaveRunner; 7 | 8 | import org.jmock.Expectations; 9 | import org.junit.runner.RunWith; 10 | import org.netbeans.jemmy.operators.JListOperator; 11 | 12 | @RunWith(JDaveRunner.class) 13 | public class ListItemChooserSpec extends Specification { 14 | public class Any { 15 | private JListOperator operator; 16 | private ListModel model; 17 | 18 | public void create() { 19 | operator = mock(JListOperator.class); 20 | model = mock(ListModel.class); 21 | checking(new Expectations() {{ 22 | one(operator).getModel(); will(returnValue(model)); 23 | one(model).getElementAt(6); will(returnValue("someItem")); 24 | }}); 25 | } 26 | 27 | public void passesWhenMatches() { 28 | specify(new ListItemChooser("someItem").checkItem(operator, 6)); 29 | } 30 | 31 | public void doesntPassWhenDoesntMatch() { 32 | specify(!new ListItemChooser("somethingElse").checkItem(operator, 6)); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/combobox/ComboBoxOperatorFactorySpec.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.combobox; 2 | 3 | import java.awt.Component; 4 | 5 | import javax.swing.JComboBox; 6 | 7 | import jdave.junit4.JDaveRunner; 8 | 9 | import org.junit.runner.RunWith; 10 | import org.robotframework.swing.factory.OperatorFactory; 11 | import org.robotframework.swing.factory.OperatorFactorySpecification; 12 | 13 | @RunWith(JDaveRunner.class) 14 | public class ComboBoxOperatorFactorySpec extends OperatorFactorySpecification { 15 | public class Any extends AnyIdentifierParsingOperatorFactory { 16 | protected OperatorFactory createOperatorFactory() { 17 | return new ComboBoxOperatorFactory(); 18 | } 19 | 20 | @Override 21 | protected Component createComponent() { 22 | return new JComboBox() { 23 | public boolean isShowing() { 24 | return true; 25 | } 26 | }; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/common/IdentifierTest.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.common; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import org.junit.Test; 6 | 7 | 8 | public class IdentifierTest { 9 | 10 | private int index = 1; 11 | private String indexId = ""+index; 12 | private Identifier indexIdentifier = new Identifier(indexId); 13 | private String strId = "fooness"; 14 | private Identifier identifier = new Identifier(strId); 15 | private String regExpId = "regexp="+strId; 16 | private Identifier regExpIdentifier = new Identifier(regExpId); 17 | 18 | @Test 19 | public void identifier() { 20 | assertEquals(strId, identifier.asString()); 21 | assertFalse(identifier.isIndex()); 22 | assertFalse(identifier.isRegExp()); 23 | } 24 | 25 | @Test 26 | public void indexIdentifier() { 27 | assertEquals(index, indexIdentifier.asIndex()); 28 | assertEquals(indexId, indexIdentifier.asString()); 29 | assertTrue(indexIdentifier.isIndex()); 30 | assertFalse(indexIdentifier.isRegExp()); 31 | } 32 | 33 | @Test 34 | public void regExpIdentifier() { 35 | assertTrue(regExpIdentifier.isRegExp()); 36 | assertEquals(strId, regExpIdentifier.asString()); 37 | assertFalse(regExpIdentifier.isIndex()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/comparator/EqualsStringComparatorSpec.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.comparator; 2 | 3 | import jdave.Specification; 4 | import jdave.junit4.JDaveRunner; 5 | 6 | import org.junit.runner.RunWith; 7 | import org.netbeans.jemmy.operators.Operator.StringComparator; 8 | 9 | @RunWith(JDaveRunner.class) 10 | public class EqualsStringComparatorSpec extends Specification { 11 | public class Any { 12 | public StringComparator create() { 13 | return new EqualsStringComparator(); 14 | } 15 | 16 | public void doesntAcceptSubstringMatches() { 17 | specify(!context.equals("fOo", "foo")); 18 | specify(!context.equals("foobar", "foo")); 19 | } 20 | 21 | public void acceptsExactMatches() { 22 | specify(context.equals("foo", "foo")); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/component/ComponentOperatorSpec.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.component; 2 | 3 | import javax.swing.JComponent; 4 | 5 | import jdave.junit4.JDaveRunner; 6 | 7 | import org.jmock.Expectations; 8 | import org.junit.runner.RunWith; 9 | import org.netbeans.jemmy.operators.JPopupMenuOperator; 10 | import org.robotframework.jdave.mock.MockSupportSpecification; 11 | import org.robotframework.swing.popup.PopupMenuOperatorFactory; 12 | 13 | @RunWith(JDaveRunner.class) 14 | public class ComponentOperatorSpec extends MockSupportSpecification { 15 | public class Any { 16 | private ComponentOperator componentOperator; 17 | 18 | public ComponentOperator create() { 19 | componentOperator = new ComponentOperator(dummy(JComponent.class)); 20 | return componentOperator; 21 | } 22 | 23 | public void createsPopupMenuOperator() { 24 | final PopupMenuOperatorFactory menuOperatorFactory = injectMockToContext(PopupMenuOperatorFactory.class); 25 | final JPopupMenuOperator popupOperator = dummy(JPopupMenuOperator.class); 26 | 27 | checking(new Expectations() {{ 28 | one(menuOperatorFactory).createPopupOperator(componentOperator); will(returnValue(popupOperator)); 29 | 30 | }}); 31 | 32 | specify(componentOperator.invokePopup(), popupOperator); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/context/ContainerOperatorFactorySpec.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.context; 2 | 3 | import java.awt.Component; 4 | import java.awt.Container; 5 | 6 | import jdave.junit4.JDaveRunner; 7 | 8 | import org.junit.runner.RunWith; 9 | import org.robotframework.swing.factory.OperatorFactory; 10 | import org.robotframework.swing.factory.OperatorFactorySpecification; 11 | 12 | 13 | @RunWith(JDaveRunner.class) 14 | public class ContainerOperatorFactorySpec extends OperatorFactorySpecification { 15 | public class Any extends AnyIdentifierParsingOperatorFactory { 16 | @Override 17 | protected OperatorFactory createOperatorFactory() { 18 | return new ContainerOperatorFactory(); 19 | } 20 | 21 | @Override 22 | protected Component createComponent() { 23 | return new Container() { 24 | @Override 25 | public boolean isShowing() { 26 | return true; 27 | } 28 | }; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/context/DefaultContextVerifierSpec.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.context; 2 | 3 | import java.awt.Panel; 4 | import java.awt.Window; 5 | 6 | import javax.swing.JInternalFrame; 7 | import javax.swing.JPanel; 8 | 9 | import jdave.junit4.JDaveRunner; 10 | 11 | import org.junit.runner.RunWith; 12 | import org.robotframework.swing.operator.ComponentWrapper; 13 | 14 | @RunWith(JDaveRunner.class) 15 | public class DefaultContextVerifierSpec extends ContextVerifierSpecification { 16 | public class WithEmptyContext extends EmptyContext { 17 | @Override 18 | protected ContextVerifier createVerifier() { 19 | return new DefaultContextVerifier(); 20 | } 21 | } 22 | 23 | public class WithContext { 24 | public DefaultContextVerifier create() { 25 | Context.setContext(mock(ComponentWrapper.class)); 26 | return new DefaultContextVerifier(); 27 | } 28 | 29 | public void passesIfContextClassIsPanel() throws Throwable { 30 | specifyContextClassMatches(Panel.class); 31 | } 32 | 33 | public void passesIfContextClassIsJPanel() throws Throwable { 34 | specifyContextClassMatches(JPanel.class); 35 | } 36 | 37 | public void passesIfContextClassIsWindow() throws Throwable { 38 | specifyContextClassMatches(Window.class); 39 | } 40 | 41 | public void passesIfContextClassIsInteralFrame() throws Throwable { 42 | specifyContextClassMatches(JInternalFrame.class); 43 | } 44 | } 45 | 46 | @Override 47 | protected String getExpectedErrorMessage() { 48 | return DefaultContextVerifier.ERROR_MESSAGE; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/factory/IdentifierParsingOperatorFactorySpec.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.factory; 2 | 3 | import jdave.Specification; 4 | import jdave.junit4.JDaveRunner; 5 | 6 | import org.junit.runner.RunWith; 7 | import org.netbeans.jemmy.operators.Operator; 8 | 9 | 10 | @RunWith(JDaveRunner.class) 11 | public class IdentifierParsingOperatorFactorySpec extends Specification> { 12 | public class Any { 13 | private Operator createdByIndex = dummy(Operator.class, "byIndex"); 14 | private Operator createdByName = dummy(Operator.class, "byName"); 15 | private IdentifierParsingOperatorFactory factory; 16 | 17 | public IdentifierParsingOperatorFactory create() { 18 | factory = new IdentifierParsingOperatorFactory() { 19 | @Override 20 | public Operator createOperatorByIndex(int index) { 21 | return createdByIndex; 22 | } 23 | 24 | @Override 25 | public Operator createOperatorByName(String name) { 26 | return createdByName; 27 | } 28 | }; 29 | return factory; 30 | } 31 | 32 | public void createsOperatorByNameForNameArguments() { 33 | specify(factory.parseArgument("someNameArgument"), should.equal(createdByName)); 34 | } 35 | 36 | public void createsOperatorByIndexForIndexArguments() { 37 | specify(factory.parseArgument("123"), should.equal(createdByIndex)); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/internalframe/InternalFrameOperatorFactorySpec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008-2011 Nokia Siemens Networks Oyj 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | package org.robotframework.swing.internalframe; 19 | 20 | import java.awt.Component; 21 | 22 | import javax.swing.JInternalFrame; 23 | 24 | import jdave.junit4.JDaveRunner; 25 | 26 | import org.junit.runner.RunWith; 27 | import org.robotframework.swing.factory.OperatorFactory; 28 | import org.robotframework.swing.factory.OperatorFactorySpecification; 29 | 30 | @RunWith(JDaveRunner.class) 31 | public class InternalFrameOperatorFactorySpec extends OperatorFactorySpecification { 32 | public class Any extends AnyIdentifierParsingOperatorFactory { 33 | @Override 34 | protected OperatorFactory createOperatorFactory() { 35 | return new InternalFrameOperatorFactory(); 36 | } 37 | 38 | @Override 39 | protected Component createComponent() { 40 | return new JInternalFrame() { 41 | public boolean isShowing() { 42 | return true; 43 | } 44 | }; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/keyword/concurrent/ThreadKeywordsSpec.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.keyword.concurrent; 2 | 3 | import jdave.Specification; 4 | import jdave.junit4.JDaveRunner; 5 | 6 | import org.junit.runner.RunWith; 7 | import org.robotframework.jdave.contract.RobotKeywordContract; 8 | import org.robotframework.jdave.contract.RobotKeywordsContract; 9 | 10 | @RunWith(JDaveRunner.class) 11 | public class ThreadKeywordsSpec extends Specification { 12 | public class Any { 13 | public ThreadKeywords create() { 14 | return new ThreadKeywords(); 15 | } 16 | 17 | public void isRobotKeywordsAnnotated() { 18 | specify(context, satisfies(new RobotKeywordsContract())); 19 | } 20 | 21 | public void hasRunKeywordInSeparateThreadKeyword() { 22 | specify(context, satisfies(new RobotKeywordContract("runKeywordInSeparateThread"))); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/keyword/testapp/SomeApplication.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.keyword.testapp; 2 | 3 | import org.junit.Assert; 4 | import org.robotframework.javalib.annotation.RobotKeywords; 5 | 6 | @RobotKeywords 7 | public class SomeApplication { 8 | public static String[] args; 9 | public static boolean wasCalled = false; 10 | 11 | public static String[] getLastUsedArguments() { 12 | return args; 13 | } 14 | 15 | public static void main(String[] args) { 16 | wasCalled = true; 17 | SomeApplication.args = args; 18 | } 19 | 20 | public void assertApplicationWasCalled() { 21 | Assert.assertTrue(wasCalled); 22 | } 23 | 24 | public String[] getReceivedArguments() { 25 | return args; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/keyword/timeout/TimeoutKeywordsSpec.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.keyword.timeout; 2 | 3 | import jdave.Specification; 4 | import jdave.junit4.JDaveRunner; 5 | 6 | import org.junit.runner.RunWith; 7 | import org.netbeans.jemmy.JemmyProperties; 8 | import org.robotframework.jdave.contract.RobotKeywordContract; 9 | import org.robotframework.jdave.contract.RobotKeywordsContract; 10 | 11 | 12 | @RunWith(JDaveRunner.class) 13 | public class TimeoutKeywordsSpec extends Specification { 14 | public class Any { 15 | public TimeoutKeywords create() { 16 | return new TimeoutKeywords(); 17 | } 18 | 19 | public void isRobotKeywordsAnnotated() { 20 | specify(context, satisfies(new RobotKeywordsContract())); 21 | } 22 | 23 | public void hasSetJemmyTimeoutKeyword() { 24 | specify(context, satisfies(new RobotKeywordContract("setJemmyTimeout"))); 25 | } 26 | 27 | public void hasSetJemmyTimeoutsKeyword() { 28 | specify(context, satisfies(new RobotKeywordContract("setJemmyTimeouts"))); 29 | } 30 | 31 | public void setsJemmyTimeout() { 32 | String timeoutName = "DialogWaiter.WaitDialogTimeout"; 33 | context.setJemmyTimeout(timeoutName, "3"); 34 | specify(JemmyProperties.getCurrentTimeout(timeoutName), must.equal(3000)); 35 | } 36 | 37 | public void setsJemmyTimeouts() { 38 | context.setJemmyTimeouts("3"); 39 | for (String timeoutName : TimeoutKeywords.JEMMY_TIMEOUTS) { 40 | specify(JemmyProperties.getCurrentTimeout(timeoutName), must.equal(3000)); 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/keyword/tree/TreeSpecification.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.keyword.tree; 2 | 3 | import org.jmock.Expectations; 4 | import org.robotframework.swing.factory.OperatorFactory; 5 | import org.robotframework.jdave.mock.MockSupportSpecification; 6 | import org.robotframework.swing.tree.TreeOperator; 7 | import org.robotframework.swing.tree.TreeSupport; 8 | 9 | public abstract class TreeSpecification extends MockSupportSpecification { 10 | protected TreeOperator treeOperator; 11 | protected String treeIdentifier = "someTree"; 12 | protected OperatorFactory operatorFactory; 13 | 14 | protected T populateWithMockOperatorFactory(T treeKeywords) { 15 | return populateWithMockOperatorFactory(treeKeywords, mock(TreeOperator.class)); 16 | } 17 | 18 | protected T populateWithMockOperatorFactory(T treeKeywords, TreeOperator treeOperator) { 19 | this.treeOperator = treeOperator; 20 | operatorFactory = injectMockTo(treeKeywords, OperatorFactory.class); 21 | checking(new Expectations() {{ 22 | one(operatorFactory).createOperator(treeIdentifier); 23 | will(returnValue(TreeSpecification.this.treeOperator)); 24 | }}); 25 | return treeKeywords; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/label/LabelOperatorFactorySpec.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.label; 2 | 3 | import java.awt.Component; 4 | 5 | import javax.swing.JLabel; 6 | 7 | import jdave.junit4.JDaveRunner; 8 | 9 | import org.junit.runner.RunWith; 10 | import org.robotframework.swing.factory.OperatorFactory; 11 | import org.robotframework.swing.factory.OperatorFactorySpecification; 12 | 13 | 14 | @RunWith(JDaveRunner.class) 15 | public class LabelOperatorFactorySpec extends OperatorFactorySpecification { 16 | public class Any extends AnyIdentifierParsingOperatorFactory { 17 | @Override 18 | protected Component createComponent() { 19 | return new JLabel() { 20 | public boolean isShowing() { 21 | return true; 22 | } 23 | }; 24 | } 25 | 26 | @Override 27 | protected OperatorFactory createOperatorFactory() { 28 | return new LabelOperatorFactory(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/list/ListOperatorFactorySpec.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.list; 2 | 3 | import java.awt.Component; 4 | 5 | import javax.swing.JList; 6 | 7 | import jdave.junit4.JDaveRunner; 8 | 9 | import org.junit.runner.RunWith; 10 | import org.robotframework.swing.factory.OperatorFactory; 11 | import org.robotframework.swing.factory.OperatorFactorySpecification; 12 | 13 | 14 | @RunWith(JDaveRunner.class) 15 | public class ListOperatorFactorySpec extends OperatorFactorySpecification { 16 | public class Any extends AnyIdentifierParsingOperatorFactory { 17 | @Override 18 | protected OperatorFactory createOperatorFactory() { 19 | return new ListOperatorFactory(); 20 | } 21 | 22 | @Override 23 | protected Component createComponent() { 24 | return new JList() { 25 | public boolean isShowing() { 26 | return true; 27 | } 28 | }; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/menu/MenuSupportSpec.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.menu; 2 | 3 | import jdave.junit4.JDaveRunner; 4 | 5 | import org.jmock.Expectations; 6 | import org.jmock.Sequence; 7 | import org.junit.runner.RunWith; 8 | import org.netbeans.jemmy.operators.JMenuBarOperator; 9 | import org.netbeans.jemmy.operators.JMenuItemOperator; 10 | import org.robotframework.jdave.mock.MockSupportSpecification; 11 | import org.robotframework.swing.comparator.EqualsStringComparator; 12 | 13 | 14 | @RunWith(JDaveRunner.class) 15 | public class MenuSupportSpec extends MockSupportSpecification { 16 | public class Any { 17 | private JMenuBarOperator menuBarOperator; 18 | 19 | public MenuSupport create() { 20 | menuBarOperator = mock(JMenuBarOperator.class); 21 | return new MenuSupport() { 22 | protected JMenuBarOperator menubarOperator() { 23 | return menuBarOperator; 24 | } 25 | }; 26 | } 27 | 28 | public void showsMenuItem() { 29 | final Sequence avoidInstability = sequence("avoidingInstability"); 30 | 31 | final JMenuItemOperator menuItemOperator = mock(JMenuItemOperator.class); 32 | final String menuPath = "some|menu"; 33 | 34 | checking(new Expectations() {{ 35 | one(menuBarOperator).showMenuItem(menuPath); 36 | will(returnValue(menuItemOperator)); inSequence(avoidInstability); 37 | one(menuItemOperator).setComparator(with(any(EqualsStringComparator.class))); inSequence(avoidInstability); 38 | one(menuItemOperator).grabFocus(); inSequence(avoidInstability); 39 | }}); 40 | 41 | context.showMenuItem(menuPath); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/radiobutton/RadioButtonOperatorFactorySpec.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.radiobutton; 2 | 3 | import java.awt.Component; 4 | 5 | import javax.swing.JRadioButton; 6 | 7 | import jdave.junit4.JDaveRunner; 8 | 9 | import org.junit.runner.RunWith; 10 | import org.robotframework.swing.factory.OperatorFactory; 11 | import org.robotframework.swing.factory.OperatorFactorySpecification; 12 | import org.robotframework.swing.operator.ComponentWrapper; 13 | 14 | @RunWith(JDaveRunner.class) 15 | public class RadioButtonOperatorFactorySpec extends OperatorFactorySpecification { 16 | public class Any extends AnyIdentifierParsingOperatorFactory { 17 | @Override 18 | protected Component createComponent() { 19 | return new JRadioButton() { 20 | public boolean isShowing() { 21 | return true; 22 | } 23 | }; 24 | } 25 | 26 | @Override 27 | protected OperatorFactory createOperatorFactory() { 28 | return new RadioButtonOperatorFactory(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/spinner/SpinnerOperatorFactorySpec.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.spinner; 2 | 3 | import java.awt.Component; 4 | 5 | import javax.swing.JSpinner; 6 | 7 | import jdave.junit4.JDaveRunner; 8 | 9 | import org.junit.runner.RunWith; 10 | import org.robotframework.swing.factory.OperatorFactory; 11 | import org.robotframework.swing.factory.OperatorFactorySpecification; 12 | 13 | @RunWith(JDaveRunner.class) 14 | public class SpinnerOperatorFactorySpec extends OperatorFactorySpecification { 15 | public class Any extends AnyIdentifierParsingOperatorFactory { 16 | @Override 17 | protected OperatorFactory createOperatorFactory() { 18 | return new SpinnerOperatorFactory(); 19 | } 20 | 21 | @Override 22 | protected Component createComponent() { 23 | return new JSpinner() { 24 | public boolean isShowing() { 25 | return true; 26 | } 27 | }; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/table/AbstractTableCellChooserSpec.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.table; 2 | 3 | import jdave.Specification; 4 | import jdave.junit4.JDaveRunner; 5 | 6 | import org.junit.runner.RunWith; 7 | import org.netbeans.jemmy.operators.JTableOperator; 8 | 9 | @RunWith(JDaveRunner.class) 10 | public class AbstractTableCellChooserSpec extends Specification { 11 | public class Any { 12 | private int row = 2; 13 | public AbstractTableCellChooser create() { 14 | return new AbstractTableCellChooser(row) { 15 | protected boolean checkColumn(JTableOperator tableOperator, int column) { 16 | return true; 17 | } 18 | }; 19 | } 20 | 21 | public void choosesCellWithMatchingRow() { 22 | specify(context.checkCell(dummy(JTableOperator.class), 2, 1)); 23 | } 24 | 25 | public void doesntChooseCellWhenRowDoesntMatch() { 26 | specify(!context.checkCell(dummy(JTableOperator.class), 3, 1)); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/table/InvalidCellExceptionSpec.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.table; 2 | 3 | import jdave.Specification; 4 | import jdave.junit4.JDaveRunner; 5 | 6 | import org.junit.runner.RunWith; 7 | 8 | @RunWith(JDaveRunner.class) 9 | public class InvalidCellExceptionSpec extends Specification { 10 | public class Any { 11 | private int row = 123; 12 | private String columnIdentifier = "nonexistentColumn"; 13 | 14 | public InvalidCellException create() { 15 | return new InvalidCellException(row, columnIdentifier); 16 | } 17 | 18 | public void errorMessageShouldDescribeThatCellDoesntExist() { 19 | String expectedErrorMessage = "The specified table cell (row: " + row + ", column: " + columnIdentifier + ") is invalid."; 20 | specify(context.getMessage(), should.equal(expectedErrorMessage)); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/table/TableContextVerifierSpec.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MarketSquare/SwingLibrary/68d544b379ef442bf599d22f3cd6650fbf3a0256/src/test/java/org/robotframework/swing/table/TableContextVerifierSpec.java -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/textcomponent/EditorPaneOperatorSpec.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.textcomponent; 2 | 3 | import javax.swing.JEditorPane; 4 | import javax.swing.event.HyperlinkEvent; 5 | import javax.swing.text.html.HTMLDocument; 6 | 7 | import jdave.junit4.JDaveRunner; 8 | 9 | import org.jmock.Expectations; 10 | import org.junit.runner.RunWith; 11 | import org.netbeans.jemmy.operators.JEditorPaneOperator; 12 | import org.robotframework.jdave.mock.MockSupportSpecification; 13 | 14 | @RunWith(JDaveRunner.class) 15 | public class EditorPaneOperatorSpec extends MockSupportSpecification { 16 | public class Any { 17 | private JEditorPaneOperator paneOperator; 18 | private HyperlinkEventFactory eventFactory; 19 | 20 | public EditorPaneOperator create() { 21 | paneOperator = mock(JEditorPaneOperator.class); 22 | 23 | checking(new Expectations() {{ 24 | one(paneOperator).getSource(); will(returnValue(dummy(JEditorPane.class))); 25 | one(paneOperator).getDocument(); will(returnValue(dummy(HTMLDocument.class))); 26 | }}); 27 | 28 | EditorPaneOperator editorPaneOperator = new EditorPaneOperator(paneOperator); 29 | 30 | eventFactory = injectMockTo(editorPaneOperator, "eventFactory", HyperlinkEventFactory.class); 31 | 32 | return editorPaneOperator; 33 | } 34 | 35 | public void activatesHyperLink() { 36 | final HyperlinkEvent event = dummy(HyperlinkEvent.class); 37 | checking(new Expectations() {{ 38 | one(eventFactory).createHyperLinkEvent("some link"); will(returnValue(event)); 39 | one(paneOperator).fireHyperlinkUpdate(event); 40 | }}); 41 | 42 | context.activateHyperLink("some link"); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/togglebutton/ToggleButtonOperatorFactorySpec.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.togglebutton; 2 | 3 | import java.awt.Component; 4 | 5 | import javax.swing.JToggleButton; 6 | 7 | import jdave.junit4.JDaveRunner; 8 | 9 | import org.junit.runner.RunWith; 10 | import org.robotframework.swing.factory.OperatorFactory; 11 | import org.robotframework.swing.factory.OperatorFactorySpecification; 12 | import org.robotframework.swing.operator.ComponentWrapper; 13 | 14 | @RunWith(JDaveRunner.class) 15 | public class ToggleButtonOperatorFactorySpec extends OperatorFactorySpecification { 16 | public class Any extends AnyIdentifierParsingOperatorFactory { 17 | @Override 18 | protected Component createComponent() { 19 | return new JToggleButton() { 20 | public boolean isShowing() { 21 | return true; 22 | } 23 | }; 24 | } 25 | 26 | @Override 27 | protected OperatorFactory createOperatorFactory() { 28 | return new ToggleButtonOperatorFactory(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/tree/JTreeLocationFactorySpec.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.tree; 2 | 3 | import javax.swing.tree.TreePath; 4 | 5 | import jdave.Specification; 6 | import jdave.junit4.JDaveRunner; 7 | 8 | import org.junit.runner.RunWith; 9 | 10 | import abbot.tester.JTreeLocation; 11 | 12 | @RunWith(JDaveRunner.class) 13 | public class JTreeLocationFactorySpec extends Specification { 14 | public class Any { 15 | public JTreeLocationFactory create() { 16 | return new JTreeLocationFactory(); 17 | } 18 | 19 | public void createsJTreeLocationWithRowIndex() { 20 | specify(context.parseArgument("0"), must.equal(new JTreeLocation(0))); 21 | } 22 | 23 | public void createsJTreeLocationWithTreePath() { 24 | String treePath = "some|path"; 25 | specify(context.parseArgument(treePath), must.equal(new JTreeLocation(new TreePath(treePath.split("\\|"))))); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/tree/TreeOperatorFactorySpec.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.tree; 2 | 3 | import java.awt.Component; 4 | 5 | import javax.swing.JTree; 6 | 7 | import jdave.junit4.JDaveRunner; 8 | 9 | import org.junit.runner.RunWith; 10 | import org.robotframework.swing.factory.OperatorFactory; 11 | import org.robotframework.swing.factory.OperatorFactorySpecification; 12 | 13 | 14 | @RunWith(JDaveRunner.class) 15 | public class TreeOperatorFactorySpec extends OperatorFactorySpecification { 16 | public class Any extends AnyIdentifierParsingOperatorFactory { 17 | @Override 18 | protected Component createComponent() { 19 | return new JTree() { 20 | public boolean isShowing() { 21 | return true; 22 | } 23 | }; 24 | } 25 | 26 | @Override 27 | protected OperatorFactory createOperatorFactory() { 28 | return new TreeOperatorFactory(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/tree/TreeSupportSpec.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.tree; 2 | 3 | import jdave.junit4.JDaveRunner; 4 | 5 | import org.jmock.Expectations; 6 | import org.junit.runner.RunWith; 7 | import org.robotframework.jdave.contract.FieldIsNotNullContract; 8 | import org.robotframework.swing.factory.OperatorFactory; 9 | import org.robotframework.jdave.mock.MockSupportSpecification; 10 | 11 | 12 | @RunWith(JDaveRunner.class) 13 | public class TreeSupportSpec extends MockSupportSpecification { 14 | public class Any { 15 | public TreeSupport create() { 16 | return new TreeSupport(); 17 | } 18 | 19 | public void hasOperatorFactory() { 20 | specify(context, satisfies(new FieldIsNotNullContract("operatorFactory"))); 21 | } 22 | } 23 | 24 | public class CreatingTreeOperator { 25 | private TreeSupport treeSupport = new TreeSupport(); 26 | private String treeIdentifier = "someTree"; 27 | private TreeOperator treeOperator = dummy(TreeOperator.class); 28 | 29 | public TreeSupport create() { 30 | injectMockOperatorFactory(); 31 | return treeSupport; 32 | } 33 | 34 | public void createsTreeOperatorAndVerifiesContext() { 35 | specify(context.treeOperator(treeIdentifier), must.equal(treeOperator)); 36 | } 37 | 38 | private void injectMockOperatorFactory() { 39 | final OperatorFactory operatorFactory = injectMockTo(treeSupport, OperatorFactory.class); 40 | checking(new Expectations() {{ 41 | one(operatorFactory).createOperator(treeIdentifier); 42 | will(returnValue(treeOperator)); 43 | }}); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/util/ComponentExistenceResolverSpec.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.util; 2 | 3 | import jdave.Specification; 4 | import jdave.junit4.JDaveRunner; 5 | 6 | import org.jmock.Expectations; 7 | import org.junit.runner.RunWith; 8 | import org.netbeans.jemmy.TimeoutExpiredException; 9 | import org.netbeans.jemmy.operators.Operator; 10 | import org.robotframework.swing.arguments.IdentifierHandler; 11 | 12 | import static org.hamcrest.Matchers.is; 13 | 14 | 15 | @RunWith(JDaveRunner.class) 16 | public class ComponentExistenceResolverSpec extends Specification { 17 | public class Any { 18 | private IdentifierHandler operatorFactory; 19 | private Operator dummyOperator = mock(Operator.class); 20 | 21 | public ComponentExistenceResolver create() { 22 | operatorFactory = mock(IdentifierHandler.class); 23 | return new ComponentExistenceResolver(operatorFactory); 24 | } 25 | 26 | public void satisfiesConditionIfComponentFound() { 27 | checking(new Expectations() {{ 28 | one(operatorFactory).parseArgument("someIdentifier"); 29 | will(returnValue(dummyOperator)); 30 | }}); 31 | 32 | specify(context.satisfiesCondition("someIdentifier")); 33 | } 34 | 35 | public void doesNotSatisfyConditionIfComponentIsNotFound() { 36 | checking(new Expectations() {{ 37 | one(operatorFactory).parseArgument("someIdentifier"); 38 | will(throwException(new TimeoutExpiredException("timeout expired"))); 39 | }}); 40 | 41 | specify(context.satisfiesCondition("someIdentifier"), is(false)); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/org/robotframework/swing/util/PropertyExtractorSpec.java: -------------------------------------------------------------------------------- 1 | package org.robotframework.swing.util; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import jdave.Specification; 7 | import jdave.junit4.JDaveRunner; 8 | 9 | import org.junit.runner.RunWith; 10 | 11 | @RunWith(JDaveRunner.class) 12 | public class PropertyExtractorSpec extends Specification { 13 | public class Any { 14 | public void extractsProperties() { 15 | Object bean = new MyBean(); 16 | Map expectedProperties = new HashMap() {{ 17 | put("something", "someValue"); 18 | put("otherProp", "otherValue"); 19 | }}; 20 | 21 | 22 | PropertyExtractor extractor = new PropertyExtractor(); 23 | specify(extractor.extractProperties(bean), expectedProperties); 24 | } 25 | } 26 | } 27 | 28 | class MyBean { 29 | public String getSomething() { 30 | return "someValue"; 31 | } 32 | 33 | public String getSomethingElse(int arg) { 34 | return "somethingElse"; 35 | } 36 | 37 | private String getSomethingPrivate() { 38 | return "somethingPrivate"; 39 | } 40 | 41 | public void setFoo() {} 42 | 43 | public Object getOtherProp() { 44 | return "otherValue"; 45 | } 46 | 47 | public boolean isTrue() { 48 | return true; 49 | } 50 | } -------------------------------------------------------------------------------- /src/test/resources/robot-tests/__init__.robot: -------------------------------------------------------------------------------- 1 | *** Settings *** 2 | Suite Setup launchApplicationAndSetTimeouts 3 | Suite teardown closeWindow Test App 4 | Library TestSwingLibrary 5 | Force Tags regression 6 | 7 | *** Keywords *** 8 | launchApplicationAndSetTimeouts 9 | setSystemProperty testApp.secret Test Text Field 10 | startApplication org.robotframework.swing.testapp.TestApplication 11 | selectMainWindow 12 | setJemmyTimeouts 1 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/test/resources/robot-tests/applicationlaunching.robot: -------------------------------------------------------------------------------- 1 | *** Settings *** 2 | Library TestSwingLibrary 3 | 4 | *** Variables *** 5 | ${testApplicationName} org.robotframework.swing.testapp.keyword.testapp.SomeApplication 6 | ${classWithoutMainMethod} org.robotframework.swing.keyword.launch.ApplicationLaunchingKeywords 7 | 8 | *** Test Cases *** 9 | Launch Application 10 | runKeywordAndExpectError Application was not called assertApplicationWasCalled 11 | launchApplication ${testApplicationName} 12 | assertApplicationWasCalled 13 | 14 | Launch Application Gives Descriptive Error Message If Main Method Is Not Found 15 | runKeywordAndExpectError Class '${classWithoutMainMethod}' doesn't have a main method. launchApplication ${classWithoutMainMethod} 16 | 17 | *** Keywords *** 18 | shouldNotHaveBeenCalled 19 | ${callStatus}= getTestAppCallStatus 20 | shouldBeEqual false ${callStatus} 21 | 22 | -------------------------------------------------------------------------------- /src/test/resources/robot-tests/awtcomponent.robot: -------------------------------------------------------------------------------- 1 | *** Settings *** 2 | Library TestSwingLibrary 3 | 4 | *** Variables *** 5 | ${AWT ERR} = AWT components are not supported by this keyword. 6 | 7 | 8 | *** Test Cases *** 9 | Unsupported AWT operation fails 10 | Run keyword and expect error ${AWT ERR} Push button awt=someButtom 11 | 12 | Clear AWT Text Field 13 | Insert Into Text Field awt=awtTextField AWTName 14 | Clear text field awt=awtTextField 15 | ${text}= Get Text Field Value awt=awtTextField 16 | Should be empty ${text} 17 | 18 | Insert Into AWT Text Field With Name 19 | Clear text field awt=awtTextField 20 | Insert Into Text Field awt=awtTextField AWTName 21 | ${text}= Get Text Field Value awt=awtTextField 22 | shouldBeEqual ${text} AWTName 23 | 24 | Insert Into AWT Text Field With Index 25 | Clear text field awt=0 26 | Insert Into Text Field awt=0 AWTindex 27 | ${text}= Get Text Field Value awt=awtTextField 28 | shouldBeEqual ${text} AWTindex 29 | 30 | Type Into AWT Text Field 31 | [Tags] Known Issue Windows 32 | Clear text field awt=awtTextField 33 | Type Into Text Field awt=awtTextField AWT Typed 34 | ${text}= Get Text Field Value awt=awtTextField 35 | shouldBeEqual ${text} AWT Typed 36 | 37 | AWT Text field should be enabled 38 | Text Field Should be enabled awt=awtTextField 39 | Run keyword and expect error Textfield 'awt=awtDisabledTextField' is disabled. 40 | ... Text Field Should be enabled awt=awtDisabledTextField 41 | 42 | AWT Text field should be disabled 43 | Text Field Should be disabled awt=awtDisabledTextField 44 | Run keyword and expect error Textfield 'awt=awtTextField' is enabled. 45 | ... Text Field Should be disabled awt=awtTextField 46 | -------------------------------------------------------------------------------- /src/test/resources/robot-tests/development.robot: -------------------------------------------------------------------------------- 1 | *** Settings *** 2 | Library TestSwingLibrary 3 | Library org.robotframework.javalib.library.ClassPathLibrary org/robotframework/swing/**/*.class 4 | 5 | *** Variables *** 6 | ${UNFORMATTED LINE}= org.robotframework.swing.testapp.TestApplication$2 7 | ${FORMATTED LINE}= Level: 0 Component: org.robotframework.swing.testapp.TestApplication$2 Index: 0 Name: Main Frame 8 | ${SECOND FORMATTED LINE}= Level: 5 Component: org.robotframework.swing.testapp.TestTextField Index: 0 Name: testTextField 9 | 10 | 11 | *** Test Cases *** 12 | List Components In Context 13 | selectMainWindow 14 | ${output}= recordStdout listComponentsInContext 15 | shouldContain ${output} ${FORMATTED LINE} 16 | shouldContain ${output} ${SECOND FORMATTED LINE} 17 | 18 | Return Value Of List Components In Context Without Formatting 19 | selectMainWindow 20 | ${output}= listComponentsInContext 21 | shouldContain ${output} ${UNFORMATTED LINE} 22 | shouldNotContain ${output} ${FORMATTED LINE} 23 | 24 | Return Value Of List Components In Context With Formatting 25 | selectMainWindow 26 | ${output}= listComponentsInContext FORMATTED 27 | shouldContain ${output} ${FORMATTED LINE} 28 | -------------------------------------------------------------------------------- /src/test/resources/robot-tests/dispatchmodel.robot: -------------------------------------------------------------------------------- 1 | *** Settings *** 2 | Library TestSwingLibrary 3 | Test teardown Set jemmy dispatch model QUEUE_SHORTCUT 4 | 5 | 6 | *** Test Cases *** 7 | Dispatch model is QUEUE_SHORTCUT by default 8 | ${old dispatch model} = Set jemmy dispatch model ROBOT 9 | Should be equal ${old dispatch model} QUEUE_SHORTCUT 10 | 11 | Dispatch model changes 12 | Set jemmy dispatch model ROBOT 13 | ${old dispatch model} = Set jemmy dispatch model ROBOT_SMOOTH 14 | Should be equal ${old dispatch model} ROBOT 15 | 16 | Unknown dispatch model 17 | Run keyword and expect error Unknown Jemmy dispatch model FOO.\nSupported models are * Set jemmy dispatch model FOO 18 | 19 | All dispatch models 20 | Set jemmy dispatch model QUEUE 21 | Set jemmy dispatch model QUEUE_SHORTCUT 22 | Set jemmy dispatch model ROBOT 23 | Set jemmy dispatch model ROBOT_SMOOTH 24 | -------------------------------------------------------------------------------- /src/test/resources/robot-tests/editorpane.robot: -------------------------------------------------------------------------------- 1 | *** Settings *** 2 | Library TestSwingLibrary 3 | 4 | *** Variables *** 5 | ${editorPaneName} testEditorPane 6 | ${linkText} Network Elements 7 | ${expectedEventDescription} DeviceName 8 | 9 | *** Test Cases *** 10 | Click Hyper Link 11 | runKeywordAndExpectError Link was not clicked linkShouldHaveBeenClicked 12 | clickHyperLink testEditorPane Network Elements 13 | linkShouldHaveBeenClicked 14 | hyperLinkEventDescriptionShouldBe ${expectedEventDescription} 15 | 16 | -------------------------------------------------------------------------------- /src/test/resources/robot-tests/extending.robot: -------------------------------------------------------------------------------- 1 | *** Settings *** 2 | Library org.robotframework.swing.testapp.extension.ExtendedSwingLibrary WITH NAME ext1 3 | Library org.robotframework.swing.testapp.extension.ExtendedSwingLibrary2 WITH NAME ext2 4 | suite teardown Restore timeouts 5 | 6 | 7 | *** Test Cases *** 8 | Test Extended Keyword Is Available 9 | ${value}= ext1.keywordInOtherPackage HelloWorld! 10 | shouldBeEqual ${value} HelloWorld! 11 | ${value}= ext2.keywordInOtherPackage HelloWorld! 12 | shouldBeEqual ${value} HelloWorld! 13 | 14 | *** Keywords *** 15 | Restore timeouts 16 | ext2.Set jemmy timeouts 1 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/test/resources/robot-tests/filechooser.robot: -------------------------------------------------------------------------------- 1 | *** Settings *** 2 | Suite Setup createTestFileToTempDirectory 3 | Library OperatingSystem 4 | Library TestSwingLibrary 5 | 6 | *** Variables *** 7 | ${fileChooserButton} openFileChooser 8 | ${fileToChoose} ${TEMPDIR}${/}test_file.txt 9 | ${anotherFile} ${TEMPDIR}${/}myFile.txt 10 | ${defaultFile} ${TEMPDIR}${/}someFile.txt 11 | 12 | *** Test Cases *** 13 | Choose From File Chooser Keyword Should Choose File From File Chooser 14 | pushButton ${fileChooserButton} 15 | chooseFromFileChooser ${fileToChoose} 16 | selectedFileShouldBe ${fileToChoose} 17 | 18 | Cancel File Chooser Keyword Should Cance File Choosing 19 | pushButton ${fileChooserButton} 20 | cancelFileChooser 21 | fileChooserShouldHaveBeenCancelled 22 | 23 | Save File In File Chooser With Non Existing File 24 | pushButton ${fileChooserButton} 25 | chooseFromFileChooser ${anotherFile} 26 | selectedFileShouldBe ${anotherFile} 27 | 28 | Choose File In File Chooser Without Args 29 | pushButton ${fileChooserButton} 30 | chooseFromFileChooser ${defaultFile} 31 | selectedFileShouldBe ${defaultFile} 32 | 33 | *** Keywords *** 34 | createTestFileToTempDirectory 35 | touch ${fileToChoose} 36 | 37 | -------------------------------------------------------------------------------- /src/test/resources/robot-tests/keyboardevent.robot: -------------------------------------------------------------------------------- 1 | *** Settings *** 2 | Test Setup selectMainWindow 3 | Library TestSwingLibrary 4 | 5 | *** Variables *** 6 | ${textFieldName} testTextField 7 | ${testText} Rf 8 | ${tableName} testTable 9 | 10 | *** Test Cases *** 11 | Send Key Event Keyword Sends Key Events 12 | [Tags] display-required 13 | shouldInsertKeysToTextField 14 | shouldSwitchCellsWithTabs 15 | 16 | *** Keywords *** 17 | shouldInsertKeysToTextField 18 | clearAndSelectTextField 19 | sendKeyboardEvent VK_R SHIFT_MASK 20 | sendKeyboardEvent VK_F 21 | textFieldContentsShouldBe ${testText} 22 | 23 | clearAndSelectTextField 24 | clearTextField ${textFieldName} 25 | FocusToComponent ${textFieldName} 26 | 27 | textFieldContentsShouldBe 28 | [Arguments] ${expectedText} 29 | selectMainWindow 30 | ${textFieldContents}= getTextFieldValue ${textFieldName} 31 | shouldBeEqual ${expectedText} ${textFieldContents} 32 | 33 | shouldSwitchCellsWithTabs 34 | selectTableCell ${tableName} 0 0 35 | tableCellShouldBeSelected ${tableName} 0 0 36 | sendKeyboardEvent VK_TAB 37 | tableCellShouldBeSelected ${tableName} 0 1 38 | sendKeyboardEvent VK_TAB SHIFT_MASK 39 | tableCellShouldBeSelected ${tableName} 0 0 40 | 41 | -------------------------------------------------------------------------------- /src/test/resources/robot-tests/platform_info.py: -------------------------------------------------------------------------------- 1 | import platform 2 | 3 | is_osx = platform.java_ver()[-1][0] == 'Mac OS X' 4 | CTRL_CMD = 'META_MASK' if is_osx else 'CTRL_MASK' 5 | -------------------------------------------------------------------------------- /src/test/resources/robot-tests/scroll.robot: -------------------------------------------------------------------------------- 1 | *** Settings *** 2 | Library TestSwingLibrary 3 | Library Dialogs 4 | 5 | *** Test Cases *** 6 | Component should be visible 7 | Component should be visible combo_0 8 | Component should not be visible 9 | Component should not be visible combo_9 10 | Component scrolling 11 | [Setup] Scroll component to view combo_0 12 | Component should not be visible combo_9 13 | Scroll component to view combo_9 14 | Component should be visible combo_9 15 | [Teardown] Scroll component to view combo_0 16 | -------------------------------------------------------------------------------- /src/test/resources/robot-tests/thread.robot: -------------------------------------------------------------------------------- 1 | *** Settings *** 2 | Library org.robotframework.swing.testapp.extension.ExtendedSwingLibrary 3 | 4 | *** Test Cases *** 5 | Runs Keyword In Separate Thread 6 | [Tags] flickering 7 | runKeywordAndExpectError * shouldBeRunInSeparateThread 8 | runInSeparateThread shouldBeRunInSeparateThread 9 | runInSeparateThread shouldberuninseparatethread 10 | runInSeparateThread Should Be Run In Separate Thread 11 | 12 | Runs Keywords From Other Packages 13 | runKeywordInSeparateThread keywordInOtherPackage arg 14 | 15 | Checks Arguments If ArgumentNames Are Available 16 | runKeywordAndExpectError Expected 1 but got 2 arguments.* runKeywordInSeparateThread keywordInOtherPackage foo bar 17 | 18 | Doesn't Fail When Argument Names Are Not Available 19 | runKeywordInSeparateThread keywordWithoutArgumentNames arg 20 | runKeywordInSeparateThread keywordWithoutArgumentNames foo bar # even when it should 21 | 22 | Works With Real Keywords 23 | runKeywordInSeparateThread selectFromMainMenuAndWait Test Menu|Show Test Dialog 24 | Set Jemmy Timeout DialogWaiter.WaitDialogTimeout 2 25 | Wait Until Keyword Succeeds 10 seconds 1 second dialogShouldBeOpen Message 26 | [Teardown] closeDialog Message 27 | 28 | Run keywords with varargs 29 | runKeywordInSeparateThread callComponentMethod testButton getToolTipText 30 | runKeywordInSeparateThread callComponentMethod testButton getBaseline 10 10 31 | runKeywordAndExpectError Expected 2 or more but got 1 arguments.* runKeywordInSeparateThread callComponentMethod foo 32 | 33 | *** Keywords *** 34 | Run In Separate Thread 35 | [Arguments] ${keyword name} 36 | runKeywordInSeparateThread ${keyword name} 37 | Wait Until Keyword Succeeds 10 seconds 1 second keywordWasRun 38 | 39 | -------------------------------------------------------------------------------- /src/test/resources/robot-tests/timeout.robot: -------------------------------------------------------------------------------- 1 | *** Settings *** 2 | Library TestSwingLibrary 3 | 4 | *** Variables *** 5 | ${tolerance} 3 6 | 7 | *** Test Cases *** 8 | Set Jemmy Timeout 9 | setJemmyTimeout DialogWaiter.WaitDialogTimeout 1 10 | ${elapsedTime}= runKeywordAndMeasureTime dialogShouldNotBeOpen Nonexistent Dialog 11 | elapsedTimeWasLessThanLimit ${elapsedTime} ${tolerance} 12 | 13 | Set Jemmy Timeout Units 14 | setJemmyTimeout DialogWaiter.WaitDialogTimeout 2 15 | ${prevms}= setJemmyTimeout DialogWaiter.WaitDialogTimeout 3000 ms 16 | shouldBeEqualAsIntegers ${prevms} 2000 17 | ${prev}= setJemmyTimeout DialogWaiter.WaitDialogTimeout 4 18 | shouldBeEqualAsIntegers ${prev} 3 19 | 20 | *** Keywords *** 21 | runKeywordAndMeasureTime [Arguments] ${keyword} @{arguments} 22 | ${startTime}= getTime epoch 23 | runKeyword ${keyword} @{arguments} 24 | ${endTime}= getTime epoch 25 | ${elapsedTime}= evaluate ${endTime}-${startTime} 26 | log ${elapsedTime} 27 | [return] ${elapsedTime} 28 | 29 | elapsedTimeWasLessThanLimit [Arguments] ${elapsedTime} ${toleranceLimit} 30 | ${elapsedWithinLimits} evaluate ${elapsedTime}<=${toleranceLimit} 31 | shouldNotBeEqualAsIntegers ${elapsedWithinLimits} 0 32 | 33 | elapsedTimeIsWithinLimits [Arguments] ${elapsedTime} ${lowerLimit} ${upperLimit} 34 | ${elapsedWithinLimits}= evaluate ${lowerLimit}<=${elapsedTime}<=${upperLimit} 35 | shouldNotBeEqualAsIntegers ${elapsedWithinLimits} 0 36 | 37 | -------------------------------------------------------------------------------- /src/test/resources/robot-tests/togglebutton.robot: -------------------------------------------------------------------------------- 1 | *** Settings *** 2 | Library TestSwingLibrary 3 | 4 | *** Variables *** 5 | ${buttonName} testToggleButton 6 | ${buttonText} Test Toggle Button 7 | 8 | *** Test Cases *** 9 | Toggle Button Should Be Selected Passes If Button Is Selected 10 | selectToggleButton ${buttonName} 11 | toggleButtonShouldBeSelected ${buttonName} 12 | toggleButtonShouldBeSelected ${buttonText} 13 | unSelectToggleButton ${buttonName} 14 | runKeywordAndExpectError Toggle Button '${buttonName}' is not selected. toggleButtonShouldBeSelected ${buttonName} 15 | runKeywordAndExpectError Toggle Button '${buttonText}' is not selected. toggleButtonShouldBeSelected ${buttonText} 16 | 17 | Toggle Button Should Not Be Selected Passes If Button Is Not Selected 18 | unSelectToggleButton ${buttonName} 19 | toggleButtonShouldNotBeSelected ${buttonName} 20 | toggleButtonShouldNotBeSelected ${buttonText} 21 | selectToggleButton ${buttonName} 22 | runKeywordAndExpectError Toggle Button '${buttonName}' is selected. toggleButtonShouldNotBeSelected ${buttonName} 23 | runKeywordAndExpectError Toggle Button '${buttonText}' is selected. toggleButtonShouldNotBeSelected ${buttonText} 24 | 25 | Toggle Button Keywords Should Fail If Context Is Not A Window 26 | selectEmptyContext 27 | runKeywordAndExpectError *To use this keyword you must first select a correct context* toggleButtonShouldBeSelected someButton 28 | runKeywordAndExpectError *To use this keyword you must first select a correct context* toggleButtonShouldNotBeSelected someButton 29 | [Teardown] selectMainWindow 30 | 31 | Push Toggle Button Toggles Selection State 32 | selectToggleButton ${buttonName} 33 | pushToggleButton ${buttonName} 34 | toggleButtonShouldNotBeSelected ${buttonName} 35 | pushToggleButton ${buttonName} 36 | toggleButtonShouldBeSelected ${buttonName} 37 | 38 | --------------------------------------------------------------------------------