I think that if you want to use a tool such as Watir or Selenium the only solution will be to execute the bookmarklet JavaScript from your test code. Open an ordinal bookmark is the same as navigating to some URL.
You can get the bookmarklet JavaScript from its properties. Let's take a List All Links bookmarklet as example. The JavaScript for is is:
javascript:WN7z=open('','Z6','width=400,height=200,scrollbars,resizable,menubar');DL5e=document.links;with(WN7z.document){write('<base target=_blank>');for(lKi=0;lKi<DL5e.length;lKi++){write(DL5e[lKi].toString().link(DL5e[lKi])+'<br><br>')};void(close())}
From the script you can see that the opened window name is Z6
- we will need it in our code. Unfortunately I do not know Watir much, so my example is in Selenium 2.0 (aka WebDriver) and it is in Java, but I think that the same can be done in Watir:
WebDriver driver = new InternetExplorerDriver();
// Open Google page
driver.get("http://www.google.com.ua/");
// Search for something
WebElement searchField = driver.findElement(By.name("q"));
searchField.sendKeys("webdriver");
searchField.submit();
// Bookmarklet script, note that javascript: was removed from original booknarklet
String script = "WN7z=open('','Z6','width=400,height=200,scrollbars,resizable,menubar');DL5e=document.links;with(WN7z.document){write('<base%20target=_blank>');for(lKi=0;lKi<DL5e.length;lKi++){write(DL5e[lKi].toString().link(DL5e[lKi])+'<br><br>')};void(close())}";
// Execute bookmarklet script
((JavascriptExecutor) driver).executeScript(script);
// Switch to the newly opened window
driver.switchTo().window("Z6");
// Find all the links in the bookmarklet window
List<WebElement> links = driver.findElements(By.tagName("a"));
// And list their text - you can do anything with them
for (WebElement link : links) {
System.out.println(link.getText());
}
driver.quit();
As I understand you are testing the bookmarklet. If you need to examine the links on the page, you can do this with Selenium (and I believe that Watir is also able to do this :)