6

Grab a Screenshot With Opera

 3 years ago
source link: https://www.otsukare.info/2011/06/30/grab-a-screenshot-with-opera
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Nicolas Hoizey asked me if it was possible to take screenshots with Opera. We released last year a way to do test automation with Opera. It means you can use Opera with a driver that will automate the Web navigation. So I asked people working on Opera Watir what should be done for taking the screenshot of a page.

Using Webdriver (Java)

Using the java OperaDriver, there is a testcase giving an example of code.

@Test
@Ignore(value="Opera problem. Areas outside current viewport are black.")
public void testFullScreenshot() throws Exception {
  getFixture("tall.html");
  File file = driver.getScreenshotAs(OutputType.FILE);

  BufferedImage img = ImageIO.read(file);
  Assert.assertEquals(5100, img.getHeight());

  // Make sure the bottom colour is green, not black.
  int botcol = img.getRGB(0, 5050);
  Assert.assertEquals(0xFF00, botcol & 0xFF00);

}

Using OperaWatir (Ruby)

You may want to use OperaWatir for testing the page. You can for example get the body element and save it as a screenshot.

require 'rubygems'
require 'operawatir'
browser = OperaWatir::Browser.new
browser.goto 'http://www.opera.com/'

browser.element(:tag_name, 'body').screenshot('~foo/path/myscreenshot.png')

browser.quit

Note: There is a known bug currently in Opera which creates a black border for the areas outside the current viewport.

Note 2: I have been told it will be a lot easier in future versions.

PS: I may have made mistakes I will fix them if any.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK