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

EarlGrey 2.0 Prototype (multiprocess, XCUITest support) #193

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ rvm:
- 2.2.5
env:
matrix:
- DESTINATION="OS=9.3,name=iPhone 6s" SDK=iphonesimulator9.3 TYPE="FUNCTIONAL_UI"
- DESTINATION="OS=9.3,name=iPhone 6s" SDK=iphonesimulator9.3 TYPE="FUNCTIONAL_SWIFT_UI"
- DESTINATION="OS=9.3,name=iPhone 6s" SDK=iphonesimulator9.3 TYPE="FUNCTIONAL"
- DESTINATION="OS=9.3,name=iPhone 6s" SDK=iphonesimulator9.3 TYPE="FUNCTIONAL_SWIFT"
- DESTINATION="OS=9.3,name=iPhone 6s" SDK=iphonesimulator9.3 TYPE="CONTRIB"
Expand Down
53 changes: 42 additions & 11 deletions EarlGrey.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions EarlGrey/Action/GREYActionBlock.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
#import "Action/GREYActionBlock.h"

#import "Assertion/GREYAssertionDefines.h"
#import "Common/GREYCoder.h"
#import "Common/GREYDefines.h"
#import "Matcher/GREYMatcher.h"

@implementation GREYActionBlock {
GREYPerformBlock _performBlock;
id<GREYMatcher> _constraints;
}

+ (instancetype)actionWithName:(NSString *)name performBlock:(GREYPerformBlock)block {
Expand All @@ -41,10 +43,23 @@ - (instancetype)initWithName:(NSString *)name
self = [super initWithName:name constraints:constraints];
if (self) {
_performBlock = block;
_constraints = constraints;
}
return self;
}

- (id)initWithCoder:(NSCoder *)coder {
return [self initWithName:[coder decodeObjectForKey:@"name"]
constraints:[coder decodeObjectForKey:@"constraints"]
performBlock:[GREYCoder decodeObject:[coder decodeObjectForKey:@"performBlock"]]];
}

- (void)encodeWithCoder:(NSCoder *)coder {
[coder encodeObject:[self name] forKey:@"name"];
[coder encodeObject:_constraints forKey:@"constraints"];
[coder encodeObject:[GREYCoder encodeObject:_performBlock] forKey:@"performBlock"];
}

#pragma mark - GREYAction

- (BOOL)perform:(id)element error:(__strong NSError **)errorOrNil {
Expand Down
30 changes: 17 additions & 13 deletions EarlGrey/Action/GREYActions.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#import "Assertion/GREYAssertionDefines.h"
#import "Common/GREYExposed.h"
#import "Common/GREYScreenshotUtil.h"
#import "Common/GREYSerializable.h"
#import "Core/GREYInteraction.h"
#import "Core/GREYKeyboard.h"
#import "Matcher/GREYAllOf.h"
Expand Down Expand Up @@ -145,12 +146,10 @@ @implementation GREYActions
}

