Monday, 28 May 2012

Automate Web Application Testing with Selenium for ABAP


Update: You find the current version of the SeleniumABAP Project at SAP Code Exchange.
Unfortunately I've caught a bad cold and I have to stay in bed exactly to the time I want to travel the Cluetrain to Vienna. Also today, which is the night of the SAP TechEd 2009 Demo Jam, I was not well enough to travel to Vienna. So I had to call Craig Cmehil this morning and canceled my attendance. But as already planned I release the source code of my project to the public. 

Demo Videos

To get an insight of what Selenium and Selenium for ABAP can do for you, please watch this Videos:

Source

The first thing what you need to record tests is Selenium IDE which comes as a Firefox plugin. If you're not running Firefox get it here.
To convert the recorded test in Selenium IDE to a ABAP Unit test class you need abap-rc.js which is a JavaScript file that can be imported into Selenium IDE by navigating to Options - Options ... - Formats in the Selenium IDE Menu. There you can click on the Add button, provide a name for the new format where I would suggest "ABAP Selenium RC" and then paste the code into the box below.
To run the generated ABAP Unit test you have to install the SAPLink Nugget ZSELENIUMABAP.nugg.zip. It provides the Selenium RC ABAP Client Driver class and also the XSL Transformations to create this class from the iedoc.xml which is the Selenium API definition.

I need your support

This is the current status of this project. What I would like to add is a possibility to generate eCATT tests in Selenium IDE and import them as an eCATT test script. If you know a way how to do that please contact me.

Tuesday, 17 April 2012

Selenium server Arguments.


Following are the arguments we can use while starting Selenium Server. If we use these arguments properly we can reduce the amount of time spent for finding a solution for complex scenarios.
-port : the port number the selenium server should use
(default 4444)
-timeout : an integer number of seconds before we should give up
-interactive: puts you into interactive mode.  See the tutorial for more details
-singleWindow: puts you into a mode where the test web site executes in a frame. This mode should only be selected if the application under test does not use frames.
-profilesLocation: Specifies the directory that holds the profiles that java clients can use to start up selenium.  Currently  supported for Firefox only.
-forcedBrowserMode : sets the browser mode to a single  argument (e.g. “*iexplore”) for all sessions, no matter what is passed to getNewBrowserSession
-forcedBrowserModeRestOfLine : sets the browser mode to all the remaining tokens on the line (e.g. “*custom /some/random/place/iexplore.exe”) for all sessions, no matter what is passed to getNewBrowserSession
-userExtensions : indicates a JavaScript file that will be loaded into selenium
-browserSessionReuse: stops re-initialization and spawning of the browser between tests
-avoidProxy: By default, we proxy every browser request; set this flag to make the browser use our proxy only for URLs containing ‘/selenium-server’
-firefoxProfileTemplate
: normally, we generate a fresh empty Firefox profile every time we launch.  You can specify a director to make us copy your profile directory instead.
-debug: puts you into debug mode, with more trace information anddiagnostics on the console
-browserSideLog: enables logging on the browser side; logging messages will be transmitted to the server.  This can affect performance.
-ensureCleanSession: If the browser does not have user profiles, make sure every new session has no artifacts from previous  sessions.  For example, enabling this option will cause all user cookies to be archived before launching IE, and restored after IE is closed.
-trustAllSSLCertificates: Forces the Selenium proxy to trust all  SSL certificates.  This doesn’t work in browsers that don’t use the  Selenium proxy.
-log : writes lots of debug information out to a log  file
-htmlSuite : Run a single HTML Selenese (Selenium Core) suite and then exit immediately, using the specified browser (e.g. “*firefox”) on the specified URL (e.g. “http://www.google.com”).  You need to specify the absolute path to the HTML test suite as well as the path to the HTML results file we’ll generate.
-proxyInjectionMode: puts you into proxy injection mode, a mode  where the selenium server acts as a proxy server for all content going to the test application.  Under this mode, multiple domains can be visited, and the following additional flags are supported:
-dontInjectRegex : an optional regular expression that proxy injection mode can use to know when to bypss injection
-userJsInjection : specifies a JavaScript file which will then be injected into all pages
-userContentTransformation : a regular  expression which is matched against all test HTML content; the  second is a string which will replace matches.  These flags can be used any number of times.  A simple example of how this could be useful: if you add “-userContentTransformation https http” then all “https” strings in the HTML of the test application will be changed to be “http”.

How to stop selenium Grid from Ant build?


How to stop selenium Grid from Ant build?
This is also a very simple process as similar to starting the Selenium Grrid from a bat/sh file[mentioned here].
First of all we need to create a bat/file with either of following commands
curl -d action=shutdown http://localhost:4444/lifecycle-manager
or 

wget --post-data action=shutdown action=shutdown http://localhost:4444/lifecycle-manager
Save the bat file in the Selenium Grid base directory. Double check bat file whether its working fine by double clicking on that[pre condition : Selenium Hub and RCs must started before].
I am using this way because there is no default ant target for shutting down the Selenium Grid.
Coming to Ant Build, we need to create a custom ant target in build.xml to execute the above bat file. It look like




Save the build.xml and execute target as ‘ant stopGrid‘.

How to start Selenium Grid hub and RCs with one click.


How to start Selenium Grid hub and RCs with one click.
Its a so simple process. We can done it by creating a bat/sh file.  Here is the steps
Open a notepad and enter following
start /B ant launch-hub 
start /B ant -Denvironment=”*firefox” -Dport=5555  -DhubURL=http://localhost:4444 launch-remote-control
start /B ant -Denvironment=”*iehta” -Dport=5557  -DhubURL=http://localhost:4444 launch-remote-control
Save the notepad as bat file in Selenium Grid base directory.  Double click on the bat file and it will start Hub and RCs.