just ram

stuff I should remember

Ruby testing - setup project folders

Its a good idea to keep your test cases seperate from your production code:

  myproject
      lib/
          workomatic.rb
      test/
          test_workomatic.rb

When you have your project setup in this way add the following line to the top of your test cases:

Inside test_workomatic.rb

  $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
  require workomatic.rb

Location of XML files

http://YOURSERVERNAME:50000/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/

documents\portalResource\USER.R3_DATASOURCE.

Castle Monorail + Active Record + Testing + CreateSchemaFromFile

It’s always a good idea to have your test database match your production database exactly to do that use:

ActiveRecordStarter.CreateSchemaFromFile()

Unlike CreateSchema which takes a best guess at how your schema should be CreateSchemaFromFile uses an SQL script which allows you to control exactly what the schema should be.

Call CreateSchemaFromFile as part of your PrepareSchema method in your AbstractTestCase class.

protected virtual void PrepareSchema() { // If you want to delete everything from the model. // Remember to do it in a descendent dependency order // Office.DeleteAll(); // User.DeleteAll(); // Another approach is to always recreate the schema // (please use a separate test database if you want to do that) ActiveRecordStarter.DropSchema(); ActiveRecordStarter.CreateSchemaFromFile("schema.sql"); }

Your schema.sql file should contain scripts in the standard MS SQL format:

`if exists (select * from dbo.sysobjects where id = object_id(N’[dbo].[Application_Status]’) and OBJECTPROPERTY(id, N’IsUserTable’) = 1) drop table [dbo].[Application_Status] GO

CREATE TABLE [dbo].[Application_Status] ( [ID] [int] NOT NULL , [Title] [varchar] (50) NOT NULL , [Description] [text] NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO `

SAP Enterprise Portal - Automated Functional Testing - Part 6 of …

Time for some more tips. I had a comment on my last post asking how to navigate around the portal so lets start there.

TOP TIP - How to navigate the portal
So how do you navigate around the portal using the menu? Simple you don’t! I found there are lots of problems using the portal menus due to the number of frames used so I simply jump directly to the URL of the PAR file I am testing. Here is a typical test:
`def test_typical
# My Helper method which logs in using the given user id and password
logon(“myuserid”, “mypassword”)

Go directly to the URL of the PAR I want to test

@ie.goto(‘http://portal:50000/irj/servlet/prt/portal/prtroot/uk.ac.ncl.testing.ISRPageProcessor’)

do tests here

end`
Ok that’s fine but how do you find the direct URL of the PAR file you want to test? Ahh thats were my next top tip comes in.

TOP TIP - How to find the direct URL of a PAR file
Open up the SAP Netweaver Developer Studio

Open your project

Open the file:
MyPortalProject dist PORTAL-INF Portalapp.xml
You should now see a “Run…” button for each portal component in your project

Click the “Run…” button and the dev studio will open up a new browser window with the URL of your PAR file. Now simply use this URL in your test scripts.

COMING UP IN PART SEVEN
Short and sweet but at least I’m posting more often. Next time… You guessed it more top tips!

SAP Enterprise Portal - Automated Functional Testing - Part 5 of …

Ok last time I promised some hints and tips so lets begin. I’m going to keep the hints and tips posts fairly short in the hope it will encourage me to post more often. I received a comment on my last post asking how I find the ID/Name attributes of my forms so I though that would be a good place to start.

**TOP TIP - How to find ID/Name attributes of a form
**To save me having to sifting through the html code of a page for the ID/Name of a control I use the FireFox browser with the Web Developer Toolbar extension installed. The Web Developer Toolbar is a great time saver not only for finding out form details but it has lots of other features too, I strongly recommend you check it out.

When you have the Web Developer Toolbar installed under the Forms menu you have the Display Form Details option, simply select this option and the page will be highlighted with yellow tags showing the ID/Name attributes of each item on the form.

NOTE: Forms items which are created using HTMLB do not get a static ID/Name attribute these attributes appear to be generated each time the page is created. If this is the case how do we write tests against HTMLB forms? That’s were the next top tip comes in…

TOP TIP - Writing Watir test against HTMLB forms
As I mentioned above HTMLB forms do not have a static ID/Name attribute, they are generated each time the page is created so you will find your HTMLB form controls will have an ID/Name of something along the lines of “htmlb18528_htmlb99983” if you then reload the page the ID/Name attributes will have changed i.e. “htmlb18328htmlb99911”. This means the following Watir test code would not work as each time the page reloaded the _:id attribute would be different.

@ie.text_field(:id, 'htmlb_18528_htmlb_9998_3').set('test me')

So how do we get around this? Well the best way I have found is to use Watir’s :index parameter when accessing form controls. The :index parameter works by sequentially counting form controls from left to right top to bottom. So to set the text of the second control on the page we use the following code:

@ie.text_field(:index, 2).set('test me')

This is not an ideal solution due to the fact if you change the layout of the page your index’s will also change and break your tests. However I’ve been using this method for a while now and it’s never been a major problem, besides I’m not sure how else it could be done!

COMING UP IN PART SIX
Well that post turned out to be slightly longer than I planned, so much for keeping these tips short. Next time more of the same.

SDN Blog

I was recently invited to start a blog on the SAP Software Developers Network (SDN). So I’ve written a series of posts about Automated Functional testing the SAP Portal using Watir:

SDN Blog

Introduction
Automated Functional Testing - Part 1 of …
Automated Functional Testing - Part 2 of …
Automated Functional Testing - Part 3 of …
Automated Functional Testing - Part 4 of …

IMHO worth a look if your interested in testing your SAP Portal. I’ll start posting the rest of the series on here from now.

Castle Monorail + Active Record + Testing + CreateSchemaFromFile

It’s always a good idea to have your test database match your production database exactly, we can do that easily using:

ActiveRecordStarter.CreateSchemaFromFile()

Unlike CreateSchema which makes a best guess at how your schema should be CreateSchemaFromFile takes an SQL script which allows you to fully control the database schema.

Call CreateSchemaFromFile as part of your PrepareSchema method in your AbstractTestCase class.

protected virtual void PrepareSchema() { ActiveRecordStarter.DropSchema(); ActiveRecordStarter.CreateSchemaFromFile("schema.sql"); }

Your schema.sql file should contain scripts in the standard MS SQL format:

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Application_Status]') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table [dbo].[Application_Status] GO CREATE TABLE [dbo].[Application_Status] ( [ID] [int] NOT NULL , [Title] [varchar] (50) NOT NULL , [Description] [text] NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO

