hin101

hin101

Setting up Wallaby with Docker Compose, Chrome and Selenium

I am trying to get Wallaby setup with Chrome and Selenium (these are hosted as docker compose), here is my docker compose file:

...
  chrome:
    image: selenium/node-chrome:3.14.0-gallium
    volumes:
      - /dev/shm:/dev/shm
    depends_on:
      - hub
    environment:
      HUB_HOST: hub

  hub:
    image: selenium/hub:3.14.0-gallium
    ports:
      - "4444:4444"

When I run the tests I get the following error:

** (RuntimeError) Wallaby had an internal issue with HTTPoison:
     %HTTPoison.Error{id: nil, reason: :econnrefused}
     stacktrace:
       (wallaby 0.25.0) lib/wallaby/httpclient.ex:50: Wallaby.HTTPClient.make_request/5
       (wallaby 0.25.0) lib/wallaby/selenium.ex:92: Wallaby.Selenium.start_session/1
       (wallaby 0.25.0) lib/wallaby.ex:90: Wallaby.start_session/1
       (wallaby 0.25.0) lib/wallaby/feature.ex:70: Wallaby.Feature.start_session/2
       (elixir 1.10.3) lib/enum.ex:1400: anonymous fn/3 in Enum.map/2
       (elixir 1.10.3) lib/enum.ex:2116: Enum.map/2
       test/hinesh_blogs_web/feature/admin_test.exs:3: HineshBlogsWeb.AdminTest.__ex_unit_setup_0/1
       test/hinesh_blogs_web/feature/admin_test.exs:1: HineshBlogsWeb.AdminTest.__ex_unit__/2

Here is my config/test.exs:

# Chrome
config :wallaby, driver: Wallaby.Chrome

# Selenium
config :wallaby, driver: Wallaby.Selenium

config :wallaby,
  hackney_options: [timeout: 5_000]

And here is the sample test I am trying to run:

defmodule HineshBlogsWeb.AdminTest do
  use ExUnit.Case, async: true
  use Wallaby.Feature

  setup do
    Wallaby.start_session(
      remote_url: "http://localhost:4444/wd/hub/",
      capabilities: %{browserName: "firefox"}
    )
  end

  feature "user can login", %{session: session} do
    session
    |> visit("/admin/login")
    |> assert(false)
  end
end

I am banging my head against the wall trying to solve this, any help would be appreciated.

Most Liked

mhanberg

mhanberg

Expert LSP Core Team

The Wallaby.Chrome driver will start chromedriver for you, whereas the Wallaby.Selenium driver does not start the selenium server automatically. I believe you are getting that error because you have not started the selenium server.

This issue you linked is regarding the old phantom js driver, so I don’t think it is relevant.

For the top-level post, to get selenium to run using chrome and Wallaby.Feature, you can set the default capabilities in your application config to use chrome

config :wallaby,
  driver: Wallaby.Selenium,
  selenium: [
    capabilities: %{
      javascriptEnabled: true,
      browserName: "chrome",
      "chromeOptions": %{
         args: [
           "--no-sandbox",
           "window-size=1280,800",
           "--disable-gpu",
           "--headless",
           "--fullscreen",
           "--user-agent=Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"
        ]
      }
    }
  ]

If you are running selenium and your tests using docker-compose, you need to make sure to set the remote_url to the appropriate value, using the docker-compose created network http://hub:4444/wd/hub/. This currently isn’t supported by app config, so if using with the Wallaby.Feature module, you’ll need to pass it in as an option to start_session.

defmodule MyAppWeb.AFeatureTest do
  use ExUnit.Case
  use Wallaby.Feature
  
  @sessions [[remote_url: "http://hub:4444/wd/hub"]]
  feature "my test", %{session: session} do
    # ...
  end
end

Or, you can write your own ExUnit.CaseTemplate to start this in a setup, while using import Wallaby.Feature instead of use Wallaby.Feature. You can find an example of this at the bottom of this page: Wallaby.Feature — wallaby v0.31.0.

I apologize for just seeing this, but I recently set an alert on the wallaby tag. I should be notified of any further questions :grinning_face_with_smiling_eyes:

mhanberg

mhanberg

Expert LSP Core Team

You would want to use the selenium driver in order to test with Firefox, edge, or safari. Or if you’re using a hosted selenium service.

mhanberg

mhanberg

Expert LSP Core Team

Good point to mention. That should be fixed. Thanks!

Last Post!

slouchpie

slouchpie

That’s great news! Are you using Chrome or Selenium? Do you have any tests that do more than 10 interactions and do you notice them randomly failing with “invalid session id”?

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 130286 1222
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement