How to use getOutputDirectory method of net.serenitybdd.junit.runners.SerenityRunner class

Best Serenity JUnit code snippet using net.serenitybdd.junit.runners.SerenityRunner.getOutputDirectory

Source:SerenityRunner.java Github

copy

Full Screen

...190 }191 private boolean requestedDriverSpecified() {192 return !isEmpty(this.requestedDriver);193 }194 public File getOutputDirectory() {195 return getConfiguration().getOutputDirectory();196 }197 /**198 * To generate reports, different AcceptanceTestReporter instances need to199 * subscribe to the listener. The listener will tell them when the test is200 * done, and the reporter can decide what to do.201 * @param reporter an implementation of the AcceptanceTestReporter interface.202 */203 public void subscribeReporter(final AcceptanceTestReporter reporter) {204 getReportService().subscribe(reporter);205 }206 public void useQualifier(final String qualifier) {207 getReportService().useQualifier(qualifier);208 }209 /**210 * Runs the tests in the acceptance test case.211 */212 @Override213 public void run(final RunNotifier notifier) {214 if (skipThisTest()) { return; }215 try {216 RunNotifier localNotifier = initializeRunNotifier(notifier);217 StepEventBus.getEventBus().registerListener(failureDetectingStepListener);218 super.run(localNotifier);219 fireNotificationsBasedOnTestResultsTo(notifier);220 } catch (Throwable someFailure) {221 someFailure.printStackTrace();222 throw someFailure;223 } finally {224 notifyTestSuiteFinished();225 generateReports();226 Map<String, List<String>> failedTests = stepListener.getFailedTests();227 failureRerunner.recordFailedTests(failedTests);228 dropListeners(notifier);229 StepEventBus.getEventBus().dropAllListeners();230 }231 }232 private Optional<TestOutcome> latestOutcome() {233 if (StepEventBus.getEventBus().getBaseStepListener().getTestOutcomes().isEmpty()) {234 return Optional.empty();235 }236 return Optional.of(StepEventBus.getEventBus().getBaseStepListener().getTestOutcomes().get(0));237 }238 private void fireNotificationsBasedOnTestResultsTo(RunNotifier notifier) {239 if (!latestOutcome().isPresent()) {240 return;241 }242 }243 private void notifyTestSuiteFinished() {244 try {245 if (dataDrivenTest()) {246 StepEventBus.getEventBus().exampleFinished();247 } else {248 StepEventBus.getEventBus().testSuiteFinished();249 }250 } catch (Throwable listenerException) {251 // We report and ignore listener exceptions so as not to mess up the rest of the test mechanics.252 logger.error("Test event bus error: " + listenerException.getMessage(), listenerException);253 }254 }255 private boolean dataDrivenTest() {256 return this instanceof TestClassRunnerForParameters;257 }258 private void dropListeners(final RunNotifier notifier) {259 JUnitStepListener listener = getStepListener();260 notifier.removeListener(listener);261 getStepListener().dropListeners();262 }263 protected void generateReports() {264 generateReportsFor(getTestOutcomes());265 }266 private boolean skipThisTest() {267 return testNotInCurrentBatch();268 }269 private boolean testNotInCurrentBatch() {270 return (batchManager != null) && (!batchManager.shouldExecuteThisTest(getDescription().testCount()));271 }272 /**273 * The Step Listener observes and records what happens during the execution of the test.274 * Once the test is over, the Step Listener can provide the acceptance test outcome in the275 * form of an TestOutcome object.276 * @return the current step listener277 */278 protected JUnitStepListener getStepListener() {279 if (stepListener == null) {280 buildAndConfigureListeners();281 }282 return stepListener;283 }284 protected void setStepListener(JUnitStepListener stepListener) {285 this.stepListener = stepListener;286 }287 private void buildAndConfigureListeners() {288 initStepEventBus();289 if (webtestsAreSupported()) {290 ThucydidesWebDriverSupport.initialize(requestedDriver);291 WebDriver driver = ThucydidesWebDriverSupport.getWebdriverManager().getWebdriver();292 initPagesObjectUsing(driver);293 setStepListener(initListenersUsing(getPages()));294 initStepFactoryUsing(getPages());295 } else {296 setStepListener(initListeners());297 initStepFactory();298 }299 }300 private RunNotifier initializeRunNotifier(RunNotifier notifier) {301 notifier.addListener(getStepListener());302 return notifier;303 }304 private int maxRetries() {305 return TEST_RETRY_COUNT.integerFrom(configuration.getEnvironmentVariables(), 0);306 }307 protected void initStepEventBus() {308 StepEventBus.getEventBus().clear();309 }310 private void initPagesObjectUsing(final WebDriver driver) {311 pages = new Pages(driver, getConfiguration());312 dependencyInjector = new PageObjectDependencyInjector(pages);313 }314 protected JUnitStepListener initListenersUsing(final Pages pageFactory) {315 return JUnitStepListener.withOutputDirectory(getConfiguration().getOutputDirectory())316 .and().withPageFactory(pageFactory)317 .and().withTestClass(getTestClass().getJavaClass())318 .and().build();319 }320 protected JUnitStepListener initListeners() {321 return JUnitStepListener.withOutputDirectory(getConfiguration().getOutputDirectory())322 .and().withTestClass(getTestClass().getJavaClass())323 .and().build();324 }325 private boolean webtestsAreSupported() {326 return TestCaseAnnotations.supportsWebTests(this.getTestClass().getJavaClass());327 }328 private void initStepFactoryUsing(final Pages pagesObject) {329 stepFactory = StepFactory.getFactory().usingPages(pagesObject);330 }331 private void initStepFactory() {332 stepFactory = StepFactory.getFactory();333 }334 private ReportService getReportService() {335 if (reportService == null) {336 reportService = new ReportService(getOutputDirectory(), getDefaultReporters());337 }338 return reportService;339 }340 /**341 * A test runner can generate reports via Reporter instances that subscribe342 * to the test runner. The test runner tells the reporter what directory to343 * place the reports in. Then, at the end of the test, the test runner344 * notifies these reporters of the test outcomes. The reporter's job is to345 * process each test run outcome and do whatever is appropriate.346 *347 * @param testOutcomeResults the test results from the previous test run.348 */349 private void generateReportsFor(final List<TestOutcome> testOutcomeResults) {350 getReportService().generateReportsFor(testOutcomeResults);...

Full Screen

Full Screen

Source:WhenRunningANonWebTestScenario.java Github

copy

Full Screen

...282 super(klass, webDriverFactory);283 testOutputDirectory = outputDirectory;284 }285 @Override286 public File getOutputDirectory() {287 return testOutputDirectory;288 }289 }290 @Test291 public void html_test_results_are_written_to_the_output_directory() throws Exception {292 File outputDirectory = temporaryFolder.newFolder();293 SerenityRunner runner = new TestableSerenityRunnerSample(SamplePassingNonWebScenario.class,outputDirectory);294 runner.run(new RunNotifier());295 List<String> generatedHtmlReports = Arrays.asList(outputDirectory.list(new HTMLFileFilter()));296 assertThat(generatedHtmlReports.size(), is(3));297 }298 @Test299 public void json_test_results_are_written_to_the_output_directory() throws Exception {300 File outputDirectory = temporaryFolder.newFolder();...

Full Screen

Full Screen

Source:SerenityParameterizedRunner.java Github

copy

Full Screen

...190 getReportService().generateConfigurationsReport();191 }192 private ReportService getReportService() {193 if (reportService == null) {194 reportService = new ReportService(getOutputDirectory(), getDefaultReporters());195 }196 return reportService;197 }198 private Collection<AcceptanceTestReporter> getDefaultReporters() {199 return ReportService.getDefaultReporters();200 }201 private File getOutputDirectory() {202 return this.configuration.getOutputDirectory();203 }204 public void subscribeReporter(final AcceptanceTestReporter reporter) {205 getReportService().subscribe(reporter);206 }207 public List<Runner> getRunners() {208 return runners;209 }210}...

Full Screen

Full Screen

Source:WhenInstanciatingANewTestRunner.java Github

copy

Full Screen

...27 public MethodRule saveSystemProperties = new SaveWebdriverSystemPropertiesRule();28 @Test29 public void the_default_output_directory_should_follow_the_maven_convention() throws InitializationError {30 SerenityRunner runner = getTestRunnerUsing(SuccessfulSingleTestScenario.class);31 File outputDirectory = runner.getOutputDirectory();32 assertThat(outputDirectory.getPath(), is("target" + FILE_SEPARATOR + "site" + FILE_SEPARATOR + "serenity"));33 }34 @Test35 public void system_should_complain_if_we_use_an_unsupported_driver()36 throws InitializationError {37 try {38 environmentVariables.setProperty("webdriver.driver", "netscape");39 SerenityRunner runner = getTestRunnerUsing(SuccessfulSingleTestScenario.class);40 runner.run(new RunNotifier());41 fail("Should have thrown DriverConfigurationError");42 } catch (DriverConfigurationError e) {43 assertThat(e.getMessage(), containsString("Unsupported browser type: netscape"));44 }45 }46 @Test47 public void lynx_is_not_a_supported_driver()48 throws InitializationError {49 try {50 environmentVariables.setProperty("webdriver.driver", "lynx");51 SerenityRunner runner = getTestRunnerUsing(SuccessfulSingleTestScenario.class);52 runner.run(new RunNotifier());53 fail("Should have thrown DriverConfigurationError");54 } catch (DriverConfigurationError e) {55 assertThat(e.getMessage(), containsString("Unsupported browser type: lynx"));56 }57 }58 @Test59 public void driver_can_be_overridden_using_the_driver_property_in_the_Managed_annotation() throws InitializationError {60 environmentVariables.setProperty("webdriver.driver", "opera");61 SerenityRunner runner = getTestRunnerUsing(SuccessfulSingleTestScenarioWithABrowser.class);62 runner.run(new RunNotifier());63 }64 @Test65 public void should_not_allow_an_incorrectly_specified_driver()66 throws InitializationError {67 try {68 environmentVariables.setProperty("webdriver.driver", "firefox");69 SerenityRunner runner = getTestRunnerUsing(SuccessfulSingleTestScenarioWithWrongBrowser.class);70 runner.run(new RunNotifier());71 fail("Should have thrown DriverConfigurationError");72 } catch (DriverConfigurationError e) {73 assertThat(e.getMessage(), containsString("Unsupported browser type: doesnotexist"));74 }75 }76 @Test77 public void the_output_directory_can_be_defined_by_a_system_property() throws InitializationError {78 environmentVariables.setProperty("thucydides.outputDirectory", "target" + FILE_SEPARATOR79 + "reports" + FILE_SEPARATOR80 + "thucydides");81 SerenityRunner runner = getTestRunnerUsing(SuccessfulSingleTestScenario.class);82 File outputDirectory = runner.getOutputDirectory();83 assertThat(outputDirectory.getPath(), is("target" + FILE_SEPARATOR84 + "reports" + FILE_SEPARATOR85 + "thucydides"));86 }87 @Test88 public void the_output_directory_can_be_defined_by_a_system_property_using_any_standard_separators() throws InitializationError {89 SerenityRunner runner = getTestRunnerUsing(SuccessfulSingleTestScenario.class);90 environmentVariables.setProperty("thucydides.outputDirectory", "target/reports/thucydides");91 File outputDirectory = runner.getOutputDirectory();92 assertThat(outputDirectory.getPath(), is("target" + FILE_SEPARATOR93 + "reports" + FILE_SEPARATOR94 + "thucydides"));95 }96 @Test97 public void a_batch_runner_is_set_by_default() throws InitializationError {98 SerenityRunner runner = getTestRunnerUsing(SuccessfulSingleTestScenario.class);99 assertThat(runner.getBatchManager(), instanceOf(SystemVariableBasedBatchManager.class));100 }101 @Test102 public void a_batch_runner_can_be_overridden_using_system_property() throws InitializationError {103// environmentVariables.setProperty(ThucydidesSystemProperty.THUCYDIDES_BATCH_STRATEGY.getPropertyName(), BatchStrategy.DIVIDE_BY_TEST_COUNT.name());104 environmentVariables.setProperty("thucydides.batch.strategy", "DIVIDE_BY_TEST_COUNT");105 SerenityRunner runner = getTestRunnerUsing(SuccessfulSingleTestScenario.class);...

Full Screen

Full Screen

Source:SerenityExtension.java Github

copy

Full Screen

...34 public void afterAll(final ExtensionContext extensionContext) {35 StepEventBus.getEventBus().dropAllListeners();36 }37 private BaseStepListener createBaseStepListener() {38 return Listeners.getBaseStepListener().withOutputDirectory(getConfiguration().getOutputDirectory());39 }40 private void registerListenersOnEventBus(final StepListener... stepListeners) {41 for (StepListener currentStepListener : stepListeners) {42 getEventBus().registerListener(currentStepListener);43 }44 }45 private StepListener testCountListener() {46 return JUnitInjectors.getInjector().getInstance(Key.get(StepListener.class, TestCounter.class));47 }48 private void injectEnvironmentVariablesInto(final Object testCase) {49 new EnvironmentDependencyInjector().injectDependenciesInto(testCase);50 }51}...

Full Screen

Full Screen

Source:SerenityReportExtension.java Github

copy

Full Screen

...25 /**26 * @param testOutcomeResults the test results from the previous test run.27 */28 private void generateReportsFor(final List<TestOutcome> testOutcomeResults) {29 final ReportService reportService = new ReportService(getOutputDirectory(), getDefaultReporters());30 reportService.generateReportsFor(testOutcomeResults);31 reportService.generateConfigurationsReport();32 }33 /**34 * @return The default reporters applicable for standard test runs.35 */36 protected Collection<AcceptanceTestReporter> getDefaultReporters() {37 return ReportService.getDefaultReporters();38 }39 public File getOutputDirectory() {40 return ConfiguredEnvironment.getConfiguration().getOutputDirectory();41 }42}...

Full Screen

Full Screen

getOutputDirectory

Using AI Code Generation

copy

Full Screen

1 public static String getOutputDirectory() {2 return outputDirectory;3 }4 public static void setOutputDirectory(String outputDirectory) {5 SerenityRunner.outputDirectory = outputDirectory;6 }7 public static String getProjectName() {8 return projectName;9 }10 public static void setProjectName(String projectName) {11 SerenityRunner.projectName = projectName;12 }13 public static String getProjectVersion() {14 return projectVersion;15 }16 public static void setProjectVersion(String projectVersion) {17 SerenityRunner.projectVersion = projectVersion;18 }19 public static String getTestSource() {20 return testSource;21 }22 public static void setTestSource(String testSource) {23 SerenityRunner.testSource = testSource;24 }25 public static String getTestType() {26 return testType;27 }28 public static void setTestType(String testType) {29 SerenityRunner.testType = testType;30 }31 public static String getTestEnvironment() {32 return testEnvironment;33 }34 public static void setTestEnvironment(String testEnvironment) {35 SerenityRunner.testEnvironment = testEnvironment;36 }37 public static String getTestTags() {38 return testTags;39 }40 public static void setTestTags(String testTags) {41 SerenityRunner.testTags = testTags;42 }43 public static String getJenkinsUrl() {44 return jenkinsUrl;45 }46 public static void setJenkinsUrl(String jenkinsUrl) {47 SerenityRunner.jenkinsUrl = jenkinsUrl;48 }49 public static String getJenkinsBuildId() {50 return jenkinsBuildId;51 }52 public static void setJenkinsBuildId(String jenkinsBuildId) {53 SerenityRunner.jenkinsBuildId = jenkinsBuildId;54 }55 public static String getJenkinsBuildUrl() {56 return jenkinsBuildUrl;57 }58 public static void setJenkinsBuildUrl(String jenkinsBuildUrl) {59 SerenityRunner.jenkinsBuildUrl = jenkinsBuildUrl;60 }61 public static String getJenkinsBuildTag() {62 return jenkinsBuildTag;63 }64 public static void setJenkinsBuildTag(String jenkinsBuildTag) {65 SerenityRunner.jenkinsBuildTag = jenkinsBuildTag;66 }67}68public class SerenityRunner extends BlockJUnit4ClassRunner {

Full Screen

Full Screen

getOutputDirectory

Using AI Code Generation

copy

Full Screen

1import net.serenitybdd.junit.runners.SerenityRunner;2import org.junit.After;3import org.junit.Before;4import org.junit.runner.RunWith;5@RunWith(SerenityRunner.class)6public class GetOutputDirectoryMethod {7 private String outputDirectory;8 public void setOutputDirectory() {9 outputDirectory = getOutputDirectory();10 }11 public void printOutputDirectory() {12 System.out.println("The output directory is: " + outputDirectory);13 }14}

Full Screen

Full Screen

getOutputDirectory

Using AI Code Generation

copy

Full Screen

1File file = new File(this.getOutputDirectory() + "/file.txt");2file.createNewFile();3file = new File(this.getReportDirectory() + "/file.txt");4file.createNewFile();5file = new File(this.getOutputDirectory() + "/file.txt");6file.createNewFile();7file = new File(this.getReportDirectory() + "/file.txt");8file.createNewFile();9file = new File(this.getOutputDirectory() + "/file.txt");10file.createNewFile();11file = new File(this.getReportDirectory() + "/file.txt");12file.createNewFile();13file = new File(this.getOutputDirectory() + "/file.txt");

Full Screen

Full Screen

getOutputDirectory

Using AI Code Generation

copy

Full Screen

1public void takeScreenshot() {2 String screenshotName = "screenshot_" + UUID.randomUUID().toString();3 File screenshot = ((TakesScreenshot) getDriver()).getScreenshotAs(OutputType.FILE);4 try {5 FileUtils.copyFile(screenshot, new File(getOutputDirectory() + "/screenshots/" + screenshotName + ".png"));6 } catch (IOException e) {7 e.printStackTrace();8 }9}10public void takeScreenshot() {11 String screenshotName = "screenshot_" + UUID.randomUUID().toString();12 File screenshot = ((TakesScreenshot) getDriver()).getScreenshotAs(OutputType.FILE);13 try {14 FileUtils.copyFile(screenshot, new File(getOutputDirectory() + "/screenshots/" + screenshotName + ".png"));15 } catch (IOException e) {16 e.printStackTrace();17 }18}19public void takeScreenshot() {20 String screenshotName = "screenshot_" + UUID.randomUUID().toString();21 File screenshot = ((TakesScreenshot) getDriver()).getScreenshotAs(OutputType.FILE);22 try {23 FileUtils.copyFile(screenshot, new File(getOutputDirectory() + "/screenshots/" + screenshotName + ".png"));24 } catch (IOException e) {25 e.printStackTrace();26 }27}28public void takeScreenshot() {29 String screenshotName = "screenshot_" + UUID.randomUUID().toString();30 File screenshot = ((TakesScreenshot) getDriver()).getScreenshotAs(OutputType.FILE);31 try {32 FileUtils.copyFile(screenshot, new File(getOutputDirectory() + "/screenshots/" + screenshot

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful