Skip to content

Commit

Permalink
Add more tests for @AjaxElement support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Toilal committed Apr 4, 2016
1 parent b6baef9 commit 366325c
Showing 1 changed file with 69 additions and 19 deletions.
@@ -1,19 +1,27 @@
package org.fluentlenium.integration; package org.fluentlenium.integration;


import org.fluentlenium.adapter.util.SharedDriver;
import org.fluentlenium.core.FluentPage; import org.fluentlenium.core.FluentPage;
import org.fluentlenium.core.annotation.AjaxElement; import org.fluentlenium.core.annotation.AjaxElement;
import org.fluentlenium.core.annotation.Page; import org.fluentlenium.core.annotation.Page;
import org.fluentlenium.core.domain.FluentWebElement; import org.fluentlenium.core.domain.FluentWebElement;
import org.fluentlenium.integration.localtest.LocalFluentCase; import org.fluentlenium.integration.localtest.LocalFluentCase;
import org.junit.Test; import org.junit.Test;
import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.TimeoutException;


import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;


public class PageWithAjaxElementTest extends LocalFluentCase { public class PageWithAjaxElementTest extends LocalFluentCase {
@Page @Page
JavascriptPage page; JavascriptPage page;


@Page
JavascriptPageSlow pageSlow;

@Page
JavascriptPageTooSlow pageTooSlow;

@Page @Page
JavascriptPageWithoutAjax pageWithoutAjax; JavascriptPageWithoutAjax pageWithoutAjax;


Expand All @@ -23,44 +31,86 @@ public void when_ajax_fields_are_considered_as_ajax_fields_then_wait_for_them()
assertThat(page.getText()).isEqualTo("new"); assertThat(page.getText()).isEqualTo("new");
} }


@Test
public void when_ajax_fields_are_faster_than_timeout_then_wait_for_them() {
pageSlow.go();
assertThat(pageSlow.getText()).isEqualTo("new");
}

@Test(expected = NoSuchElementException.class)
public void when_ajax_fields_are_slower_than_timeout_then_NoSuchElementException_is_thrown() {
pageTooSlow.go();
assertThat(pageTooSlow.getText()).isEqualTo("new");
}

@Test(expected = NoSuchElementException.class) @Test(expected = NoSuchElementException.class)
public void when_ajax_fields_are_considered_as_normal_fields_then_an_noSuchElementException_is_thrown() { public void when_ajax_fields_are_considered_as_normal_fields_then_NoSuchElementException_is_thrown() {
pageWithoutAjax.go(); pageWithoutAjax.go();
assertThat(pageWithoutAjax.getText()).isEqualTo("new"); assertThat(pageWithoutAjax.getText()).isEqualTo("new");
} }




} private static class JavascriptPage extends FluentPage {


class JavascriptPage extends FluentPage { @AjaxElement
FluentWebElement newField;


@AjaxElement @Override
FluentWebElement newField; public String getUrl() {
return LocalFluentCase.JAVASCRIPT_URL;
}


@Override public String getText() {
public String getUrl() { return newField.getText();
return LocalFluentCase.JAVASCRIPT_URL; }
} }


public String getText() { private static class JavascriptPageSlow extends FluentPage {
return newField.getText();
@AjaxElement(timeOutInSeconds = 3)
FluentWebElement newFieldSlow;

@Override
public String getUrl() {
return LocalFluentCase.JAVASCRIPT_URL;
}

public String getText() {
return newFieldSlow.getText();
}
} }
}


private static class JavascriptPageTooSlow extends FluentPage {


class JavascriptPageWithoutAjax extends FluentPage { @AjaxElement
FluentWebElement newFieldSlow;


FluentWebElement newField; @Override
public String getUrl() {
return LocalFluentCase.JAVASCRIPT_URL;
}


@Override public String getText() {
public String getUrl() { return newFieldSlow.getText();
return LocalFluentCase.JAVASCRIPT_URL; }
} }


public String getText() {


click(newField); private static class JavascriptPageWithoutAjax extends FluentPage {


return newField.getText(); FluentWebElement newField;

@Override
public String getUrl() {
return LocalFluentCase.JAVASCRIPT_URL;
}

public String getText() {

click(newField);

return newField.getText();
}
} }
} }

0 comments on commit 366325c

Please sign in to comment.