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

Glossary Removal #1316

Closed
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
34 changes: 16 additions & 18 deletions AppFramework/Action/GREYActions.m
Original file line number Diff line number Diff line change
Expand Up @@ -573,24 +573,24 @@ + (void)initialize {
}
// Wait for keyboard to show up and any other UI changes to take effect.
if (![GREYKeyboard waitForKeyboardToAppear]) {
NSString *description =
@"Keyboard did not appear after tapping on [Element]. "
@"Are you sure that tapping on this element will bring up the keyboard?";
__block NSString *elementDescription;
grey_dispatch_sync_on_main_thread(^{
elementDescription = [element grey_description];
});
NSDictionary<NSString *, NSString *> *glossary = @{@"Element" : elementDescription};
I_GREYPopulateErrorNoted(errorOrNil, kGREYInteractionErrorDomain,
kGREYInteractionActionFailedErrorCode, description,
glossary);
NSString *description
= [NSString stringWithFormat:
@"Keyboard did not appear after tapping on an element. "
@"\nAre you sure that tapping on this element will bring up the keyboard?"
@"\nElement: \n%@", element];
I_GREYPopulateError(errorOrNil, kGREYInteractionErrorDomain,
kGREYInteractionActionFailedErrorCode, description);
return NO;
}
}

// If a position is given, move the text cursor to that position.
__block id firstResponder = nil;
__block NSDictionary<NSString *, NSString *> *errorGlossary = nil;
__block NSString *description = nil;
grey_dispatch_sync_on_main_thread(^{
firstResponder = [[expectedFirstResponderView window] firstResponder];
if (position) {
Expand All @@ -599,20 +599,18 @@ + (void)initialize {
toPosition:position];
[firstResponder setSelectedTextRange:newRange];
} else {
errorGlossary = @{
@"First Responder" : [firstResponder description],
@"Element" : [expectedFirstResponderView description]
};
description
= [NSString stringWithFormat:
@"First Responder of Element does not conform to UITextInput protocol."
@"\nFirst Responder: %@ \nElement: %@", [firstResponder description],
[expectedFirstResponderView description]];
}
}
});

if (errorGlossary) {
NSString *description = @"[First Responder] of [Element] does not conform to "
@"UITextInput protocol.";
I_GREYPopulateErrorNoted(errorOrNil, kGREYInteractionErrorDomain,
kGREYInteractionActionFailedErrorCode, description,
errorGlossary);
if (description) {
I_GREYPopulateError(errorOrNil, kGREYInteractionErrorDomain,
kGREYInteractionActionFailedErrorCode, description);
return NO;
}

Expand Down
11 changes: 5 additions & 6 deletions AppFramework/Action/GREYChangeStepperAction.m
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,11 @@ - (GREYStepperButtons *)grey_stepperButtonsForStepper:(UIStepper *)stepper
});

if (!(foundMinusButton && foundPlusButton)) {
NSString *description = [NSString stringWithFormat:@"Failed to find stepper buttons "
@"in [Stepper]"];
NSDictionary<NSString *, NSString *> *glossary = @{@"[Stepper]" : [stepper description]};

I_GREYPopulateErrorNoted(error, kGREYInteractionErrorDomain,
kGREYInteractionActionFailedErrorCode, description, glossary);
NSString *description
= [NSString stringWithFormat:@"Failed to find stepper buttons in stepper:\n"
@"%@", [stepper description]];
I_GREYPopulateError(error, kGREYInteractionErrorDomain,
kGREYInteractionActionFailedErrorCode, description);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format

return nil;
}
return
Expand Down
10 changes: 5 additions & 5 deletions AppFramework/Action/GREYMultiFingerSwipeAction.m
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ - (BOOL)perform:(id)element error:(__strong NSError **)error {
} else {
NSString *errorDescription =
[NSString stringWithFormat:
@"Cannot perform multi-finger swipe on view [V], as it has "
@"no window and it isn't a window itself."];
I_GREYPopulateErrorNoted(error, kGREYSyntheticEventInjectionErrorDomain,
kGREYOrientationChangeFailedErrorCode, errorDescription,
@{@"V" : [element grey_description]});
@"Cannot perform multi-finger swipe on the following view, as it has "
@"no window and it isn't a window itself:\n"
@"%@", [element grey_description]];
I_GREYPopulateError(error, kGREYSyntheticEventInjectionErrorDomain,
kGREYOrientationChangeFailedErrorCode, errorDescription);
return;
}
}
Expand Down
12 changes: 5 additions & 7 deletions AppFramework/Action/GREYPickerAction.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,11 @@ - (BOOL)grey_perform:(UIPickerView *)pickerView error:(__strong NSError **)error
NSInteger componentCount = [dataSource numberOfComponentsInPickerView:pickerView];

if (componentCount < _column) {
NSString *description = [NSString stringWithFormat:@"Invalid column on [Picker] "
@"cannot find the column %lu.",
(unsigned long)_column];
NSDictionary<NSString *, NSString *> *glossary = @{@"Picker" : [pickerView description]};
I_GREYPopulateErrorNoted(error, kGREYInteractionErrorDomain,
kGREYInteractionActionFailedErrorCode, description, glossary);

NSMutableString *description = [NSMutableString stringWithFormat:@"Failed to Find Picker Column."];
[description appendFormat:@"\n\nColumn: %lu", (unsigned long)_column];
[description appendFormat:@"\n\nPicker: %@\n", [pickerView description]];
I_GREYPopulateError(error, kGREYInteractionErrorDomain,
kGREYInteractionActionFailedErrorCode, description);
return NO;
}

Expand Down
41 changes: 14 additions & 27 deletions AppFramework/Action/GREYPinchAction.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ - (BOOL)perform:(id)element error:(__strong NSError **)error {
[viewToPinch isKindOfClass:[UIWindow class]] ? (UIWindow *)viewToPinch : viewToPinch.window;

if (!window) {
NSString *errorDescription = [NSString stringWithFormat:@"Cannot pinch on [View], "
NSString *errorDescription = [NSString stringWithFormat:@"Cannot pinch on this view "
@"as it has no window "
@"and it isn't a window itself."];
NSDictionary<NSString *, NSString *> *glossary = @{@"View" : element};
I_GREYPopulateErrorNoted(error, kGREYPinchErrorDomain, kGREYPinchFailedErrorCode,
errorDescription, glossary);
@"and it isn't a window itself:"
@"\n%@", element];
I_GREYPopulateError(error, kGREYPinchErrorDomain,
kGREYPinchFailedErrorCode, errorDescription);
return;
}

Expand All @@ -117,29 +117,16 @@ - (NSArray *)calculateTouchPaths:(UIView *)view
error:(__strong NSError **)error {
CGRect pinchActionFrame = CGRectIntersection(view.accessibilityFrame, window.bounds);
if (CGRectIsNull(pinchActionFrame)) {
NSMutableDictionary *errorDetails = [[NSMutableDictionary alloc] init];

errorDetails[kErrorDetailActionNameKey] = self.name;
errorDetails[kErrorDetailElementKey] = [view grey_description];
errorDetails[kErrorDetailWindowKey] = window.description;
errorDetails[kErrorDetailRecoverySuggestionKey] = @"Make sure the element lies in the window";

NSArray *keyOrder = @[
kErrorDetailActionNameKey, kErrorDetailElementKey, kErrorDetailWindowKey,
kErrorDetailRecoverySuggestionKey
];

NSString *reasonDetail = [GREYObjectFormatter formatDictionary:errorDetails
indent:2
hideEmpty:YES
keyOrder:keyOrder];

NSMutableString *errorDetails;
[errorDetails appendFormat:@"\n%@: %@", kErrorDetailActionNameKey, self.name];
[errorDetails appendFormat:@"\n%@: %@", kErrorDetailElementKey, [view grey_description]];
[errorDetails appendFormat:@"\n%@: %@", kErrorDetailWindowKey, window.description];
[errorDetails appendFormat:@"\n%@: %@", kErrorDetailRecoverySuggestionKey,
@"Make sure the element lies in the window"];
NSString *reason = [NSString
stringWithFormat:@"Cannot apply pinch action on the element. Error: %@\n", reasonDetail];

I_GREYPopulateErrorNoted(error, kGREYPinchErrorDomain, kGREYPinchFailedErrorCode, reason,
@{@"V" : view});

stringWithFormat:@"Cannot apply pinch action on the element."
@"\nError Details: %@", errorDetails];
I_GREYPopulateError(error, kGREYPinchErrorDomain, kGREYPinchFailedErrorCode, reason);
return nil;
}

Expand Down
14 changes: 6 additions & 8 deletions AppFramework/Action/GREYSwipeAction.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,12 @@ - (BOOL)perform:(id)element error:(__strong NSError **)error {
window = (UIWindow *)element;
} else {
NSString *errorDescription =
[NSString stringWithFormat:@"Cannot swipe on [View], as it has no window and "
@"it isn't a window itself."];
NSDictionary<NSString *, NSString *> *glossary = @{@"View" : [element grey_description]};
GREYError *injectionError =
GREYErrorMakeWithHierarchy(kGREYSyntheticEventInjectionErrorDomain,
kGREYOrientationChangeFailedErrorCode, errorDescription);
injectionError.descriptionGlossary = glossary;
*error = injectionError;
[NSString stringWithFormat:@"Cannot swipe on this view as it has no window and "
@"isn't a window itself:"
@"\n%@", [element grey_description]];
*error = GREYErrorMakeWithHierarchy(kGREYSyntheticEventInjectionErrorDomain,
kGREYOrientationChangeFailedErrorCode,
errorDescription);
return;
}
}
Expand Down
10 changes: 4 additions & 6 deletions AppFramework/Action/GREYTapAction.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,10 @@ - (BOOL)perform:(id)element error:(__strong NSError **)error {
});
if (!window) {
NSString *description =
[NSString stringWithFormat:@"[Element] is not attached to a window."];
NSDictionary<NSString *, NSString *> *glossary = @{@"Element" : [element grey_description]};

I_GREYPopulateErrorNoted(error, kGREYInteractionErrorDomain,
kGREYInteractionActionFailedErrorCode, description, glossary);

[NSString stringWithFormat:@"Element is not attached to a window:"
@"\n%@", [element grey_description]];
I_GREYPopulateError(error, kGREYInteractionErrorDomain,
kGREYInteractionActionFailedErrorCode, description);
return NO;
}
return [GREYTapper tapOnWindow:window
Expand Down
21 changes: 7 additions & 14 deletions AppFramework/Assertion/GREYAssertions.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,15 @@ @implementation GREYAssertions
GREYStringDescription *mismatch = [[GREYStringDescription alloc] init];
if (![matcher matches:element describingMismatchTo:mismatch]) {
NSMutableString *reason = [[NSMutableString alloc] init];
NSMutableDictionary<NSString *, NSString *> *glossary = [[NSMutableDictionary alloc] init];
if (!element) {
[reason appendFormat:@"Assertion with [Matcher] failed: No UI element was matched."];
glossary[@"Matcher"] = [matcher description];

I_GREYPopulateErrorNoted(errorOrNil, kGREYInteractionErrorDomain,
kGREYInteractionElementNotFoundErrorCode, reason, glossary);
[reason appendFormat:@"Assertion with Matcher failed: No UI element was matched.\n"];
[reason appendFormat:@"Matcher: \n%@", [matcher description]];
I_GREYPopulateError(errorOrNil, kGREYInteractionErrorDomain,
kGREYInteractionElementNotFoundErrorCode, reason);
} else {
[reason appendFormat:@"Assertion with [Matcher] failed: UI [Element] failed to match "
@"the following matcher(s): [Mismatch]"];
glossary[@"Matcher"] = [matcher description];
glossary[@"Element"] = [element grey_description];
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add these back in to the reason

glossary[@"Mismatch"] = [mismatch description];

I_GREYPopulateErrorNoted(errorOrNil, kGREYInteractionErrorDomain,
kGREYInteractionAssertionFailedErrorCode, reason, glossary);
[reason appendFormat:@"An assertion failed."];
I_GREYPopulateError(errorOrNil, kGREYInteractionErrorDomain,
kGREYInteractionAssertionFailedErrorCode, reason);
}
return NO;
}
Expand Down
2 changes: 1 addition & 1 deletion AppFramework/Core/GREYElementInteraction.m
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ - (NSError *)grey_errorToReturnForInteractionError:(GREYError *)interactionError
if ([interactionError isKindOfClass:[GREYError class]]) {
wrappedError = I_GREYErrorMake(
interactionError.domain, interactionError.code, userInfo, interactionError.filePath,
interactionError.line, interactionError.functionName, interactionError.descriptionGlossary,
interactionError.line, interactionError.functionName,
interactionError.stackTrace, hierarchy, appScreenshots);
} else {
// In case the error is an internal error from a custom matcher or assertion, just convert it
Expand Down
27 changes: 2 additions & 25 deletions AppFramework/Error/GREYAppError.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#define GREYErrorMakeWithHierarchy(domain, code, description) \
I_GREYErrorMake((domain), (code), @{NSLocalizedDescriptionKey : (description)}, \
[NSString stringWithUTF8String:__FILE__], __LINE__, \
[NSString stringWithUTF8String:__PRETTY_FUNCTION__], nil, \
[NSString stringWithUTF8String:__PRETTY_FUNCTION__], \
[NSThread callStackSymbols], [GREYElementHierarchy hierarchyString], \
[GREYFailureScreenshotter screenshots])

Expand All @@ -62,7 +62,7 @@
(domain), (code), \
@{NSLocalizedDescriptionKey : (description), NSUnderlyingErrorKey : (nestedError)}, \
[NSString stringWithUTF8String:__FILE__], __LINE__, \
[NSString stringWithUTF8String:__PRETTY_FUNCTION__], nil, [NSThread callStackSymbols], nil, \
[NSString stringWithUTF8String:__PRETTY_FUNCTION__], [NSThread callStackSymbols], nil, \
nil)

/**
Expand All @@ -86,29 +86,6 @@
} \
})

/**
* If @c errorRef is not @c NULL, it is set to a @c GREYError object that is created with
* the given @c domain, @c code, @c description and @c note.
* The description is accessible by querying error's @c userInfo with
* @c NSLocalizedDescriptionKey.
*
* @param[out] errorRef A @c GREYError reference for retrieving the created
* error object.
* @param domain The error domain.
* @param code The error code.
* @param description The error's localized description.
* @param glossary A glossary dictionary that is going to be populated with the error.
*
*/
#define I_GREYPopulateErrorNoted(errorRef, domain, code, description, glossary) \
({ \
GREYError *e = GREYErrorMakeWithHierarchy((domain), (code), (description)); \
e.descriptionGlossary = (glossary); \
if (errorRef) { \
*errorRef = e; \
} \
})

/**
* If @c errorRef is not @c NULL, it is set to a @c GREYError object that is created
* with the given @c domain, @c code, @c description and @c nestedError.
Expand Down
15 changes: 11 additions & 4 deletions AppFramework/Synchronization/GREYUIThreadExecutor.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#import "GREYDefines.h"
#import "GREYLogger.h"
#import "GREYStopwatch.h"
#import "GREYObjectFormatter.h"

// Extern.
NSString *const kGREYUIThreadExecutorErrorDomain =
Expand Down Expand Up @@ -203,10 +204,16 @@ - (BOOL)executeSyncWithTimeout:(CFTimeInterval)seconds
if (!isAppIdle) {
NSOrderedSet *busyResources = [self grey_busyResources];
if ([busyResources count] > 0) {
NSString *description = @"Failed to execute block because idling resources are busy.";
I_GREYPopulateErrorNoted(error, kGREYUIThreadExecutorErrorDomain,
kGREYUIThreadExecutorTimeoutErrorCode, description,
[self grey_errorDictionaryForBusyResources:busyResources]);
NSDictionary *errorDictionary = [self grey_errorDictionaryForBusyResources:busyResources];
NSString *busyResources = [GREYObjectFormatter formatDictionary:errorDictionary
indent:2
hideEmpty:YES
keyOrder:errorDictionary.allKeys];
NSString *description = [NSString stringWithFormat:@"Failed to execute block because idling resources are busy.\n%@",
busyResources];
I_GREYPopulateError(error, kGREYUIThreadExecutorErrorDomain,
kGREYUIThreadExecutorTimeoutErrorCode,
description);
} else {
I_GREYPopulateError(error, kGREYUIThreadExecutorErrorDomain,
kGREYUIThreadExecutorTimeoutErrorCode,
Expand Down
5 changes: 0 additions & 5 deletions CommonLib/Error/GREYError+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ GREY_EXTERN NSString *const kErrorAppUIHierarchyKey;
*/
GREY_EXTERN NSString *const kErrorAppScreenShotsKey;

/**
* Key used to retrieve the description glossary from an error object dictionary.
*/
GREY_EXTERN NSString *const kErrorDescriptionGlossaryKey;

@interface GREYError (Private)

@property(nonatomic) NSString *testCaseClassName;
Expand Down
Loading