Search in sources :

Example 1 with JenkinsWrapper

use of com.sonar.it.jenkins.orchestrator.container.JenkinsWrapper in project sonar-scanner-jenkins by SonarSource.

the class JenkinsOrchestrator method start.

public void start() {
    if (started.getAndSet(true)) {
        throw new IllegalStateException("Jenkins is already started");
    }
    int port = config.getInt("jenkins.container.port", 0);
    if (port <= 0) {
        port = NetworkUtils.getNextAvailablePort(NetworkUtils.getLocalhost());
    }
    distribution.setPort(port);
    FileSystem fileSystem = config.fileSystem();
    ServerInstaller serverInstaller = new ServerInstaller(fileSystem);
    server = serverInstaller.install(distribution);
    server.setUrl(String.format("http://localhost:%d", port));
    jenkinsWrapper = new JenkinsWrapper(server, config, fileSystem.javaHome(), port);
    jenkinsWrapper.start();
    FirefoxProfile profile = new FirefoxProfile();
    // force language to be English
    profile.setPreference("intl.accept_languages", "en");
    FirefoxOptions options = new FirefoxOptions().setProfile(profile);
    driver = new FirefoxDriver(options);
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    driver.get(server.getUrl());
    // Fix window size for having reproducible test behavior
    driver.manage().window().setPosition(new Point(20, 20));
    driver.manage().window().setSize(new Dimension(1024, 768));
    try {
        cli = new CLI(new URL(server.getUrl()));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    // Force updatecenter initialization
    driver.get(server.getUrl() + "/pluginManager");
    findElement(By.linkText("Advanced")).click();
    findElement(buttonByText("Check now")).click();
}
Also used : CLI(hudson.cli.CLI) JenkinsWrapper(com.sonar.it.jenkins.orchestrator.container.JenkinsWrapper) Point(org.openqa.selenium.Point) Dimension(org.openqa.selenium.Dimension) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) Point(org.openqa.selenium.Point) URL(java.net.URL) IOException(java.io.IOException) NoSuchElementException(org.openqa.selenium.NoSuchElementException) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FileSystem(com.sonar.orchestrator.config.FileSystem) ServerInstaller(com.sonar.it.jenkins.orchestrator.container.ServerInstaller)

Aggregations

JenkinsWrapper (com.sonar.it.jenkins.orchestrator.container.JenkinsWrapper)1 ServerInstaller (com.sonar.it.jenkins.orchestrator.container.ServerInstaller)1 FileSystem (com.sonar.orchestrator.config.FileSystem)1 CLI (hudson.cli.CLI)1 IOException (java.io.IOException)1 URL (java.net.URL)1 Dimension (org.openqa.selenium.Dimension)1 NoSuchElementException (org.openqa.selenium.NoSuchElementException)1 Point (org.openqa.selenium.Point)1 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)1 FirefoxOptions (org.openqa.selenium.firefox.FirefoxOptions)1 FirefoxProfile (org.openqa.selenium.firefox.FirefoxProfile)1