org.jboss.arquillian.test.spi.event.suite.Before Java Examples

The following examples show how to use org.jboss.arquillian.test.spi.event.suite.Before. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RequestContextLifecycle.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public void on(@Observes(precedence = DEFAULT_PRECEDENCE) Before event) throws Throwable {
    //we are outside the runtime class loader, so we don't have direct access to the container
    ClassLoader classLoader = appClassloader.get();
    if (classLoader != null) {
        Class<?> arcClz = classLoader.loadClass(Arc.class.getName());
        Object container = arcClz.getMethod("container").invoke(null);
        if (container != null) {
            boolean running = (boolean) container.getClass().getMethod("isRunning").invoke(container);
            if (running) {
                Object context = container.getClass().getMethod("requestContext").invoke(container);
                context.getClass().getMethod("activate").invoke(context);
                LOGGER.debug("RequestContextLifecycle activating CDI Request context.");
            }
        }
    }
}
 
Example #2
Source File: RecorderLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 6 votes vote down vote up
@Test
public void startBeforeSuiteTrueTest() throws Exception {

    Mockito.when(configuration.getStartBeforeSuite()).thenReturn(true);

    fire(new VideoExtensionConfigured());

    fire(new BeforeSuite());
    fire(new BeforeClass(DummyTestCase.class));
    fire(new Before(DummyTestCase.class, DummyTestCase.class.getMethod("test")));

    bind(TestScoped.class, TestResult.class, TestResult.passed());

    fire(new After(DummyTestCase.class, DummyTestCase.class.getMethod("test")));
    fire(new AfterClass(DummyTestCase.class));
    fire(new AfterSuite());

    assertEventFired(BeforeVideoStart.class, 1);
    assertEventFired(StartRecordSuiteVideo.class, 1);
    assertEventFired(AfterVideoStart.class, 1);

    assertEventFired(BeforeVideoStop.class, 1);
    assertEventFired(StopRecordSuiteVideo.class, 1);
    assertEventFired(AfterVideoStop.class, 1);
}
 
Example #3
Source File: RecorderLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 6 votes vote down vote up
@Test
public void startBeforeClassTrueTest() throws Exception {

    Mockito.when(configuration.getStartBeforeClass()).thenReturn(true);

    fire(new VideoExtensionConfigured());

    fire(new BeforeSuite());
    fire(new BeforeClass(DummyTestCase.class));
    fire(new Before(DummyTestCase.class, DummyTestCase.class.getMethod("test")));

    bind(TestScoped.class, TestResult.class, TestResult.passed());

    fire(new AfterRules(DummyTestCase.class, DummyTestCase.class.getMethod("test"), LifecycleMethodExecutor.NO_OP));
    fire(new AfterClass(DummyTestCase.class));
    fire(new AfterSuite());

    assertEventFired(BeforeVideoStart.class, 1);
    assertEventFired(StartRecordClassVideo.class, 1);
    assertEventFired(AfterVideoStart.class, 1);

    assertEventFired(BeforeVideoStop.class, 1);
    assertEventFired(StopRecordClassVideo.class, 1);
    assertEventFired(AfterVideoStop.class, 1);
}
 
Example #4
Source File: RecorderLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 6 votes vote down vote up
@Test
public void startBeforeTestTrueTest() throws Exception {

    Mockito.when(configuration.getStartBeforeTest()).thenReturn(true);

    fire(new VideoExtensionConfigured());

    fire(new BeforeSuite());
    fire(new BeforeClass(DummyTestCase.class));
    fire(new Before(DummyTestCase.class, DummyTestCase.class.getMethod("test")));

    bind(TestScoped.class, TestResult.class, TestResult.passed());

    fire(new AfterRules(DummyTestCase.class, DummyTestCase.class.getMethod("test"), LifecycleMethodExecutor.NO_OP));
    fire(new AfterClass(DummyTestCase.class));
    fire(new AfterSuite());

    assertEventFired(BeforeVideoStart.class, 1);
    assertEventFired(StartRecordVideo.class, 1);
    assertEventFired(AfterVideoStart.class, 1);

    assertEventFired(BeforeVideoStop.class, 1);
    assertEventFired(StopRecordVideo.class, 1);
    assertEventFired(AfterVideoStop.class, 1);
}
 
Example #5
Source File: ScreenshooterLifecycleObserver.java    From arquillian-recorder with Apache License 2.0 6 votes vote down vote up
public void beforeTest(@Observes(precedence = -50) Before event) {

        if (new TakingScreenshotDecider(recorderStrategyRegister.get()).decide(event, null)) {
            ScreenshotMetaData metaData = getMetaData(event);
            metaData.setResourceType(getScreenshotType());

            DefaultFileNameBuilder nameBuilder = new DefaultFileNameBuilder();
            String screenshotName = nameBuilder
                .withMetaData(metaData)
                .withStage(When.BEFORE)
                .build();

            beforeScreenshotTaken.fire(new BeforeScreenshotTaken(metaData));

            TakeScreenshot takeScreenshooter = new TakeScreenshot(screenshotName, metaData, When.BEFORE, event.getTestMethod().getAnnotation(Screenshot.class));
            takeScreenshot.fire(takeScreenshooter);

            metaData.setBlurLevel(resolveBlurLevel(event));
            org.arquillian.extension.recorder.screenshooter.Screenshot screenshot = takeScreenshooter.getScreenshot();
            if(screenshot != null) {
                metaData.setFilename(screenshot.getResource());
            }

            afterScreenshotTaken.fire(new AfterScreenshotTaken(metaData));
        }
    }
 
Example #6
Source File: ScreenshooterLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 5 votes vote down vote up
@org.junit.Before
public void setMocks() throws Exception {
    bind(ApplicationScoped.class, ServiceLoader.class, serviceLoader);
    bind(ApplicationScoped.class, ScreenshooterConfiguration.class, configuration);
    bind(ApplicationScoped.class, Screenshooter.class, screenshooter);
    bind(ApplicationScoped.class, RecorderStrategyRegister.class, recorderStrategyRegister);

    Mockito.when(screenshooter.getScreenshotType()).thenReturn(ScreenshotType.PNG);

    Mockito.doNothing().when(cleaner).clean(configuration);

    Mockito.when(serviceLoader.onlyOne(ScreenshooterEnvironmentCleaner.class, DefaultScreenshooterEnvironmentCleaner.class))
        .thenReturn(cleaner);
}
 
Example #7
Source File: RecorderLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 5 votes vote down vote up
@Test
public void defaultConfigurationTest() throws Exception {

    // by default, no videos are taken at all

    fire(new VideoExtensionConfigured());

    fire(new BeforeSuite());
    fire(new BeforeClass(DummyTestCase.class));
    fire(new Before(DummyTestCase.class, DummyTestCase.class.getMethod("test")));

    bind(TestScoped.class, TestResult.class, TestResult.passed());

    fire(new AfterRules(DummyTestCase.class, DummyTestCase.class.getMethod("test"), LifecycleMethodExecutor.NO_OP));
    fire(new AfterClass(DummyTestCase.class));
    fire(new AfterSuite());

    assertEventFired(BeforeVideoStart.class, 0);
    assertEventFired(StartRecordVideo.class, 0);
    assertEventFired(StartRecordSuiteVideo.class, 0);
    assertEventFired(AfterVideoStart.class, 0);

    assertEventFired(BeforeVideoStop.class, 0);
    assertEventFired(StopRecordVideo.class, 0);
    assertEventFired(StopRecordSuiteVideo.class, 0);
    assertEventFired(AfterVideoStop.class, 0);
}
 
Example #8
Source File: RecorderLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 5 votes vote down vote up
@org.junit.Before
    public void setup() throws Exception {
        bind(ApplicationScoped.class, ServiceLoader.class, serviceLoader);
        bind(ApplicationScoped.class, VideoConfiguration.class, configuration);
        bind(ApplicationScoped.class, Recorder.class, recorder);
        bind(ApplicationScoped.class, TakenResourceRegister.class, takenResourceRegister);

        strategy.setConfiguration(configuration);
        bind(ApplicationScoped.class, VideoStrategy.class, strategy);

        Mockito.when(recorder.getVideoType()).thenReturn(VideoType.MP4);

        Mockito.doNothing().when(cleaner).clean(configuration);

        Mockito.when(serviceLoader.onlyOne(VideoRecorderEnvironmentCleaner.class, DefaultVideoRecorderEnvironmentCleaner.class))
            .thenReturn(cleaner);

//        Mockito.when(serviceLoader.onlyOne(VideoStrategy.class, DefaultVideoStrategy.class))
//            .thenReturn(strategy);

        videoFile = File.createTempFile("fakeVideo", recorder.getVideoType().toString().toLowerCase());

        Mockito.when(configuration.getVideoName()).thenReturn("record");

        Mockito.when(video.getResource()).thenReturn(videoFile);
        Mockito.when(video.getResourceType()).thenReturn(VideoType.MP4);
        Mockito.when(video.getWidth()).thenReturn(100);
        Mockito.when(video.getHeight()).thenReturn(100);

        Mockito.when(recorder.stopRecording()).thenReturn(video);
    }
 
