My blog has moved!
You should be automatically redirected in 5 seconds. If not, visit http://samueladesoga.wordpress.com and update your bookmarks.

Monday 23 November 2009

Workaround: Flash selenium test would not run in firefox 3.5 except when the browser mode is *firefoxProxy

I looked into flash selenium a few weeks back and i thought it was a great way for me to test certain part of the apps i have been ignoring for some time.

However after knocking up a few test i discovered that my test would not run in my version of firefox (3.5). I got this error:

INFO - Got result: ERROR: Threw an exception: NPMethod called on non-NPObject wrapped JSObject! on session 471c65508e46457fa43f4deb873d0592
Then i read in some issue raised in the flash selenium site that flash selenium would only work in firefox 3.0 and it worked fine in IE for me.

Today while i was investigating another issue, i decided to try running the flashSelenium test in the "*firefoxproxy" mode and my tests ran succcessfully.

I am sure this workaround would be welcome by people facing this issue as well, please leave a comment if this is any help.

Thanks




selenium failed to start browser in iexplore mode when selenium server is started dynamically in code

In a previous post, i have written about how i have been starting/ stoping the selenium server dynamically. What i didnt mention was that i was not able to run my tests using Internet Explorer. I got this error

11:56:55.272 INFO - Command request: getNewBrowserSession[*iexplore, http://localhost:8080, ] on session null
11:56:55.272 INFO - creating new remote session
11:56:55.381 INFO - Allocated session 688eff769c8b4751b5fb9477bba213f3 for http://localhost:8080, launching...
11:56:55.397 ERROR - Failed to start new browser session, shutdown browser and clear all session data
java.lang.RuntimeException: java.io.FileNotFoundException: C:\DOCUME~1\SAdesoga\LOCALS~1\Temp\customProfileDir688eff769c8b4751b5fb9477bba213f3\core\RemoteRunner.html (The system cannot find the file specified)
at org.openqa.selenium.server.browserlaunchers.HTABrowserLauncher.createHTAFiles(HTABrowserLauncher.java:100)
at org.openqa.selenium.server.browserlaunchers.HTABrowserLauncher.launch(HTABrowserLauncher.java:60)
at org.openqa.selenium.server.browserlaunchers.HTABrowserLauncher.launchRemoteSession(HTABrowserLauncher.java:140)
at org.openqa.selenium.server.browserlaunchers.InternetExplorerLauncher.launchRemoteSession(InternetExplorerLauncher.java:77)
at org.openqa.selenium.server.BrowserSessionFactory.createNewRemoteSession(BrowserSessionFactory.java:357)
at org.openqa.selenium.server.BrowserSessionFactory.getNewBrowserSession(BrowserSessionFactory.java:122)
at org.openqa.selenium.server.BrowserSessionFactory.getNewBrowserSession(BrowserSessionFactory.java:84)
at org.openqa.selenium.server.SeleniumDriverResourceHandler.getNewBrowserSession(SeleniumDriverResourceHandler.java:712)
at org.openqa.selenium.server.SeleniumDriverResourceHandler.doCommand(SeleniumDriverResourceHandler.java:393)
at org.openqa.selenium.server.SeleniumDriverResourceHandler.handleCommandRequest(SeleniumDriverResourceHandler.java:364)
at org.openqa.selenium.server.SeleniumDriverResourceHandler.handle(SeleniumDriverResourceHandler.java:125)
at org.mortbay.http.HttpContext.handle(HttpContext.java:1530)
at org.mortbay.http.HttpContext.handle(HttpContext.java:1482)
at org.mortbay.http.HttpServer.service(HttpServer.java:909)
at org.mortbay.http.HttpConnection.service(HttpConnection.java:820)
at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:986)
at org.mortbay.http.HttpConnection.handle(HttpConnection.java:837)
at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:245)
at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357)
at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
Caused by: java.io.FileNotFoundException: C:\DOCUME~1\SAdesoga\LOCALS~1\Temp\customProfileDir688eff769c8b4751b5fb9477bba213f3\core\RemoteRunner.html (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(Unknown Source)
at org.apache.tools.ant.types.resources.FileResource.getInputStream(FileResource.java:185)
at org.apache.tools.ant.util.ResourceUtils.copyResource(ResourceUtils.java:372)
at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:475)
at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:438)
at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:404)
at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:379)
at org.apache.tools.ant.util.FileUtils.copyFile(FileUtils.java:317)
at org.openqa.selenium.server.browserlaunchers.HTABrowserLauncher.createHTAFiles(HTABrowserLauncher.java:97)
... 19 more
This points out that selenium is trying to start in the iehta mode, even though i have specified that it start in iexplore mode. Doing i quick search i discovered that there has been some work to start up selenium in iehta even when iexplore is being specified. And the only way to get the original *iexplore is to try *iexploreproxy or piiexplore

So i changed my config file to start selenium using "*iexploreproxy" instead of "*iexplore" and voila i am able run my test on ie.

Hope this helps you too

Wednesday 18 November 2009

Search for a single digit within a string using regex as provided in java api

In my current work, i have been writing a lot of test in Java, which obviously means i need to learn a lot more about the Java api, which is good i think?????

Well i needed to match the single digit in this string "home-area-1" and return this digit. With a quick google i found this piece of code here.

Pattern p = Pattern.compile("a*b");
Matcher m = p.matcher("aaaaab");
boolean b = m.matches();
System.out.println(b);

A quick run of this code printed "true" which means the code works.

So i wrote this:

Pattern p = Pattern.compile("[1,2,3,4]");
Matcher m = p.matcher("promo-area-3");
System.out.println(m.group());

and guess what this fails ...... giving me an "illegal state exception"

Pattern p = Pattern.compile("[1,2,3,4]");
Matcher m = p.matcher("promo-area-3");
boolean b = m.matches();
System.out.println(b);

This returns false which suggests that matching is not working properly.

After a lot of guesses and try and errors , i did

Pattern p = Pattern.compile("[1,2,3,4]");
Matcher m = p.matcher("promo-area-3");
while (m.find()) {
System.out.println("regex stuff " + m.group());
}

My thinking is this, the first code with this pattern "Pattern.compile("a*b");" was searching for a text which the subsequent one "Pattern.compile("[1,2,3,4]")" was a search for a character within a sequence and maybe this account for the while loop with m.find ........

Am not sure, maybe if anyone has a better explanation ... i would appreciate

Monday 16 November 2009

Start the Selenium Server dynamically

I have been working on a test suite in java using testng as the testing framework. I could not have suggested any other test frame work as it allows me to do a lot of configurable setups and teardowns. Yeah am not gonna promote testng anymore, lol.

I could have started using selenium server using a usual batch file that maven could call in one of its targets but i think doing it this way is cleaner.

public class SeleniumManager {
private SeleniumServer seleniumServer;

private static Selenium selenium;

private RemoteControlConfiguration rcc;

@BeforeSuite
@Parameters( { "selenium.port" })
public void startSeleniumServer(String port) {

rcc = new RemoteControlConfiguration();
rcc.setPort(Integer.parseInt(port));

try {
seleniumServer = new SeleniumServer(false, rcc);
// seleniumServer= new SeleniumServer();
seleniumServer.start();

} catch (Exception e) {
throw new IllegalStateException("Can't start selenium server", e);
}
}

@AfterSuite(alwaysRun = true)
public void stopSeleniumServer() {
if (seleniumServer != null) {
seleniumServer.stop();
}
}

public static Selenium startSelenium(String host, String port, String browser, String url) {
selenium = new DefaultSelenium(host, Integer.parseInt(port), browser, url);
selenium.start();
return selenium;
}

public static void stopSelenium(Selenium selenium) {
selenium.stop();
}

}
As you can see i have a seleniumManager class which would dynamically start the selenium server before my testSuite starts and kill the SeleniumServer after the test suite is completed.

