Current section
Files
Jump to
Current section
Files
lib/test/chromium_test.ex
defmodule ChromiumTest do
@moduledoc false
def test_url do
{:ok, %{body: body}} =
GotenbergElixir.Chromium.url_into_pdf("https://google.com",
landscape: true,
cookies: [
%{name: "test_cookie", value: "test_value", domain: "google.com"},
%{
name: "test_cookie_2",
value: "test_value_2",
domain: "google.com",
http_only: true
}
],
extra_http_headers: %{"X-Test-Header" => "test-value"},
fail_on_http_status_codes: [299, 399, 499, 200],
fail_on_http_resource_status_codes: [299, 399, 499, 200]
)
File.write!("lib/test/results/test.pdf", body)
end
def test_url_screenshot do
{:ok, %{body: body}} =
GotenbergElixir.Chromium.url_into_screenshot("https://google.com",
width: 1200,
height: 1400,
clip: true,
format: "jpeg"
)
File.write!("lib/test/results/test.jpeg", body)
end
def test_html do
index = File.read!("lib/test/data/index.html")
header = File.read!("lib/test/data/header.html")
footer = File.read!("lib/test/data/footer.html")
css_file = File.read!("lib/test/data/index.css")
img = File.read!("lib/test/data/gotenberg.png")
{:ok, %{body: body}} =
GotenbergElixir.Chromium.html_file_into_pdf(
index,
[
{"index.css", css_file},
{"gotenberg.png", img},
{"footer.html", footer},
{"header.html", header}
],
wait_for_expression: "window.globalVar == 'ready'"
)
File.write!("lib/test/results/test.pdf", body)
end
def test_html_screenshot do
index = File.read!("lib/test/data/index.html")
header = File.read!("lib/test/data/header.html")
footer = File.read!("lib/test/data/footer.html")
css_file = File.read!("lib/test/data/index.css")
img = File.read!("lib/test/data/gotenberg.png")
{:ok, %{body: body}} =
GotenbergElixir.Chromium.html_file_into_screenshot(
index,
[
{"index.css", css_file},
{"gotenberg.png", img},
{"footer.html", footer},
{"header.html", header}
],
wait_for_expression: "window.globalVar == 'ready'",
width: 1200,
height: 1400,
clip: true,
format: "jpeg"
)
File.write!("lib/test/results/test.jpeg", body)
end
def test_markdown do
index = File.read!("lib/test/data/index_md.html")
file_1 = File.read!("lib/test/data/file_1.md")
file_2 = File.read!("lib/test/data/file_2.md")
{:ok, %{body: body}} =
GotenbergElixir.Chromium.markdown_files_into_pdf(
index,
[
{"file_1.md", file_1},
{"file_2.md", file_2}
],
landscape: true
)
File.write!("lib/test/results/test.pdf", body)
end
def test_markdown_screenshot do
index = File.read!("lib/test/data/index_md.html")
file_1 = File.read!("lib/test/data/file_1.md")
file_2 = File.read!("lib/test/data/file_2.md")
{:ok, %{body: body}} =
GotenbergElixir.Chromium.markdown_files_into_screenshot(
index,
[
{"file_1.md", file_1},
{"file_2.md", file_2}
],
width: 1200,
height: 1400,
clip: true,
format: "jpeg"
)
File.write!("lib/test/results/test.jpeg", body)
end
end