How to use performSampleReporting method of com.galenframework.components.report.ReportingListenerTestUtils class

Best Galen code snippet using com.galenframework.components.report.ReportingListenerTestUtils.performSampleReporting

Source:ReportingTest.java Github

copy

Full Screen

...64 GalenTestInfo testInfo = new GalenTestInfo("Home page test", new GalenEmptyTest("Home page test", asList("mobile", "HOMEPAGE")));65 TestReport report = new TestReport();66 LayoutReport layoutReport = new LayoutReport();67 layoutReport.setScreenshot(null);68 ReportingListenerTestUtils.performSampleReporting("Home page test", null, new LayoutReportListener(layoutReport), null);69 report.info("Just a simple info node with attachment")70 .withAttachment("some-file.txt", File.createTempFile("some-file", ".txt"))71 .setTime(new Date(1404681346001L));72 report.addNode(new LayoutReportNode(report.getFileStorage(), layoutReport, "check layout"))73 .setTime(new Date(1404681346002L));74 testInfo.setReport(report);75 testInfos.add(testInfo);76 testInfo.setStartedAt(new Date(1404681346000L));77 testInfo.setEndedAt(new Date(1404681416000L));78 new JsonReportBuilder().build(testInfos, reportPath);79 assertJsonFileContents("Report overview", reportPath + "/report.json", "/expected-reports/json/report.json");80 assertJsonFileContents("Test report", reportPath + "/1-home-page-test.json", "/expected-reports/json/2-home-page-test.json");81 // Check that all files from storage were saved in report folder82 assertThat("Report folder contains files", asList(new File(reportPath).list()), containsInAnyOrder(83 "1-home-page-test.json",84 "file-4-some-file.txt",85 "layout-1-objectB1-actual.png",86 "layout-2-objectB1-expected.png",87 "layout-3-objectB1-map.png",88 "report.json"89 ));90 }91 @Test92 public void shouldReport_inJsonFormat() throws Exception {93 String reportPath = Files.createTempDir().getAbsolutePath() + "/json-report";94 List<GalenTestInfo> testInfos = new LinkedList<>();95 GalenTestInfo testInfo = new GalenTestInfo("Home page test", new GalenEmptyTest("Home page test", asList("mobile", "HOMEPAGE")));96 TestReport report = new TestReport();97 LayoutReport layoutReport = new LayoutReport();98 layoutReport.setScreenshot(layoutReport.getFileStorage().registerFile("screenshot.png", File.createTempFile("screenshot", ".png")));99 ReportingListenerTestUtils.performSampleReporting("Home page test", null, new LayoutReportListener(layoutReport), null);100 report.info("Just a simple info node with attachment")101 .withAttachment("some-file.txt", File.createTempFile("some-file", ".txt"))102 .setTime(new Date(1404681346001L));103 report.addNode(new LayoutReportNode(report.getFileStorage(), layoutReport, "check layout"))104 .setTime(new Date(1404681346002L));105 testInfo.setReport(report);106 testInfos.add(testInfo);107 testInfo.setStartedAt(new Date(1404681346000L));108 testInfo.setEndedAt(new Date(1404681416000L));109 new JsonReportBuilder().build(testInfos, reportPath);110 assertJsonFileContents("Report overview", reportPath + "/report.json", "/expected-reports/json/report.json");111 assertJsonFileContents("Test report", reportPath + "/1-home-page-test.json", "/expected-reports/json/1-home-page-test.json");112 // Check that all files from storage were saved in report folder113 assertThat("Report folder contains files", asList(new File(reportPath).list()), containsInAnyOrder(114 "1-home-page-test.json",115 "file-5-some-file.txt",116 "layout-1-screenshot.png",117 "layout-2-objectB1-actual.png",118 "layout-3-objectB1-expected.png",119 "layout-4-objectB1-map.png",120 "report.json"121 ));122 }123 private void resetUniqueIdForFileTempStorage() throws NoSuchFieldException, IllegalAccessException {124 Field _uniqueIdField = FileTempStorage.class.getDeclaredField("_uniqueId");125 _uniqueIdField.setAccessible(true);126 _uniqueIdField.set(null, 0L);127 }128 @Test public void shouldReport_inTestNgFormat_successfully() throws IOException, TemplateException {129 String reportPath = Files.createTempDir().getAbsolutePath() + "/testng-report/report.xml";130 131 List<GalenTestInfo> testInfos = new LinkedList<>();132 133 GalenTestInfo testInfo = new GalenTestInfo("Home page test", null);134 testInfo.setReport(new TestReport());135 testInfo.setStartedAt(asDate(2014, 4, 10, 18, 56, 40));136 testInfo.setEndedAt(asDate(2014, 4, 10, 20, 35, 30));137 testInfo.setException(new FakeException("Some exception here"));138 testInfos.add(testInfo);139 140 testInfo = new GalenTestInfo("Login page test", null);141 testInfo.setReport(new TestReport());142 testInfo.setStartedAt(asDate(2014, 4, 10, 18, 56, 40));143 testInfo.setEndedAt(asDate(2014, 4, 10, 20, 35, 30));144 testInfos.add(testInfo);145 146 147 new TestNgReportBuilder().build(testInfos, reportPath);148 149 String expectedXml = IOUtils.toString(getClass().getResourceAsStream("/expected-reports/testng-report.xml"));150 151 String realXml = readFileToString(new File(reportPath));152 153 Assert.assertEquals(trimEveryLine(expectedXml), trimEveryLine(realXml));154 }155 private Date asDate(int year, int month, int dayOfMonth, int hourOfDay, int minute, int second) {156 return new GregorianCalendar(year, month, dayOfMonth, hourOfDay, minute, second)157 .getTime();158 }159 160 @Test public void shouldReport_inHtmlFormat_withException_andAttachments() throws IOException, TemplateException {161 String reportDirPath = Files.createTempDir().getAbsolutePath() + "/reports";162 163 List<GalenTestInfo> testInfos = new LinkedList<>();164 GalenTestInfo testInfo = new GalenTestInfo("Home page test", null);165 testInfo.setStartedAt(new Date(1399741000000L));166 testInfo.setEndedAt(new Date(1399746930000L));167 File attachmentFile = new File(Files.createTempDir().getAbsolutePath() + File.separator + "custom.txt");168 attachmentFile.createNewFile();169 170 testInfo.getReport().error(new FakeException("Some exception here")).withAttachment("custom.txt", attachmentFile);171 testInfo.getReport().info("Some detailed report").withDetails("Some details");172 testInfo.getReport().getNodes().get(0).setTime(new Date(1399741000000L));173 testInfo.getReport().getNodes().get(1).setTime(new Date(1399741000000L));174 testInfos.add(testInfo);175 new HtmlReportBuilder().build(testInfos, reportDirPath);176 177 assertThat("Should place attachment file in same folder", new File(reportDirPath + "/file-1-custom.txt").exists(), is(true));178 }179 180 @Test public void shouldReport_inHtmlWithJsonFormat_successfully_andSplitFiles_perTest() throws IOException, TemplateException {181 String reportDirPath = Files.createTempDir().getAbsolutePath() + "/reports";182 183 List<GalenTestInfo> testInfos = new LinkedList<>();184 185 GalenTestInfo testInfo = new GalenTestInfo("Home page test", null);186 TestReport report = new TestReport();187 LayoutReport layoutReport = new LayoutReport();188 layoutReport.setScreenshot(layoutReport.getFileStorage().registerFile("screenshot.png", File.createTempFile("screenshot", ".png")));189 ReportingListenerTestUtils.performSampleReporting("Home page test", null, new LayoutReportListener(layoutReport), null);190 report.info("Just a simple info node with attachment")191 .withAttachment("some-file.txt", File.createTempFile("some-file", ".txt"))192 .setTime(new Date(1404681346001L));193 report.addNode(new LayoutReportNode(report.getFileStorage(), layoutReport, "check layout"))194 .setTime(new Date(1404681346002L));195 testInfo.setReport(report);196 testInfos.add(testInfo);197 testInfo.setStartedAt(new Date(1404681346000L));198 testInfo.setEndedAt(new Date(1404681416000L));199 new HtmlReportBuilder().build(testInfos, reportDirPath);200 201 assertThat("Report folder contains files", asList(new File(reportDirPath).list()), containsInAnyOrder(202 "1-home-page-test.html",203 "1-home-page-test.json",204 "file-5-some-file.txt",205 "layout-1-screenshot.png",206 "layout-2-objectB1-actual.png",207 "layout-3-objectB1-expected.png",208 "layout-4-objectB1-map.png",209 "report.html",210 "report.json",211 "handlebars-v2.0.0.js",212 "galen-report.js",213 "report.css",214 "icon-sprites.png",215 "jquery-1.11.2.min.js",216 "tablesorter.js",217 "tablesorter.css"218 ));219 }220 private String trimEveryLine(String text) {221 String lines[] = text.split("\\r?\\n");222 StringBuilder builder = new StringBuilder();223 224 for (String line: lines) {225 builder.append(line.trim());226 builder.append("\n");227 }228 229 return builder.toString();230 }231 @Test public void shouldReport_toConsole_successfully() throws IOException {232 performConsoleReporting_andCompare("/expected-reports/console.txt");233 }234 @Test public void shouldReport_toConsole_onlySuites_whenLogLevel_is_1() throws IOException {235 System.setProperty(GALEN_LOG_LEVEL, "1");236 performConsoleReporting_andCompare("/expected-reports/console-1.txt");237 }238 239 @Test public void shouldReport_toConsole_onlySuites_andPages_whenLogLevel_is_2() throws IOException {240 System.setProperty(GALEN_LOG_LEVEL, "2");241 performConsoleReporting_andCompare("/expected-reports/console-2.txt");242 }243 244 private void performConsoleReporting_andCompare(String expectedReport) throws IOException {245 ByteArrayOutputStream baos = new ByteArrayOutputStream();246 PrintStream ps = new PrintStream(baos);247 ConsoleReportingListener listener = new ConsoleReportingListener(ps, ps);248 ReportingListenerTestUtils.performSampleReporting("page1.test", listener, listener, listener);249 250 listener.done();251 String expectedText = IOUtils.toString(getClass().getResourceAsStream(expectedReport)).replace("\\t ", "\t");252 253 Assert.assertEquals(expectedText, baos.toString("UTF-8"));254 }255 private void assertJsonFileContents(String title, String actualPath, String expectedPath) throws IOException {256 String actualContent = readFileToString(new File(actualPath));257 String expectedContent = readFileToString(new File(getClass().getResource(expectedPath).getFile()));258 ObjectMapper mapper = new ObjectMapper();259 JsonNode actualTree = mapper.readTree(actualContent);260 JsonNode expectedTree = mapper.readTree(expectedContent);261 assertThat(title + " content should be", actualTree, is(expectedTree));262 }...

Full Screen

Full Screen

performSampleReporting

Using AI Code Generation

copy

Full Screen

1 import static com.galenframework.components.report.ReportingListenerTestUtils.performSampleReporting2 import com.galenframework.components.report.ReportingListener3 import com.galenframework.components.report.TestReport4 import com.galenframework.components.report.TestReportInfo5 import com.galenframework.components.report.TestReportStatus6 import com.galenframework.reports.TestReportBuilder7 import com.galenframe

Full Screen

Full Screen

performSampleReporting

Using AI Code Generation

copy

Full Screen

1 public void sampleReportingTest() throws Exception {2 GalenTestInfo test = GalenTestInfo.fromString("Sample test");3 test.getReport().layout("/samplePage.spec", Arrays.asList("desktop"));4 test.getReport().layout("/samplePage.spec", Arrays.asList("tablet"));5 test.getReport().layout("/samplePage.spec", Arrays.asList("mobile"));6 ReportingListenerTestUtils.performSampleReporting(test);7 }8}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Galen automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful