LiveView Testing

I have a multipart form that is sending data with a file attached
<Field name="upload" class="mt-6" > <Label class="label">Upload File APK</Label> {{ live_file_input @uploads.file }} </Field>
but when I test it returns the following error ** (RuntimeError) no uploads allowed for file

but on update I have allowed for the file as shown below

`def update(%{book: book } = assigns, socket) do
changeset = Apks.change_book(book)
user = assigns.user

title =
  case assigns.action do
    :new -> "Add Book"
    :edit -> "Edit Book"

 |> assign(assigns)
 |> assign(:changeset, changeset)
 |>assign(:user, user)
 |> assign(:title, title)
 |> allow_upload(:file,
    accept: ~w(.txt),
    max_entries: 1,
    max_file_size: 5_000_000_000,
    auto_upload: true

This is my failing test
test “the Add book form is submitted successfully”, %{conn: conn, user: user} do
conn = Plug.Test.init_test_session(conn, %{current_user: user, user_uuid: user.uuid})
{:ok, view, html}= live(conn, “/admin/book/new”)
file =
|>file_input("#my_form_containing_book",:file, [%{

            name: "39e09448-305b-4d52-9a0f-a04f04c2602c.txt",
            type: "text/plain"

            |>form("#my_form_containing_book", post: %{"title"=> "test", "package_name"=> "test", "category_id" => "2"})
      assert render_upload(file, "39e09448-305b-4d52-9a0f-a04f04c2602c.txt") =~ "100%"


Not sure where the problem is?

In the future, please enclose your code with triple backticks before and after, for proper formatting.

I’m not sure exactly why your test isn’t working, but here’s an example of a similar test from one of my own projects:

{:ok, view, _html} = live(conn, "/forum?settings=1")
refute render(view) =~ "100%"

# Upload the file to the server
avatar = avatar_fixture(view)
assert render_upload(avatar, "elixir.png") =~ "100%"

# File is already uploaded, now just submit the form
view |> element("#change-user-avatar-form") |> render_submit
assert has_element?(view, "#avatar-updated-ok")

and the fixture:

def avatar_fixture(view) do
  file_input(view, "#change-user-avatar-form", :avatar, [
      last_modified: 1_594_171_879_000,
      name: "elixir.png",
      size: 2_118,
      type: "image/png"

Hope this can help.

@APB9785 thanks for the triple backticks hack. I still have not resolved the issue. The form submission works when you do a manual test. The problem is when running an automated test it still refuses to recognize that the : :file field exists at @uploads.file.