hin101

hin101

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.

Showing Posts 1 to 10

Exadra37

Exadra37

I don’t have any experience with Wallaby, chrome or selenium, but I have some with Docker.

Can you try:

 "http://hub:4444/wd/hub/",

So you are replacing localhost by the name of the service in docker compose, because that’s how containers communicate between them. Using localhost inside a container will reach the container internal network, not the your host network or the other container network.

hin101

hin101 OP

Nope didn’t work :frowning:

There has to be a way for it to work with containers but can’t figure it out.

michallepicki

michallepicki

Are you trying to use the Chromedriver Wallaby backend or the Selenium Wallaby backend? If you have both of the above lines in your config, you’ll end up using Selenium. I am not familiar with how the selenium/hub and selenium/node-chrome docker images work but it seems that they are exposing Selenium.

Looking at the Feature module documentation, won’t that result in the test trying to create two browser instances? I think the feature macro will call start_session for you already, but I may be wrong.

I think to set capabilities when using the feature macro, the @sessions module attribute should be used. But you should double check with the documentation.

Are you sure that Firefox is available to be started by your selenium hub? You can check that by navigating to http://localhost:4444/wd/hub/ in your browser, clicking Create Browser and selecting Firefox in the dropdown.

slouchpie

slouchpie

Hi there,

I have been setting up Wallaby in docker with my new Phoenix app and today I finished setting up. It works very well and I have no problems, but I am using the default Wallaby.Chrome driver.

Out of curiousity, I added this one line to my config/test.exs:

config :wallaby, driver: Wallaby.Selenium

and ran the tests again. I immediately got this error:

** (RuntimeError) Wallaby had an internal issue with HTTPoison:
     %HTTPoison.Error{id: nil, reason: :checkout_timeout}
     %HTTPoison.Error{id: nil, reason: :econnrefused}
     stacktrace:
       (wallaby 0.26.2) lib/wallaby/httpclient.ex:50: Wallaby.HTTPClient.make_request/5
       (wallaby 0.26.2) lib/wallaby/selenium.ex:92: Wallaby.Selenium.start_session/1

which seems to be the same problem as you.

Then I saw this:

https://github.com/elixir-wallaby/wallaby/issues/351

which describes the same problem over two years ago.

I strongly recommend not using Wallaby.Selenium and sticking with the default Wallaby.Chrome driver.

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:

slouchpie

slouchpie

Thanks for the clarification.

Can you advise please - is there any reason why Selenium driver might be preferred over Chrome driver?

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.

slouchpie

slouchpie

There is a crucial problem in this that you should change. The remote_url has to end in a trailing slash / or else it won’t work.

You can see this in webdriver_client.ex in the wallaby lib:

    request(:post, "#{base_url}session", params)

It just does bare string interpolation.

mhanberg

mhanberg

Expert LSP Core Team

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

slouchpie

slouchpie

While I have your attention, I am getting a problem while trying to use Selenium (default driver works fine for me). I am using

    {:ok, session} = Wallaby.start_session(metadata: metadata, capabilities: chrome_capabilities, remote_url: "http://selenium-hub:4444/wd/hub/")

and I get this error:

* (RuntimeError) Content-Type header does not indicate utf-8 encoded json: application/json
     stacktrace:
       (wallaby 0.26.2) lib/wallaby/httpclient.ex:136: Wallaby.HTTPClient.check_for_response_errors/1
       (wallaby 0.26.2) lib/wallaby/httpclient.ex:56: Wallaby.HTTPClient.make_request/5
       (wallaby 0.26.2) lib/wallaby/selenium.ex:92: Wallaby.Selenium.start_session/1
       (wallaby 0.26.2) lib/wallaby.ex:83: Wallaby.start_session/1

Any ideas? No need to spend much time on it, just if you have any “hunch” of what might be happening.

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
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
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews