Skip to content
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

Adds quick screenshot method to all SLElement objects #129

Merged
merged 4 commits into from
Mar 5, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Sources/Classes/UIAutomation/User Interface Elements/SLElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,29 @@
*/
- (void)logElement;

#pragma mark - Screenshots
/// ----------------------------------------
/// @name Screenshot an element
/// ----------------------------------------

/**
Takes a screenshot of the specified element.

The rect for the screenshot of the element is automatically provided.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to mention this--it's kinda an implementation detail.


The image is viewable from the UIAutomation debug log in Instruments.

When running `subliminal-test` from the command line, the images are also saved
as PNGs within the specified output directory.

@param filename A string to use as the name for the resultant image file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that this is optional.


@exception `NSInternalInconsistencyException` if `rect` is `CGRectNull` for specified element.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method abstracts away the use of -[SLDevice captureScreenshot:inRect:], so I don't think it should leak the requirement of that method that rect be non-null. Rather, if rect is null, let's just have the method log a warning (-[SLLogger logWarning:]) like "Could not take screenshot with filename filename: Could not determine element's position on-screen."

Since -rect requires that the element be valid, though, we should include the standard SLUIAElementInvalidException warning here.


*/

- (void) screenshotWithFilename:(NSString *)filename;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you name the method captureScreenshotWithFilename:, please? screenshotWithFilename: sounds like it might return an image.

Also, minor point of style: please remove the space between (void) and the method name.


@end


Expand Down
13 changes: 13 additions & 0 deletions Sources/Classes/UIAutomation/User Interface Elements/SLElement.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#import "NSObject+SLVisibility.h"
#import "NSObject+SLAccessibilityDescription.h"
#import "UIScrollView+SLProgrammaticScrolling.h"
#import "SLDevice.h"


// The real value (set in `+load`) is not a compile-time constant,
Expand Down Expand Up @@ -398,4 +399,16 @@ - (void)logElementTree {
[super logElementTree];
}

#pragma mark -

- (void) screenshotWithFilename:(NSString *)filename
{
// maybe consider using a timestamp? not sure if it's worth introducing the complexity of NSDateFormatter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I don't think it's worth appending a timestamp. If the user really cares about distinguishing these screenshots, they can pass a filename.

// The UIAutomation framework automatically appends an integer to screenshots with the same name to prevent overwriting
if (!filename) {
filename = @"element_screenshot";
}
[[SLDevice currentDevice] captureScreenshotWithFilename:filename inRect:self.rect];
}

@end