Best Serenity JUnit code snippet using net.serenitybdd.junit.runners.SerenityRunner.getPages
Source:SerenityRunner.java  
...77    private DriverConfiguration configuration;78    private TagScanner tagScanner;79    private BatchManager batchManager;80    private final Logger logger = LoggerFactory.getLogger(SerenityRunner.class);81    public Pages getPages() {82        return pages;83    }84    /**85     * Creates a new test runner for WebDriver web tests.86     *87     * @param klass the class under test88     * @throws InitializationError if some JUnit-related initialization problem occurred89     */90    public SerenityRunner(final Class<?> klass) throws InitializationError {91        this(klass, Injectors.getInjector(new WebDriverModule()));92    }93    /**94     * Creates a new test runner for WebDriver web tests.95     *96     * @param klass the class under test97     * @param module used to inject a custom Guice module98     * @throws InitializationError if some JUnit-related initialization problem occurred99     */100    public SerenityRunner(Class<?> klass, Module module) throws InitializationError {101        this(klass, Injectors.getInjector(module));102    }103    public SerenityRunner(final Class<?> klass,104                          final Injector injector) throws InitializationError {105        this(klass,106                ThucydidesWebDriverSupport.getWebdriverManager(),107                injector.getInstance(DriverConfiguration.class),108                injector.getInstance(BatchManager.class)109        );110    }111    public SerenityRunner(final Class<?> klass,112                          final WebDriverFactory webDriverFactory) throws InitializationError {113        this(klass, webDriverFactory, WebDriverConfiguredEnvironment.getDriverConfiguration());114    }115    public SerenityRunner(final Class<?> klass,116                          final WebDriverFactory webDriverFactory,117                          final DriverConfiguration configuration) throws InitializationError {118        this(klass,119                webDriverFactory,120                configuration,121                new BatchManagerProvider(configuration).get()122        );123    }124    public SerenityRunner(final Class<?> klass,125                          final WebDriverFactory webDriverFactory,126                          final DriverConfiguration configuration,127                          final BatchManager batchManager) throws InitializationError {128        this(klass,129                ThucydidesWebDriverSupport.getWebdriverManager(webDriverFactory, configuration),130                configuration,131                batchManager132        );133    }134    public SerenityRunner(final Class<?> klass, final BatchManager batchManager) throws InitializationError {135        this(klass,136                ThucydidesWebDriverSupport.getWebdriverManager(),137                WebDriverConfiguredEnvironment.getDriverConfiguration(),138                batchManager);139    }140    public SerenityRunner(final Class<?> klass,141                          final WebdriverManager webDriverManager,142                          final DriverConfiguration configuration,143                          final BatchManager batchManager) throws InitializationError {144        super(klass);145        this.theTest = TestConfiguration.forClass(klass).withSystemConfiguration(configuration);146        this.webdriverManager = webDriverManager;147        this.configuration = configuration;148        this.requestedDriver = getSpecifiedDriver(klass);149        this.tagScanner = new TagScanner(configuration.getEnvironmentVariables());150        this.failureDetectingStepListener = new FailureDetectingStepListener();151        this.failureRerunner = new FailureRerunnerXml(configuration);152        if (TestCaseAnnotations.supportsWebTests(klass)) {153            checkRequestedDriverType();154        }155        this.batchManager = batchManager;156        batchManager.registerTestCase(klass);157    }158    private String getSpecifiedDriver(Class<?> klass) {159        if (ManagedWebDriverAnnotatedField.hasManagedWebdriverField(klass)) {160            return ManagedWebDriverAnnotatedField.findFirstAnnotatedField(klass).getDriver();161        } else {162            return null;163        }164    }165    /**166     * The Configuration class manages output directories and driver types.167     * They can be defined as system values, or have sensible defaults.168     * @return the current configuration169     */170    protected DriverConfiguration getConfiguration() {171        return configuration;172    }173    /**174     * Batch Manager used for running tests in parallel batches175     * @return the current batch manager object176     */177    protected BatchManager getBatchManager() {178        return batchManager;179    }180    /**181     * Ensure that the requested driver type is valid before we start the tests.182     * Otherwise, throw an InitializationError.183     */184    private void checkRequestedDriverType() {185        if (requestedDriverSpecified()) {186            SupportedWebDriver.getDriverTypeFor(requestedDriver);187        } else {188            getConfiguration().getDriverType();189        }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);351        getReportService().generateConfigurationsReport();352    }353    @Override354    protected void runChild(FrameworkMethod method, RunNotifier notifier) {355        TestMethodConfiguration theMethod = TestMethodConfiguration.forMethod(method);356        clearMetadataIfRequired();357        resetStepLibrariesIfRequired();358        if(!failureRerunner.hasToRunTest(method.getDeclaringClass().getCanonicalName(),method.getMethod().getName()))359        {360            return;361        }362        if (shouldSkipTest(method)) {363            return;364        }365        if (theMethod.isManual()) {366            markAsManual(method).accept(notifier);367            return;368        } else if (theMethod.isPending()) {369            markAsPending(method);370            notifier.fireTestIgnored(describeChild(method));371            return;372        } else {373            processTestMethodAnnotationsFor(method);374        }375        initializeTestSession();376        prepareBrowserForTest();377        additionalBrowserCleanup();378        performRunChild(method, notifier);379        if (failureDetectingStepListener.lastTestFailed() && maxRetries() > 0) {380            retryAtMost(maxRetries(), new RerunSerenityTest(method, notifier));381        }382    }383    private void retryAtMost(int remainingTries,384                             RerunTest rerunTest) {385        if (remainingTries <= 0) { return; }386        logger.info(rerunTest.toString() + ": attempt " + (maxRetries() - remainingTries));387        StepEventBus.getEventBus().cancelPreviousTest();388        rerunTest.perform();389        if (failureDetectingStepListener.lastTestFailed()) {390            retryAtMost(remainingTries - 1, rerunTest);391        } else {392            StepEventBus.getEventBus().lastTestPassedAfterRetries(remainingTries,393                                                                  failureDetectingStepListener.getFailureMessages(),failureDetectingStepListener.getTestFailureCause());394        }395    }396    private void performRunChild(FrameworkMethod method, RunNotifier notifier) {397        super.runChild(method, notifier);398    }399    interface RerunTest {400        void perform();401    }402    class RerunSerenityTest implements RerunTest {403        private final FrameworkMethod method;404        private final RunNotifier notifier;405        RerunSerenityTest(FrameworkMethod method, RunNotifier notifier) {406            this.method = method;407            this.notifier = notifier;408        }409        @Override410        public void perform() {411            performRunChild(method, notifier);412        }413        @Override414        public String toString() {415            return "Retrying " + method.getDeclaringClass() + " " + method.getMethod().getName();416        }417    }418    private void clearMetadataIfRequired() {419        if (theTest.shouldClearMetadata()) {420            Serenity.getCurrentSession().clearMetaData();421        }422    }423    private void resetStepLibrariesIfRequired() {424        if (theTest.shouldResetStepLibraries()) {425            stepFactory.reset();426        }427    }428    protected void additionalBrowserCleanup() {429        // Template method. Override this to do additional cleanup e.g. killing IE processes.430    }431    private boolean shouldSkipTest(FrameworkMethod method) {432        return !tagScanner.shouldRunMethod(getTestClass().getJavaClass(), method.getName());433    }434    private void markAsPending(FrameworkMethod method) {435        testStarted(method);436        StepEventBus.getEventBus().testPending();437        StepEventBus.getEventBus().testFinished();438    }439    private Consumer<RunNotifier> markAsManual(FrameworkMethod method) {440        TestMethodConfiguration theMethod = TestMethodConfiguration.forMethod(method);441        testStarted(method);442        StepEventBus.getEventBus().testIsManual();443        StepEventBus.getEventBus().getBaseStepListener().latestTestOutcome().ifPresent(444                outcome -> outcome.setResult(theMethod.getManualResult())445        );446        switch(theMethod.getManualResult()) {447            case SUCCESS:448                StepEventBus.getEventBus().testFinished();449                return (notifier -> notifier.fireTestFinished(Description.EMPTY));450            case FAILURE:451                Throwable failure = new ManualTestMarkedAsFailure(theMethod.getManualResultReason());452                StepEventBus.getEventBus().testFailed(failure);453                return (notifier -> notifier.fireTestFailure(454                        new Failure(Description.createTestDescription(method.getDeclaringClass(), method.getName()),failure)));455            case ERROR:456            case COMPROMISED:457            case UNSUCCESSFUL:458                Throwable error = new ManualTestMarkedAsError(theMethod.getManualResultReason());459                StepEventBus.getEventBus().testFailed(error);460                return (notifier -> notifier.fireTestFailure(461                        new Failure(Description.createTestDescription(method.getDeclaringClass(), method.getName()),error)));462            case IGNORED:463                StepEventBus.getEventBus().testIgnored();464                return (notifier -> notifier.fireTestIgnored(Description.createTestDescription(method.getDeclaringClass(), method.getName())));465            case SKIPPED:466                StepEventBus.getEventBus().testSkipped();467                return (notifier -> notifier.fireTestIgnored(Description.createTestDescription(method.getDeclaringClass(), method.getName())));468            default:469                StepEventBus.getEventBus().testPending();470                return (notifier -> notifier.fireTestIgnored(Description.createTestDescription(method.getDeclaringClass(), method.getName())));471        }472    }473    private void testStarted(FrameworkMethod method) {474        getStepListener().testStarted(Description.createTestDescription(method.getMethod().getDeclaringClass(), testName(method)));475    }476    /**477     * Process any Serenity annotations in the test class.478     * Ignored tests will just be skipped by JUnit - we need to ensure479     * that they are included in the Serenity reports480     * If a test method is pending, all the steps should be skipped.481     */482    private void processTestMethodAnnotationsFor(FrameworkMethod method) {483        if (isIgnored(method)) {484            testStarted(method);485            StepEventBus.getEventBus().testIgnored();486            StepEventBus.getEventBus().testFinished();487        }488    }489    protected void prepareBrowserForTest() {490        if (theTest.shouldClearTheBrowserSession()) {491            WebdriverProxyFactory.clearBrowserSession(getDriver());492        }493    }494    /**495     * Running a unit test, which represents a test scenario.496     */497    @Override498    protected Statement methodInvoker(final FrameworkMethod method, final Object test) {499        if (webtestsAreSupported()) {500            injectDriverInto(test);501            initPagesObjectUsing(driverFor(method));502            injectAnnotatedPagesObjectInto(test);503            initStepFactoryUsing(getPages());504        }505        injectScenarioStepsInto(test);506        injectEnvironmentVariablesInto(test);507        useStepFactoryForDataDrivenSteps();508        Statement baseStatement = super.methodInvoker(method, test);509        return new SerenityStatement(baseStatement, stepListener.getBaseStepListener());510    }511    private void useStepFactoryForDataDrivenSteps() {512        StepData.setDefaultStepFactory(stepFactory);513    }514    /**515     * Instantiate the @Managed-annotated WebDriver instance with current WebDriver.516     * @param testCase A Serenity-annotated test class517     */...Source:SerenityPageExtension.java  
...17import java.util.function.Consumer;18import static java.util.Optional.empty;19import static java.util.Optional.of;20import static java.util.Optional.ofNullable;21import static net.thucydides.core.webdriver.ThucydidesWebDriverSupport.getPages;22import static net.thucydides.core.webdriver.ThucydidesWebDriverSupport.initializeFieldsIn;23/**24 * Extension for webtest support in Serenity.25 *26 * Must be used before {{@link SerenityStepExtension}} as step injection/instantiation requires the correct {{@link Pages} to be set}.27 *28 * Note that in contrast to JUnit4 {{@link SerenityExtension}} always creates the29 * {@link net.thucydides.core.steps.BaseStepListener} without pages in order30 * to decouple the general setup from the setup for page support. The later is the task of this extension.31 */32public class SerenityPageExtension implements BeforeEachCallback {33    // Junit4: net.serenitybdd.junit.runners.SerenityRunner.buildAndConfigureListeners via net.serenitybdd.junit.runners.SerenityRunner.run34    // Junit4: net.thucydides.core.steps.BaseStepListener.BaseStepListener(java.io.File, net.thucydides.core.pages.Page35    @Override36    public void beforeEach(final ExtensionContext extensionContext) throws Exception {37        final TestConfiguration testConfiguration = TestConfiguration.forClass(extensionContext.getRequiredTestClass()).withSystemConfiguration(WebDriverConfiguredEnvironment.getDriverConfiguration());38        if (testConfiguration.isAWebTest()) {39            applyTestClassOrTestMethodSpecificWebDriverConfiguration(extensionContext);40            initializeFieldsIn(extensionContext.getRequiredTestInstance());41            injectPageObjectIntoTest(extensionContext.getRequiredTestInstance());42            prepareBrowserForTest(extensionContext);43        }44    }45    private void applyTestClassOrTestMethodSpecificWebDriverConfiguration(final ExtensionContext extensionContext) {46        ThucydidesWebDriverSupport.clearDefaultDriver();47        final Optional<ExplicitWebDriverConfiguration> explicitWebDriverConfiguration = explicitWebDriverConfiguration(extensionContext);48        explicitWebDriverConfiguration.ifPresent(it -> {49            final String value = it.getTestSpecificDriver();50            final Consumer<String> consumer = ThucydidesWebDriverSupport::useDefaultDriver;51            notEmpty(value).ifPresent(consumer);52            notEmpty(it.getDriverOptions()).ifPresent(ThucydidesWebDriverSupport::useDriverOptions);53            workaroundForOtherwiseIgnoredWebDriverOptions();54        });55    }56    private Optional<String> notEmpty(final String value) {57        return ofNullable(value).filter(StringUtils::isNotEmpty);58    }59    /**60     * ThucydidesWebDriverSupport#getDriver creates the web driver used for the page factory (Pages). For the creation of the61     * the web driver options are only considered if a driver name is set. On the other hand TestCaseAnnotations#injectDrivers62     * which injects the driver into @Managed web driver fields of the test class, considers the options the @Managed annotation.63     * So if e.g. @Managed(options = "testOption") is used the web driver injected into the field has the defined options. But64     * the web driver injected into pages and steps does not have this option set. This is also the case in Junit4. Probably this65     * is a corner case that is usually not applied in real life. #66     *67     * options:68     * a) keep it as it is (consistent with Junit4)69     * b) change ThucydidesWebDriverSupport#getDriver to consider options also when no driver is set70     * c) consider this unintended usage  => e.g. fail with an exception71     *72     * This method is basically a workaround for b until the serenity-core implementation is adjusted.73     */74    private void workaroundForOtherwiseIgnoredWebDriverOptions() {75        if (!ThucydidesWebDriverSupport.getDefaultDriverType().isPresent() && ThucydidesWebDriverSupport.getDefaultDriverOptions().isPresent()) {76            ThucydidesWebDriverSupport.useDefaultDriver(WebDriverConfiguredEnvironment.getDriverConfiguration().getDriverType().name()); // analog to net.thucydides.core.annotations.TestCaseAnnotations.configuredDriverType77        }78    }79    private Optional<ExplicitWebDriverConfiguration> explicitWebDriverConfiguration(final ExtensionContext extensionContext) {80        final Method testMethod = extensionContext.getRequiredTestMethod();81        final Class<?> requiredTestClass = extensionContext.getRequiredTestClass();82        if (hasExplicitWebDriverConfigurationOnTestMethod(testMethod)) {83            final String testSpecificDriver = TestMethodAnnotations.forTest(testMethod).specifiedDriver();84            final String driverOptions = TestMethodAnnotations.forTest(testMethod).driverOptions();85            return explicitWebDriverConfiguration(testSpecificDriver, driverOptions);86        } else if (hasExplicitWebDriverConfigurationOnTestClass(requiredTestClass)) {87            // CAUTION: unstable behaviour in case of multiple @Managed fields88            // findFirstAnnotatedField seems to be misleading. It finds "a" annotated field, because the ordering is not defined.89            // If there are multiple @Managed fields it is not clear which one should be used to define the default web driver used for the Steps.90            // So either A) this is an invalid use case that should be detected and rejected with an exception OR B) the default that would be used otherwise should be used91            // If net.thucydides.core.annotations.PatchedManagedWebDriverAnnotatedField.findAnnotatedFields would be public this case could at least be detected.92            // Note that even this block would be removed net.thucydides.core.annotations.TestCaseAnnotations#injectDrivers would still set a default but without explicitly93            // updating the PageFactory (which will happen as a side-effect to ThucydidesWebDriverSupport#getDriver calls.94            final ManagedWebDriverAnnotatedField firstAnnotatedField = ManagedWebDriverAnnotatedField.findFirstAnnotatedField(requiredTestClass);95            return explicitWebDriverConfiguration(firstAnnotatedField.getDriver(), firstAnnotatedField.getOptions());96        }97        return empty();98    }99    private void prepareBrowserForTest(final ExtensionContext extensionContext) {100        PatchedManagedWebDriverAnnotatedField.findAnnotatedFields(extensionContext.getRequiredTestClass()).stream()101                .filter(it -> ClearCookiesPolicy.BeforeEachTest.equals(it.getClearCookiesPolicy()))102                .map(it -> it.getValue(extensionContext.getRequiredTestInstance()))103                .forEach(WebdriverProxyFactory::clearBrowserSession);104        /* JUNIT4 analog impl:105        private void prepareBrowserForTest(TestConfiguration theTest) {106            if (theTest.shouldClearTheBrowserSession()) {107                // CAUTION: unstable behaviour in case of multiple @Managed fields108                // What is the expected behaviour in case of multiple @Managed fields? The current implementation picks an arbitrary @Managed field to decide109                // if a web driver instance should be cleared. It seems iterating over all @Manager fields and for those configured to clear the session, do so.110                // If net.thucydides.core.annotations.PatchedManagedWebDriverAnnotatedField.findAnnotatedFields would be public one could iterate easily111                // over the fields.112                WebdriverProxyFactory.clearBrowserSession(ThucydidesWebDriverSupport.getWebdriverManager().getCurrentDriver());113            }114        }115         */116    }117    @NotNull118    private Optional<ExplicitWebDriverConfiguration> explicitWebDriverConfiguration(final String testSpecificDriver, final String driverOptions) {119        return of(new ExplicitWebDriverConfiguration(testSpecificDriver, driverOptions));120    }121    private boolean hasExplicitWebDriverConfigurationOnTestClass(final Class<?> requiredTestClass) {122        return ManagedWebDriverAnnotatedField.hasManagedWebdriverField(requiredTestClass);123    }124    private boolean hasExplicitWebDriverConfigurationOnTestMethod(final Method testMethod) {125        return TestMethodAnnotations.forTest(testMethod).isDriverSpecified();126    }127    private void injectPageObjectIntoTest(final Object testClass) {128        new PageObjectDependencyInjector(getPages()).injectDependenciesInto(testClass);129    }130    public static class ExplicitWebDriverConfiguration {131        private final String testSpecificDriver;132        private final String driverOptions;133        public ExplicitWebDriverConfiguration(final String testSpecificDriver, final String driverOptions) {134            this.testSpecificDriver = testSpecificDriver;135            this.driverOptions = driverOptions;136        }137        public String getTestSpecificDriver() {138            return testSpecificDriver;139        }140        public String getDriverOptions() {141            return driverOptions;142        }...getPages
Using AI Code Generation
1@RunWith(SerenityRunner.class)2public class TestClass {3    @Managed(driver = "chrome")4    WebDriver driver;5    TestSteps testSteps;6    public void test() {7        testSteps.openMainPage();8        testSteps.checkPageTitle();9    }10}11public class TestSteps {12    private final static String MAIN_PAGE_TITLE = "Main page title";13    MainPage mainPage;14    public void openMainPage() {15        mainPage.open();16    }17    public void checkPageTitle() {18        mainPage.checkPageTitle(MAIN_PAGE_TITLE);19    }20}21public class MainPage extends PageObject {22    private final static String MAIN_PAGE_TITLE = "Main page title";23    public void checkPageTitle(String expectedTitle) {24        assertThat(getTitle(), is(expectedTitle));25    }26}getPages
Using AI Code Generation
1@net.thucydides.core.annotations.Step("Get all the pages of the current test")2public java.util.List<net.thucydides.core.pages.Pages> getPages() {3    return this.pages;4}5@net.thucydides.core.annotations.Step("Get all the pages of the current test")6public java.util.List<net.thucydides.core.pages.Pages> getPages() {7    return this.pages;8}9@net.thucydides.core.annotations.Step("Get all the pages of the current test")10public java.util.List<net.thucydides.core.pages.Pages> getPages() {11    return this.pages;12}13@net.thucydides.core.annotations.Step("Get all the pages of the current test")14public java.util.List<net.thucydides.core.pages.Pages> getPages() {15    return this.pages;16}17@net.thucydides.core.annotations.Step("Get all the pages of the current test")18public java.util.List<net.thucydides.core.pages.Pages> getPages() {19    return this.pages;20}21@net.thucydides.core.annotations.Step("Get all the pages of the current test")22public java.util.List<net.thucydides.core.pages.Pages> getPages() {23    return this.pages;24}25@net.thucydides.core.annotations.Step("Get all the pages of the current test")26public java.util.List<net.thucydides.core.pages.Pages> getPages() {getPages
Using AI Code Generation
1package com.serenitybdd;2import net.thucydides.core.annotations.Managed;3import net.thucydides.core.pages.Pages;4import net.thucydides.core.pages.PageObject;5import org.junit.Before;6import org.junit.Test;7import org.junit.runner.RunWith;8import org.openqa.selenium.WebDriver;9import net.serenitybdd.junit.runners.SerenityRunner;10@RunWith(SerenityRunner.class)11public class SerenityRunnerTest {12    WebDriver driver;13    public void setUp() {14        driver.manage().window().maximize();15    }16    public void test() {17        Pages pages = new Pages(driver);18        for (PageObject page : pages.getPages()) {19            System.out.println("Page: " + page);20        }21    }22}getPages
Using AI Code Generation
1@RunWith(SerenityRunner.class)2public class SerenityRunnerTest {3    public void test() {4        SerenityRunner runner = new SerenityRunner(SerenityRunnerTest.class);5        List<Class> pages = runner.getPages();6        for (Class page : pages) {7            System.out.println("Page title: " + page.getSimpleName());8        }9    }10}getPages
Using AI Code Generation
1public class PageTest extends SerenityRunner {    2    private SampleSteps sampleSteps;3    public void testPage() {4        sampleSteps.step1();5        sampleSteps.step2();6        sampleSteps.step3();7        sampleSteps.step4();8        sampleSteps.step5();9        sampleSteps.step6();10        sampleSteps.step7();11        sampleSteps.step8();12        sampleSteps.step9();13        sampleSteps.step10();14        sampleSteps.step11();15        sampleSteps.step12();16        sampleSteps.step13();17        sampleSteps.step14();18        sampleSteps.step15();19        sampleSteps.step16();20        sampleSteps.step17();21        sampleSteps.step18();22        sampleSteps.step19();23        sampleSteps.step20();24        sampleSteps.step21();25        sampleSteps.step22();26        sampleSteps.step23();27        sampleSteps.step24();28        sampleSteps.step25();29        sampleSteps.step26();30        sampleSteps.step27();31        sampleSteps.step28();32        sampleSteps.step29();33        sampleSteps.step30();34        sampleSteps.step31();35        sampleSteps.step32();36        sampleSteps.step33();37        sampleSteps.step34();38        sampleSteps.step35();39        sampleSteps.step36();40        sampleSteps.step37();41        sampleSteps.step38();42        sampleSteps.step39();43        sampleSteps.step40();44        sampleSteps.step41();45        sampleSteps.step42();46        sampleSteps.step43();47        sampleSteps.step44();48        sampleSteps.step45();49        sampleSteps.step46();50        sampleSteps.step47();51        sampleSteps.step48();52        sampleSteps.step49();53        sampleSteps.step50();54        sampleSteps.step51();55        sampleSteps.step52();56        sampleSteps.step53();57        sampleSteps.step54();58        sampleSteps.step55();59        sampleSteps.step56();60        sampleSteps.step57();61        sampleSteps.step58();62        sampleSteps.step59();63        sampleSteps.step60();64        sampleSteps.step61();65        sampleSteps.step62();66        sampleSteps.step63();67        sampleSteps.step64();68        sampleSteps.step65();69        sampleSteps.step66();70        sampleSteps.step67();71        sampleSteps.step68();72        sampleSteps.step69();73        sampleSteps.step70();74        sampleSteps.step71();75        sampleSteps.step72();76        sampleSteps.step73();77        sampleSteps.step74();getPages
Using AI Code Generation
1import net.serenitybdd.junit.runners.SerenityRunner2import net.thucydides.core.pages.PageObject3import net.thucydides.core.pages.Pages4import net.thucydides.core.webdriver.WebDriverFacade5import org.junit.Test6import org.junit.runner.RunWith7import org.openqa.selenium.WebDriver8@RunWith(SerenityRunner.class)9class TestPageObject {10    void test(){11        WebDriver driver = new WebDriverFacade()12        PageObject pageObject = new PageObject(driver, pages)13        List<PageObject> pageObjects = pageObject.getPages()14        pageObjects.each{15            println it.getPage()16        }17    }18}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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