Please try this out and leave comments

Setting user extensions when the Selenium Server has been started dynamically

I hope this helps someone someday, I needed to set user extension for a selenium test suite, dynamically in the code as i was starting the Selenium server via same.

public void startSeleniumServer(String port) {

rcc = new RemoteControlConfiguration();
rcc.setPort(Integer.parseInt(port));


try {
seleniumServer = new SeleniumServer(false, rcc);
seleniumServer.start();

} catch (Exception e) {
throw new IllegalStateException("Can't start selenium server", e);
}
}

public void stopSeleniumServer() {
if (seleniumServer != null) {
seleniumServer.stop();
}
}

i was setting the user extension file using the remoteControlConfiguration object

so i had typed:

rcc.setUserExtensions(new File({path_location_to_user_extension.js}));

This didnt work and an extensive search in the api wasnt very useful.
A colleague however found out that doing a

seleniumServer.boot(); would make the user-extension file to work.

Great isn't it ...........

Friday 4 September 2009

Selenium Remote cant start firefox session due to lock on file

I am sure you have on this page, because you have run into problem with selenium not been able to run due to a lock on some profile files. Yes, you know what the error is. I really found useful two blogs here and here. However, inas much as i don not want to repeat what has been saidin the blogs i would paste and quote what i found useful and explain a little bit more.

Preparing Firefox profile...

The source of the problem is in the *.rdf files inside the selenium server jar. The Selenium guys have hardcoded a version ceiling for Firefox at version 2.0.0.* (in my case it was 3.5.*). The fix is really simple.

Step 1: Extract the files needing change (from the directory where you have the jar). -

jar xf selenium-server.jar customProfileDirCUSTFFCHROME/
extensions/readystate@openqa.org/install.rdf
jar xf selenium-server.jar customProfileDirCUSTFFCHROME/
extensions/{538F0036-F358-4f84-A764-89FB437166B4}/install.rdf
jar xf selenium-server.jar customProfileDirCUSTFFCHROME/
extensions/\{503A0CD4-EDC8-489b-853B-19E0BAA8F0A4\}/install.rdf
jar xf selenium-server.jar customProfileDirCUSTFF/extensions/
readystate\@openqa.org/install.rdf
jar xf selenium-server.jar customProfileDirCUSTFF/extensions/
\{538F0036-F358-4f84-A764-89FB437166B4\}/install.rdf

Step 2: Change the max version in the rdf (Resource Description Framework) files.

The line of interest looks like this: 2.0.0.*

* you can change this to 4.*, should buy some time.

Step 3: Update the jar with your changes.

jar uf selenium-server.jar customProfileDirCUSTFFCHROME/
extensions/readystate@openqa.org/install.rdf
jar uf selenium-server.jar customProfileDirCUSTFFCHROME/
extensions/{538F0036-F358-4f84-A764-89FB437166B4}/install.rdf
jar uf selenium-server.jar customProfileDirCUSTFFCHROME/
extensions/\{503A0CD4-EDC8-489b-853B-19E0BAA8F0A4\}/install.rdf
jar uf selenium-server.jar customProfileDirCUSTFF/
extensions/readystate\@openqa.org/install.rdf
jar uf selenium-server.jar customProfileDirCUSTFF/
extensions/\{538F0036-F358-4f84-A764-89FB437166B4\}/install.rdf

That's it, once that's changed you should be good to go for testing against Firefox 3!

So that was a summary of what i found, but my case was a bit different as the version of firefox that was hardcoded in the selenium-server 1.0.1 was 3.5.* and my version of firefox was 3.5.2, so naturally i expected firefox to work for me. But as it did not work, as a trail and error, i changed the hardcoded version to 4.5.*. and voila it worked for me.

Also i did not use the jar uf command, what i did was to temporarily change the extension of the selenium server jar file to a .zip file and then i opened the zipped file created with winzip.

