-
Notifications
You must be signed in to change notification settings - Fork 145
Set screenshot dir #197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Set screenshot dir #197
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,73 @@ defmodule ScreenshotTest do | |
|
||
hound_session() | ||
|
||
test "should take a screenshot" do | ||
setup do | ||
navigate_to("http://localhost:9090/page1.html") | ||
path = take_screenshot("screenshot-test.png") | ||
:ok | ||
end | ||
|
||
test "should take a screenshot with a generated file name" do | ||
default_path = File.cwd!() | ||
|
||
path = take_screenshot() | ||
|
||
assert File.exists?(path) | ||
assert path =~ default_path | ||
assert file_name(path) =~ ~r/^screenshot-\d{4}(?:-\d{1,2}){5}\.png$/ | ||
end | ||
|
||
test "file names generated 1 second apart are unique" do | ||
default_path = File.cwd!() | ||
|
||
path1 = take_screenshot() | ||
:timer.sleep(1000) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This adds an extra second to an already slow test, so I'm happy to rip this test out if you don't think it's necessary. I couldn't think of a better way to test this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests speed is not that much of an issue yet, but is the granularity of the file name 1 second? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tuvistavie yeah, based on the way the filename is currently generated, it will only be unique down to the second. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, I completely forgot we were generating the name this way. Thanks. |
||
path2 = take_screenshot() | ||
|
||
paths = [path1, path2] | ||
assert paths == Enum.uniq(paths) | ||
end | ||
|
||
describe "When given a file name" do | ||
test "should take a screenshot at the default location with the specified file name" do | ||
default_path = File.cwd!() | ||
|
||
take_screenshot("screenshot-test.png") | ||
|
||
assert File.exists?("#{default_path}/screenshot-test.png") | ||
end | ||
end | ||
|
||
describe "When given a file name with path" do | ||
test "should take a screenshot at the specified location with the specified file name" do | ||
take_screenshot("test/screenshot-test.png") | ||
|
||
assert File.exists?("test/screenshot-test.png") | ||
end | ||
end | ||
|
||
describe "When :screenshot_dir is set" do | ||
setup do | ||
screenshot_dir = "tmp/screenshots/" | ||
Application.put_env(:hound, :screenshot_dir, screenshot_dir) | ||
change_session_to(:with_opts, [screenshot_dir: screenshot_dir]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These seem to happen too late in the application lifecycle. I'm not sure if there's an earlier event I can hook into? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will normally be configured by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tuvistavie sorry, should have been more clear. Neither of the options (line 54 or 55 above) actually change the screenshot directory in the test so all it's currently testing is that the file name is generated in the same way. This line actually fails right now: |
||
|
||
navigate_to("http://localhost:9090/page1.html") | ||
:ok | ||
end | ||
|
||
test "should take a screenshot in the screenshot dir with a generated file name" do | ||
path = take_screenshot() | ||
|
||
assert File.exists?(path) | ||
# ConnectionServer already started so new screenshot_dir not picked up | ||
# assert path =~ "tmp/screenshots/" | ||
assert file_name(path) =~ ~r/^screenshot-\d{4}(?:-\d{1,2}){5}\.png$/ | ||
end | ||
end | ||
|
||
defp file_name(path) do | ||
path | ||
|> String.split("/") | ||
|> List.last() | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if this is actually true, or useful to document.