Search in sources :

Example 1 with Wait

use of org.jenkinsci.test.acceptance.junit.Wait in project acceptance-test-harness by jenkinsci.

the class CapybaraPortingLayerImpl method runThenHandleAlert.

public void runThenHandleAlert(Runnable runnable, Consumer<Alert> action, int timeoutSeconds) {
    String oldWindow = driver.getWindowHandle();
    if (runnable != null) {
        runnable.run();
    }
    Wait<WebDriver> wait = new Wait<>(driver, time).pollingEvery(500, TimeUnit.MILLISECONDS).withTimeout(timeoutSeconds, TimeUnit.SECONDS);
    Alert alert = wait.until(ExpectedConditions.alertIsPresent());
    try {
        action.accept(alert);
    } finally {
        driver.switchTo().window(oldWindow);
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Alert(org.openqa.selenium.Alert) Wait(org.jenkinsci.test.acceptance.junit.Wait)

Example 2 with Wait

use of org.jenkinsci.test.acceptance.junit.Wait in project acceptance-test-harness by jenkinsci.

the class Scroller method scrollIntoView.

/**
 * The framework is expected to take care of the correct scrolling. When you are tempted to scroll from PageObjects
 * or tests, there is likely a framework problem to be fixed.
 */
public void scrollIntoView(WebElement e, WebDriver driver) {
    if (driver instanceof HtmlUnitDriver || (driver instanceof WrapsDriver && ((WrapsDriver) driver).getWrappedDriver() instanceof HtmlUnitDriver)) {
        return;
    }
    WebElement element = e;
    if (Objects.equals(element.getTagName(), "option")) {
        // scroll select into view not option
        element = e.findElement(By.xpath(".."));
    }
    final int eYCoord = element.getLocation().getY();
    final int eXCoord = element.getLocation().getX();
    final String id = element.getAttribute("id");
    final JavascriptExecutor executor = (JavascriptExecutor) driver;
    // Wait until web element is successfully scrolled.
    try {
        new Wait<>(Boolean.TRUE).withTimeout(5, // Wall-clock time
        TimeUnit.SECONDS).until(() -> (Boolean) executor.executeScript(scrollJs, eYCoord, eXCoord, id));
    } catch (TimeoutException ex) {
        // Scrolling failed, but sometimes the element to click is already visible, let the test continue and eventually fail later
        // This log message should be sufficient to diagnose the issue
        LOGGER.log(Level.WARNING, "Scrolling failed, letting the test to continue anyways, but \"Element is not clickable\" error will likely be thrown", ex);
    }
}
Also used : JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) WebElement(org.openqa.selenium.WebElement) Wait(org.jenkinsci.test.acceptance.junit.Wait) WrapsDriver(org.openqa.selenium.WrapsDriver) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) TimeoutException(org.openqa.selenium.TimeoutException)

Example 3 with Wait

use of org.jenkinsci.test.acceptance.junit.Wait in project acceptance-test-harness by jenkinsci.

the class FreestyleJobTest method buildPeriodically.

@Test
@Category(SmokeTest.class)
public void buildPeriodically() {
    FreeStyleJob j = jenkins.jobs.create(FreeStyleJob.class);
    j.configure();
    TimerTrigger trigger = j.addTrigger(TimerTrigger.class);
    trigger.spec.set("* * * * *");
    j.save();
    Build first = j.build(1);
    new Wait<>(first).withTimeout(70, // Wall-clock time
    TimeUnit.SECONDS).until(pageObjectExists());
    assertThat(first.getConsole(), containsString("Started by timer"));
    assertThat(j.build(3), pageObjectDoesNotExist());
}
Also used : Build(org.jenkinsci.test.acceptance.po.Build) FreeStyleJob(org.jenkinsci.test.acceptance.po.FreeStyleJob) Wait(org.jenkinsci.test.acceptance.junit.Wait) TimerTrigger(org.jenkinsci.test.acceptance.po.TimerTrigger) Category(org.junit.experimental.categories.Category) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) SmokeTest(org.jenkinsci.test.acceptance.junit.SmokeTest) Test(org.junit.Test)

Example 4 with Wait

use of org.jenkinsci.test.acceptance.junit.Wait in project acceptance-test-harness by jenkinsci.

the class WorkflowPluginTest method linearFlow.