I then extracted the 5files which i need to amended to my desktop, amended the file with a text utility and then drop the files back into the zippped selenium server file. Lastly i changed the extensions back to .jar.

And it worked. i hope this works for someone as well

Monday 13 July 2009

css selectors in place of xpath for selenium locators

yeah so in all these year, i have always resolved to using xpath whenever i am creating selenium scripts and i need to do stuff with element that have no id. well as you would probably know, xpath executes so slow on IE.

For intance i have a test suite that would run in 1hr 30mins on firefox/ safari but the same test suites would take over 4hrs to run to completion on IE.

So with the help of a colleagues, i have been using css selectors from last week and i can say this has drastically improved the speed of our test and you would notice too much difference between IE and FF/Safari anymore.

It takes some time to get used to but these are some link that might be useful to get start with ....

Enjoy .....

Thursday 30 April 2009

Selenium Test execution speed on Safari vs Internet Explorer

I have been working on a selenium test suite that contains about 150 tests.
These test would normally take about 4hrs 30mins for it to execute to completion.

I tried to run same tests on Safari today, and it took exactly 1hr 9min. This is such a big difference 
and i think it is because of the extreme use of Xpath in the test suite. And as it is known thatXpath execute soooo slow in IE.

This is quite good as i have decided to run intraday tests in safari so as to get faster feedback, cos up until now i am unable to kick off these test because a test suite that takes 4hr 30min to executes would have taken almost half of my day and does little good.

I would be writing another post that talk about how to efficiently use Xpath in your tests whenever you need to ......


Any comments ............

Wednesday 4 March 2009

Not able to accept meetings in Outlook



Need to say i got an error displaying on the invite: This meeting is not in the calendar, it may have been moved or deleted.

Discovered that when i click on the "Accept Button" for meetings which i have been invited, the Accept button doesn't do anything. The invite sent to me,looks like this :




Doing a bit of google got me this link, and it worked for me

Just incase the link goes down some day, here is what you need to do

1. Kill all services relating to Microsoft products (i.e. Word, Outlook, Messenger etc.)
2. Then from the Run line, enter "outlook.exe /cleanfreebusy".

Wednesday 25 February 2009

Waiting for Elements in an IFrame on a WebPage to Load

Waiting for a page to load while writing selenium scripts is pretty straightforward using the
selenium.WaitForPageToLoad("timeout") timeout is time in millisecond.

Sometimes using this command doesn't work, especially when you the whole page is not loaded or reloaded but a popup is loaded in a div on the page. In situation like this i would used the
selenium.WaitForCondition("ScriptToReturnwhich ReturnTrue OrFalse", "timeout");
e.g. of scripts would be

selenium.WaitForCondition(selenium.browserbot.get CurrentWindow().document
.getElement ById('idOfElement ToBelocated')!=null", "60000");

This has always worked well for well until today, i had a special case where the element that i needed to wait for it to load was inside an IFrame, which is loaded within a parent page. Using the Wait for condition as above kept timing out as the Javascript could not access the IFrame.

what worked for me after several hours of trying is:

selenium.WaitForCondition("selenium.browserbot.getCurrent Window()
.frames['Name Of IFrame'].document.get Element ById
'idOfElement ToBelocated')!= null", "60000");


This brilliantly eliminated my nightmare .......

Comments are welcome

Saturday 31 January 2009

Need to get a value of an attribute using selenium

I was in this situation when i needed to get the value of an html attribute and i found the selenium.getattribute very handy .....

Okay the scenario was such that there was an element which is collapsible on the page and the only attibute for that element that indictated the status of the collapsible element was the 'Class'. when the element was collapsed, the value of the class attribute was 'asleep' and when the element was expanded, the value of the class atttribute was 'awake'.

The script used to determine the status of this element is
selenium.GetAttribute("elementLocator@nameofAttribute");

so if the id of my element is FundingClass and the attribute we are interested in is the 'Class'

The selenium code will be
selenium.GetAttribute("FundingClass@Class");

Hope this helps someone .....