
|
|
Using FlexMonkiumFlexMonkium is a plugin for Selenium that adds FlexMonkey recording and playback to Selenium-IDE and Selenium-RC. Install FlexMonkium by following the instructions in FlexMonkey Setup. FlexMonkium consists four components:
Preparing Flex SWF’s for use with Selenium
-include-libraries automation_monkeyN.x.swc
"${flexlib}/libs/automation/automation_agent.swc"
Instead of for automaton_monkeyN.x., substitute the name of the swc you are actually using, for example automation_monkey4.x.swc. he above arguments link in FlexMonkium as well as the Flex Automation libraries. Flex Builder automatically sets ${flexlib} to point to your default Flex SDK. Recording and Playback with Selenium-IDEFlexMonkium works mostly seamlessly with Selenium-IDE, interleaving Flex recording and playback with Selenium’s usual browser recording. To learn more about Selenium-IDE, see the Selenium-IDE User Guide. Simply open the Selenium-IDE window and turn on recording. In addition to the usual browser commands, Selenium will also record Flex commands from any Flex SWF which has been linked with the required libraries. Each action recorded will create a waitForFlexMonkey command in Selenium-IDE. Note: The current version of FlexMonkium does not work with pages containing more than one SWF. Whenever a SWF loads, Selenium will record a waitForFlexMonkey command, which at playback time will pause the script until the SWF loads. Playback works like usual Selenium playback. Understanding Recorded CommandsAll Flex UI interactions will be recorded as Selenium waitForFlexMonkey commands. The command locator will contain an XML representation of a FlexMonkey command corresponding to the recorded user interaction. The general form of the XML is: <UIEvent command="commandName" prop="propertyName" value="propertyValue" /> commandName is the name of the command to be executed. propertyName is the name of a property to use to identify the component being recorded. By default, the propertyName is automationName. value is the property value used to identify the component. The following is an example of a command specifying to click on a button labeled "Add". <UIEvent command="click" value="add"/> Any prop/value pair can be used to identify a component. The following specifies a click on the component with tooltip="Show details". <UIEvent command="click" prop="toolTip" value="Show details"/> To learn more about FlexMonkey commands, see the FlexMonkey documentation. Using the FlexMonkium ConsoleTo open the FlexMonkium console, click on the FlexMonkium icon on the Selenium-IDE toolbar. The console contains three icons: Create Verify, Connection Status, and Help.
The Connection Status icon will be green whenever a FlexMonkium-enabled SWF is loaded in the current browser page, and will be yellow otherwise. Note: In the current version of FlexMonkium, recording and playback will not work properly if more than one FlexMonkium-enabled SWF is running during recording or playback. Ensure that only one SWF is running in the current page, and that no other SWF’s are running in other browser windows or tabs. Creating FlexMonkey Verify CommandsClick on the Verify icon in the FlexMonkium console to switch to snapshot mode. Click on the browsers title bar, and then mousing over a SWF will highlight underlying components. Click to select a component for which you want to verify some value. A window will open where you can select attributes to be verified. For more information about FlexMonkey verify commands, see the FlexMonkey User Guide. When you create a Verify command, Selenium-IDE records a waitForFlexMonkey command. The locator will contain an XML-encoded FlexMonkey VerifyProperty command with the following general form: <VerifyProperty prop="propertyName" value="propertyValue" propertyString="propertyPath" expectedValue="valueExpected"/> propertyName and propertyValue identify the component to be verified. See the discussion of recorded commands above to learn more about component identification. propertyPath is a property name or path expression whose value is to be verified. valueExpected is the value expected for the specified propertyPath. Note: Prior to FlexMonkium 4.1.4, verifications were recorded as Verify instead of VerifyProperty commands. Beginning with FlexMonkium 4.1.4, VerifyProperty commands were recorded instead because there easier to read and edit, and because they allow verification of property path expressions in addition to simply property names. The following command checks that the field with automationName="FirstName" contains the value "Fred" for its text property. <VerifyProperty value="FirstName" propertyString="text" expectedValue="Fred/> In the above, the prop attribute was omitt not need to be explicitly specified, since it defaults to automationName. The following command checks that a DataGrid with automationName="SomeGrid" contains five rows (by checking the length of the associated dataProvider): <VerifyProperty value="SomeGrid" propertyString="dataProvider.length" expectedValue="5"/> Note: FlexMonkey bitmap verification is currently unavailable in FlexMonkium. Understanding FlexMonkey WaitFor CommandsBy default, FlexMonkey records a waitForFlexMonkey Selenium command for each recorded user action or verification step. If you do not want to wait, but instead want the command to fail if it's not true on the first try, use the flexMonkey Selenium command instead of the waitForFlexMonkey command. For VerifyProperty commands, Selenium will wait until the specified condition becomes true, or until a timeout occurs. For UIEvent commands, Selenium will wait until the specified component appears in the application. At playback time, waitForFlexMonkey commands will be handled like any other Selenium waitFor command, with playback pausing until the condition becomes true, or until a timeout occurs. Retrieving Flex component property valuesUse the getFlexMonkeyValue Selenium command to retrieve property and grid cell values from your Flex app under test. Note: Prior to FlexMonkium 4.1.4, the getFlexMokeyCellValue command was used to retrieve grid cell values. Beginning with FlexMonkium 4.1.4, getFlexMonkeyCellValue is deprecated, and getFlexMokeyValue is used for both property and cell values. You can "bootstrap" the creation of a getFlexMonkeyValue command in Selenium-IDE by interactively creating a VerifyProperty command with the FlexMonkiumConsole, and then modifying as described below. To retrieve a property value, you can create a VerifyProperty for the property, and then just change the command name from waitForFlexMonkey to getFlexMonkeyValue. In the "value" field of the command in Se-IDE, put the name of the variable where you want the value stored. For example, you could run the following commands from Se-IDE:
Within Se-IDE, you can use ${vars} within FlexMonkey XML commands, so you can, for example, retrieve the value from one field, and then use it later as input to another. To retrieve a grid cell value, change the XML command from VerifyProperty to VerifyGrid, and specify the grid itself as the component to be verified. Then add "row" and "col" attributes to the VerifyGrid command specifying the coordinates of the cell whose value you want to retrieve. For example:
When you generate code, for the "get" commands you'll get something like this: proc.getString("getFlexMonkeyValue", new String[] {"<VerifyGrid row=\"0\" col=\"2\" value=\"grid\" prop=\"automationName\">"}); You will need of course to add a variable to the generated code to actually store the result, eg: String result = proc.getString.... Understanding Selenium Command Extensions for FlexMonkeyCurrently, FlexMoney commands are stored as XML within the locator field of the following Selenium commands flexMonkey – Execute the FlexMonkey command xxxFlexMonkey – Evaluate the FlexMonkey verify command as the corresponding Selenium xxx command, where xxx is one of verify, assert, waitFor. getFlexMonkeyValue - Retrieve the value specified for verification by the FlexMonkey verify command. Generating Code for Selenium-RCFlexMonkium generates JUnit-based tests for use with Selenium-RC. To generate a test, select Export Test Case/Suite as… > FlexMonkium (JUnit) – Selenium-RC from the Selenium-IDE File menu. To learn more about running JUnit tests with Selenium-RC, see the Selenium-RC User guide. Note: You must export as FlexMonkium (JUNit) - Selenium-RC. The other Selenium export formats (Ruby, etc.), are not currently supported by FlexMonkium. When starting the Selenium-RC server, you must include the FlexMonkium extensions by supplying a path to FlexMonkium’s user-extension.js file. For example: java -jar selenium-server.jar -userExtensions /pathToFlexMonkium/user-extensions.js To Run Selinium Junit tests from command line you need the following on your classpath
To Set your class path used the following Windows Example:
Unix (bash) Example:
compile your class file using javac [fileyounamedinselinium].java To run the tests run this command (java org.junit.runner.JUnitCore <test class name>)
|