4

是否可以将 UIAutomation 与 cocos2d 或任何 opengl 应用程序一起使用?

具体来说,我想使用zucchini 框架来测试我的 cocos2d 游戏,但无论如何它只是使用 UIAutomation。

4

2 回答 2

1

您可以在 Zucchini 中创建自定义步骤并指定要点击的坐标,例如

'Choose the red bird' : ->
   target.tap({x:278, y:36})

'Press Fire' : ->
   target.tap({x:170, y:260}) 
于 2012-02-08T02:43:49.030 回答
0

所以,我开始使用 calabash-iOS 并扩展它的后门。这仅适用于初学者,但通过它您可以获得当前 CCScene 的可访问性标签,因此您可以检查当前在哪个屏幕上,从而用于脚本操作。我不习惯使用 objc 运行时,但正如您所见,它可以获取属性、方法等。多一点挖掘,应该可以包装更多功能,希望也能包装 cocos2d CCNode 结构. 这是一个进展中的工作。

要使用它,您需要安装https://github.com/calabash/calabash-ios,然后在应用程序委托中实现以下功能。不要忘记在代码中将 .accessibilityLabel 设置为 @"menu"、@"game" 或类似名称。理想情况下,仅对于 *-cal 目标,您不希望在生产构建中使用此代码。

-(NSString*)calabashBackdoor:(NSString*)aIgnorable {
    DLog(@"calabashBackdoor: %@", aIgnorable);

//  UIApplication* app = [UIApplication sharedApplication];
    if (aIgnorable != nil) {
        NSArray* p = [aIgnorable componentsSeparatedByString:@" "];
        NSString* command = [p objectAtIndex:0];

        if ([command isEqualToString:@"getCurrentSceneLabel"]) {
            CCDirector* director = [CCDirector sharedDirector];
            DLog(@"director.runningScene.accessibilityLabel: %@", director.runningScene.accessibilityLabel);
            return director.runningScene.accessibilityLabel;
        }
        else if ([command isEqualToString:@"class_copyMethodList"]) {
            CCDirector* director = [CCDirector sharedDirector];
            id inspectThisObject = director.runningScene;
            DLog(@"inspectThisObject: %@, %@", [inspectThisObject class], inspectThisObject);
            unsigned int count;

            // To get the class methods of a class, use class_copyMethodList(object_getClass(cls), &count).
            Method* methods = class_copyMethodList(object_getClass(inspectThisObject), &count);
            //NSMutableString* returnstring = [NSMutableString string];
            NSMutableArray* arrayOfMethodnames = [NSMutableArray array];
            if (methods != NULL) {
                for (int i = 0; i < count; i++) {
                    Method method = methods[i];
                    NSString* stringMethod = NSStringFromSelector(method_getName(method)); //NSStringFromSelector(method->method_name);
                    [arrayOfMethodnames addObject:stringMethod];
                }
                // An array of pointers of type Method describing the instance methods implemented by the class—any instance methods implemented by superclasses are not included. The array contains *outCount pointers followed by a NULL terminator. You must free the array with free().
                free(methods);
            }
            DLog(@"arrayOfMethodnames: %@", arrayOfMethodnames);
            return [arrayOfMethodnames componentsJoinedByString:@","];
        }
        else if ([command isEqualToString:@"class_copyPropertyList"]) {
            CCDirector* director = [CCDirector sharedDirector];
            id inspectThisObject = director.runningScene;
            DLog(@"inspectThisObject: %@, %@", [inspectThisObject class], inspectThisObject);
            unsigned int count;

//          An array of pointers of type objc_property_t describing the properties declared by the class. Any properties declared by superclasses are not included. The array contains *outCount pointers followed by a NULL terminator. You must free the array with free().
//
//          If cls declares no properties, or cls is Nil, returns NULL and *outCount is 0.
//          
            objc_property_t* properties = class_copyPropertyList(object_getClass(inspectThisObject), &count);

            NSMutableArray* arrayOfProperties = [NSMutableArray array];
            if (properties != NULL) {
                for (int i = 0; i < count; i++) {
                    objc_property_t property = properties[i];
                    const char* CCS = property_getName(property);
                    NSString* str = [NSString stringWithUTF8String:CCS];
                    [arrayOfProperties addObject:str];
                }
                free(properties);
            }
            DLog(@"arrayOfProperties: %@", arrayOfProperties);
            return [arrayOfProperties componentsJoinedByString:@","];           
        }
        else {
            DLog(@"Unhandled command: %@", command);
        }
    }

    return @"calabashBackdoor nil!";
}

在 Prefix.pch 中放这个

#ifdef DEBUG
#   define DLog( s, ... ) NSLog( @"<%p %@:(%d)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )
#else
#   define DLog(...) /* */
#endif
#define ALog(...) NSLog(__VA_ARGS__)

当你得到 calabash-ios 并运行时,在 step_definitions/somesteps.rb 中添加:

Then(/^I backdoor (.+)$/) do |x|
  backdoor("calabashBackdoor:", x)
end
于 2013-06-13T09:14:04.640 回答