Continuous Integration + CruiseControl.Net + Subversion + MSBuild + .Net 2.0

I’ve read quite a bit about Continuous Integration and the .Net implementation CruiseControl.Net. It always seemed like a really good idea but I’ve never gotten around to trying it out, until now…

By the way setting up the server was a lot easier than I thought it would be! Here’s what I did:

CruiseControl.Net Setup

Download and run CruiseControl.Net setup http://sourceforge.net/project/showfiles.php?group_id=71179&package_id=83198

I’ve used version 1.0.1:

CruiseControl.NET-1.0.1-Setup.exe

NOTE: After setup if your server has .Net 1.1 and 2.0 as mine did you may need to change the ccnet website to use .Net 2.0. This can be done through the IIS control panel, get the properties of the ccnet site and change via the ASP.NET tab.

Subversion Client

Your server will need the subversion console client on the server to allow CruiseControl to checkout your source.

http://subversion.tigris.org/

.Net 2 SDK

To allow us to build .Net 2 projects without the need for Visual Studio we need to download and install .Net 2 SDK onto the server

http://www.microsoft.com/downloads/details.aspx?familyid=fe6f2099-b7b4-4f47-a244-c96d69c35dec&displaylang=en

Setup MSBuild

To use MSBuild with CC.Net we need the logger dll -ThoughtWorks.CruiseControl.MsBuild.dll from:

http://ccnetlive.thoughtworks.com/MSBuildXmlLogger%2DBuilds/

Download and copy to: C:\Program Files\CruiseControl.NET\webdashboard\bin\

Directory structure

Setup your directory structure:

C:\CI\Myproject\ C:\CI\Myproject\build C:\CI\Myproject\logs

Using your subversion client checkout source to C:\CI\MyProject\build

ccnet.config

Add the project config to ccnet.confg:

<cruisecontrol>
 <project name="MyProject">
  <!-- after a change is detected, wait 10 mins and then kick off the build-->
  <schedule type="schedule" sleepSeconds="600" />
  <!--set the sourcecontrol type to subversion and point to the subversion exe-->
  <sourcecontrol type="svn">
   <executable>C:\Program Files\Subversion\bin\svn.exe</executable>
   <workingDirectory>C:\CI\MyProject\build</workingDirectory>
   <trunkUrl>svn://svnserver/MyProject/trunk</trunkUrl>
   <autoGetSource>true</autoGetSource>
   <username>myuser</username>
   <password>mypassword</password>
  </sourcecontrol>
  <tasks>
   <!-- Configure MSBuild to compile the updated files -->c:\
   <msbuild>
    <executable>C:\windows\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe</executable>
    <workingDirectory>C:\CI\MyProject\build\src\</workingDirectory>
    <projectFile>MyProject.sln</projectFile>
    <buildArgs>/noconsolelogger /p:Configuration=Debug</buildArgs>
    <targets></targets>
    <timeout>15</timeout>
    <logger>ThoughtWorks.CruiseControl.MsBuild.XmlLogger,C:\Program Files\CruiseControl.NET\webdashboard\bin\ThoughtWorks.CruiseControl.MsBuild.dll</logger>
   </msbuild>
  </tasks>
  <!--Publishers will be done after the build has completed-->
  <publishers>
   <xmllogger>
    <logDir>C:\CI\MyProject\Logs</logDir>
   </xmllogger>
  </publishers>
  <modificationDelaySeconds>10</modificationDelaySeconds>
 </project>
</cruisecontrol>

CC Tray

You will also want to install the CC Tray monitoring software on your pc:

CCTray

It will allow you to keep an eye on the server from the comfort of your own pc.

That’s it we’re down!

Castle Monorail – Moving from Beta5 to latest build

I’ve decided to move my “toy” MonoRail project from the Beta 5 version to the latest build so I can have a play with the new features. Mostly Formhelper!

Moving to the latest build broke a few things in my solution:

The Build

Nunit framework

My web test project was using Nunit version 2.2.0.0. Which is used by Castle.MonoRail.TestSupport I believe although don’t quote me on that I could be wrong. Any who it now requires the latest version of the nunit.framework.dll (2.2.8.0). I change the reference and all was well.

DataBindAttribute Next up was the DataBindAttribute which appears to have changs slightly. I did have:

public void LoginSubmit([DataBind(Prefix = "student")] Student student)

It appears the Prefix parameter is now explicit, a simple change:

public void LoginSubmit([DataBind("student")] Student student)

The Tests

Ok now my solution builds but all of my ActiveRecord unit tests fail. I get the following error:

TestFixture failed: You can't invoke ActiveRecordStarter.Initialize more than once

Turns out to be a problem in the InitFramework method of my AbstractModelTestCase class. Initalialze is being called twice:

`protected virtual void InitFramework() { IConfigurationSource source = ConfigurationManager.GetSection(“activerecord”) as IConfigurationSource;

ActiveRecordStarter.Initialize(source);

ActiveRecordStarter.Initialize( source, typeof(Student), typeof(LoginAudit) ); }`

I guess there is now no need for the first ActiveRecordStarter.Initialize(source); call so I remove it and all is well!

The Run

Ok now my solution builds and passes the test but all is not well at run time I get the following error:

Looks like you forgot to register the http module Castle.MonoRail.Framework.EngineContextModule Add '<add name="monorail" type="Castle.MonoRail.Framework.EngineContextModule, Castle.MonoRail.Framework" />' to the <httpModules> section on your web.config

This is a breaking change mentioned in the release notes and you must update your web.config. But don’t get your httpModules and your httpHandlers mixed up as I did. Simply add the httpModules to your web.config:

`

</system.web> `

The End

That’s it we’re down! Now I get to play with the latest version.