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 ...........