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

I've implemented a screenshot function of NSView, UIView and GLKView. #230

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
24 changes: 24 additions & 0 deletions Frank.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@
4C1DD76D12BADFE100E10B8C /* OrientationCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C1DD76912BADFE100E10B8C /* OrientationCommand.h */; };
4C1DD76E12BADFE100E10B8C /* AppCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C1DD76A12BADFE100E10B8C /* AppCommand.m */; };
4C1DD76F12BADFE100E10B8C /* AppCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C1DD76B12BADFE100E10B8C /* AppCommand.h */; };
520C60F617858EB9003D2535 /* NSView+Frank.m in Sources */ = {isa = PBXBuildFile; fileRef = 520C60F417858EB9003D2535 /* NSView+Frank.m */; };
520C60F917858FD7003D2535 /* NSView+Frank.h in Headers */ = {isa = PBXBuildFile; fileRef = 520C60F817858FD7003D2535 /* NSView+Frank.h */; };
520C60FB1785901D003D2535 /* UIView+Frank.h in Headers */ = {isa = PBXBuildFile; fileRef = 520C60FA1785901D003D2535 /* UIView+Frank.h */; };
52B355C717844C2700060740 /* GLKView+ImageCapture.h in Headers */ = {isa = PBXBuildFile; fileRef = 52B355C517844C2700060740 /* GLKView+ImageCapture.h */; };
52B355C817844C2700060740 /* GLKView+ImageCapture.m in Sources */ = {isa = PBXBuildFile; fileRef = 52B355C617844C2700060740 /* GLKView+ImageCapture.m */; };
52B355CB17844DA400060740 /* GLKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52B355CA17844DA400060740 /* GLKit.framework */; };
65DBDD7416A89CCA007D3D43 /* GCDAsyncSocket.m in Sources */ = {isa = PBXBuildFile; fileRef = AB7947C115C4418700052B74 /* GCDAsyncSocket.m */; };
65DBDD8D16A89CCA007D3D43 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AACBBE490F95108600F1A2B1 /* Foundation.framework */; };
65DBDDA816A89CDC007D3D43 /* DDAbstractDatabaseLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = ABA9E4BB15C81E7900112290 /* DDAbstractDatabaseLogger.m */; };
Expand Down Expand Up @@ -316,6 +322,12 @@
4C1DD76912BADFE100E10B8C /* OrientationCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OrientationCommand.h; sourceTree = "<group>"; };
4C1DD76A12BADFE100E10B8C /* AppCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppCommand.m; sourceTree = "<group>"; };
4C1DD76B12BADFE100E10B8C /* AppCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppCommand.h; sourceTree = "<group>"; };
520C60F417858EB9003D2535 /* NSView+Frank.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSView+Frank.m"; sourceTree = "<group>"; };
520C60F817858FD7003D2535 /* NSView+Frank.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSView+Frank.h"; sourceTree = "<group>"; };
520C60FA1785901D003D2535 /* UIView+Frank.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+Frank.h"; sourceTree = "<group>"; };
52B355C517844C2700060740 /* GLKView+ImageCapture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GLKView+ImageCapture.h"; sourceTree = "<group>"; };
52B355C617844C2700060740 /* GLKView+ImageCapture.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GLKView+ImageCapture.m"; sourceTree = "<group>"; };
52B355CA17844DA400060740 /* GLKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GLKit.framework; path = System/Library/Frameworks/GLKit.framework; sourceTree = SDKROOT; };
65DBDD9216A89CCA007D3D43 /* libCocoaAsyncSocket.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libCocoaAsyncSocket.a; sourceTree = BUILT_PRODUCTS_DIR; };
65DBDDB516A89CDC007D3D43 /* libCocoaLumberjack.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libCocoaLumberjack.a; sourceTree = BUILT_PRODUCTS_DIR; };
65DBDDDA16A89E5B007D3D43 /* libCocoaAsyncSocketMac.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libCocoaAsyncSocketMac.a; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -489,6 +501,7 @@
AACBBE4A0F95108600F1A2B1 /* Foundation.framework in Frameworks */,
D629938011AB2DF300CE0FB0 /* UIKit.framework in Frameworks */,
00E864C5161D708B00E01209 /* MapKit.framework in Frameworks */,
52B355CB17844DA400060740 /* GLKit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -517,6 +530,7 @@
305CA7A31642063E00C4ACE5 /* Foundation.framework */,
C18A5F20160D572300DC25F6 /* libPublicAutomation.a */,
00E864C4161D708B00E01209 /* MapKit.framework */,
52B355CA17844DA400060740 /* GLKit.framework */,
08FB77AEFE84172EC02AAC07 /* src */,
D629926711AB2CF700CE0FB0 /* lib */,
0867D69AFE84028FC02AAC07 /* Frameworks */,
Expand Down Expand Up @@ -754,9 +768,12 @@
children = (
C9605E681606BFAE00170F88 /* UIImage+Frank.h */,
C9605E691606BFAE00170F88 /* UIImage+Frank.m */,
520C60FA1785901D003D2535 /* UIView+Frank.h */,
D6A1D27E15A8D05E00EC056C /* UIView+Frank.m */,
C18A5EF3160D4AD300DC25F6 /* UIView+ImageCapture.h */,
C18A5EF4160D4AD300DC25F6 /* UIView+ImageCapture.m */,
52B355C517844C2700060740 /* GLKView+ImageCapture.h */,
52B355C617844C2700060740 /* GLKView+ImageCapture.m */,
C9605E661606BF8E00170F88 /* UIView+MapKitWorkaround.m */,
C18A5F1D160D547A00DC25F6 /* UIView+PublicAutomation.m */,
387BFA7C17036DDA007B9F17 /* UISlider+PublicAutomation.m */,
Expand All @@ -767,6 +784,8 @@
302B803F1646DE02000F9861 /* NSImage+Frank.h */,
302B80401646DE02000F9861 /* NSImage+Frank.m */,
303A751116702D3D00B93673 /* NSObject+FrankAutomation.m */,
520C60F817858FD7003D2535 /* NSView+Frank.h */,
520C60F417858EB9003D2535 /* NSView+Frank.m */,
30412D2E165333E300719CD2 /* NSView+FrankImageCapture.h */,
30412D2F165333E300719CD2 /* NSView+FrankImageCapture.m */,
);
Expand Down Expand Up @@ -822,6 +841,7 @@
C189EF1F16BB5A8100F8236D /* VersionCommand.h in Headers */,
303CFCE516C80B830004BD05 /* DeviceCommand.h in Headers */,
30E82E3317128AB500E5BC7C /* ResolutionCommand.h in Headers */,
520C60F917858FD7003D2535 /* NSView+Frank.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -865,6 +885,8 @@
303CFCE416C80B830004BD05 /* DeviceCommand.h in Headers */,
30E82E3217128AB500E5BC7C /* ResolutionCommand.h in Headers */,
0626BFAE174300240020B33B /* DumpCommandRoute.h in Headers */,
52B355C717844C2700060740 /* GLKView+ImageCapture.h in Headers */,
520C60FB1785901D003D2535 /* UIView+Frank.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1109,6 +1131,7 @@
C189EF2116BB5A8100F8236D /* VersionCommand.m in Sources */,
303CFCE716C80B830004BD05 /* DeviceCommand.m in Sources */,
30E82E3517128AB500E5BC7C /* ResolutionCommand.m in Sources */,
520C60F617858EB9003D2535 /* NSView+Frank.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1238,6 +1261,7 @@
30E82E3417128AB500E5BC7C /* ResolutionCommand.m in Sources */,
387BFA7D17036DDA007B9F17 /* UISlider+PublicAutomation.m in Sources */,
0626BFAF174300240020B33B /* DumpCommandRoute.m in Sources */,
52B355C817844C2700060740 /* GLKView+ImageCapture.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion gem/frank-skeleton/frankify.xcconfig.tt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
INSTALL_PATH = /./

FRANK_CORE_LDFLAGS = -all_load -ObjC -framework CFNetwork -framework Security -lShelley -lFrank <%= @libs.map { |lib| "-l#{lib}" }.join(' ') %>
FRANK_CORE_LDFLAGS = -all_load -ObjC -framework CFNetwork -framework Security -framework GLKit -lShelley -lFrank <%= @libs.map { |lib| "-l#{lib}" }.join(' ') %>
FRANK_CORE_MAC_LDFLAGS = -all_load -ObjC -framework CFNetwork -framework Security -lShelleyMac -lFrankMac <%= @libsMac.map { |lib| "-l#{lib}" }.join(' ') %>

FRANK_CORE_GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS = FRANKIFIED
20 changes: 20 additions & 0 deletions gem/lib/frank-cucumber/frank_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'json'
require 'base64'
require 'frank-cucumber/gateway'
require 'frank-cucumber/host_scripting'
require 'frank-cucumber/wait_helper'
Expand Down Expand Up @@ -88,6 +89,25 @@ def touch( selector )
touch_successes
end

# grab screenshots of all views matching the specified selector.
# @param [String] selector a view selector.
# @return [Array<PNG>] an array of PNG-image binary.
# @raise an expection if no views matched the selector
# @raise an expection if no views which matched the selector could be capture
def capture( selector )
view_uids = frankly_map( selector, 'FEX_UID' )
raise "could not find anything matching [#{selector}] to capture" if view_uids.empty?
raise "some views could not be capture image" if view_uids.include?(nil)

frank_server.send_get( 'screenshot/snapshot-all-views' )
screenshots = view_uids.map{|uid|
path = "screenshot/view-snapshot/#{uid}"
frank_server.send_get( path )
}
raise "some views failed to capture image" if screenshots.include?(nil)
screenshots
end

# Fill in text in a text field.
#
# @param [String] the placeholder text for the desired text field
Expand Down
14 changes: 14 additions & 0 deletions src/GLKView+ImageCapture.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// GLKView+ImageCapture.h
// Frank
//
// Created by Toshiyuki Suzumura on 2013/07/03.
//

#import <GLKit/GLKit.h>

@interface GLKView (ImageCapture)

- (UIImage *)captureImage;

@end
16 changes: 16 additions & 0 deletions src/GLKView+ImageCapture.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// GLKView+ImageCapture.m
// Frank
//
// Created by Toshiyuki Suzumura on 2013/07/03.
//

#import "GLKView+ImageCapture.h"

@implementation GLKView (ImageCapture)

- (UIImage*)captureImage {
return [self snapshot];
}

@end
6 changes: 4 additions & 2 deletions src/ImageCaptureRoute.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@

#if TARGET_OS_IPHONE
#import "UIImage+Frank.h"
#import "UIView+Frank.h"
#import "UIView+ImageCapture.h"
#else
#import "NSImage+Frank.h"
#import "NSView+Frank.h"
#import "NSView+FrankImageCapture.h"
#endif
#import "FranklyProtocolHelper.h"
Expand Down Expand Up @@ -49,15 +51,15 @@ - (void) snapshotView:(UIView *)view{
UIImage *image = [view captureImage];
NSData *imgData = UIImagePNGRepresentation(image);

NSString *viewUID = [NSString stringWithFormat:@"%i",(int)view];
NSString *viewUID = [view FEX_UID];
[imgData writeToFile:[self pathForSnapshotOfViewWithUID:viewUID] atomically:NO];
}
#else
- (void) snapshotView:(NSView *)view{
NSImage *image = [view captureImage];
NSData *imgData = [[[image representations] objectAtIndex:0] representationUsingType:NSPNGFileType properties:nil];

NSString *viewUID = [NSString stringWithFormat:@"%lu",(uintptr_t)view];
NSString *viewUID = [view FEX_UID];
[imgData writeToFile:[self pathForSnapshotOfViewWithUID:viewUID] atomically:NO];
}
#endif
Expand Down
14 changes: 14 additions & 0 deletions src/NSView+Frank.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// NSView+Frank.h
// Frank
//
// Created by Toshiyuki Suzumura on 2013/07/04.
//

#import <Cocoa/Cocoa.h>

@interface NSView (Frank)

- (NSString *) FEX_UID;

@end
16 changes: 16 additions & 0 deletions src/NSView+Frank.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// NSView+Frank.m
// Frank
//
// Created by Toshiyuki Suzumura on 2013/07/04.
//

#import "NSView+Frank.h"

@implementation NSView (Frank)

- (NSString *) FEX_UID {
return [NSString stringWithFormat:@"%lu",(uintptr_t)self];
}

@end
14 changes: 14 additions & 0 deletions src/UIView+Frank.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// UIView+Frank.h
// Frank
//
// Created by Toshiyuki Suzumura on 2013/07/04.
//

#import <UIKit/UIKit.h>

@interface UIView (Frank)

- (NSString *) FEX_UID;

@end
6 changes: 5 additions & 1 deletion src/UIView+Frank.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright (c) 2012 ThoughtWorks. All rights reserved.
//


#import "UIView+Frank.h"
#import "LoadableCategory.h"

MAKE_CATEGORIES_LOADABLE(UIView_Frank)
Expand Down Expand Up @@ -51,4 +51,8 @@ - (BOOL)FEX_isFullyWithinWindow {
return CGRectContainsRect(self.window.bounds, myFrameInWindowCoords);
}

- (NSString *) FEX_UID {
return [NSString stringWithFormat:@"%i",(int)self];
}

@end