RemoteWebDriver does not support taking screenshots

54 views
Skip to first unread message

Graham Abell

unread,
Jul 18, 2012, 6:13:19 AM7/18/12
to fighting-l...@googlegroups.com
Hi All,

I'm getting an error while trying to validate a page via RemoteWebDriver. It's indicating that RemoteWebDriver does not support taking screenshots which I don't think is the case since I screenshot with it all the time in other contexts:

public static File screenshot() {
   WebDriver augmentedDriver = new Augmenter().augment(remoteWebDriver));
   return ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE);
}

Exception: 
java.lang.UnsupportedOperationException: org.openqa.selenium.remote.RemoteWebDriver does not support taking screenshots.
at com.googlecode.fightinglayoutbugs.ScreenshotCache.takeScreenshot(ScreenshotCache.java:251)
at com.googlecode.fightinglayoutbugs.ScreenshotCache.takeScreenshot(ScreenshotCache.java:163)
at com.googlecode.fightinglayoutbugs.ScreenshotCache.getScreenshot(ScreenshotCache.java:77)
at com.googlecode.fightinglayoutbugs.ScreenshotCache.takeScreenshot(ScreenshotCache.java:144)
at com.googlecode.fightinglayoutbugs.WebPage.takeScreenshot(WebPage.java:162)
at com.googlecode.fightinglayoutbugs.AnimationAwareTextDetector.detectTextPixelsIn(AnimationAwareTextDetector.java:78)
at com.googlecode.fightinglayoutbugs.WebPage.getTextPixels(WebPage.java:176)
at com.googlecode.fightinglayoutbugs.DetectTextNearOrOverlappingHorizontalEdge.findLayoutBugsIn(DetectTextNearOrOverlappingHorizontalEdge.java:37)
at com.googlecode.fightinglayoutbugs.FightingLayoutBugs.findLayoutBugsIn(FightingLayoutBugs.java:146)
at com.paddypower.selenium.framework.PageValidation.checkLayoutBugs(PageValidation.java:46)

thanks,
Graham

Michael Tamm

unread,
Jul 29, 2012, 11:39:17 AM7/29/12
to fighting-l...@googlegroups.com
I guess you passed the RemoteWebDriver instance directly to the WebPage constructor.
Currently you must construct the WebPage with the augmented driver instead.

Kind regards, Michael

P.S. I guess I will add some code now,
so that FLB will do the new Augmenter().augment(...) magic itself in the future ...

2012/7/18 Graham Abell <niceg...@gmail.com>

Andrey Zamovskiy

unread,
Jul 29, 2012, 11:45:53 AM7/29/12
to fighting-l...@googlegroups.com
getScreenshotAs method is actually missing in RemoteWebDriver class.
I think it's a bug in selenium, because i've found no reason why it
can't be used and implemented it for my needs.
But forgot to submit a patch.
As fastest solution you can extend RemoteWebDriver class, like this:

import org.openqa.selenium.Platform;
import org.openqa.selenium.remote.*;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot

public class ExtendedRemoteWebDriver extends RemoteWebDriver
implements TakesScreenshot
{
public <X> X getScreenshotAs(OutputType<X> target) {
// Get the screenshot as base64.
String base64 = execute(DriverCommand.SCREENSHOT).getValue().toString();
// ... and convert it.
return target.convertFromBase64Png(base64);
--
Andrey
Reply all
Reply to author
Forward
0 new messages