|
| 1 | +package agent_java_core; |
| 2 | + |
| 3 | +import org.testng.Assert; |
| 4 | +import org.testng.annotations.BeforeSuite; |
| 5 | +import org.testng.annotations.DataProvider; |
| 6 | +import org.testng.annotations.Test; |
| 7 | + |
| 8 | +import java.net.MalformedURLException; |
| 9 | + |
| 10 | +public class Example { |
| 11 | + VisualKnightOptions visualKnightOptions; |
| 12 | + VisualKnightCore core; |
| 13 | + |
| 14 | + @BeforeSuite |
| 15 | + public void setUp() throws MalformedURLException { |
| 16 | + visualKnightOptions = VisualKnightOptions.builder() |
| 17 | + .apiEndpoint("http://localhost:3333/graphql") |
| 18 | + .build(); |
| 19 | + |
| 20 | + core = new VisualKnightCore(visualKnightOptions); |
| 21 | + } |
| 22 | +// |
| 23 | +// @Test |
| 24 | +// public void asd() throws MalformedURLException { |
| 25 | +// VisualKnightCapabilities visualKnightCapabilities = VisualKnightCapabilities.builder().browserName("Chrome").os("Windows").build(); |
| 26 | +// VisualKnightOptions visualKnightOptions = VisualKnightOptions.builder() |
| 27 | +// .apiEndpoint("http://localhost:3333/graphql") |
| 28 | +// .apiKey("asdasd") |
| 29 | +// .project("test") |
| 30 | +// .visualKnightCapabilities(visualKnightCapabilities) |
| 31 | +// .build(); |
| 32 | +// |
| 33 | +// VisualKnightCore core = new VisualKnightCore(visualKnightOptions); |
| 34 | +// |
| 35 | +//// core.invokeTestSession("test", capabilities); |
| 36 | +// |
| 37 | +// System.out.println("END"); |
| 38 | +// } |
| 39 | +// |
| 40 | +// @Test |
| 41 | +// public void uploadScreenshot() throws IOException { |
| 42 | +// VisualKnightCapabilities visualKnightCapabilities = VisualKnightCapabilities.builder().browserName("Chrome").os("Windows").build(); |
| 43 | +// VisualKnightOptions visualKnightOptions = VisualKnightOptions.builder() |
| 44 | +// .apiEndpoint("http://localhost:3333/graphql") |
| 45 | +// .apiKey("asdasd") |
| 46 | +// .project("test") |
| 47 | +// .visualKnightCapabilities(visualKnightCapabilities) |
| 48 | +// .build(); |
| 49 | +// |
| 50 | +// VisualKnightCore core = new VisualKnightCore(visualKnightOptions); |
| 51 | +// |
| 52 | +//// byte[] fileContent = FileUtils.readFileToByteArray(new File(getClass().getResource("large.png").getFile())); |
| 53 | +//// core.uploadScreenshot("ck8t908ie000111pjg8z2x58o", Base64.getEncoder().encodeToString(fileContent)); |
| 54 | +// core.uploadScreenshot("ck8t908ie000111pjg8z2x58o", "asdsfgsdf"); |
| 55 | +// |
| 56 | +// System.out.println("END"); |
| 57 | +// } |
| 58 | + |
| 59 | + @DataProvider(name = "processTestSessionResultCases") |
| 60 | + public Object[][] complexParamsDataProvider() { |
| 61 | + return new Object[][]{ |
| 62 | + { |
| 63 | + UploadScreenshotMutation.builder() |
| 64 | + .misMatchPercentage(null) |
| 65 | + .misMatchTolerance(0.01f) |
| 66 | + .isSameDimensions(null) |
| 67 | + .link("http://google.com") |
| 68 | + .build(), |
| 69 | + "For this image is no baseline defined! -> http://google.com", |
| 70 | + }, |
| 71 | + { |
| 72 | + UploadScreenshotMutation.builder() |
| 73 | + .misMatchPercentage(null) |
| 74 | + .misMatchTolerance(0.01f) |
| 75 | + .isSameDimensions(true) |
| 76 | + .link("http://google.com") |
| 77 | + .build(), |
| 78 | + "For this image is no baseline defined! -> http://google.com", |
| 79 | + }, |
| 80 | + { |
| 81 | + UploadScreenshotMutation.builder() |
| 82 | + .misMatchPercentage(null) |
| 83 | + .misMatchTolerance(0.01f) |
| 84 | + .isSameDimensions(false) |
| 85 | + .link("http://google.com") |
| 86 | + .build(), |
| 87 | + "Compared Screenshots are not in the same dimension! -> http://google.com", |
| 88 | + }, |
| 89 | + { |
| 90 | + UploadScreenshotMutation.builder() |
| 91 | + .misMatchPercentage(0.02f) |
| 92 | + .misMatchTolerance(0.01f) |
| 93 | + .isSameDimensions(true) |
| 94 | + .link("http://google.com") |
| 95 | + .build(), |
| 96 | + "Mismatch of 0.02 is greater than the tolerance 0.01 -> http://google.com", |
| 97 | + }, |
| 98 | + }; |
| 99 | + } |
| 100 | + |
| 101 | + @Test(dataProvider = "processTestSessionResultCases") |
| 102 | + public void processTestSessionResult(UploadScreenshotMutation testSessionResult, String expectedMessage) { |
| 103 | + String actualMessage = ""; |
| 104 | + try { |
| 105 | + core.processTestSessionResult(testSessionResult); |
| 106 | + } catch (ImageProcessException exception) { |
| 107 | + actualMessage = exception.getMessage(); |
| 108 | + } |
| 109 | + Assert.assertEquals(actualMessage, expectedMessage); |
| 110 | + } |
| 111 | +} |
0 commit comments