|
| 1 | +# Java implementation for [Visual Knight](https://github.com/visual-knight/platform-community-edition) API |
| 2 | +Port from JavaScript implementation [link](https://github.com/visual-knight/libraries/tree/master/packages/core) |
| 3 | + |
| 4 | +## Gradle |
| 5 | +``` |
| 6 | +repositories { |
| 7 | + maven { url 'https://jitpack.io' } |
| 8 | +} |
| 9 | +``` |
| 10 | +``` |
| 11 | +dependencies { |
| 12 | + implementation 'com.github.pashidlos:visualknight_agent_java_core:${VERSION}' |
| 13 | +} |
| 14 | +``` |
| 15 | +## Maven |
| 16 | +``` |
| 17 | +<repositories> |
| 18 | + <repository> |
| 19 | + <id>jitpack.io</id> |
| 20 | + <url>https://jitpack.io</url> |
| 21 | + </repository> |
| 22 | +</repositories> |
| 23 | +``` |
| 24 | +``` |
| 25 | +<dependency> |
| 26 | + <groupId>com.github.pashidlos</groupId> |
| 27 | + <artifactId>visualknight_agent_java_core</artifactId> |
| 28 | + <version>${VERSION}</version> |
| 29 | +</dependency> |
| 30 | +``` |
| 31 | +[Available versions](https://github.com/pashidlos/visualknight_agent_java_core/releases) |
| 32 | + |
| 33 | +More info about https://jitpack.io/ |
| 34 | + |
| 35 | +## Usage |
| 36 | +* Setup options object |
| 37 | +``` |
| 38 | +VisualKnightOptions visualKnightOptions = VisualKnightOptions.builder() |
| 39 | + // URL to Visual Knight backend |
| 40 | + // Required |
| 41 | + .apiEndpoint("http://localhost:3333/graphql") |
| 42 | +
|
| 43 | + // Your Visual Knight API key |
| 44 | + // Required |
| 45 | + .apiKey("API_KEY") |
| 46 | +
|
| 47 | + // Your project name or ID |
| 48 | + // Required |
| 49 | + .project("PROJECT_KEY_OR_NAME") |
| 50 | +
|
| 51 | + // The mismatch tolerance for the comparison, 0.01 is 1% |
| 52 | + // Optional |
| 53 | + // Default: 0.01 |
| 54 | + .misMatchTolerance(0.01) |
| 55 | +
|
| 56 | + // Accept first testsession for a variation as baseline |
| 57 | + // Optional |
| 58 | + // Default: false |
| 59 | + .autoBaseline(false) |
| 60 | + .build(); |
| 61 | +``` |
| 62 | +* Create instance of `VisualKnightCore` |
| 63 | +``` |
| 64 | +VisualKnightCore visualKnightCore = new VisualKnightCore(visualKnightOptions); |
| 65 | +``` |
| 66 | +* Take a screenshot as String in Base64 format |
| 67 | +``` |
| 68 | +// Selenium example |
| 69 | +String screenshotBase64 = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BASE64); |
| 70 | +``` |
| 71 | +* Create instance of `VisualKnightCapabilities` |
| 72 | +``` |
| 73 | +VisualKnightCapabilities visualKnightCapabilities = VisualKnightCapabilities.builder() |
| 74 | + // Available: 'Windows', 'Mac OS', `Puppeteer` |
| 75 | + .os("Windows") |
| 76 | +
|
| 77 | + // Available: 'Internet Explorer', 'Firefox', 'Safari', 'Chrome', 'Opera' |
| 78 | + .browserName("Chrome") |
| 79 | + .build() |
| 80 | +``` |
| 81 | +* Process image |
| 82 | +``` |
| 83 | +visualKnightCore.processScreenshot( |
| 84 | + "Name for test", |
| 85 | + screenshotBase64, |
| 86 | + visualKnightCapabilities |
| 87 | +); |
| 88 | +``` |
0 commit comments