官术网_书友最值得收藏!

Selenide

What we have seen about Selenium is very cool. It brings the opportunity to probe that our application is doing things well, but sometimes it is a bit tricky to configure and use. Selenide is a project based on Selenium that offers a good syntax for writing tests and makes them more readable. It hides the usage of WebDriver and configurations from you, while still maintaining a high-level of customization:

  1. Like all the other libraries we have used until now, the first step is to add the Gradle dependency:
dependencies { 
    testCompile 'com.codeborne:selenide:2.17' 
}
  1. Let's see how we can write the previous Selenium test using Selenide
    instead. The syntax might be familiar to for those who know JQuery (https://jquery.com/):
public class SelenideTest { 
  @Test 
  public void wikipediaSearchFeature() throws 
InterruptedException {
// Opening Wikipedia page open("http://en.wikipedia.org/wiki/Main_Page"); // Searching TDD $(By.name("search")).setValue("Test-driven development"); // Clicking search button $(By.name("go")).click(); // Checks assertThat(title(),
startsWith("Test-driven development")); } }

This was a more expressive way to write a test. On top of a more fluent syntax, there are some things that happen behind this code and would require additional lines of Selenium. For example, a click action will wait until an element in question is available, and will fail only if the predefined period of time has expired. Selenium, on the other hand, would fail immediately. In today's world, with many elements being loaded dynamically through JavaScript, we cannot expect everything to appear at once. Hence, this Selenide feature proves to be useful and saves us from using repetitive boilerplate code. There are many other benefits Selenide brings to the table. Due to the benefits that Selenide provides when compared with Selenium, it will be our framework of choice throughout this book. Furthermore, there is a whole chapter dedicated to web testing using this framework. Visit http://selenide.org/ for more information on ways to use web drivers in your tests.

No matter whether tests were written with one framework or another, the effect is the same. When tests are run, a Firefox browser window will emerge and execute all steps defined in the test sequentially. Unless a headless browser was chosen as your driver of choice, you will be able to see what is going on throughout the test. If something goes wrong, a failure trace is available. On top of that, we can take browser screenshots at any point. For example, it is a common practice to record the situation at the time of a failure.

The complete source code can be found in the SelenideTest class in the
https://bitbucket.org/vfarcic/tdd-java-ch02-example-web repository.

Armed with a basic knowledge of web-testing frameworks, it is time to take a short look at BDD.

主站蜘蛛池模板: 桐柏县| 枣庄市| 盖州市| 嵊泗县| 高青县| 共和县| 庄浪县| 湟中县| 阿克| 无棣县| 澎湖县| 禄劝| 延庆县| 韩城市| 孝昌县| 精河县| 扎赉特旗| 沙洋县| 南郑县| 元朗区| 措勤县| 韶关市| 日土县| 平塘县| 盘锦市| 黑水县| 文水县| 阜宁县| 南澳县| 炉霍县| 澳门| 抚州市| 铜山县| 京山县| 岐山县| 合阳县| 合山市| 嵩明县| 册亨县| 报价| 启东市|