Attaching a screenshot from a separate .swift file

Good afternoon,


From within my XCUITest target, I have a separate file that has a few functions that I created that extend the XCUIElement class. From within these functions, I want to attach a screenshot to the overall test. I can't seem to get that working, as it seems I need to call the .add function from within the XCUITestCase class.


Is there any way to get what I'm looking for to work?


Thank you!

James

You’ll need to provide some sort of path from your

XCUIElement
subclass to the
XCUITestCase
. How you do that is up to you, but some common approaches would be:
  • Add a delegate to your

    XCUIElement
    and have your
    XCUITestCase
    implement that delegate
  • Post a notification from your

    XCUIElement
    and have your your
    XCUITestCase
    listen for that notification

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Attaching a screenshot from a separate .swift file
 
 
Q