Skip to content

Commit dee1db5

Browse files
committed
Add git integrations page UI tests and set up env for running e2e tests from local env
1 parent cc65c3a commit dee1db5

File tree

12 files changed

+368
-51
lines changed

12 files changed

+368
-51
lines changed

e2e/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ e2e-*.tar
2424

2525
# Temporary files, for example, from tests.
2626
/tmp/
27-
/out/
27+
/out/
28+
.envrc

e2e/Dockerfile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
ARG ELIXIR_VERSION=1.14.3
2+
ARG OTP_VERSION=25.2.3
3+
ARG ALPINE_VERSION=3.18.0
4+
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-alpine-${ALPINE_VERSION}"
5+
6+
# Base stage with common dependencies
7+
FROM ${BUILDER_IMAGE} AS base
8+
9+
# Set Wallaby env var
10+
ENV START_WALLABY=true
11+
12+
# Install system dependencies including ChromeDriver
13+
RUN apk update && \
14+
apk add --no-cache \
15+
build-base \
16+
git \
17+
python3 \
18+
curl \
19+
openssh \
20+
chromium \
21+
chromium-chromedriver \
22+
xvfb \
23+
bash \
24+
# Add additional dependencies that may be required
25+
ttf-freefont \
26+
fontconfig \
27+
dbus \
28+
&& apk add --no-cache --upgrade busybox busybox-binsh ssl_client
29+
30+
# Set up Chrome for headless operation
31+
ENV CHROME_BIN=/usr/bin/chromium-browser
32+
ENV CHROME_PATH=/usr/lib/chromium/
33+
ENV CHROME_DRIVER_PATH=/usr/bin/chromedriver
34+
35+
# Set up Elixir environment
36+
WORKDIR /app
37+
38+
# Install hex and rebar
39+
RUN mix local.hex --force && \
40+
mix local.rebar --force
41+
42+
# Copy and compile dependencies
43+
COPY mix.exs mix.lock ./
44+
RUN mix deps.get && mix deps.compile
45+
46+
# Copy application code
47+
COPY . .
48+
49+
# Set Wallaby to use Chrome in headless mode
50+
ENV WALLABY_DRIVER=chrome
51+
ENV WALLABY_CHROME_HEADLESS=true
52+
53+
# Create directory for screenshots
54+
RUN mkdir -p /app/out/screenshots

e2e/Makefile

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: format test test.ui
1+
.PHONY: format test test.ui console.bash test.ui.docker
22

33
SHELL := /bin/bash
44
export MIX_ENV ?= test
@@ -17,12 +17,54 @@ ifeq (test.ui,$(MAKECMDGOALS))
1717
export START_WALLABY=true
1818
endif
1919

20+
ifeq (test.ui.docker,$(MAKECMDGOALS))
21+
export START_WALLABY=true
22+
endif
23+
24+
ifeq (console.bash,$(MAKECMDGOALS))
25+
export START_WALLABY=true
26+
endif
27+
2028
gcloud.auth:
2129
gcloud config set project $(GOOGLE_PROJECT_NAME) --quiet && gcloud auth login --cred-file=$(GOOGLE_APPLICATION_CREDENTIALS)
2230

2331
console.ex: env.assert mix.prepare
2432
iex -S mix
2533

34+
# Start a bash shell in the Docker container
35+
console.bash: env.assert
36+
docker compose run --rm \
37+
-e START_WALLABY=true \
38+
-e MIX_ENV=$(MIX_ENV) \
39+
-e BASE_DOMAIN=$(BASE_DOMAIN) \
40+
-e CLOUD_TEST_ENV_PREFIX=$(CLOUD_TEST_ENV_PREFIX) \
41+
-e GITHUB_ORGANIZATION=$(GITHUB_ORGANIZATION) \
42+
-e GITHUB_REPOSITORY=$(GITHUB_REPOSITORY) \
43+
-e GITHUB_BRANCH=$(GITHUB_BRANCH) \
44+
-e SEMAPHORE_ORGANIZATION=$(SEMAPHORE_ORGANIZATION) \
45+
-e SEMAPHORE_BASE_DOMAIN=$(SEMAPHORE_BASE_DOMAIN) \
46+
-e SEMAPHORE_USER_EMAIL=$(SEMAPHORE_USER_EMAIL) \
47+
-e SEMAPHORE_API_TOKEN=$(SEMAPHORE_API_TOKEN) \
48+
-e SEMAPHORE_USER_PASSWORD=$(SEMAPHORE_USER_PASSWORD) \
49+
e2e-tests sh
50+
51+
# Run UI tests in Docker
52+
test.ui.docker: env.assert
53+
docker compose run --rm \
54+
-e START_WALLABY=true \
55+
-e MIX_ENV=$(MIX_ENV) \
56+
-e BASE_DOMAIN=$(BASE_DOMAIN) \
57+
-e CLOUD_TEST_ENV_PREFIX=$(CLOUD_TEST_ENV_PREFIX) \
58+
-e GITHUB_ORGANIZATION=$(GITHUB_ORGANIZATION) \
59+
-e GITHUB_REPOSITORY=$(GITHUB_REPOSITORY) \
60+
-e GITHUB_BRANCH=$(GITHUB_BRANCH) \
61+
-e SEMAPHORE_ORGANIZATION=$(SEMAPHORE_ORGANIZATION) \
62+
-e SEMAPHORE_BASE_DOMAIN=$(SEMAPHORE_BASE_DOMAIN) \
63+
-e SEMAPHORE_USER_EMAIL=$(SEMAPHORE_USER_EMAIL) \
64+
-e SEMAPHORE_API_TOKEN=$(SEMAPHORE_API_TOKEN) \
65+
-e SEMAPHORE_USER_PASSWORD=$(SEMAPHORE_USER_PASSWORD) \
66+
e2e-tests sh -c "chromedriver --port=9515 --whitelisted-ips='' --url-base=/wd/hub & mix test $(if $(TEST_FILE),$(TEST_FILE),test/e2e/ui)"
67+
2668
format:
2769
SEMAPHORE_API_TOKEN="" \
2870
SEMAPHORE_USER_PASSWORD="" \

e2e/docker-compose.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
version: "3"
2+
3+
services:
4+
e2e-tests:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
platform: linux/arm64 # Use ARM64 platform for Apple Silicon Macs
9+
shm_size: 2gb # Increase shared memory for Chrome
10+
volumes:
11+
- .:/app
12+
- ./out/screenshots:/app/out/screenshots
13+
environment:
14+
- START_WALLABY
15+
- WALLABY_DRIVER=chrome
16+
- WALLABY_CHROME_HEADLESS=true
17+
- MIX_ENV
18+
# Chrome/Chromium configuration
19+
- CHROME_BIN=/usr/bin/chromium-browser
20+
- CHROME_PATH=/usr/lib/chromium/
21+
# Pass Semaphore environment variables from the host
22+
- SEMAPHORE_API_TOKEN
23+
- SEMAPHORE_USER_PASSWORD
24+
- SEMAPHORE_BASE_DOMAIN
25+
- SEMAPHORE_USER_EMAIL
26+
- SEMAPHORE_ORGANIZATION
27+
- CLOUD_TEST_ENV_PREFIX
28+
- BASE_DOMAIN
29+
- GITHUB_ORGANIZATION
30+
- GITHUB_REPOSITORY
31+
- GITHUB_BRANCH
32+
- GOOGLE_PROJECT_NAME
33+
- GOOGLE_APPLICATION_CREDENTIALS
34+
ports:
35+
- "9515:9515" # ChromeDriver port
36+
command: >
37+
sh -c "chromedriver --port=9515 --verbose --whitelisted-ips='' --url-base=/wd/hub & mix test --include browser"

e2e/lib/e2e/clients/common.ex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,18 @@ defmodule E2E.Clients.Common do
4545
url = api_url(endpoint)
4646
timeout = Application.get_env(:e2e, :http_timeout, 30_000)
4747

48-
case HTTPoison.get(url, headers, timeout: timeout, recv_timeout: timeout, follow_redirect: true) do
48+
case HTTPoison.get(url, headers,
49+
timeout: timeout,
50+
recv_timeout: timeout,
51+
follow_redirect: true
52+
) do
4953
{:ok, response} ->
5054
{:ok, response}
5155

5256
{:error, %HTTPoison.Error{reason: :timeout}} ->
5357
# Retry once on timeout
5458
Process.sleep(1000)
59+
5560
HTTPoison.get(url, headers, timeout: timeout, recv_timeout: timeout, follow_redirect: true)
5661

5762
error ->

e2e/lib/e2e/clients/job.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,4 @@ defmodule E2E.Clients.Job do
2323
{:error, reason}
2424
end
2525
end
26-
2726
end

e2e/test/e2e/api/secrets_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ defmodule E2E.API.SecretsTest do
3232
name = "test-project-#{:rand.uniform(1_000_000)}"
3333
repository_url = "[email protected]:#{organization}/#{repository}.git"
3434
{:ok, project} = Support.prepare_project(name, repository_url)
35-
35+
3636
on_exit(fn ->
3737
:ok = Project.delete(name)
3838
end)

e2e/test/e2e/api/task_test.exs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,32 @@ defmodule E2E.API.TaskTest do
1313
name = "test-project-#{:rand.uniform(1_000_000)}"
1414

1515
# Create project with a task
16-
task_definitions = [%{
17-
"name" => "test-task",
18-
"status" => "ACTIVE",
19-
"description" => "Test periodic task",
20-
"at" => "0 * * * *",
21-
"pipeline_file" => ".semaphore/semaphore.yml",
22-
"branch" => "main",
23-
"parameters" => []
24-
}]
16+
task_definitions = [
17+
%{
18+
"name" => "test-task",
19+
"status" => "ACTIVE",
20+
"description" => "Test periodic task",
21+
"at" => "0 * * * *",
22+
"pipeline_file" => ".semaphore/semaphore.yml",
23+
"branch" => "main",
24+
"parameters" => []
25+
}
26+
]
2527

2628
{:ok, created_project} = Support.prepare_project(name, repository_url, task_definitions)
29+
2730
on_exit(fn ->
2831
:ok = Project.delete(name)
2932
end)
3033

3134
task = created_project["spec"]["tasks"] |> hd
32-
{:ok,
33-
project_id: created_project["metadata"]["id"],
34-
task_id: task["id"]
35-
}
35+
{:ok, project_id: created_project["metadata"]["id"], task_id: task["id"]}
3636
end
3737

38-
test "run task with run_now and wait for completion", %{project_id: project_id, task_id: task_id} do
38+
test "run task with run_now and wait for completion", %{
39+
project_id: project_id,
40+
task_id: task_id
41+
} do
3942
# Trigger run_now
4043
{:ok, response} = E2E.Clients.Task.run_now(task_id)
4144

e2e/test/e2e/api/workflow_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ defmodule E2E.API.WorkflowTest do
5555
Enum.each(pipelines, fn pipeline ->
5656
if pipeline["result"] != "PASSED" do
5757
{:ok, job_ids} = Pipeline.failed_jobs_id(pipeline["ppl_id"])
58+
5859
Enum.each(job_ids, fn job_id ->
5960
{:ok, events} = Job.events(job_id)
6061
Enum.each(events, fn event -> IO.puts(inspect(event)) end)

e2e/test/e2e/ui/example_user_test.exs

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)