Example #9
Source File: DefaultVideoStrategy.java    From arquillian-recorder with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isTakingAction(Event event) {
    if (event instanceof BeforeSuite
            || event instanceof AfterSuite) {
        return configuration.getStartBeforeSuite();
    } else if (event instanceof BeforeClass
            || event instanceof AfterClass) {
        return configuration.getStartBeforeClass();
    } else if (event instanceof Before) {
        return configuration.getStartBeforeTest()
            || configuration.getTakeOnlyOnFail();
    }

    return false;
}
 
Example #10
Source File: VideoLifecycleObserver.java    From arquillian-recorder with Apache License 2.0 5 votes vote down vote up
public void beforeTest(@Observes Before event) {
    if (strategy.get().isTakingAction(event)) {
        VideoMetaData testMetaData = getMetaData(event);
        VideoType videoType = getVideoType();

        beforeVideoStart.fire(new BeforeVideoStart(videoType, testMetaData));

        startRecordVideo.fire(new StartRecordVideo(videoType, testMetaData));

        afterVideoStart.fire(new AfterVideoStart(videoType, testMetaData));
    }
}
 
Example #11
Source File: ScreenshooterLifecycleObserver.java    From arquillian-recorder with Apache License 2.0 5 votes vote down vote up
private boolean hasScreenshotAnnotation(org.jboss.arquillian.core.spi.event.Event event) {
    if (event instanceof Before) {
        return ScreenshotAnnotationScanner.getScreenshotAnnotation(((Before) event).getTestMethod()) != null;
    } else if (event instanceof AfterTestLifecycleEvent) {
        return ScreenshotAnnotationScanner
            .getScreenshotAnnotation(((AfterTestLifecycleEvent) event).getTestMethod()) != null;
    }
    return false;
}
 
Example #12
Source File: RecorderLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 5 votes vote down vote up
@Test
public void takeOnlyOnFailTestFailedTest() throws Exception {

    Mockito.when(configuration.getTakeOnlyOnFail()).thenReturn(true);

    fire(new VideoExtensionConfigured());

    fire(new BeforeSuite());
    fire(new BeforeClass(DummyTestCase.class));
    fire(new Before(DummyTestCase.class, DummyTestCase.class.getMethod("test")));

    bind(TestScoped.class, TestResult.class, TestResult.failed(new RuntimeException("some exception")));

    fire(new AfterRules(DummyTestCase.class, DummyTestCase.class.getMethod("test"), LifecycleMethodExecutor.NO_OP));
    fire(new AfterClass(DummyTestCase.class));
    fire(new AfterSuite());

    assertEventFired(BeforeVideoStart.class, 1);
    assertEventFired(StartRecordVideo.class, 1);
    assertEventFired(AfterVideoStart.class, 1);

    assertEventFired(PropertyReportEvent.class, 1);

    assertEventFired(BeforeVideoStop.class, 1);
    assertEventFired(StopRecordVideo.class, 1);
    assertEventFired(AfterVideoStop.class, 1);
}
 
Example #13
Source File: RecorderLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 5 votes vote down vote up
@Test
public void takeOnlyOnFailTestPassedTest() throws Exception {

    Mockito.when(configuration.getTakeOnlyOnFail()).thenReturn(true);

    fire(new VideoExtensionConfigured());

    fire(new BeforeSuite());
    fire(new BeforeClass(DummyTestCase.class));
    fire(new Before(DummyTestCase.class, DummyTestCase.class.getMethod("test")));

    bind(TestScoped.class, TestResult.class, TestResult.passed());

    fire(new AfterRules(DummyTestCase.class, DummyTestCase.class.getMethod("test"), LifecycleMethodExecutor.NO_OP));
    fire(new AfterClass(DummyTestCase.class));
    fire(new AfterSuite());

    assertEventFired(BeforeVideoStart.class, 1);
    assertEventFired(StartRecordVideo.class, 1);
    assertEventFired(AfterVideoStart.class, 1);

    assertEventFired(PropertyReportEvent.class, 0);

    assertEventFired(BeforeVideoStop.class, 1);
    assertEventFired(StopRecordVideo.class, 1);
    assertEventFired(AfterVideoStop.class, 1);
}
 
Example #14
Source File: AsciidoctorTestObserver.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
public void beforeTestCreateUnsharedAsciidoctorInstance(@Observes(precedence = 5) Before before) {

        if (isUnsharedInstanceRequired(before.getTestClass().getJavaClass(), AsciidoctorJRuby.class)
                || isUnsharedInstanceRequired(before.getTestMethod(), Asciidoctor.class)) {
            scopedAsciidoctor.get().setUnsharedAsciidoctor(
                    AsciidoctorJRuby.Factory.create());
        } else if (isUnsharedInstanceRequired(before.getTestClass().getJavaClass(), Asciidoctor.class)
                || isUnsharedInstanceRequired(before.getTestMethod(), Asciidoctor.class)) {
            scopedAsciidoctor.get().setUnsharedAsciidoctor(
                    Asciidoctor.Factory.create());
        }

    }
 
Example #15
Source File: AsciidoctorTestObserver.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
public void beforeTestCreateUnsharedTemporaryFolder(@Observes(precedence = 5) Before before) throws IOException {

        if (isUnsharedInstanceRequired(before.getTestClass().getJavaClass(), TemporaryFolder.class)
                || isUnsharedInstanceRequired(before.getTestMethod(), TemporaryFolder.class)) {
            TemporaryFolder temporaryFolder = new TemporaryFolder();
            temporaryFolder.create();
            scopedTemporaryFolder.get().setUnsharedTemporaryFolder(
                    temporaryFolder);
        }

    }
 
Example #16
Source File: DefaultAnnotationScreenshootingStrategy.java    From arquillian-recorder with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isTakingAction(Event event) {

    if (event instanceof Before) {
        Screenshot screenshotAnnotation = ScreenshotAnnotationScanner.getScreenshotAnnotation(((Before) event).getTestMethod());

        if (screenshotAnnotation != null) {
            return screenshotAnnotation.takeBeforeTest();
        }
    }

    return false;
}
 
Example #17
Source File: ArquillianSuiteExtension.java    From appengine-tck with Apache License 2.0 4 votes vote down vote up
public void resotreProtocolMetaData(@Observes EventContext<Before> eventContext) {
    testScopedProtocolMetaData.set(cachedProtocolMetaData);
    eventContext.proceed();
}
 
Example #18
Source File: UserLogin.java    From appengine-tck with Apache License 2.0 4 votes vote down vote up
public void login(@Observes EventContext<Before> event) throws Exception {
    Before before = event.getEvent();

    UserIsLoggedIn userIsLoggedIn = null;
    if (before.getTestMethod().isAnnotationPresent(UserIsLoggedIn.class)) {
        userIsLoggedIn = before.getTestMethod().getAnnotation(UserIsLoggedIn.class);
    } else if (before.getTestClass().isAnnotationPresent(UserIsLoggedIn.class)) {
        userIsLoggedIn = before.getTestClass().getAnnotation(UserIsLoggedIn.class);
    }

    if (userIsLoggedIn != null) {
        final LoginContext context = new UserLoginContext(userIsLoggedIn);

        log.info(String.format("Found @UserIsLoggedIn: %s [%s]", context.getEmail(), userIsLoggedIn.location()));

        final URI baseUri = getBaseURI(before.getTestMethod());
        final WebDriver driver = createWebDriver();
        try {
            driver.manage().deleteAllCookies();

            driver.navigate().to(baseUri + USER_LOGIN_SERVLET_PATH + "?location=" + URLEncoder.encode(userIsLoggedIn.location(), "UTF-8"));

            // did we navigate to this requested page, or did we get redirected/forwarded to login already
            List<WebElement> loginUrlElts = driver.findElements(By.id("login-url"));
            if (loginUrlElts.size() > 0) {
                String loginURL = loginUrlElts.get(0).getText();

                // check
                if (isInternalLink(loginURL)) {
                    loginURL = baseUri + loginURL;
                }

                // go-to login page
                driver.navigate().to(loginURL);
            }

            // find custom login handler, if exists
            LoginHandler loginHandler = TestBase.instance(getClass(), LoginHandler.class);
            if (loginHandler == null) {
                loginHandler = new DefaultLoginHandler();
            }
            loginHandler.login(driver, context);
            log.info("Logged-in: " + context.getEmail());
            // copy cookies
            Set<Cookie> cookies = driver.manage().getCookies();
            for (Cookie cookie : cookies) {
                ModulesApi.addCookie(cookie.getName(), cookie.getValue());
            }
        } finally {
            driver.close();
        }
    }

    event.proceed();
}
 
Example #19
Source File: AuthServerTestEnricher.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public void beforeTest(@Observes(precedence = 100) Before event) throws IOException {
    suiteContext.getServerLogChecker().updateLastCheckedPositionsOfAllFilesToEndOfFile();
}
 
Example #20
Source File: KeycloakContainerFeaturesController.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public void handleEnableFeaturesAnnotationBeforeTest(@Observes(precedence = 1) Before event) throws Exception {
    if (!shouldExecuteAsLast(event.getTestMethod())) {
        checkAnnotatedElementForFeatureAnnotations(event.getTestMethod(), State.BEFORE);
    }
}
 
Example #21
Source File: KeycloakContainerFeaturesController.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public void handleChangeStateFeaturePriorityBeforeTest(@Observes(precedence = -100) Before event) throws Exception {
    if (shouldExecuteAsLast(event.getTestMethod())) {
        checkAnnotatedElementForFeatureAnnotations(event.getTestMethod(), State.BEFORE);
    }
}
 
Example #22
Source File: ScreenshooterLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 4 votes vote down vote up
@Test
public void takeWhenTestFailedTrueScreenshotMethodTest() throws Exception {

    Mockito.when(configuration.getTakeWhenTestFailed()).thenReturn(false); // false in config

    fire(new ScreenshooterExtensionConfigured());

    initRecorderStrategyRegister();

    // true in annotation
    fire(new Before(FakeAnnotatedClass.class, FakeAnnotatedClass.class.getMethod("takeWhenTestFailedMethod")));

    bind(TestScoped.class, TestResult.class, TestResult.failed(new Throwable()));

    fire(new AfterRules(FakeAnnotatedClass.class, FakeAnnotatedClass.class.getMethod("takeWhenTestFailedMethod"),
        LifecycleMethodExecutor.NO_OP));

    // so we take it
    assertEventFired(BeforeScreenshotTaken.class, 1);
    assertEventFired(TakeScreenshot.class, 1);
    assertEventFired(AfterScreenshotTaken.class, 1);
}
 
Example #23
Source File: ScreenshooterLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 4 votes vote down vote up
@Test
public void takeAfterTestTrueScreenshotMethodTest() throws Exception {

    Mockito.when(configuration.getTakeAfterTest()).thenReturn(false); // false in config

    fire(new ScreenshooterExtensionConfigured());

    initRecorderStrategyRegister();

    // true in annotation
    fire(new Before(FakeAnnotatedClass.class, FakeAnnotatedClass.class.getMethod("takeAfterTestMethod")));

    bind(TestScoped.class, TestResult.class, TestResult.passed());

    fire(new AfterRules(FakeAnnotatedClass.class, FakeAnnotatedClass.class.getMethod("takeAfterTestMethod"),
        LifecycleMethodExecutor.NO_OP));

    // so we take it
    assertEventFired(BeforeScreenshotTaken.class, 1);
    assertEventFired(TakeScreenshot.class, 1);
    assertEventFired(AfterScreenshotTaken.class, 1);
}
 
Example #24
Source File: ScreenshooterLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 4 votes vote down vote up
@Test
public void takeBeforeTestFalseScreenshotMethodTest() throws Exception {

    Mockito.when(configuration.getTakeBeforeTest()).thenReturn(true); // true in config

    fire(new ScreenshooterExtensionConfigured());

    initRecorderStrategyRegister();

    // false in annotation
    fire(new Before(FakeAnnotatedClass.class, FakeAnnotatedClass.class.getMethod("takeBeforeTestFalseMethod")));

    bind(TestScoped.class, TestResult.class, TestResult.passed());

    fire(new AfterRules(FakeAnnotatedClass.class, FakeAnnotatedClass.class.getMethod("takeBeforeTestFalseMethod"),
        LifecycleMethodExecutor.NO_OP));

    // so we dont take it
    assertEventFired(BeforeScreenshotTaken.class, 0);
    assertEventFired(TakeScreenshot.class, 0);
    assertEventFired(AfterScreenshotTaken.class, 0);
}
 
Example #25
Source File: ScreenshooterLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 4 votes vote down vote up
@Test
public void takeBeforeTestTrueScreenshotMethodTest() throws Exception {

    Mockito.when(configuration.getTakeBeforeTest()).thenReturn(false); // false in config

    fire(new ScreenshooterExtensionConfigured());

    initRecorderStrategyRegister();

    // true in annotation
    fire(new Before(FakeAnnotatedClass.class, FakeAnnotatedClass.class.getMethod("takeBeforeTestTrueMethod")));

    bind(TestScoped.class, TestResult.class, TestResult.passed());

    fire(new AfterRules(FakeAnnotatedClass.class, FakeAnnotatedClass.class.getMethod("takeBeforeTestTrueMethod"),
        LifecycleMethodExecutor.NO_OP));

    // so we take it
    assertEventFired(BeforeScreenshotTaken.class, 1);
    assertEventFired(TakeScreenshot.class, 1);
    assertEventFired(AfterScreenshotTaken.class, 1);
}
 
Example #26
Source File: ScreenshooterLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 4 votes vote down vote up
@Test
public void afterTestEventTestStatusPassed() throws Exception {

    Mockito.when(configuration.getTakeAfterTest()).thenReturn(true);

    fire(new ScreenshooterExtensionConfigured());

    initRecorderStrategyRegister();

    fire(new Before(FakeTestClass.class, FakeTestClass.class.getMethod("fakeTest")));

    bind(TestScoped.class, TestResult.class, TestResult.passed());

    fire(new AfterRules(FakeTestClass.class, FakeTestClass.class.getMethod("fakeTest"),
        LifecycleMethodExecutor.NO_OP));

    assertEventFired(BeforeScreenshotTaken.class, 1);
    assertEventFired(TakeScreenshot.class, 1);
    assertEventFired(AfterScreenshotTaken.class, 1);
}
 
Example #27
Source File: ScreenshooterLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 4 votes vote down vote up
@Test
public void afterTestEventTestStatusFailedTakeAfterTestTrueTakeWhenFailedTrue() throws Exception {

    Mockito.when(configuration.getTakeAfterTest()).thenReturn(true);
    Mockito.when(configuration.getTakeWhenTestFailed()).thenReturn(true);

    fire(new ScreenshooterExtensionConfigured());

    initRecorderStrategyRegister();

    fire(new Before(FakeTestClass.class, FakeTestClass.class.getMethod("fakeTest")));

    bind(TestScoped.class, TestResult.class, TestResult.failed(new RuntimeException()));

    fire(new AfterRules(FakeTestClass.class, FakeTestClass.class.getMethod("fakeTest"),
        LifecycleMethodExecutor.NO_OP));

    assertEventFired(BeforeScreenshotTaken.class, 1);
    assertEventFired(TakeScreenshot.class, 1);
    assertEventFired(AfterScreenshotTaken.class, 1);
}
 
Example #28
Source File: ScreenshooterLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 4 votes vote down vote up
@Test
public void afterTestEventTestStatusFailedTakeAfterTestTrueTakeWhenFailedFalse() throws Exception {

    Mockito.when(configuration.getTakeAfterTest()).thenReturn(true);
    Mockito.when(configuration.getTakeWhenTestFailed()).thenReturn(false);

    fire(new ScreenshooterExtensionConfigured());

    initRecorderStrategyRegister();

    fire(new Before(FakeTestClass.class, FakeTestClass.class.getMethod("fakeTest")));

    bind(TestScoped.class, TestResult.class, TestResult.failed(new RuntimeException()));

    fire(new AfterRules(FakeTestClass.class, FakeTestClass.class.getMethod("fakeTest"),
        LifecycleMethodExecutor.NO_OP));

    assertEventFired(BeforeScreenshotTaken.class, 1);
    assertEventFired(TakeScreenshot.class, 1);
    assertEventFired(AfterScreenshotTaken.class, 1);
}
 
Example #29
Source File: ScreenshooterLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 4 votes vote down vote up
@Test
public void afterTestEventTakeAfterTestTrue() throws Exception {

    Mockito.when(configuration.getTakeAfterTest()).thenReturn(true);

    fire(new ScreenshooterExtensionConfigured());

    initRecorderStrategyRegister();

    fire(new Before(FakeTestClass.class, FakeTestClass.class.getMethod("fakeTest")));

    bind(TestScoped.class, TestResult.class, TestResult.passed());

    fire(new AfterRules(FakeTestClass.class, FakeTestClass.class.getMethod("fakeTest"),
        LifecycleMethodExecutor.NO_OP));

    assertEventFired(BeforeScreenshotTaken.class, 1);
    assertEventFired(TakeScreenshot.class, 1);
    assertEventFired(AfterScreenshotTaken.class, 1);
}
 
Example #30
Source File: DefaultScreenshootingStrategy.java    From arquillian-recorder with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isTakingAction(Event event) {
    return event instanceof Before && configuration.getTakeBeforeTest();
}