Sunday, April 19, 2009

Build FLEX application with automation libraries using Flex3 SDK and ANT

To test Flex Application with any automated testing tool (like QTP), automation libraries should be included in the application SWF file to make the application testable. Flex Automation libraries are not part of the Flex SDK, these comes with Flex Builder 3. If you are using Flex SDK and ANT as build tool, you need to perform following steps to compile your application.

  1. Copy flex automation libraries (automation.swc, automation_agent.swc, automation_dmv.swc, automation_flashflexkit.swc) from Flex Build 3 installation (/frameworks/libs) to your local directory (let say C:\flex-automation).
  2. Copy automation tool library (qtp.swc in case if you are using QTP as testing tool) in C:\flex-automation
  3. Copy flex agents (automation_agent_rb.swc, automation_rb.swc) in C:/flex-automation/locale/en_US. Flex agent facilitates communication between a flex application and an automation tool.
  4. Copy FLEX_HOME/frameworks/flex-config.xml to flex-config-auto.xml and keep it in same directory (FLEX_HOME/frameworks)
  5. Add following entries in include-libraries section of flex-config-auto.xml
  6. <include-libraries>
    <library>C:/flex-automation/automation.swc</library>
    <library>C:/flex-automation/automation_agent.swc</library>
    <library>C:/flex-automation/automation_dmv.swc</library>
    <library>C:/flex-automation/automation_flashflexkit.swc</library>
    <library>C:/flex-automation/qtp.swc</library>
    </include-libraries>
  7. In mxmlc task of ant build file specify load-config path as
  8. <load-config filename="FLEX_HOME/frameworks/flex-config-auto.xml"/>
  9. Add compiler-library-path in mxmlc task
  10. <compiler.library-path dir="C:/flex-automation" append="true">
    <include name="locale/en_US" />
    </compiler.library-path>
so your mxmlc task would look like this:

<mxmlc file="${APP_ROOT}/Main.mxml" output="${build.dir}/main.swf">
<load-config filename="${FLEX_HOME}/frameworks/flex-config-auto.xml"/>
<source-path path-element="${FLEX_HOME}/frameworks"/>
<compiler.library-path dir="${FLEX_HOME}/frameworks" append="true">
<include name="libs" />
<include name="locale/en_US" />
</compiler.library-path>
<compiler.library-path dir="${FLEX_AUTOMATION_HOME}" append="true">
<include name="locale/en_US" />
</compiler.library-path>
</mxmlc>

mxmlc ANT task comes with flexbuilder3 and flex sdk. In flex builder, the location of task is : _FLEX_BUILDER_INSTALL_LOCATION_\sdks\3.0.0\ant\flexTasks.jar

To use this ant task in ant build file use ant taskdef task as below:
< taskdef resource="flexTasks.tasks" classpath="_PATH_TO_TASK_/flexTasks.jar"/>

Wednesday, April 15, 2009

JMeter: run tests using ANT

Do you run your test cases in jmeter GUI, i really never like to run my tests in it. I always like to have command line options or preferably ANT. Following are the steps to run any JMeter test cases using ANT:

1. Install ANT and JMeter
2. Copy ant-jmeter.jar ant ANT_HOME/lib directory.
3. Create a common.xml file (as mentioned below) which can be referred by any Jmeter Test plan.
4. Create a build.xml for every test plan, which refers to common.xml
5. Use xslt task to create the html report of the test cases.

common.xml

<project name="jmeter-test-common" default="run" basedir=".">

<property name="jmeter.dir" value="C:/Jmeter"/>
<taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>

<target name="run-test">

<echo message="${jmeter.dir}"/>
<jmeter jmeterhome="${jmeter.dir}"
testplan="${test.dir}/${jmeter.file}.jmx"
resultlog="${test.dir}/${jmeter.file}.jtl">
<property name="jmeter.save.saveservice.output_format" value="xml"/>
<property name="jmeter.save.saveservice.assertion_results" value="all"/>
<property name="request.threads" value="${request.threads}"/>
<property name="request.loop" value="${request.loop}"/>
<jvmarg value="-Duser.dir=${test.dir}"/>
</jmeter>

<echo message="Generating Report ..."/>

