just in ram

A list of stuff I should remember but never do

Archive for the ‘Watir’ Category

SAP Enterprise Portal + Automated Functional Testing – Part 7 of …

without comments

In anticipation of posting about a new topic I’m going to wrap up my Watir Automated testing posts with a few more top tips.

TOP TIP – How do I run a single test?

So you have lots of tests in your test suite but only want to run one? No need to create an ad-hoc test case, simply pass in the –name parameter when running the test:

ruby test_mytestcase.rb --name test_just_this_method

TOP TIP – How do I run the test in background mode?

Running the test so you can see what is going on in the browser is sometimes useful but most of the time you’ll want to run the tests in the background and just see the results. This is easily done by passing the -b parameter on the command line:

ruby test_mytestcase.rb -b

TOP TIP – Helper methods

I have a couple of helper methods which I use in most of my test cases:

def should_find(find_me)
assert(@ie.contains_text(find_me), "*\n*\n*\nText not found: #{find_me}\n*\n*\n*")
end

def should_not_find(find_me)
assert_nil(@ie.contains_text(find_me), "*\n*\n*\nFound text which should not be present: #{find_me}\n*\n*\n*")
end

No clever code here it just means I can write tests which are easier to read:

should_not_find("Portal Runtime Error")
should_find("Success")

FIN
Well I’m running out of content about testing as you can probably tell! So I guess that’s a wrap. I’ll no doubt re-visit automated testing again at some point but for now that’s my lot.

NEXT TIME
I’ve been working on creating web services for Enterprise Portal and calling those web services from Microsoft .Net. I’ve taken lots of notes, so expect a series of EP web services posts real soon.

Written by Justin Ramel

December 5th, 2006 at 2:42 pm

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

without comments

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!

Written by Justin Ramel

October 27th, 2006 at 10:58 am

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

without comments

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 “htmlb_18528_htmlb_9998_3″ if you then reload the page the ID/Name attributes will have changed i.e. “htmlb_18328_htmlb_9991_1″. 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.

Written by Justin Ramel

October 18th, 2006 at 11:13 am

SDN Blog

with one comment

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.

Written by Justin Ramel

October 17th, 2006 at 9:15 am

Ruby unit tests – run only one test method

without comments

What if you don’t wish to run all the unit tests in your test case?

You can tell ruby to run only one test method by passing in the name of the test:

  ruby test_mytestcase.rb --name test_just_this_method

Written by Justin Ramel

March 30th, 2006 at 9:04 pm

Posted in Ruby, Testing, Watir

Functionally testing SAP Enterprise Portal using Watir

without comments

It’s taken about a day but I’ve managed to get some functional tests running using Watir. It’s not been as easy as it could have been mainly due to the way the SAP Enterprise Portal uses iFrames and the anti cross site scripting in Internet Explorer. I got there in the end though! I can now logon to the portal and functionally test iViews using a fairly simple Watir (Ruby) script:

def logon
$ie.goto($html_root)

if $ie.contains_text("Log Off")
logoff()
end

$ie.text_field(:id, 'logonuidfield').set($user_id)
$ie.text_field(:id, 'logonpassfield').set($password)
$ie.button(:name, 'uidPasswordLogon').click
end

A couple of things to note:

Talk to the iView directly
Due to the use of iFrames and IE anti cross site scripting accessing an iView which is embedded in a portal page is not possible with the current (1.4.1) version of Watir. Simply get the url of the iView and access it directly.

Problem with HTMLB Text Fields
ID’s and Names of HTMLB Text Field controls appear to be generated on execution, so I had to write a little script which would find a text field using the title property:

def find_text_field_by_title(my_title)
found_text_field = nil

$ie.text_fields.each do |tf|
if tf.title == my_title then
found_text_field = tf
break
end
end

raise "No text field found with title = " +
my_title if found_text_field.nil?

return found_text_field
end

NOTE: I’m sure my Ruby/Watir scripts leave a lot to be desired, I don’t really know who to code in Ruby but they do seem to work!

Written by Justin Ramel

February 28th, 2006 at 12:57 pm

Searching Google for Watir help

without comments

Having trouble finding help on Watir?

Try the following in google:

site:rubyforge.org "[Wtr-general]" your search

Written by Justin Ramel

February 27th, 2006 at 2:52 pm

Posted in Watir

Installing Watir via the gem utility

without comments

The install should be as simple as dropping into dos, cd to your Ruby folder and run the command:
gem install watir

Unfortunately it wasn’t that simple for me, we work via a proxy here so I had to tell the gem utility about it.

Running gem install when you are behind a proxy

Set the HTTP_PROXY environment variable.

Example:
set HTTP_PROXY=http://mycache:8080

You can now run:
gem install watir

Or you can pass the proxy information as a parameter to gem via the -p switch:

gem install watir -p http://mycache:8080

Gem will now go off download and install the latest Watir package, version 1.4.1 in my case. Be patient this can take some time depending on server load.

Written by Justin Ramel

February 27th, 2006 at 10:57 am

Posted in Watir

Watir – Testing your website

without comments

I am hoping to use this software to test my web developments, from what I have read it looks very promising.

“WATIR stands for “Web Application Testing in Ruby”. Watir
is a free, open-source functional testing tool for
automating browser-based tests of web applications. It is pronounced water.”

The install…

Using the Ruby One-Click installer for windows (version ruby182-15.exe), just run standard install accepting all defaults.

NOTE: I tried the final version of Ruby 182-14 and had lots of install problems so use at least version 182-15!

Using the Watir One-Click installer for windows (version watir-1.4.1.exe), just run standard install accepting all defaults.

Now onto learning what can be done with this thing…

User Guide

Ruby Cheat Sheet

Watir Cheat Sheet

Written by Justin Ramel

February 27th, 2006 at 10:49 am

Posted in Watir