google/EarlGrey

Custom Action with Earlgrey2

kevinlegoff-tdl opened this issue · 0 comments

Can you still write custom action in Earlgrey2 ?

I am trying to implement a custom action in earlgrey2.
But I am facing 2 issues whenever I am calling an Earlgrey method within my custom action Earlgrey get stuck.

@implementation RateAction

- (instancetype)initWithGrade:(double)grade {
    if (self = [super init]) {
        _grade = grade;
        _name = [NSString stringWithFormat:@"Slide to value: %g", grade];
    }
    return self;
}

- (nonnull NSString *)name {
    return _name;
}

- (BOOL)perform:(nonnull UIView *)element error:(NSError * __strong * _Nullable)errorOrNil {
    if (element == nil) {
        *errorOrNil = [NSError errorWithDomain:@"UITesting-> rateAction nil element"
                                          code: 1001
                                      userInfo:nil];
        return NO;
    }

    SEL setValueSelector = NSSelectorFromString(@"setValue:sendValueChangedAction:");
    if ([element respondsToSelector:setValueSelector]) {
        [element performSelector: setValueSelector
                      withObject: [NSNumber numberWithDouble: _grade]
         ];
    }
    return YES;
}

- (BOOL)shouldRunOnMainThread {
    return YES;
}
@end

So I have come to try using selector on my view to make it do what I want. But when I try I think the view the perform method receive is a copy of the view in the application. So it does not work as expected.

Is there any guide on writing CustomAction from Earlgrey2 or this possibility has just been remove from the framework ?