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. SpriteKit屏幕截圖的屏幕截圖
- 4. 以當前屏幕截圖
- 5. 以黃瓜爲屏幕截圖
- 6. 屏幕截圖
- 7. 屏幕截圖爲黑色
- 8. C++截取屏幕截圖
- 9. 截取屏幕截圖
- 10. 以屏幕截圖(以編程方式)
- 11. Webdriver屏幕截圖
- 12. UIWebView屏幕截圖
- 13. iPhone屏幕截圖
- 14. Roku屏幕截圖
- 15. C++屏幕截圖
- 16. ASP.NET屏幕截圖
- 17. iPhone:屏幕截圖
- 18. android屏幕截圖
- 19. UICollectionView屏幕截圖
- 20. 屏幕截圖未連接屏幕截圖的軟件(RDP)
- 21. 屏幕截圖按住屏幕截圖時卡住
- 22. 屏幕部分的屏幕截圖
- 23. 屏幕截圖到任何屏幕(Android Root,就像屏幕截圖UX)
- 24. 以多個子視圖爲屏幕截圖作爲wkwebview
- 25. 以WebBrowser控件的屏幕截圖
- 26. 以silverlight 5/xna拍攝屏幕截圖
- 27. 以多屏幕截圖硒和java
- 28. 以場景的屏幕截圖或2.2
- 29. 以編程方式拍攝整個屏幕的屏幕截圖
- 30. Media Projection api可以在棒棒糖主屏幕上截取屏幕截圖嗎?