<xslt in="${test.dir}/${jmeter.file}.jtl"
out="${test.dir}/${jmeter.file}_summary.html"
style="${jmeter.dir}/extras/jmeter-results-report_21.xsl"/>

<xslt in="${test.dir}/${jmeter.file}.jtl"
out="${test.dir}/${jmeter.file}_detailed.html"
style="${jmeter.dir}/extras/jmeter-results-detail-report_21.xsl"/>
</target>
</project>


build.xml


<project name="my-test" default="run" basedir=".">

<import file="${ant.file.my-test}/common.xml"/>

<target name="run">
<antcall target="run-test">
<param name="jmeter.file" value="LOGIN"/>
<!-- here LOGIN is the jmx file name -->
<param name="test.dir" value="${ant.file}/.."/>
<param name="request.threads" value="5"/>
<param name="request.loop" value="1"/>
</antcall>
</target>

</project>


JMeter: Using Variables

In JMeter value of user.dir varaible is set to jmeter/bin directory. Jmeter saves and loads the test script from user.dir, so by default it is jmeter/bin. But what if your test scripts are saved in directory other than jmeter/bin which is the case most of the time.
We can override the value of this varaible in jmeter/bin/jmeter.properties as mentioned below:
user.dir=C:/perftest/mytest
Now the jmeter wil look for test script in C:/perftest/mytest instead of its default location. We can also specify this varaibale as jvm arg; if we are running jmeter from command prompt. (-Duser.dir=C:/perftest/mytest)

Accessing user.dir value in Jmeter test plan
In Test Plan -> User Defined Variables add a new variable
Name: userdir
Value: ${__property(user.dir)}

Now this userdir varaible can be used in jmeter test plan as location of the test script (${userdir}).

Reading values from a file
${__CSVRead(${userdir}/env.txt,0)} -> It will read the first column of the first line from the env.txt file

__P
This is a property function which is intended for use with properties defined on the command line. Unlike the __property function, there is no option to save the value in a variable, and if no default value is supplied, it is assumed to be 1.
${__P(request.threads)} -> return the value of request.threads
${__P(request.loop)} -> return the value of request.loops
${__javaScript(${__P(request.threads)}*2)} -> multiply the value of request.threads by 2

Use JMeter to load test FLEX Applications

Flex applications use a binary protocol called AMF (Action Message Format) that they use to remotely communicate with the server. The easiest way to use JMeter with a Flex application is to use HTTP proxy server.

