Search in sources :

Example 1 with TestScope

use of org.jenkinsci.test.acceptance.guice.TestScope in project acceptance-test-harness by jenkinsci.

the class FallbackConfig method createController.

/**
 * Instantiates a controller through the "TYPE" attribute and {@link JenkinsControllerFactory}.
 */
@Provides
@TestScope
public JenkinsController createController(Injector injector, ExtensionList<JenkinsControllerFactory> factories) throws IOException {
    // this is lower case for backward compatibility
    String type = System.getenv("type");
    if (type == null)
        type = System.getenv("TYPE");
    if (type == null) {
        File socket = getSocket();
        if (socket.exists() && !JenkinsControllerPoolProcess.MAIN) {
            LOGGER.info("Found pooled jenkins controller listening on socket " + socket.getAbsolutePath());
            return new PooledJenkinsController(injector, socket);
        } else {
            LOGGER.warning("No pooled jenkins controller listening on socket " + socket.getAbsolutePath());
            type = "winstone";
        }
    }
    for (JenkinsControllerFactory f : factories) {
        if (f.getId().equalsIgnoreCase(type)) {
            final JenkinsController c = f.create();
            c.postConstruct(injector);
            return c;
        }
    }
    throw new AssertionError("Invalid controller type: " + type);
}
Also used : JenkinsController(org.jenkinsci.test.acceptance.controller.JenkinsController) PooledJenkinsController(org.jenkinsci.test.acceptance.server.PooledJenkinsController) JenkinsControllerFactory(org.jenkinsci.test.acceptance.controller.JenkinsControllerFactory) File(java.io.File) PooledJenkinsController(org.jenkinsci.test.acceptance.server.PooledJenkinsController) TestScope(org.jenkinsci.test.acceptance.guice.TestScope) Provides(com.google.inject.Provides)

Example 2 with TestScope

use of org.jenkinsci.test.acceptance.guice.TestScope in project acceptance-test-harness by jenkinsci.

the class FallbackConfig method createWebDriver.

/**
 * Creates a {@link WebDriver} for each test, then make sure to clean it up at the end.
 */
@Provides
@TestScope
public WebDriver createWebDriver(TestCleaner cleaner, TestName testName, ElasticTime time) throws IOException {
    WebDriver base = createWebDriver(cleaner, testName);
    // Make sure the window has minimal resolution set, even when out of the visible screen.
    // Note - not maximizing here any more because that doesn't do anything.
    Dimension oldSize = base.manage().window().getSize();
    if (oldSize.height < 1050 || oldSize.width < 1680) {
        base.manage().window().setSize(new Dimension(1680, 1050));
    }
    final EventFiringWebDriver d = new EventFiringWebDriver(base);
    d.register(new Scroller());
    try {
        d.manage().timeouts().pageLoadTimeout(time.seconds(PAGE_LOAD_TIMEOUT), TimeUnit.MILLISECONDS);
        d.manage().timeouts().implicitlyWait(time.seconds(IMPLICIT_WAIT_TIMEOUT), TimeUnit.MILLISECONDS);
    } catch (UnsupportedCommandException e) {
        // sauce labs RemoteWebDriver doesn't support this
        LOGGER.info(base + " doesn't support page load timeout");
    }
    cleaner.addTask(new Statement() {

        @Override
        public void evaluate() {
            switch(getBrowser()) {
                case "firefox":
                case "saucelabs-firefox":
                case "remote-webdriver-firefox":
                    // https://github.com/mozilla/geckodriver/issues/1151
                    // https://bugzilla.mozilla.org/show_bug.cgi?id=1264259
                    // https://bugzilla.mozilla.org/show_bug.cgi?id=1434872
                    d.navigate().to("about:mozilla");
                    Alert alert = ExpectedConditions.alertIsPresent().apply(d);
                    if (alert != null) {
                        alert.accept();
                        d.navigate().refresh();
                    }
            }
            d.quit();
        }

        @Override
        public String toString() {
            return "Close WebDriver after test";
        }
    });
    return d;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) EventFiringWebDriver(org.openqa.selenium.support.events.EventFiringWebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) UnsupportedCommandException(org.openqa.selenium.UnsupportedCommandException) Statement(org.junit.runners.model.Statement) EventFiringWebDriver(org.openqa.selenium.support.events.EventFiringWebDriver) Alert(org.openqa.selenium.Alert) Dimension(org.openqa.selenium.Dimension) Scroller(org.jenkinsci.test.acceptance.selenium.Scroller) TestScope(org.jenkinsci.test.acceptance.guice.TestScope) Provides(com.google.inject.Provides)

Aggregations

Provides (com.google.inject.Provides)2 TestScope (org.jenkinsci.test.acceptance.guice.TestScope)2 File (java.io.File)1 JenkinsController (org.jenkinsci.test.acceptance.controller.JenkinsController)1 JenkinsControllerFactory (org.jenkinsci.test.acceptance.controller.JenkinsControllerFactory)1 Scroller (org.jenkinsci.test.acceptance.selenium.Scroller)1 PooledJenkinsController (org.jenkinsci.test.acceptance.server.PooledJenkinsController)1 Statement (org.junit.runners.model.Statement)1 Alert (org.openqa.selenium.Alert)1 Dimension (org.openqa.selenium.Dimension)1 UnsupportedCommandException (org.openqa.selenium.UnsupportedCommandException)1 WebDriver (org.openqa.selenium.WebDriver)1 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)1 EventFiringWebDriver (org.openqa.selenium.support.events.EventFiringWebDriver)1