@WithPlugins({ "workflow-job", "workflow-cps@2.10", "workflow-basic-steps@2.1", "workflow-durable-task-step", "pipeline-input-step", "junit@1.18", "git@2.3" })
@Test
public void linearFlow() throws Exception {
    assumeTrue("This test requires a restartable Jenkins", jenkins.canRestart());
    MavenInstallation.installMaven(jenkins, "M3", "3.5.0");
    final DumbSlave slave = (DumbSlave) slaveController.install(jenkins).get();
    slave.configure(() -> slave.labels.set("remote"));
    WorkflowJob job = jenkins.jobs.create(WorkflowJob.class);
    job.script.set("node('remote') {\n" + "  git 'https://github.com/jglick/simple-maven-project-with-tests.git'\n" + "  def v = version()\n" + "  if (v) {\n" + "    echo(/Building version $v/)\n" + "  }\n" + "  def mvnHome = tool 'M3'\n" + "  withEnv([\"PATH+MAVEN=$mvnHome/bin\", \"M2_HOME=$mvnHome\"]) {\n" + "    sh 'mvn -B -Dmaven.test.failure.ignore verify'\n" + "  }\n" + "  input 'Ready to go?'\n" + "  archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true\n" + "  junit '**/target/surefire-reports/TEST-*.xml'\n" + "}\n" + "def version() {\n" + "  def matcher = readFile('pom.xml') =~ '<version>(.+)</version>'\n" + "  matcher ? matcher[0][1] : null\n" + "}");
    job.sandbox.check();
    job.save();
    final Build build = job.startBuild();
    waitFor().until(new Wait.Predicate<Boolean>() {

        @Override
        public Boolean apply() throws Exception {
            return build.getConsole().contains("Ready to go?");
        }

        @Override
        public String diagnose(Throwable lastException, String message) {
            return "Console output:\n" + build.getConsole() + "\n";
        }
    });
    assertThat(build.getConsole(), containsString("Building version 1.0-SNAPSHOT"));
    jenkins.restart();
    // Default 120s timeout of Build.waitUntilFinished sometimes expires waiting for RetentionStrategy.Always to tick (after initial failure of CommandLauncher.launch: EOFException: unexpected stream termination):
    // TODO rather wait for build output: "Ready to run"
    slave.waitUntilOnline();
    visit(build.getConsoleUrl());
    clickLink("Proceed");
    try {
        build.shouldSucceed();
    } catch (AssertionError x) {
        // Tests in this project are currently designed to fail at random, so either status is OK.
        // TODO if resultIs were public and there were a disjunction combinator for Matcher we could use it here.
        build.shouldBeUnstable();
    }
    new Artifact(build, "target/simple-maven-project-with-tests-1.0-SNAPSHOT.jar").assertThatExists(true);
    build.open();
    clickLink("Test Result");
    assertThat(driver, hasContent("All Tests"));
}
Also used : Build(org.jenkinsci.test.acceptance.po.Build) Matchers.containsString(org.hamcrest.Matchers.containsString) DumbSlave(org.jenkinsci.test.acceptance.po.DumbSlave) WorkflowJob(org.jenkinsci.test.acceptance.po.WorkflowJob) Wait(org.jenkinsci.test.acceptance.junit.Wait) IOException(java.io.IOException) Artifact(org.jenkinsci.test.acceptance.po.Artifact) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) DockerTest(org.jenkinsci.test.acceptance.junit.DockerTest) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Aggregations

Wait (org.jenkinsci.test.acceptance.junit.Wait)4 AbstractJUnitTest (org.jenkinsci.test.acceptance.junit.AbstractJUnitTest)2 Build (org.jenkinsci.test.acceptance.po.Build)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 DockerTest (org.jenkinsci.test.acceptance.junit.DockerTest)1 SmokeTest (org.jenkinsci.test.acceptance.junit.SmokeTest)1 WithPlugins (org.jenkinsci.test.acceptance.junit.WithPlugins)1 Artifact (org.jenkinsci.test.acceptance.po.Artifact)1 DumbSlave (org.jenkinsci.test.acceptance.po.DumbSlave)1 FreeStyleJob (org.jenkinsci.test.acceptance.po.FreeStyleJob)1 TimerTrigger (org.jenkinsci.test.acceptance.po.TimerTrigger)1 WorkflowJob (org.jenkinsci.test.acceptance.po.WorkflowJob)1 Category (org.junit.experimental.categories.Category)1 Alert (org.openqa.selenium.Alert)1 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)1 TimeoutException (org.openqa.selenium.TimeoutException)1 WebDriver (org.openqa.selenium.WebDriver)1 WebElement (org.openqa.selenium.WebElement)1