- Create a New Test Plan
- Right Click on Test Plan, Add -> Thread Group
- Right Click on Thread Group, Add -> Config Element -> HTTP Request Defaults
- Select 'HTTP Request Defaults'
- Specify Server Name or IP, for eg. www.mysite.com
- Specify Port number, eg. 8888
- Specify protocol, i.e. http
- Specify Path, foe eg. /main/index.html
- Select Work Bench
- Right Click on Work bench, Add -> Non-Test Elements -> HTTP Proxy Server
- Select 'HTTP Proxy Server'
- Specify port number for proxy (default is 8080)
- Set Target Controller to 'Test Plan -> Thread Group'
- Set inlude URL patterns , .* to include all
- Set exclude URL patterns, for eg. , .*\.gif, .*\.png, .*\.css, .*\.js
- Open Internet Explorer
- Goto Tools -> Internet Options -> Connections -> LAN settings
- In Proxy Server panel, specify address as 'localhost' and port number (which is specified in
meter's HTTP proxy server, i.e. 8080)

- Select 'HTTP Proxy Server'
- Click on Start
- Open IE and open URL 'http://www.mysite.com:8888/main/index.html'
- As soon as you visit the URL jmeter starts the recording, and you can see all the requests in
METER

- For AMF requests (for Adobe FLEX), request is saved as file with extension '.binary' in the bin
irectory of jmeter

- Click on Stop button of 'HTTP Proxy Server' to stop the recording.

Test Plan is ready. You can modify it now according to your requirements.

Proxy Server setup document from Apache:
http://jakarta.apache.org/jmeter/usermanual/jmeter_proxy_step_by_step.pdf

Sunday, March 22, 2009

PERL round function

Following is the round function in PERL, which you can put into your script and actually call to round numbers instead of cutting them with ceil or cut.

In the following round function, you can specify the number to round and the number of digits to show after the decimal.

sub round {
my $number = shift || 0;
my $dec = 10 ** (shift || 0);
return int( $dec * $number + .5 * ($number <=> 0)) / $dec;
}

$result = round(123.4567,3);

it would return 123.457




About url in firefox

There are few special URLs which begins with about: that you can type into the firefox location bar:

about: => The same page as Help -> About
about:blank => A blank page
about:cache => Displays cache statistics and directory location
about:config => GUI for modifying user preferences
about:plugins => List all plugins
about:logo => Displays the firefox logo

There is an extension available for firefox to save advanced preferences. gui:config makes it easier to change preferences that can only be found in the “about:config”. This add on can be downloaded from https://addons.mozilla.org/en-US/firefox/addon/5523

Friday, March 20, 2009

TOAD: Tips and Tricks

Tips for TOAD's sql editor

  • Tired of typing long column/table name while writing a sql query? Use Auto Complete feature of TOAD. Type a part of the table/column name and then press CTRL + . (period). TOAD will automatically identify the name of the table/column and fill in the rest of the word. If there is more than one option available then TOAD will list all the available options and you can select from there.
  • Forgot the queries which you ran in past? In TOAD's sql editor Press ALT + UP/DOWN key and it will show you the past queries (similar to SQL recall feature , F8)
  • You constantly making spell mistakes while writing queries? Right click in the editor and select “Editing Options”. On this new option screen click on the “Auto Replace” button in the bottom right hand corner. Here you will see a list of the common misspelled words our user’s experience. If there are words you constantly misspell, then you can add them to the list by using the “Add” button. So, now in the editor if you mistype the word “select” as “seelct” … it will automatically fix itself once you hit the spacebar.
  • Wanted to control number of rows in your grid? Use OCI array size option to tell toad how many rows you want retrieved at a time. If you want to only see first 100 rows of an table, set this option to 100.
  • Generating Schema Documentation- From the Database menu, select Report -> HTML Schema Doc Generator.

Sunday, December 28, 2008

Perl : Get filename or directory name from an absolute path

Use Perl's File module to get Filename or directory name from an absolute path. Below is an example of how to do this:

#!/usr/bin/perl
use File::Basename;

print getDirPath("/mnt/users/vishnu/blog/PerlPost.html");
print getFileNameWithoutExt("/mnt/users/vishnu/blog/PerlPost.html");
print getFileName("/mnt/users/vishnu/blog/PerlPost.html");

sub getDirPath() {
return dirname($_[0]);
}

sub getFileNameWithoutExt() {
my $file = basename($_[0]);
$file =~ s/\.[^.]*$//;
return $file;
}

sub getFileName() {
return basename($_[0]);
}


Output of above program would be:
/mnt/users/vishnu/blog
PerlPost
PerlPost.html

Saturday, December 20, 2008

Perl error: Can't locate module in @INC

If you get a Perl error message like Can't locate module.pm in @INC, this message means that the Perl module you're trying to include (like the module named module) can't be found in Perl's include path, which is represented by the variable named @INC.

Perl uses an @INC variable that contains the directories it will search in when you specify that you want to include a module, but you can't look at it like an environment variable. Although Perl doesn't have something like the CLASSPATH environment variable you can easily look at, you can print the @INC variable with a simple one-line command. The following Perl command shows the directories that Perl looks in when it tries to load modules:

perl -e 'print join("\n", @INC);'

Including a perl module your @INC include path

There are different ways by which you can add your perl module in @INC include path
1. Specify it in PERL5LIB environment variable
export PERL5LIB=path

2. Perl takes -I option where you can specify the additional directories where it should search for modules.
perl -I path myscript.pl

3. Modify your Perl program to find the module by adding below line near the top of Perl programs. This simple line of code tells your Perl program to add this directory to it's @INC search directory.
use lib "path"

Friday, December 19, 2008

Perl: FileDiff utility

I have 2 csv files (pipe seperated), one column (basically an Id field) is common in both the files. I need to compare both the files on the basis of this common field and print the lines which has common Id, Lines with id which is only in file1 and vice-versa. I thought up for writing perl script for this task. See below script.