PageRenderTime 52ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/docs/docs/assertion-libraries.md

https://github.com/FluentLenium/FluentLenium
Markdown | 129 lines | 103 code | 26 blank | 0 comment | 0 complexity | 92df16b83610e3532e41ba3264fbcd47 MD5 | raw file
  1. ---
  2. layout: page
  3. title: Assertions
  4. subtitle: FluentLenium
  5. sidebar:
  6. AssertJ: "#assertj"
  7. Junit: "#junit"
  8. Hamcrest: "#hamcrest"
  9. Kotest: "#kotest"
  10. ---
  11. ## Supported Assertions Libraries
  12. - [AssertJ (recommended)](#assertj)
  13. - [Junit](#junit)
  14. - [Hamcrest](#hamcrest)
  15. - [Kotest](#kotest)
  16. ## AssertJ
  17. We recommend to use AssertJ because we extend it with FluentWebElement and FluentList custom assertions.
  18. - Import this additional maven dependency.
  19. ```xml
  20. <dependency>
  21. <groupId>org.fluentlenium</groupId>
  22. <artifactId>fluentlenium-assertj</artifactId>
  23. <version>5.0.1</version>
  24. <scope>test</scope>
  25. </dependency>
  26. ```
  27. - Add those static imports.
  28. ```java
  29. import static org.assertj.core.api.Assertions.*;
  30. import static org.fluentlenium.assertj.FluentLeniumAssertions.*;
  31. ```
  32. ```java
  33. goTo("http://mywebpage/");
  34. $("#firstName").fill().with("toto");
  35. $("#create-button").click();
  36. assertThat(window().title()).isEqualTo("Hello toto");
  37. assertThat($(".fluent")).hasText("present text");
  38. assertThat($(".fluent")).hasNotText("not present text");
  39. assertThat($(".another")).hasSize(7);
  40. assertThat($(".another2")).hasSize().lessThan(5);
  41. assertThat($(".another2")).hasSize().lessThanOrEqualTo(5);
  42. assertThat($(".another3")).hasSize().greaterThan(2);
  43. assertThat($(".another3")).hasSize().greaterThanOrEqualTo(2);
  44. ```
  45. ## JUnit
  46. You can use FluentLenium using [JUnit](http://www.junit.org) assertions.
  47. We assume you would like to use Junit assertions together with Junit test runner so no additional imports is required.
  48. ```java
  49. goTo("http://mywebpage/");
  50. $("#firstName").fill().with("toto");
  51. $("#create-button").click();
  52. assertEqual("Hello toto", window().title());
  53. ```
  54. ## Hamcrest
  55. - Import this additional maven dependency.
  56. ```xml
  57. <dependency>
  58. <groupId>org.hamcrest</groupId>
  59. <artifactId>hamcrest-core</artifactId>
  60. <version>1.3</version>
  61. <scope>test</scope>
  62. </dependency>
  63. ```
  64. - Add those static imports.
  65. ```java
  66. import static org.hamcrest.Matchers.*;
  67. import static org.junit.Assert.assertThat;
  68. ```
  69. ```java
  70. goTo("http://mywebpage/");
  71. $("#firstName").fill().with("toto");
  72. $("#create-button").click();
  73. assertThat(window().title(), equalTo("Hello toto"));
  74. ```
  75. ## Kotest
  76. There is a set of custom Kotest Matchers available to make assertions on
  77. * Page
  78. * Alert
  79. * FluentWebElement
  80. * FluentList
  81. - Import this additional maven dependency.
  82. ```xml
  83. <dependency>
  84. <groupId>org.fluentlenium</groupId>
  85. <artifactId>fluentlenium-kotest-assertions</artifactId>
  86. <version>5.0.1</version>
  87. <scope>test</scope>
  88. </dependency>
  89. ```
  90. ```groovy
  91. testImplementation 'org.fluentlenium:fluentlenium-kotest-assertions:5.0.1'
  92. ```
  93. ```kotlin
  94. testImplementation("org.fluentlenium:fluentlenium-kotest-assertions:5.0.1")
  95. ```
  96. - Add those static imports.
  97. ```kotlin
  98. import org.fluentlenium.kotest.matchers.el.*
  99. import org.fluentlenium.kotest.matchers.jq.*
  100. import org.fluentlenium.kotest.matchers.alert.*
  101. import org.fluentlenium.kotest.matchers.page.*
  102. ```
  103. check the [example](https://github.com/FluentLenium/FluentLenium/blob/develop/examples/kotest/src/test/kotlin/org/fluentlenium/example/kotest/DuckDuckGoSpec.kt) and the [tests](../../fluentlenium-kotest-assertions) for usage examples.