coen.bakker

coen.bakker

TLDR: I have a page that is partly rendered on the server and partly on the client. I am looking for a good way to test this page. Can I somehow end-to-end test the page, while using test environment-only data fixtures?


Playwright is a framework for testing web applications end-to-end. There is a part of one of my live views that I cannot test with LiveView’s built-in tests only. At least, that’s my suspicion.

Here’s a dumbed down version of the behaviour that I am testing.

A live view renders a large text as pages on the client. The client renders one page at a time. Scrolling is not possible, because the rendered page adjusts to the dimensions of the containing html element.

Currently, I have a fully functional live view. But… I took the “build first, test later” approach. There is one part of the live view that I want to test from “end to end”. That’s the following part of the implementation:

A live view sends a text to the client. This text might overflow it’s containing div. The client adjusts the text to render the UI properly and sends back a short report to the live view. The live view needs this report to handle a certain client event.

I am looking for a good way to test this behaviour/implementation. Testing with Playwright across many real browsers works well. But how can I use a fixed test environment-only dataset to use alongside the Playwright framework?

As the title of my post suggests, I have considered that maybe I can use LiveView’s DataCase somehow? I am, however, not sure how. And whether that is a good way to approach the problem.

The implementation of the desired behaviour might seem a bit odd, considering alternatives (in case you can tell from the little information in this post). I case you are interested, I am indeed looking for better implementations. Currently, I am not using LiveView’s streams. However, that might very well be a better way forward.

Showing Posts 1 to 6

coen.bakker

coen.bakker OP

Btw, Playwright test code looks like:

import { test, expect } from '@playwright/test'

test.describe("something", () => {
  test("A", async ({ page }) => {
    // some browser behaviour
    // refute or assert something
  })
})

Testing localhost:xxxx and https:// are both possible.

LostKobrakai

LostKobrakai

You can use Phoenix.Ecto.SQL.Sandbox — Phoenix/Ecto v4.4.2 to integrate the ecto sandbox with any e2e test tooling, but you’ll need to setup any data you need for the test run through the UI.

If you also want to be being able to setup the db state directly something like wallaby (maybe with a playwright driver as an alternative to chromium/selenium) seems like the better option.

coen.bakker

coen.bakker OP

Oh I see. So, for example, a user is registered through the UI using an end-to-end framework, and that user is inserted into the sandbox, rather than to the actual database?

Do you have any tips or resources at hand for how I can best start figuring out how to set this up? I am new to simultaneous production, testing and deployment, so still getting familiar with how to handle test, development and production environments alongside each other.

I’ll start with the documentation.

coen.bakker

coen.bakker OP

I initially thought you were referring to WallabyJS. But following the link you sent me I see you were referring to the Wallaby hex package.

I’m not tied to Playwright so I’m def checking this out in detail. Thanks.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

The sandbox is the actual database. Ecto creates a “sandbox” within postgres by starting a transaction, routing all reads / writes for that test case into that transaction, and then ROLLBACKing that transaction at the end.

coen.bakker

coen.bakker OP

Oh, yes. That’s right.

Also, I just wanted to mention that I have Wallaby up and running now, and it really is exciting how well it integrates with my prior “mix test”-tests. And from a first glance the options and syntax seem great.

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews