swift-snapshot-testing icon indicating copy to clipboard operation
swift-snapshot-testing copied to clipboard

Setting SNAPSHOT_ARTIFACTS in Test action

Open lewisgodowski opened this issue 4 years ago • 5 comments

Hello, I've spent a while now attempting to get a custom directory for the failure images by using the SNAPSHOT_ARTIFACTS environment variable. I finally got it working, but ran into a slight hiccup, and I'm not sure if it's caused by the library or maybe some project or build settings on my end.

If I set SNAPSHOT_ARTIFACTS in the Test action, I get the following error: failed - You can’t save the file “X” because the volume is read only.

However, if I set SNAPSHOT_ARTIFACTS in the Run action, and then enable Use the Run action's arguments and environment variables, it works. But, unfortunately, this means I can't use my own arguments and environment variables in the Test action.

Ideally, I wouldn't have to use the Run action's arguments and environment variables in the Test action, so that I could set whatever additional arguments and environment variables I need.

lewisgodowski avatar Apr 29 '21 18:04 lewisgodowski

Thanks @lewisgodowski for the Run action workaround, I can confirm it works by default, but unfortunately when using Test Plans, the Use the Run action's stuff feature becomes no longer available, so I'm stuck with the "read only" error and can't customize where failed snapshots go. The default location that's deep inside the Simulator's bowels is inconvenient to get to and slows down workflow.

I need to use Test Plans for reasons, so I'd really be grateful for either a fix or another workaround that's compatible with Test Plans.

tw-space avatar Jul 15 '21 22:07 tw-space

Selecting my tests target in the "Expand Variables Based On" dropdown worked for me:

image

DimitarNestorov avatar Apr 12 '23 17:04 DimitarNestorov

@tw-space testplans do have "Environment variables" in Configurations tab. Have you tried? Screenshot 2023-08-29 at 10 23 11 PM

hlung avatar Aug 29 '23 14:08 hlung

Also, I need prepend $(SOURCE_ROOT) e.g. SNAPSHOT_ARTIFACTS=$(SOURCE_ROOT)/__FailedSnapshots__. Using SNAPSHOT_ARTIFACTS=__FailedSnapshots__ makes it try to write at the root directory file://..., which is of course read-only, and fails with error message: "You can’t save the file “XxxTests” because the volume is read only."

hlung avatar Aug 29 '23 14:08 hlung

As mentioned in https://stackoverflow.com/a/69237460 it's also possible to prefix the variable name to pass it to the test directly.

With TEST_RUNNER_SNAPSHOT_ARTIFACTS = mypath I was able to store the artifacts in mypath without changing anything in the XCode GUI.

zbynek avatar Sep 15 '23 14:09 zbynek