Gemini UI Screenshot Testing
Gemini is a utility for regression testing the visual appearance of web pages, primarily interacting via a command-line interface and configuration files. It captures screenshots across various browsers to detect visual deviations from reference images, making it particularly useful for UI library developers. The package helps identify subtle rendering artifacts, text caret differences, and provides CSS test coverage statistics. The current stable version is 7.5.2, released in July 2019. The project appears to have a sporadic release cadence, with major version updates becoming infrequent, and the last code activity observed in March 2021. Its differentiators include granular control over capture elements and built-in image comparison tolerance for minor, expected visual variations.
Common errors
-
WebDriverError: Unable to connect to WebDriver service at http://localhost:4444/wd/hub
cause The Selenium WebDriver server (or ChromeDriver, etc.) is not running or is not accessible at the configured URL.fixStart your WebDriver server using `selenium-standalone start` or `chromedriver` before running Gemini tests. Verify the `gridUrl` in your `.gemini.js` is correct. -
Error: Looks-same: Comparison failed because of different image sizes
cause The reference image and the captured image have different dimensions, often due to layout shifts, responsive changes, or unexpected browser behavior.fixManually inspect the images to understand the cause. If the change is intended, run `gemini update` to generate new reference images. If unintended, fix the layout issue in your application. -
Reference image does not exist. Run 'gemini update' to create it.
cause Gemini could not find a reference image for a specific test state, typically on the first run of a new test or after a reference image was deleted.fixExecute `gemini update` to create initial reference images based on the current UI state. Ensure that the `screenshotsDir` in your config is writable.
Warnings
- breaking Starting with v7.0.0, Gemini requires Node.js version 8.0.0 or higher. Older Node.js versions are not supported and will lead to execution failures.
- breaking The `gemini gather` command was deprecated in favor of `gemini update` in v4.0.0. Using `gather` will not work as expected and may result in errors.
- breaking The test execution events (`TEST_RESULT`, `UPDATE_RESULT`, `RETRY`, `ERROR`) changed their payload in v6.0.0. They now emit an object containing `path` and `size` for images, instead of just the image path string.
- gotcha Gemini heavily relies on a running WebDriver server (e.g., Selenium Server, ChromeDriver). Failure to start this server before running tests will result in connection errors and tests not executing.
- gotcha The project appears largely unmaintained since 2021. While functional for older tech stacks, it may lack updates for modern browser versions, WebDriver protocols, or complex frontend frameworks, potentially leading to instability or compatibility issues.
Install
-
npm install gemini -
yarn add gemini -
pnpm add gemini
Imports
- gemini
import gemini from 'gemini';
const gemini = require('gemini'); - suite
gemini.suite('my-suite', (suite) => { /* ... */ }); - config
export default { /* ... */ }; // in .gemini.jsmodule.exports = { /* ... */ }; // in .gemini.js
Quickstart
/* .gemini.js (config file in project root) */
module.exports = {
rootUrl: 'http://localhost:3000/', // Your application's base URL
gridUrl: 'http://127.0.0.1:4444/wd/hub', // WebDriver URL (e.g., Selenium Standalone, ChromeDriver)
browsers: {
chrome: {
desiredCapabilities: { browserName: 'chrome' }
},
firefox: {
desiredCapabilities: { browserName: 'firefox' }
}
},
// Define where test files are located
sets: {
desktop: {
files: 'gemini/**/*.gemini.js',
browsers: ['chrome', 'firefox']
}
},
// Directory to save screenshots and diffs
screenshotsDir: 'gemini/screens'
};
/* gemini/my-component.gemini.js (test file) */
gemini.suite('MyComponent', (suite) => {
suite.setUrl('/my-component') // Navigate to a specific path relative to rootUrl
.setCaptureElements('.my-component-selector') // Define element(s) to capture
.capture('initial-state', { // Capture a state for comparison
tolerance: 2.5 // Allow some pixel difference
});
});
// To run:
// 1. Install gemini and selenium-standalone globally: npm install -g gemini selenium-standalone
// 2. Install browser drivers: selenium-standalone install
// 3. Start Selenium Server: selenium-standalone start
// 4. Update reference images (first run): gemini update
// 5. Run tests: gemini test