3
A
回答
2
這個搞亂了一會兒後,我已將此添加到我的KIFTestStep.m
+ (id)stepToTakeScreenShotwithName:(NSString *)name;
{
NSString *description = [NSString stringWithFormat:@"Take a screenshot saved by the name %@", name];
return [self stepWithDescription:description executionBlock:^(KIFTestStep *step, NSError **error) {
NSString *outputPath = [NSString stringWithFormat:@"/Users/%@/ScreenShots", NSUserName()];
NSArray *windows = [[UIApplication sharedApplication] windows];
if (windows.count == 0) {
return KIFTestStepResultFailure;
}
UIGraphicsBeginImageContext([[windows objectAtIndex:0] bounds].size);
for (UIWindow *window in windows) {
[window.layer renderInContext:UIGraphicsGetCurrentContext()];
}
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSTimeInterval timeStamp = [[NSDate date] timeIntervalSince1970];
NSNumber *timeStampObj = [NSNumber numberWithDouble: timeStamp];
outputPath = [outputPath stringByExpandingTildeInPath];
outputPath = [outputPath stringByAppendingPathComponent:[name stringByReplacingOccurrencesOfString:@"/" withString:@"_"]];
outputPath = [outputPath stringByAppendingString:[timeStampObj stringValue]];
outputPath = [outputPath stringByAppendingPathExtension:@"png"];
[UIImagePNGRepresentation(image) writeToFile:outputPath atomically:YES];
return KIFTestStepResultSuccess;
}];
}
3
這在KIF 3.0.4添加。見here。
相關問題
- 1. 以當前屏幕的屏幕截圖
- 2. 以整個屏幕的屏幕截圖
- 3. 以當前屏幕截圖
- 4. 以黃瓜爲屏幕截圖
- 5. 屏幕截圖
- 6. 截取屏幕截圖
- 7. C++截取屏幕截圖
- 8. 以屏幕截圖(以編程方式)
- 9. iPhone:屏幕截圖
- 10. Webdriver屏幕截圖
- 11. ASP.NET屏幕截圖
- 12. C++屏幕截圖
- 13. iPhone屏幕截圖
- 14. Roku屏幕截圖
- 15. 屏幕截圖按住屏幕截圖時卡住
- 16. 以WebBrowser控件的屏幕截圖
- 17. 以silverlight 5/xna拍攝屏幕截圖
- 18. 以編程方式拍攝整個屏幕的屏幕截圖
- 19. Media Projection api可以在棒棒糖主屏幕上截取屏幕截圖嗎?
- 20. osx上的屏幕截圖
- 21. iOS屏幕截圖延遲
- 22. Android設備屏幕截圖
- 23. 跨平臺屏幕截圖
- 24. 窗口的屏幕截圖
- 25. 屏幕截圖的C++ CLI
- 26. 瀏覽器屏幕截圖
- 27. 屏幕截圖ala Draw Something
- 28. iOS:獲取屏幕截圖
- 29. 捕獲屏幕截圖
- 30. InAppBrowser的屏幕截圖?