CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-seleniumhq-selenium--selenium-firefox-driver

Selenium Firefox WebDriver implementation for automating Firefox browser interactions

Pending
Overview
Eval results
Files

screenshot-capabilities.mddocs/

Screenshot Capabilities

Full-page screenshot functionality beyond standard WebDriver screenshot capabilities. Firefox WebDriver provides enhanced screenshot features for capturing complete page content.

Capabilities

HasFullPageScreenshot Interface

Interface for taking full-page screenshots that capture entire page content beyond the viewport.

/**
 * Interface for taking full-page screenshots.
 * Extends standard WebDriver screenshot functionality to capture complete page content.
 */
@Beta
public interface HasFullPageScreenshot {
    
    /**
     * Takes a full-page screenshot of the current page.
     * Captures the entire page content, not just the visible viewport.
     * @param outputType Output format for the screenshot (FILE, BYTES, BASE64)
     * @param <X> Return type determined by OutputType
     * @return Screenshot in the specified format
     */
    <X> X getFullPageScreenshotAs(OutputType<X> outputType);
}

Usage Examples:

import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.HasFullPageScreenshot;
import org.openqa.selenium.OutputType;
import java.io.File;

FirefoxDriver driver = new FirefoxDriver();
HasFullPageScreenshot screenshotCapability = driver;  // FirefoxDriver implements HasFullPageScreenshot

driver.get("https://example.com/long-page");

// Take full-page screenshot as file
File screenshotFile = screenshotCapability.getFullPageScreenshotAs(OutputType.FILE);
System.out.println("Full-page screenshot saved to: " + screenshotFile.getAbsolutePath());

// Take full-page screenshot as byte array
byte[] screenshotBytes = screenshotCapability.getFullPageScreenshotAs(OutputType.BYTES);
System.out.println("Screenshot size: " + screenshotBytes.length + " bytes");

// Take full-page screenshot as Base64 string
String screenshotBase64 = screenshotCapability.getFullPageScreenshotAs(OutputType.BASE64);
System.out.println("Base64 screenshot length: " + screenshotBase64.length());

OutputType Support

The full-page screenshot functionality supports all standard WebDriver OutputType formats.

// Standard OutputType options for screenshots
public final class OutputType<T> {
    public static final OutputType<File> FILE;      // Save to temporary file
    public static final OutputType<byte[]> BYTES;   // Return as byte array
    public static final OutputType<String> BASE64;  // Return as Base64 string
}

Comparison with Standard Screenshots

Understanding the difference between standard WebDriver screenshots and full-page screenshots:

Standard WebDriver Screenshot (TakesScreenshot interface):

import org.openqa.selenium.TakesScreenshot;

// Standard viewport screenshot
TakesScreenshot takesScreenshot = (TakesScreenshot) driver;
File viewportScreenshot = takesScreenshot.getScreenshotAs(OutputType.FILE);
// Only captures visible viewport area

Full-Page Screenshot (HasFullPageScreenshot interface):

import org.openqa.selenium.firefox.HasFullPageScreenshot;

// Full-page screenshot
HasFullPageScreenshot fullPageCapability = (HasFullPageScreenshot) driver;
File fullPageScreenshot = fullPageCapability.getFullPageScreenshotAs(OutputType.FILE);
// Captures entire page content, including content below the fold

Practical Usage Examples

Basic Full-Page Screenshot:

import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.OutputType;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;

FirefoxDriver driver = new FirefoxDriver();

// Navigate to page with long content
driver.get("https://example.com/documentation");

// Take full-page screenshot
File screenshot = driver.getFullPageScreenshotAs(OutputType.FILE);

// Copy to permanent location with meaningful name
File permanentLocation = new File("/screenshots/documentation-full-page.png");
Files.copy(screenshot.toPath(), permanentLocation.toPath(), 
           StandardCopyOption.REPLACE_EXISTING);

System.out.println("Full-page screenshot saved to: " + permanentLocation);

Screenshot Comparison Testing:

import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.OutputType;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

FirefoxDriver driver = new FirefoxDriver();
driver.get("https://example.com");

// Take both types of screenshots for comparison
byte[] viewportScreenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
byte[] fullPageScreenshot = driver.getFullPageScreenshotAs(OutputType.BYTES);

// Save both screenshots
try (FileOutputStream viewport = new FileOutputStream("viewport.png");
     FileOutputStream fullPage = new FileOutputStream("fullpage.png")) {
    
    viewport.write(viewportScreenshot);
    fullPage.write(fullPageScreenshot);
    
    System.out.println("Viewport screenshot size: " + viewportScreenshot.length);
    System.out.println("Full-page screenshot size: " + fullPageScreenshot.length);
}

Automated Screenshot Documentation:

import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.OutputType;
import java.io.File;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

public class DocumentationScreenshots {
    private FirefoxDriver driver;
    private String screenshotDir;
    
    public DocumentationScreenshots() {
        this.driver = new FirefoxDriver();
        this.screenshotDir = "/documentation/screenshots/";
    }
    
    public void capturePageDocumentation(List<String> urls) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss");
        
        for (String url : urls) {
            try {
                driver.get(url);
                
                // Wait for page to fully load
                Thread.sleep(2000);
                
                // Generate filename from URL and timestamp
                String filename = url.replaceAll("[^a-zA-Z0-9.-]", "_") + 
                                "_" + LocalDateTime.now().format(formatter) + ".png";
                
                // Take full-page screenshot
                File screenshot = driver.getFullPageScreenshotAs(OutputType.FILE);
                
                // Move to documentation directory
                File destination = new File(screenshotDir + filename);
                screenshot.renameTo(destination);
                
                System.out.println("Captured: " + url + " -> " + filename);
                
            } catch (Exception e) {
                System.err.println("Failed to capture " + url + ": " + e.getMessage());
            }
        }
    }
    
    public void close() {
        if (driver != null) {
            driver.quit();
        }
    }
}

// Usage
DocumentationScreenshots capture = new DocumentationScreenshots();
List<String> pages = Arrays.asList(
    "https://example.com/",
    "https://example.com/products",
    "https://example.com/documentation"
);

capture.capturePageDocumentation(pages);
capture.close();

Screenshot with Custom Handling:

import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.OutputType;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;

FirefoxDriver driver = new FirefoxDriver();
driver.get("https://example.com");

// Get screenshot as bytes for processing
byte[] screenshotBytes = driver.getFullPageScreenshotAs(OutputType.BYTES);

// Convert to BufferedImage for manipulation
try (ByteArrayInputStream bis = new ByteArrayInputStream(screenshotBytes)) {
    BufferedImage image = ImageIO.read(bis);
    
    System.out.println("Screenshot dimensions: " + 
                      image.getWidth() + "x" + image.getHeight());
    
    // Save in different format
    ImageIO.write(image, "jpg", new File("screenshot.jpg"));
    
    // Could also resize, crop, or apply other transformations here
    
} catch (IOException e) {
    System.err.println("Error processing screenshot: " + e.getMessage());
}

Integration with Test Frameworks:

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.AfterEach;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.OutputType;
import java.io.File;

public class FullPageScreenshotTest {
    private FirefoxDriver driver;
    
    @Test
    public void testFullPageCapture() {
        driver = new FirefoxDriver();
        driver.get("https://example.com/long-content");
        
        // Test specific functionality
        // ...
        
        // Capture full-page screenshot for verification
        File screenshot = driver.getFullPageScreenshotAs(OutputType.FILE);
        
        // Verify screenshot was created
        assert screenshot.exists();
        assert screenshot.length() > 0;
        
        System.out.println("Test screenshot: " + screenshot.getAbsolutePath());
    }
    
    @AfterEach
    public void tearDown() {
        if (driver != null) {
            driver.quit();
        }
    }
}

Install with Tessl CLI

npx tessl i tessl/maven-org-seleniumhq-selenium--selenium-firefox-driver

docs

browser-configuration.md

context-management.md

driver-management.md

extension-management.md

index.md

profile-management.md

screenshot-capabilities.md

service-management.md

tile.json