Fish

Wednesday, 22 June 2011

Selenium – Flex Integration Steps

Selenium – Flex Integration Steps

Download the following
• Install Selenium-IDE (if the link is problematic, download at http://release.seleniumhq.org/selenium-ide/1.0.10/selenium-ide-1.0.10.xpi and open it in Firefox, or see here). If the Selenium IDE window appears, you can just close it.
• Install the FlexMonkiumConsole by running the FlexMonkium installer. Please make a note of where you install the executable because you will need to tell the Firefox plugin where it can find it. When the installation completes, the FlexMonkiumConsole window will appear (a small application window with three buttons); you can close it for now.
• Download and unzip the FlexMonkium zip file. It contains:
o flexmonkium.xpi - The FlexMonkium Firefox extension installer.
o User-extensions.js - The FlexMonkium extensions for Selenium-RC.
• Install the FlexMonkium Firefox plugin by opening flexmonkium.xpi in Firefox.
• Flex_SDK 4.5
• Flash Builder 4

Preparing Flex SWF’s for use with Selenium

Open your Flash Builder
• Create new flex project
• Create one MonkeyContacts.mxml,PhoneGridItemRenderer,MonkeyContact.as files under in src folder
Copy the appropriate version of automation_monkey.swc (from the FlexMonkium.zip download) to the project's libs folder. For Flex 4, use automation_monkey4.x.swc. For 3.4 or 3.5, use FlexMonkey3.x.swc. For 3.2 or 3.3, use automation_monkey3.2 or automation_monkey3.3, respectively.
Add
1. Select the above created Project > Properties window in FlashBuilder
2. On the Flex Build path panel>Select libs folder>Click Add SWC button-Add Your automation_monkey4.x.swc file
3. On the Flex Compiler panel, add the following Additional Compiler Arguments:
-locale en_US-include-libraries libs/ automation_monkey4.x.swc

Once Build is Successful your project bin-debug system creates one MonkeyContacts.SWFfile with html and other files.

Recording Test Script use with Selenium IDE

• Open Selenium IDE in Firefox Browser and make sure by default it should be recordable.
• Now open your Created MonkeyContacts.html File in Firefox Browser
[Like:- file:///D:/Srini/Selenium_Flex_Demo/MonkeyContactsExample/bin-debug/MonkeyContacts.html]
• Do some validations on the Monkey Contacts Application.
• Now Selenium IDE able to identify your flex objects successfully. And we are able to replay again without any errors

Creating an Code for Selenium-RC

• FlexMonkium generates JUnit-based tests for use with Selenium-RC. To generate a test, select Options...>Format…> FlexMonkium (JUnit) – Selenium-RC from the Selenium-IDE File menu.
• Copy the FlexMonkium Code Selenium IDE.
• Launch the Eclipse IDE and create a one java project in Eclipse IDE include needed .jar files
• Create one Class and name it as any [like Flex Test]
• Paste the entire copied FlexMonkium Code under class file from the Selenium IDE
Please find the following flex code for sample with Selenium RC
package sample;
import com.thoughtworks.selenium.*;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
@SuppressWarnings("unused")

public class FlexTest {
private Selenium selenium;
private HttpCommandProcessor proc;
@Before
public void setUp() throws Exception {
proc = new HttpCommandProcessor("localhost", 4444, "*firefox", "file:///D:/FlexMonkey/MonkeyContactsExample/bin-debug/MonkeyContacts.html");
selenium = new DefaultSelenium(proc);
selenium.start();
selenium.windowMaximize();
}
@After
public void tearDown() throws Exception {
if (selenium != null) {
selenium.stop();
selenium = null;
}
}
@Test
public void myTestMethod() throws Exception {
selenium.open("file:///D:/FlexMonkey/MonkeyContactsExample/bin-debug/MonkeyContacts.html");
for (int t = 0;; t++) {
if (t >= 80) fail("timeout");
try {
if (proc.getBoolean("isFlexMonkey", new String[] {" "})) break;
} catch (Exception e) { }
Thread.sleep(500);
}
for (int t = 0;; t++) {
if (t >= 60) fail("timeout");
try {
if (proc.getBoolean("isFlexMonkey", new String[] {""})) break;
} catch (Exception e) { }
Thread.sleep(500);
}
}
}
• Now we are going to Launch the Selenium-Server
• When starting the Selenium-RC server, you must include the FlexMonkium extensions by supplying a path to FlexMonkium’s user-extension.js file.
java -jar selenium-server.jar -userextensions /pathToFlexMonkium/user-extensions.js

Example:- D:\Engines>java -jar selenium-server.jar -userextensions /"D:\Flex Monkium\FlexM
onkiumConsole\flexmonkium4.1.8"/user-extensions.js
Run Test Script with Junit Engine it will generates the test reports.

5 comments:

  1. Please make a note of where you install the executable because you will need to tell the Firefox plugin where it can find it.--- i can not understand.please explain in details.

    ReplyDelete
  2. Hi Vasu,

    I am using FF10 and when I try to record the events using flex-monkium it is unable to connect to SWF..
    Please help

    ReplyDelete
  3. i am not able to install felxmoniumconsole using adobe air. getting error as diginital signaure invalid.
    do you have any other alternative for resolve this issue or is there any opensource tool for automating flex web applications

    ReplyDelete
  4. I am not able to install Flex Monkium Console. Getting following error.

    "The application could not be installed because the installer file is damaged. Try obtaining a new installer file from the application author."

    Please help

    ReplyDelete
  5. Please tell me where i can download flexmonkium console. (are flex monkium console and flexmonky console same or different?). If same where i can downlaod them please help me.

    Please help

    ReplyDelete