+ (id<GREYAction>)actionForTurnSwitchOn:(BOOL)on {
id<GREYMatcher> constraints = grey_allOf(grey_not(grey_systemAlertViewShown()),
grey_respondsToSelector(@selector(isOn)), nil);
NSString *actionName = [NSString stringWithFormat:@"Turn switch to %@ state",
[UISwitch grey_stringFromOnState:on]];
return [GREYActionBlock actionWithName:actionName
constraints:constraints
constraints:grey_respondsToSelector(@selector(isOn))
performBlock:^BOOL (id switchView, __strong NSError **errorOrNil) {
if (([switchView isOn] && !on) || (![switchView isOn] && on)) {
id<GREYAction> longPressAction =
Expand Down Expand Up @@ -203,12 +202,12 @@ @implementation GREYActions
}

+ (id<GREYAction>)actionForSetDate:(NSDate *)date {
id<GREYMatcher> constraints = grey_allOf(grey_interactable(),
grey_not(grey_systemAlertViewShown()),
grey_kindOfClass([UIDatePicker class]),
nil);
GREY_SERIALIZE(Object, NSDate *, date);

return [[GREYActionBlock alloc] initWithName:[NSString stringWithFormat:@"Set date to %@", date]
constraints:constraints
constraints:grey_allOf(grey_interactable(),
grey_kindOfClass([UIDatePicker class]),
nil)
performBlock:^BOOL (UIDatePicker *datePicker,
__strong NSError **errorOrNil) {
NSDate *previousDate = [datePicker date];
Expand All @@ -228,12 +227,11 @@ @implementation GREYActions

+ (id<GREYAction>)actionForJavaScriptExecution:(NSString *)js
output:(out __strong NSString **)outResult {
GREY_SERIALIZE2(Object, NSString *, js, Out, __strong id *, outResult);

// TODO: JS Errors should be propagated up.
id<GREYMatcher> constraints = grey_allOf(grey_not(grey_systemAlertViewShown()),
grey_kindOfClass([UIWebView class]),
nil);
return [[GREYActionBlock alloc] initWithName:@"Execute JavaScript"
constraints:constraints
constraints:grey_kindOfClass([UIWebView class])
performBlock:^BOOL (UIWebView *webView,
__strong NSError **errorOrNil) {
if (outResult) {
Expand All @@ -248,6 +246,8 @@ @implementation GREYActions
}

+ (id<GREYAction>)actionForSnapshot:(out __strong UIImage **)outImage {
GREY_SERIALIZE(Out, __strong id *, outImage);

NSParameterAssert(outImage);

return [[GREYActionBlock alloc] initWithName:@"Element Snapshot"
Expand Down Expand Up @@ -317,6 +317,8 @@ + (void)grey_webSetText:(id)element text:(NSString *)text {
* the error occured and so the UI may be in an unrecoverable state.
*/
+ (id<GREYAction>)grey_actionForReplaceText:(NSString *)text {
GREY_SERIALIZE(Object, NSString *, text);

SEL setTextSelector = NSSelectorFromString(@"setText:");
id<GREYMatcher> constraints =
grey_anyOf(grey_respondsToSelector(setTextSelector),
Expand Down Expand Up @@ -350,8 +352,10 @@ + (void)grey_webSetText:(id)element text:(NSString *)text {
*/
+ (id<GREYAction>)grey_actionForTypeText:(NSString *)text
atUITextPosition:(UITextPosition *)position {
GREY_SERIALIZE2(Object, NSString *, text, Object, UITextPosition *, position);

return [GREYActionBlock actionWithName:[NSString stringWithFormat:@"Type \"%@\"", text]
constraints:grey_not(grey_systemAlertViewShown())
constraints:nil
performBlock:^BOOL (id element, __strong NSError **errorOrNil) {
UIView *expectedFirstResponderView;
if (![element isKindOfClass:[UIView class]]) {
Expand Down
9 changes: 8 additions & 1 deletion EarlGrey/Action/GREYChangeStepperAction.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ @implementation GREYChangeStepperAction {
- (instancetype)initWithValue:(double)value {
self = [super initWithName:[NSString stringWithFormat:@"Change stepper to %g", value]
constraints:grey_allOf(grey_interactable(),
grey_not(grey_systemAlertViewShown()),
grey_kindOfClass([UIStepper class]),
nil)];
if (self) {
Expand All @@ -45,6 +44,14 @@ - (instancetype)initWithValue:(double)value {
return self;
}

- (id)initWithCoder:(NSCoder *)coder {
return [self initWithValue:[coder decodeDoubleForKey:@"value"]];
}

- (void)encodeWithCoder:(NSCoder *)coder {
[coder encodeDouble:_value forKey:@"value"];
}

#pragma mark - GREYAction

- (BOOL)perform:(UIStepper *)stepper error:(__strong NSError **)errorOrNil {
Expand Down
11 changes: 10 additions & 1 deletion EarlGrey/Action/GREYPickerAction.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ - (instancetype)initWithColumn:(NSInteger)column value:(NSString *)value {
NSString *name =
[NSString stringWithFormat:@"Set picker column %ld to value \"%@\"", (long)column, value];
self = [super initWithName:name constraints:grey_allOf(grey_interactable(),
grey_not(grey_systemAlertViewShown()),
grey_kindOfClass([UIPickerView class]),
nil)];
if (self) {
Expand All @@ -50,6 +49,16 @@ - (instancetype)initWithColumn:(NSInteger)column value:(NSString *)value {
return self;
}

- (id)initWithCoder:(NSCoder *)coder {
return [self initWithColumn:[coder decodeIntegerForKey:@"column"]
value:[coder decodeObjectForKey:@"value"]];
}

- (void)encodeWithCoder:(NSCoder *)coder {
[coder encodeInteger:_column forKey:@"column"];
[coder encodeObject:_value forKey:@"value"];
}

#pragma mark - GREYAction

- (BOOL)perform:(UIPickerView *)pickerView error:(__strong NSError **)errorOrNil {
Expand Down
11 changes: 10 additions & 1 deletion EarlGrey/Action/GREYPinchAction.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#import "Action/GREYPinchAction.h"

#import <OCHamcrest/HCStringDescription.h>
#include <tgmath.h>

#import "Additions/NSError+GREYAdditions.h"
Expand Down Expand Up @@ -71,6 +70,16 @@ - (instancetype)initWithDirection:(GREYPinchDirection)pinchDirection
return self;
}

- (id)initWithCoder:(NSCoder *)coder {
return [self initWithDirection:[coder decodeIntegerForKey:@"pinchDirection"]
duration:[coder decodeDoubleForKey:@"duration"]];
}

- (void)encodeWithCoder:(NSCoder *)coder {
[coder encodeInteger:_pinchDirection forKey:@"pinchDirection"];
[coder encodeDouble:_duration forKey:@"duration"];
}

#pragma mark - GREYAction

- (BOOL)perform:(id)element error:(__strong NSError **)errorOrNil {
Expand Down
19 changes: 15 additions & 4 deletions EarlGrey/Action/GREYScrollAction.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#import "Additions/NSString+GREYAdditions.h"
#import "Additions/UIScrollView+GREYAdditions.h"
#import "Assertion/GREYAssertionDefines.h"
#import "Common/GREYCoder.h"
#import "Event/GREYSyntheticEvents.h"
#import "Matcher/GREYAllOf.h"
#import "Matcher/GREYAnyOf.h"
Expand Down Expand Up @@ -67,10 +68,8 @@ - (instancetype)initWithDirection:(GREYDirection)direction
NSString *name =
[NSString stringWithFormat:@"Scroll %@ for %g", NSStringFromGREYDirection(direction), amount];
self = [super initWithName:name
constraints:grey_allOf(grey_anyOf(grey_kindOfClass([UIScrollView class]),
grey_kindOfClass([UIWebView class]),
nil),
grey_not(grey_systemAlertViewShown()),
constraints:grey_anyOf(grey_kindOfClass([UIScrollView class]),
grey_kindOfClass([UIWebView class]),
nil)];
if (self) {
_direction = direction;
Expand All @@ -84,6 +83,18 @@ - (instancetype)initWithDirection:(GREYDirection)direction amount:(CGFloat)amoun
return [self initWithDirection:direction amount:amount startPointPercents:GREYCGPointNull];
}

- (id)initWithCoder:(NSCoder *)coder {
return [self initWithDirection:[coder decodeIntegerForKey:@"direction"]
amount:[GREYCoder decodeCGFloat:[coder decodeObjectForKey:@"amount"]]
startPointPercents:[GREYCoder decodeCGPoint:[coder decodeObjectForKey:@"startPointPercents"]]];
}

- (void)encodeWithCoder:(NSCoder *)coder {
[coder encodeInteger:_direction forKey:@"direction"];
[coder encodeObject:[GREYCoder encodeCGFloat:_amount] forKey:@"amount"];
[coder encodeObject:[GREYCoder encodeCGPoint:_startPointPercents] forKey:@"startPointPercents"];
}

#pragma mark - GREYAction

- (BOOL)perform:(id)element error:(__strong NSError **)errorOrNil {
Expand Down
17 changes: 13 additions & 4 deletions EarlGrey/Action/GREYScrollToContentEdgeAction.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#import "Additions/NSString+GREYAdditions.h"
#import "Additions/UIScrollView+GREYAdditions.h"
#import "Assertion/GREYAssertionDefines.h"
#import "Common/GREYCoder.h"
#import "Common/GREYVisibilityChecker.h"
#import "Event/GREYSyntheticEvents.h"
#import "Matcher/GREYAllOf.h"
Expand Down Expand Up @@ -53,10 +54,8 @@ - (instancetype)initWithEdge:(GREYContentEdge)edge startPointPercents:(CGPoint)s
NSString *name =
[NSString stringWithFormat:@"Scroll To %@ content edge", NSStringFromGREYContentEdge(edge)];
self = [super initWithName:name
constraints:grey_allOf(grey_anyOf(grey_kindOfClass([UIScrollView class]),
grey_kindOfClass([UIWebView class]),
nil),
grey_not(grey_systemAlertViewShown()),
constraints:grey_anyOf(grey_kindOfClass([UIScrollView class]),
grey_kindOfClass([UIWebView class]),
nil)];
if (self) {
_edge = edge;
Expand All @@ -69,6 +68,16 @@ - (instancetype)initWithEdge:(GREYContentEdge)edge {
return [self initWithEdge:edge startPointPercents:GREYCGPointNull];
}

- (id)initWithCoder:(NSCoder *)coder {
return [self initWithEdge:[coder decodeIntegerForKey:@"edge"]
startPointPercents:[GREYCoder decodeCGPoint:[coder decodeObjectForKey:@"startPointPercents"]]];
}

- (void)encodeWithCoder:(NSCoder *)coder {
[coder encodeInteger:_edge forKey:@"edge"];
[coder encodeObject:[GREYCoder encodeCGPoint:_startPointPercents] forKey:@"startPointPercents"];
}

#pragma mark - GREYAction

- (BOOL)perform:(UIScrollView *)element error:(__strong NSError **)errorOrNil {
Expand Down
9 changes: 8 additions & 1 deletion EarlGrey/Action/GREYSlideAction.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ @implementation GREYSlideAction {
- (instancetype)initWithSliderValue:(float)value {
self = [super initWithName:[NSString stringWithFormat:@"Slide to value: %g", value]
constraints:grey_allOf(grey_interactable(),
grey_not(grey_systemAlertViewShown()),
grey_kindOfClass([UISlider class]),
nil)];
if (self) {
Expand All @@ -48,6 +47,14 @@ - (instancetype)initWithSliderValue:(float)value {
return self;
}

- (id)initWithCoder:(NSCoder *)coder {
return [self initWithSliderValue:[coder decodeFloatForKey:@"finalValue"]];
}

- (void)encodeWithCoder:(NSCoder *)coder {
[coder encodeFloat:_finalValue forKey:@"finalValue"];
}

#pragma mark - GREYAction

- (BOOL)perform:(UISlider *)slider error:(__strong NSError **)errorOrNil {
Expand Down
14 changes: 13 additions & 1 deletion EarlGrey/Action/GREYSwipeAction.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#import "Action/GREYPathGestureUtils.h"
#import "Additions/NSString+GREYAdditions.h"
#import "Assertion/GREYAssertionDefines.h"
#import "Common/GREYCoder.h"
#import "Event/GREYSyntheticEvents.h"
#import "Matcher/GREYAllOf.h"
#import "Matcher/GREYMatcher.h"
Expand Down Expand Up @@ -53,7 +54,6 @@ - (instancetype)initWithDirection:(GREYDirection)direction
duration];
self = [super initWithName:name
constraints:grey_allOf(grey_interactable(),
grey_not(grey_systemAlertViewShown()),
grey_kindOfClass([UIView class]),
grey_respondsToSelector(@selector(accessibilityFrame)),
nil)];
Expand Down Expand Up @@ -81,6 +81,18 @@ - (instancetype)initWithDirection:(GREYDirection)direction
percentPoint:startPercents];
}

- (id)initWithCoder:(NSCoder *)coder {
return [self initWithDirection:[coder decodeIntegerForKey:@"direction"]
duration:[coder decodeDoubleForKey:@"duration"]
percentPoint:[GREYCoder decodeCGPoint:[coder decodeObjectForKey:@"startPercents"]]];
}

- (void)encodeWithCoder:(NSCoder *)coder {
[coder encodeInteger:_direction forKey:@"direction"];
[coder encodeDouble:_duration forKey:@"duration"];
[coder encodeObject:[GREYCoder encodeCGPoint:_startPercents] forKey:@"startPercents"];
}

#pragma mark - GREYAction

- (BOOL)perform:(id)element error:(__strong NSError **)errorOrNil {
Expand Down
18 changes: 16 additions & 2 deletions EarlGrey/Action/GREYTapAction.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#import "Additions/CGGeometry+GREYAdditions.h"
#import "Additions/NSError+GREYAdditions.h"
#import "Additions/NSObject+GREYAdditions.h"
#import "Common/GREYCoder.h"
#import "Common/GREYDefines.h"
#import "Common/GREYVisibilityChecker.h"
#import "Core/GREYInteraction.h"
Expand Down Expand Up @@ -88,8 +89,7 @@ - (instancetype)initWithType:(GREYTapType)tapType
duration:duration
numberOfTaps:numberOfTaps];
self = [super initWithName:name
constraints:grey_allOf(grey_not(grey_systemAlertViewShown()),
grey_anyOf(grey_accessibilityElement(),
constraints:grey_allOf(grey_anyOf(grey_accessibilityElement(),
grey_kindOfClass([UIView class]),
nil),
grey_enabled(),
Expand All @@ -105,6 +105,20 @@ - (instancetype)initWithType:(GREYTapType)tapType
return self;
}

- (instancetype)initWithCoder:(NSCoder *)coder {
return [self initWithType:[coder decodeIntegerForKey:@"type"]
numberOfTaps:[GREYCoder decodeNSUInteger:[coder decodeObjectForKey:@"numberOfTaps"]]
duration:[coder decodeDoubleForKey:@"duration"]
location:[GREYCoder decodeCGPoint:[coder decodeObjectForKey:@"tapLocation"]]];
}

- (void)encodeWithCoder:(NSCoder *)coder {
[coder encodeInteger:_type forKey:@"type"];
[coder encodeObject:[GREYCoder encodeNSUInteger:_numberOfTaps] forKey:@"numberOfTaps"];
[coder encodeDouble:_duration forKey:@"duration"];
[coder encodeObject:[GREYCoder encodeCGPoint:_tapLocation] forKey:@"tapLocation"];
}

#pragma mark - GREYAction protocol

- (BOOL)perform:(id)element error:(__strong NSError **)errorOrNil {
Expand Down
Loading