In my current job, I have been doing a lot of acceptance test using Cucumber, Watir and RSpec, obvious all in Ruby. I have been using Cucumber 0.6.x, in which blank cells in the step table are represented by empty string (""). This was okay for me until today when i had to use a previous version of Cucumber 0.3.11 due to reasons including compatibility with other projects in the CI build. And my tests start failing because blank cells are represented as nil.
There was fix put in the current release of cucumber to change blanks to be represented as empty and not as nil(for whatever reason, which i don't really care, as both nil and "" has got its own arguments.)
Some code to explain this, Assuming i have a step table as below:
Given that i have the following detail in my app
|Header1|Header2|Header3|Header4|
|Body1 |Body2 |Body3 | |
Notice that the last column of the second row is blank, this would be represented as nil in cucumber 0.3.11 while it is represented as empty string "" in cucumber 0.6.x
In my step definition file, I have fixed this by converting every nil value to empty ("")
Given /have the following detail/ do |table|
table.rows.each do |row|
row.map! {|value| convert_nil_to_empty_string(value)}
# do some other stuff with row as every nil object has been converted to empty string
# The map! method for Array, allow you to invoke the block for the array and it amends
# the existing array
end
end
The method which i call to convert nil to empty is below:
def convert_nil_to_empty_string(test_string)
if (test_string.nil?)
return ""
else
return test_string
end
end
There might have been a better way to do this but this surely worked for me in this scenario and the reason i decided to use a method was that the map! method would only allow me use the variable "value" only once in the block. I am sure there are some rubyist out there, that could advice me on some shorthand for this ....... Hope it helps you too
My blog has moved!
You should be automatically redirected in 5 seconds. If not, visit
http://samueladesoga.wordpress.com
and update your bookmarks.
Showing posts with label test. Show all posts
Showing posts with label test. Show all posts
Wednesday, 10 March 2010
Monday, 23 November 2009
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
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
11:56:55.272 INFO - Command request: getNewBrowserSession[*iexplore, http://localhost:8080, ] on session nullThis 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
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
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
Labels:
iehta,
iexplore,
iexploreproxy,
Java,
selenium server,
test
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
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
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 ...........
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 ...........
Labels:
Java,
Javascipt,
selenium,
selenium rc,
selenium-server,
test,
user-extensions
Subscribe to:
Posts (Atom)