Wallaby

From Elixir Wiki
Jump to navigation Jump to search

Wallaby[edit]

File:Wallaby logo.png
Wallaby Logo

Wallaby is a powerful and feature-rich testing library for Elixir that focuses on providing developers with a seamless integration between Elixir and browser automation. With Wallaby, developers can easily write expressive tests that simulate user interactions with web applications.

Features[edit]

- Browser automation: Wallaby leverages various browser automation drivers, such as ChromeDriver, to interact with web browsers and perform actions like clicking buttons, filling forms, and navigating through web pages. - Interactive test sessions: With Wallaby, developers can run tests in an interactive mode, which allows them to see the browser window and visually inspect the behavior of their web application during test execution. - Concurrent test execution: Wallaby is designed to run tests concurrently, boosting test execution speed and efficiency. - Support for JavaScript testing: Wallaby provides seamless integration with JavaScript testing frameworks, such as Jasmine or Mocha, allowing developers to test both front-end and back-end components together. - Easy setup: Wallaby comes with a simple setup process, ensuring that developers can quickly get started with writing automated tests for their Elixir projects. - Extensive documentation: Wallaby provides comprehensive documentation, making it easy for developers to learn and utilize its powerful features.

Example[edit]

```elixir defmodule MyAppWeb.UserTest do

 use MyAppWeb.ConnCase
 use Wallaby.XUnit
 @endpoint Application.fetch_env!(:my_app, :endpoint)
 test "sign up and login", %{conn: conn} do
   # Start a browser session
   {:ok, session} = Wallaby.start_session(browser: :chrome)
   # Visit the sign-up page
   session |> visit(@endpoint <> "/signup")
   # Fill in the sign-up form
   session
   |> fill_in("user[email]", "[email protected]")
   |> fill_in("user[password]", "password")
   |> click_on("Sign up")
   # Ensure successful sign-up
   assert session |> has_content?("Welcome, [email protected]")
   # Visit the login page
   session |> visit(@endpoint <> "/login")
   # Fill in the login form
   session
   |> fill_in("user[email]", "[email protected]")
   |> fill_in("user[password]", "password")
   |> click_on("Log in")
   # Ensure successful login
   assert session |> has_content?("Logged in as [email protected]")
   # Close the browser session
   Wallaby.close_session(session)
 end

end ```

Resources[edit]

- Wallaby on GitHub - Wallaby documentation