My blog has moved!
You should be automatically redirected in 5 seconds. If not, visit and update your bookmarks.

Tuesday, 23 December 2008

Using selenium.GetEval(script)to execute Javascript

The task at hand was to navigate through the DOM of a particular webpage and check the
style.display attribute of an object or element if you prefer. There are two elements on this page that displayed either success or failure messages.(msgSuccess and msgFailed)
For perfomance reasons, if previously a successful message was displayed and subsequently the you get a failure message, what the developers of the page did was to amend the style.display attribute.

<span style="display: none;" id="msgSuccess" class="MyMsgSuccess">

The HTML code above implies the element 'msgSuccess' would not be displayed

<span style="" id="msgSuccess" class="MyMsgSuccess">

In the second case, the msg success would be displayed ....

The problem i encountered was, sometimes i would have

< span style="display: none;" id="msgSuccess" class="MyMsgSuccess" > Operation Successful </span >

If i do a selenium.GetText("msgSuccess"), i get the text returned even though the style.display is set to none. Hence the need for the Selenium.GetEval to check the value of the style.display attribute as that seem as a true test for the web page

I have done:

const string script = "document.getElementById(\"msgSuccess\").style.display";
string evalResult = selenium.GetEval(script);

The above script failed as selenium was executing the javascript in the selenium console and not on the Application under test (AUT)
and searching the internet got me doing:

const string script = "selenium.browserbot.getCurrentWindow().document.getElementById(\"msgSuccess\").style.display";
string evalResult = selenium.GetEval(script);

This way i got the javascript to be run on the Application under test ....

Saturday, 8 November 2008

Internet Explorer doesnt handle xpath to locate images exceptionally well

So i have been doing a lot of selenium and the website i am trying to automate test for
doesnt have a lot of element with id, name, or any other HTML attributes that makes selenium testing a bit easier.

So i have been using of xpath, my intent was to click on an image and i have used the src attribute of the image element.

so my original command, ("xpath=//img[@src="location/of/image/on/disc"]");

This works excellently on firefox but on IE, i keep getting the error "Element not found!"

so after several tries, this definitely work on both IE and firefox ...... ("xpath=//img[@contains(@href, "")]");
The second parameter of the xpath "contains" a segment of the link that the image element points to.Note that the img element has a href and that is why i am able to use the "contains" method of the xpath to locate the img.

Thursday, 6 November 2008

Use selenium to create screenshot

I just stunbled across selenium as a tool to take screenshot.
Thuis could be useful for anything.

In my case i used it to take the screenshot of a page just before it throws an error in my selenium test. and that i could have a look and investigate what the problem might have been.

very simple command and the great thing is it can be easily used for screenshots of a page across different browsers.

browser.CaptureEntirePageScreenshot("C:\\actual _path_to_where_you_want the_file _placed\\screenshot.png");

Selenium and Javascript events

Have you ver been in situattion when youhave typed a value into a text box and you expect a
Javascript event to be called such as "OnBlur"

welll selenium has a method "FireEvent" which triggers the event for you, but then the trick is you have to strip the "on" and name for the event wouldbe "OnBlur"

I guess abit of example would make more sense, lol.
This is what my html look like

<input type="text" value="" onblur="JavaScript:ValidateSimpleMail(true);" size="25" name="EMAIL_1" id="EMAIL_1"/>

selenium command to type into an email box, which doesnt fire the event attached to the text box

browser.Type("EMAIL_1", "");

The work around is to use selenium to fire the event after it has typed in the textbox
FireEvent(locator, eventName) which in my case is

browser.FireEvent("EMAIL_1", "blur");

Monday, 3 November 2008

Selenium: Xpath locator can not be used as Option Locator

In my new job been doing a lot of selenium and i needed to scroll through the list of
options in a select element and click on a particular options.

i have initially used the browser.DoubleClick


But then this didnt work because selenium doesn't have the functionality to scroll down the select element in other to make my desired option visible.

Looking through the selenium api, i have used another method, which take in two parameters, the select locator and the option locator.

so i used:

browser.Select("xpath=//select", "xpath =//option[child::text()='Option_Label']");

that hasnt work either as the option locator type cannot be xpath. it has to be a label, id, atrribute, name or any other html locator

so i have done

browser.Select("xpath=//select", "label=Option_Label");

which in myown opinion i think is good as it is robust for a selenium test.

Saturday, 18 October 2008

Sorting out devices - Wireless, Inbuilt Microphone on Ubuntu Hardy Heron

Faced with the reality of having to hand in my MAC to my former workplace, i decided to buy a Windows machine (HP 6735s Laptop, AMD Athlon TM X2 Dual Core QL-60 1.9Ghz, 4GB memory, 250GB HDD, DVD+-RW SMDL LightScribe writer, Webcam 15.4" WXGA (1280 x 800) WLAN Bluetooth Microsoft Windows Vista Home Premium )

and being a MAC - convert, coupled with the numerous negative feedback about Vista. I have installed Ubuntu Hardy Heron on a seperate partition. For some reason i have been spending about 4hours each day trying to sort Ubuntu to recognise my hardware, the first was my wireless wasnt working, ubuntu did not recognise the Broadcom wireless hardware which the laptop.

I am not gonna start copying stuff, there is a lot of blogs out there, two which helped me are:

Well my wireless now work , the next huddle is to get the Microphone to work, so i should get that done next week, if i get some time to get round to it.

Friday, 29 August 2008

Nant SCP Task: deploy file to a remote server

Actually started the task by attempting to use MSBuild to deploy my application to a remote server.
which would require some secure means, scp, sftp or something of that sort.
The closest i got was SSHSharp which was written by a third party and not thoroughly tested,
i then decided maybe that wasn't the path to go.

Tried to go for Nant instead, and found that Nant core doesnt have a task for secure copy,
Hence, the other option was NantContrib which seem okay to an extent, except for incomplete documentation.

Once big issue was having a "scp" failed to start ---> The file cannot be found error when i tried to execute the build file. I spent a great deal of my time trying to figure out what file was not found, thinking it was my file that i intend to copy that wasn't found.

Actually it was the program "scp.exe" that could not be found, it took a lot of time and guesses, as there weren't a lot of resources on the
search engines about this. May be i was just being dumb. So i had to install pscp on my machine and add that to the path.

and it works fine...........

Summary is that you for you to use the scp task,

Download the nantcontrib dll files and read the "ReadMe.txt"

And add that to your Target with uses the SCP task

loadtasks assembly="${project::get-base-directory()}/lib_build/nantcontrib-0.85/bin/NAnt.Contrib.Tasks.dll"

This would the directory where your .dll files are.
Make sure that that scp which is default is installed on your machine, you could actually use other application , e.g pscp, ssh bu that would have to the specified in the SCP task.

Finally, This is what my file looked like:

<?xml version="1.0"?>
<project name="Project Name" default="DeployToPlay" basedir=".">
<property name="debug" value="true" overwrite="false" />

<target name ="DeployToServer">
<loadtasks assembly="${project::get-base-directory()}/lib_build/nantcontrib-0.85/bin/NAnt.Contrib.Tasks.dll" />

<zip zipfile="" >
<include name = "*.aspx;*.asax;web.config"/>
<include name = "Content\**\*.*"/>
<include name = "home\**\*.*"/>
<include name = "Views\**\*.*"/>
<include name = "bin\Debug\**\*.*"/>
<scp file="" server="myservername" path="/pathOnTheServer" />