Unverified Commit b484a912 authored by Dan Field's avatar Dan Field Committed by GitHub

add2app test (#27712)

* add2app test
parent ad68ba30
...@@ -141,6 +141,7 @@ task: ...@@ -141,6 +141,7 @@ task:
- tests-macos - tests-macos
- tool_tests-macos - tool_tests-macos
- build_tests-macos - build_tests-macos
- add2app-macos
env: env:
# Name the SDK directory to include a space so that we constantly # Name the SDK directory to include a space so that we constantly
# test path names with spaces in them. # test path names with spaces in them.
...@@ -168,11 +169,12 @@ task: ...@@ -168,11 +169,12 @@ task:
task: task:
use_compute_credits: $CIRRUS_USER_COLLABORATOR == 'true' use_compute_credits: $CIRRUS_USER_COLLABORATOR == 'true'
osx_instance: osx_instance:
image: high-sierra-xcode-9.4.1 image: mojave-xcode-10.1
depends_on: depends_on:
- analyze - analyze
env: env:
CIRRUS_WORKING_DIR: "/tmp/flutter sdk" CIRRUS_WORKING_DIR: "/tmp/flutter sdk"
COCOAPODS_DISABLE_STATS: true
install_cocoapods_script: install_cocoapods_script:
- sudo gem install cocoapods - sudo gem install cocoapods
git_fetch_script: git_fetch_script:
...@@ -208,7 +210,9 @@ task: ...@@ -208,7 +210,9 @@ task:
container: container:
cpu: 4 cpu: 4
memory: 12G memory: 12G
- name: add2app-macos
env:
SHARD: add2app_test
docker_builder: docker_builder:
# Only build a new docker image when we tag a release (for dev, beta, or release.) # Only build a new docker image when we tag a release (for dev, beta, or release.)
......
...@@ -23,6 +23,7 @@ const Map<String, ShardRunner> _kShards = <String, ShardRunner>{ ...@@ -23,6 +23,7 @@ const Map<String, ShardRunner> _kShards = <String, ShardRunner>{
'tool_tests': _runToolTests, 'tool_tests': _runToolTests,
'build_tests': _runBuildTests, 'build_tests': _runBuildTests,
'coverage': _runCoverage, 'coverage': _runCoverage,
'add2app_test': _runAdd2AppTest,
}; };
const Duration _kLongTimeout = Duration(minutes: 45); const Duration _kLongTimeout = Duration(minutes: 45);
...@@ -236,6 +237,21 @@ Future<void> _flutterBuildIpa(String relativePathToApplication) async { ...@@ -236,6 +237,21 @@ Future<void> _flutterBuildIpa(String relativePathToApplication) async {
print('Done.'); print('Done.');
} }
Future<void> _runAdd2AppTest() async {
if (!Platform.isMacOS) {
return;
}
print('Running Add2App iOS integration tests...');
final String add2AppDir = path.join(flutterRoot, 'dev', 'integration_tests', 'ios_add2app');
await runCommand('./build_and_test.sh',
<String>[],
workingDirectory: add2AppDir,
expectNonZeroExit: false,
timeout: _kShortTimeout,
);
print('Done.');
}
Future<void> _runTests() async { Future<void> _runTests() async {
await _runSmokeTests(); await _runSmokeTests();
......
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
.DS_Store
## Build generated
build/
DerivedData/
## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/
## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint
## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM
# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
#
# Add this line if you want to avoid checking in source code from the Xcode workspace
# *.xcworkspace
# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts
Carthage/Build
# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/test_output
# Code Injection
#
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode
iOSInjectionProject/
\ No newline at end of file
Copyright 2014 The Chromium Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
platform :ios, '12.0'
flutter_application_path = 'flutterapp/'
framework_dir = File.join(flutter_application_path, '.ios', 'Flutter')
engine_dir = File.join(framework_dir, 'engine')
if !File.exist?(engine_dir)
# Copy the debug engine to have something to link against if the xcode backend script has not run yet.
debug_framework_dir = File.join(flutter_root(flutter_application_path), 'bin', 'cache', 'artifacts', 'engine', 'ios')
FileUtils.mkdir_p(engine_dir)
FileUtils.cp_r(File.join(debug_framework_dir, 'Flutter.framework'), engine_dir)
FileUtils.cp(File.join(debug_framework_dir, 'Flutter.podspec'), engine_dir)
end
target 'ios_add2app' do
eval(File.read(File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb')), binding)
end
target 'ios_add2appTests' do
pod 'Flutter', :path => engine_dir
inherit! :search_paths
pod 'EarlGrey'
end
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
/**
* Umbrella public header for the EarlGrey framework.
*
* Instead of importing individual headers, import this header using:
* @code
* @import EarlGrey; // if your project uses modules
* @endcode
* OR if your project doesn't use modules:
* @code
* #import <EarlGrey/EarlGrey.h>
* @endcode
*
* To learn more, check out: http://github.com/google/EarlGrey
*/
#import <Foundation/Foundation.h>
#import <EarlGrey/GREYAction.h>
#import <EarlGrey/GREYActionBlock.h>
#import <EarlGrey/GREYActions.h>
#import <EarlGrey/GREYBaseAction.h>
#import <EarlGrey/GREYScrollActionError.h>
#import <EarlGrey/GREYIdlingResource.h>
#import <EarlGrey/GREYAssertion.h>
#import <EarlGrey/GREYAssertionBlock.h>
#import <EarlGrey/GREYAssertionDefines.h>
#import <EarlGrey/GREYAssertions.h>
#import <EarlGrey/GREYConfiguration.h>
#import <EarlGrey/GREYConstants.h>
#import <EarlGrey/GREYDefines.h>
#import <EarlGrey/GREYElementHierarchy.h>
#import <EarlGrey/GREYScreenshotUtil.h>
#import <EarlGrey/GREYTestHelper.h>
#import <EarlGrey/EarlGreyImpl.h>
#import <EarlGrey/GREYElementFinder.h>
#import <EarlGrey/GREYElementInteraction.h>
#import <EarlGrey/GREYInteraction.h>
#import <EarlGrey/GREYFailureHandler.h>
#import <EarlGrey/GREYFrameworkException.h>
#import <EarlGrey/GREYAllOf.h>
#import <EarlGrey/GREYAnyOf.h>
#import <EarlGrey/GREYBaseMatcher.h>
#import <EarlGrey/GREYDescription.h>
#import <EarlGrey/GREYElementMatcherBlock.h>
#import <EarlGrey/GREYLayoutConstraint.h>
#import <EarlGrey/GREYMatcher.h>
#import <EarlGrey/GREYMatchers.h>
#import <EarlGrey/GREYNot.h>
#import <EarlGrey/GREYDataEnumerator.h>
#import <EarlGrey/GREYProvider.h>
#import <EarlGrey/GREYCondition.h>
#import <EarlGrey/GREYDispatchQueueIdlingResource.h>
#import <EarlGrey/GREYManagedObjectContextIdlingResource.h>
#import <EarlGrey/GREYNSTimerIdlingResource.h>
#import <EarlGrey/GREYOperationQueueIdlingResource.h>
#import <EarlGrey/GREYSyncAPI.h>
#import <EarlGrey/GREYUIThreadExecutor.h>
//
// Copyright 2018 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <EarlGrey/GREYDefines.h>
@class GREYElementInteraction, GREYFrameworkException;
@protocol GREYMatcher, GREYFailureHandler;
/**
* Convenience replacement for every EarlGrey method call with
* EarlGreyImpl::invokedFromFile:lineNumber: so it can get the invocation file and line to
* report to XCTest on failure.
*/
#define EarlGrey \
[EarlGreyImpl invokedFromFile:[NSString stringWithUTF8String:__FILE__] ?: @"UNKNOWN FILE" \
lineNumber:__LINE__]
NS_ASSUME_NONNULL_BEGIN
/**
* Key for currently set failure handler for EarlGrey in thread's local storage dictionary.
*/
GREY_EXTERN NSString *const kGREYFailureHandlerKey;
/**
* Error domain for keyboard dismissal.
*/
GREY_EXTERN NSString *const kGREYKeyboardDismissalErrorDomain;
/**
* Error code for keyboard dismissal actions.
*/
typedef NS_ENUM(NSInteger, GREYKeyboardDismissalErrorCode) {
/**
* The keyboard dismissal failed.
*/
GREYKeyboardDismissalFailedErrorCode = 0, // Keyboard Dismissal failed.
};
/**
* Entrypoint to the EarlGrey framework.
* Use methods of this class to initiate interaction with any UI element on the screen.
*/
@interface EarlGreyImpl : NSObject
/**
* Provides the file name and line number of the code that is calling into EarlGrey.
* In case of a failure, the information is used to tell XCTest the exact line which caused
* the failure so it can be highlighted in the IDE.
*
* @param fileName The name of the file where the failing code exists.
* @param lineNumber The line number of the failing code.
*
* @return An EarlGreyImpl instance, with details of the code invoking EarlGrey.
*/
+ (instancetype)invokedFromFile:(NSString *)fileName lineNumber:(NSUInteger)lineNumber;
/**
* @remark init is not an available initializer. Use the <b>EarlGrey</b> macro to start an
* interaction.
*/
- (instancetype)init NS_UNAVAILABLE;
/**
* Creates a pending interaction with a single UI element on the screen.
*
* In this step, a matcher is supplied to EarlGrey which is later used to sift through the elements
* in the UI Hierarchy. This method only denotes that you have an intent to perform an action and
* packages a GREYElementInteraction object to do so.
* The interaction is *actually* started when it's performed with a @c GREYAction or
* @c GREYAssertion.
*
* An interaction will fail when multiple elements are matched. In that case, you will have to
* refine the @c elementMatcher to match a single element or use GREYInteraction::atIndex: to
* specify the index of the element in the list of elements matched.
*
* By default, EarlGrey looks at all the windows from front to back and
* searches for the UI element. To focus on a specific window or container, use
* GREYElementInteraction::inRoot: method.
*
* For example, this code will match a UI element with accessibility identifier "foo"
* inside a custom UIWindow of type MyCustomWindow:
* @code
* [[EarlGrey selectElementWithMatcher:grey_accessibilityID(@"foo")]
* inRoot:grey_kindOfClass([MyCustomWindow class])]
* @endcode
*
* @param elementMatcher The matcher specifying the UI element that will be targeted by the
* interaction.
*
* @return A GREYElementInteraction instance, initialized with an appropriate matcher.
*/
- (GREYElementInteraction *)selectElementWithMatcher:(id<GREYMatcher>)elementMatcher;
/**
* Sets the global failure handler for all framework related failures.
*
* A default failure handler is provided by the framework and it is @b strongly advised to use
* that if you don't need to customize error handling in your test. Passing in @c nil will revert
* the failure handler to default framework provided failure handler.
*
* @param handler The failure handler to be used for all test failures.
*/
- (void)setFailureHandler:(_Nullable id<GREYFailureHandler>)handler;
/**
* Convenience wrapper to invoke GREYFailureHandler::handleException:details: on the global
* failure handler.
*
* @param exception The exception to be handled.
* @param details Any extra details about the failure.
*/
- (void)handleException:(GREYFrameworkException *)exception details:(NSString *)details;
/**
* Rotate the device to a given @c deviceOrientation. All device orientations except for
* @c UIDeviceOrientationUnknown are supported. If a non-nil @c errorOrNil is provided, it will
* be populated with the failure reason if the orientation change fails, otherwise a test failure
* will be registered.
*
* @param deviceOrientation The desired orientation of the device.
* @param[out] errorOrNil Error that will be populated on failure. If @c nil, a test
* failure will be reported if the rotation attempt fails.
*
* @return @c YES if the rotation was successful, @c NO otherwise.
*/
- (BOOL)rotateDeviceToOrientation:(UIDeviceOrientation)deviceOrientation
errorOrNil:(__strong NSError **)errorOrNil;
/**
* Shakes the device. If a non-nil @c errorOrNil is provided, it will
* be populated with the failure reason if the orientation change fails, otherwise a test failure
* will be registered.
*
* @param[out] errorOrNil Error that will be populated on failure. If @c nil, the a test
* failure will be reported if the shake attempt fails.
*
* @throws GREYFrameworkException if the action fails and @c errorOrNil is @c nil.
* @return @c YES if the shake was successful, @c NO otherwise. If @c errorOrNil is @c nil and
* the operation fails, it will throw an exception.
*/
- (BOOL)shakeDeviceWithError:(__strong NSError **)errorOrNil;
/**
* Dismisses the keyboard by resigning the first responder, if any. Will populate the provided
* error if the first responder is not present or if the keyboard is not visible.
*
* @param[out] errorOrNil Error that will be populated on failure. If @c nil, a test
* failure will be reported if the dismissing fails.
*
* @return @c YES if the dismissing of the keyboard was successful, @c NO otherwise.
*/
- (BOOL)dismissKeyboardWithError:(__strong NSError **)errorOrNil;
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
* A protocol for actions that are performed on accessibility elements.
*/
@protocol GREYAction<NSObject>
/**
* Perform the action specified by the GREYAction object on an @c element if and only if the
* @c element matches the constraints of the action.
*
* @param element The element the action is to be performed on. This must not be @c nil.
* @param[out] errorOrNil Error that will be populated on failure. The implementing class should
* handle the behavior when it is @c nil by, for example, logging the error
* or throwing an exception.
*
* @return @c YES if the action succeeded, else @c NO. If an action returns @c NO, it does not
* mean that the action was not performed at all but somewhere during the action execution
* the error occurred and so the UI may be in an unrecoverable state.
*/
- (BOOL)perform:(id)element error:(__strong NSError *_Nullable *)errorOrNil;
/**
* A method to get the name of this action.
*
* @return The name of the action. If the action fails, then the name is printed along with all
* other relevant information.
*/
- (NSString *)name;
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <EarlGrey/GREYBaseAction.h>
@protocol GREYMatcher;
NS_ASSUME_NONNULL_BEGIN
/**
* Block type for defining the action's 'perform' code.
*
* @param element The element on which the block is going to be performed.
* @param[out] errorOrNil The error set on failure. The error returned can be @c nil, signifying
* that the action succeeded.
*
* @throws NSException when there is a failure and @c errorOrNil is not provided
* (i.e. it is @c nil).
*
* @return @c YES if the action performed succeeded, else @c NO.
*/
typedef BOOL (^GREYPerformBlock)(id element, __strong NSError *_Nullable *errorOrNil);
/**
* A class for creating block based GREYAction.
*/
@interface GREYActionBlock : GREYBaseAction
/**
* Creates a GREYAction that performs the action in the provided @c block.
*
* @param name The name of the action
* @param block A block that contains the action to execute.
*
* @return A GREYActionBlock instance with the given name.
*/
+ (instancetype)actionWithName:(NSString *)name performBlock:(GREYPerformBlock)block;
/**
* Creates a GREYAction that performs the action in the provided @c block subject to the
* provided @c constraints.
*
* @param name The name of the action.
* @param constraints Constraints that must be satisfied before the action is performed
* This is optional and can be @c nil.
* @param block A block that contains the action to execute.
*
* @return A GREYActionBlock instance with the given name and constraints.
*/
+ (instancetype)actionWithName:(NSString *)name
constraints:(id<GREYMatcher> _Nullable)constraints
performBlock:(GREYPerformBlock)block;
/**
* @remark init is not an available initializer. Use the other initializers.
*/
- (instancetype)init NS_UNAVAILABLE;
/**
* @remark initWithName::constraints: is overridden from its superclass.
*/
- (instancetype)initWithName:(NSString *)name
constraints:(id<GREYMatcher>)constraints NS_UNAVAILABLE;
/**
* Designated Initializer.
*
* @param name The name of the action.
* @param constraints Constraints that must be satisfied before the action is performed
* This is optional and can be @c nil.
* @param block A block that contains the action to execute.
*
* @return A GREYActionBlock instance with the given name and constraints.
*/
- (instancetype)initWithName:(NSString *)name
constraints:(id<GREYMatcher> _Nullable)constraints
performBlock:(GREYPerformBlock)block NS_DESIGNATED_INITIALIZER;
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <Foundation/Foundation.h>
#import <EarlGrey/GREYDefines.h>
#import <EarlGrey/GREYBaseMatcher.h>
NS_ASSUME_NONNULL_BEGIN
/**
* A matcher for combining multiple matchers with a logical @c AND operator, so that a match
* only occurs when all combined matchers match the element. The invocation of the matchers
* is in the same order in which they are passed. As soon as one matcher fails, the
* rest of the matchers are not invoked.
*/
@interface GREYAllOf : GREYBaseMatcher
/**
* @remark init is not an available initializer. Use the other initializers.
*/
- (instancetype)init NS_UNAVAILABLE;
/**
* Designated initializer that adds the different matchers to be combined.
*
* @param matchers Matchers that conform to GREYMatcher and will be combined together with
* a logical AND in the order they are passed in.
*
* @return An instance of GREYAllOf, initialized with the provided @c matchers.
*/
- (instancetype)initWithMatchers:(NSArray<__kindof id<GREYMatcher>> *)matchers
NS_DESIGNATED_INITIALIZER;
#if !(GREY_DISABLE_SHORTHAND)
/**
* A shorthand matcher that is a logical AND of all the matchers passed in as variable arguments.
*
* @param first The first matcher in the list of matchers.
* @param second The second matcher in the list of matchers.
* @param thirdOrNil The third matcher in the list of matchers, optionally the nil terminator.
* @param ... Any more matchers to be added. Matchers are invoked in the order they are
* specified and only if the preceding matcher passes. This va-arg must be
* terminated with a @c nil value.
*
* @return An object conforming to GREYMatcher, initialized with the required matchers.
*/
GREY_EXPORT id<GREYMatcher> grey_allOf(id<GREYMatcher> first,
id<GREYMatcher> second,
id<GREYMatcher> _Nullable thirdOrNil,
...)
NS_SWIFT_UNAVAILABLE("Use grey_allOf(_:) instead") NS_REQUIRES_NIL_TERMINATION;
/**
* A shorthand matcher that is a logical AND of all the matchers passed in within an NSArray.
*
* @param matchers An NSArray of one or more matchers to be added. Matchers are invoked in the
* order they are specified and only if the preceding matcher passes.
*
* @return An object conforming to GREYMatcher, initialized with the required matchers.
*/
GREY_EXPORT id<GREYMatcher>
grey_allOfMatchers(NSArray<__kindof id<GREYMatcher>> *matchers)
NS_SWIFT_NAME(grey_allOf(_:));
#endif // GREY_DISABLE_SHORTHAND
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <Foundation/Foundation.h>
#import <EarlGrey/GREYDefines.h>
#import <EarlGrey/GREYBaseMatcher.h>
NS_ASSUME_NONNULL_BEGIN
/**
* Matcher for combining multiple matchers with a logical @c OR operator, so that a match occurs
* when any of the matchers match the element. The invocation of the matchers is in the same
* order in which they are passed. As soon as one of the matchers succeeds, the rest are
* not invoked.
*/
@interface GREYAnyOf : GREYBaseMatcher
/**
* @remark init is not an available initializer. Use the other initializers.
*/
- (instancetype)init NS_UNAVAILABLE;
/**
* Designated initializer to add all the matchers to be checked.
*
* @param matchers The matchers, one of which is required to be matched by the matcher.
* They are invoked in the order that they are passed in.
*
* @return An instance of GREYAnyOf, initialized with the provided matchers.
*/
- (instancetype)initWithMatchers:(NSArray<__kindof id<GREYMatcher>> *)matchers
NS_DESIGNATED_INITIALIZER;
#if !(GREY_DISABLE_SHORTHAND)
/**
* A matcher that is a logical OR of all the matchers passed in as variable arguments.
*
* @param first The first matcher in the list of matchers.
* @param second The second matcher in the list of matchers.
* @param thirdOrNil The third matcher in the list of matchers, optionally the nil terminator.
* @param ... Any more matchers to be added. Matchers are invoked in the order they are
* specified and only if the preceding matcher fails.
* This va-arg must be terminated with a @c nil value.
*
* @return An object conforming to GREYMatcher, initialized with the required matchers.
*/
GREY_EXPORT id<GREYMatcher> grey_anyOf(id<GREYMatcher> first,
id<GREYMatcher> second,
id<GREYMatcher> _Nullable thirdOrNil,
...)
NS_SWIFT_UNAVAILABLE("Use grey_anyOf(_:) instead")
NS_REQUIRES_NIL_TERMINATION;
/**
* A matcher that is a logical OR of all the matchers passed in within an NSArray.
*
* @param matchers An array of one more matchers to be added. Matchers are invoked in the order
* they are specified and only if the preceding matcher fails.
*
* @return An object conforming to GREYMatcher, initialized with the required matchers.
*/
GREY_EXPORT id<GREYMatcher> grey_anyOfMatchers(NSArray<__kindof id<GREYMatcher>> *matchers)
NS_SWIFT_NAME(grey_anyOf(_:));
#endif // GREY_DISABLE_SHORTHAND
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
* Protocol to which EarlGrey assertion classes must conform.
*/
@protocol GREYAssertion<NSObject>
/**
* Checks whether the assertion is valid for the provided @c element, throwing an exception if the
* if the assertion fails and the @c errorOrNil parameter is @c nil. If a non-nil @c errorOrNil is
* provided, it will be set to error that represents the assertion failure cause.
* If the assertion does not accept @c nil elements, the error domain should be
* @c kGREYInteractionErrorDomain and the error code @c kGREYInteractionElementNotFoundErrorCode.
* GREYAssertionDefines.h defines macros for throwing common exception types.
*
* @param element Element on which the assertion should be checked.
* @param[out] errorOrNil If non-nil, set to the cause of the assertion failure.
*
* @throws NSException If the assertion fails and the provided @c errorOrNil is @c nil.
* The specific type depends on the implementation.
*
* @return @c YES if the assertion holds for the specified element, @c NO otherwise.
*/
- (BOOL)assert:(_Nullable id)element error:(__strong NSError *_Nullable *_Nullable)errorOrNil;
/**
* @return The name of the assertion.
*/
- (NSString *)name;
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <EarlGrey/GREYAssertion.h>
NS_ASSUME_NONNULL_BEGIN
/**
* A block that accepts an @c element, which will be invoked when an assertion is going to be
* performed on the element. If the assertion fails and a non-nil @c errorOrNil is provided,
* the block should populate it with the cause of failure.
*
* @param element Element that the assertion will be checked against.
* @param[out] errorOrNil If non-nil, set to the cause of the assertion failure.
*
* @return @c YES if the assertion is valid for @c element, @c NO otherwise.
*/
typedef BOOL (^GREYCheckBlockWithError)(_Nullable id element,
__strong NSError *_Nullable *_Nullable errorOrNil);
/**
* An interface to create GREYAssertions from blocks.
*/
@interface GREYAssertionBlock : NSObject<GREYAssertion>
/**
* Creates an assertion with the given @c name and @c block that is executed when
* GREYAssertion::assert:error: selector is performed on the assertion.
*
* @param name The assertion name.
* @param block The block that will be invoked to perform the assertion.
*
* @return A new block-based assertion object.
*/
+ (instancetype)assertionWithName:(NSString *)name
assertionBlockWithError:(GREYCheckBlockWithError)block;
/**
* @remark init is not an available initializer. Use the other initializers.
*/
- (instancetype)init NS_UNAVAILABLE;
/**
* Initializes an assertion with the given @c name and @c block that is executed when
* GREYAssertion::assert:error: selector is performed on the assertion.
*
* @param name The assertion name.
* @param block The block that will be invoked to perform the assertion.
*
* @return The initialized assertion object.
*/
- (instancetype)initWithName:(NSString *)name
assertionBlockWithError:(GREYCheckBlockWithError)block NS_DESIGNATED_INITIALIZER;
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <Foundation/Foundation.h>
/**
* An interface that exposes UI element assertions.
*/
@interface GREYAssertions : NSObject
@end
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <EarlGrey/GREYAction.h>
@protocol GREYMatcher;
NS_ASSUME_NONNULL_BEGIN
/**
* A base class for all actions that incorporates commonalities between initialization
* parameters and constraint checking.
*/
@interface GREYBaseAction : NSObject<GREYAction>
/**
* @remark init is not an available initializer. Use the other initializers.
*/
- (instancetype)init NS_UNAVAILABLE;
/**
* The designated initializer for a base action with the provided @c constraints.
*
* @param name The name of the GREYAction being performed.
*
* @param constraints The constraints to be satisified by the element before the
* action is performed.
*
* @return An instance of GREYBaseAction, initialized with the @c constraints for it to check for.
*/
- (instancetype)initWithName:(NSString *)name
constraints:(id<GREYMatcher>)constraints NS_DESIGNATED_INITIALIZER;
/**
* A method that checks that @c element satisfies @c constraints this action was initialized with.
* Subclasses should call this method if they want to check for constraints in their perform:error:
* implementation.
*
* @param element A UI element being checked for the @c constraints.
* @param[out] errorOrNilPtr Error stored when an element did not satisfy the @c constraints.
* If an error is set but this pointer is @c nil,
* then an action failed exception is thrown.
*
* @throws GREYFrameworkException if constraints fail and @c errorOrNilPtr is not provided.
*
* @return @c YES if the constraints are satisfied on the element. @c NO otherwise.
*/
- (BOOL)satisfiesConstraintsForElement:(id)element error:(__strong NSError **)errorOrNilPtr;
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <Foundation/Foundation.h>
#import <EarlGrey/GREYMatcher.h>
NS_ASSUME_NONNULL_BEGIN
/**
* A base class that implements the GREYMatcher protocol methods.
* Prefer subclassing this class over creating your own matchers.
* Every subclass must override and provide its own implementation for GREYBaseMatcher::matches:
* and GREYBaseMatcher::describeTo: methods.
*/
@interface GREYBaseMatcher : NSObject<GREYMatcher, NSCopying>
#pragma mark - GREYMatcher
/**
* @see GREYMatcher::matches:
*
* @remark Subclasses are required to implement this method.
*/
- (BOOL)matches:(_Nullable id)item;
/**
* @see GREYMatcher::describeTo:
*
* @remark Subclasses are required to implement this method.
*/
- (void)describeTo:(id<GREYDescription>)description;
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
* A class for creating boolean conditions that can be waited on until the condition is satisfied
* or a timeout elapses.
*
* Conditions are specified in the form of a block that returns a @c BOOL value indicating whether
* the condition is met.
*/
@interface GREYCondition : NSObject
/**
* Creates a condition with a block that should return @c YES when the condition is met.
*
* @param name A descriptive name for the condition
* @param conditionBlock The block that will be used to evaluate the condition.
*
* @return A new initialized GREYCondition instance.
*/
+ (instancetype)conditionWithName:(NSString *)name block:(BOOL(^)(void))conditionBlock;
/**
* @remark init is not an available initializer. Use the other initializers.
*/
- (instancetype)init NS_UNAVAILABLE;
/**
* Initializes a condition with a block that should return @c YES when the condition is met.
*
* @param name A descriptive name for the condition
* @param conditionBlock The block that will be used to evaluate the condition.
*
* @return The initialized instance.
*/
- (instancetype)initWithName:(NSString *)name
block:(BOOL(^)(void))conditionBlock NS_DESIGNATED_INITIALIZER;
/**
* Waits for the condition to be met until the specified @c seconds have elapsed.
*
* Will poll the condition as often as possible on the main thread while still giving a fair chance
* for other sources and handlers to be serviced.
*
* @remark Waiting on conditions with this method is very CPU intensive on the main thread. If
* you do not need to return immediately after the condition is met, the consider using
* GREYCondition::waitWithTimeout:pollInterval:
*
* @param seconds Amount of time to wait for the condition to be met, in seconds.
*
* @return @c YES if the condition was met before the timeout, @c NO otherwise.
*/
- (BOOL)waitWithTimeout:(CFTimeInterval)seconds;
/**
* Waits for the condition to be met until the specified @c seconds have elapsed. Will poll the
* condition immediately and then no more than once every @c interval seconds. Will attempt to poll
* the condition as close as possible to every @c interval seconds.
*
* @remark Will allow the main thread to sleep instead of busily checking the condition.
*
* @param seconds Amount of time to wait for the condition to be met, in seconds.
* @param interval The minimum time that should elapse between checking the condition.
*
* @return @c YES if the condition was met before the timeout, @c NO otherwise.
*/
- (BOOL)waitWithTimeout:(CFTimeInterval)seconds pollInterval:(CFTimeInterval)interval;
/**
* @return Name of the condition.
*/
- (NSString *)name;
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <UIKit/UIKit.h>
#import <EarlGrey/GREYDefines.h>
NS_ASSUME_NONNULL_BEGIN
/**
* Any alpha less than this value is considered hidden by Apple.
* @see
* https://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/uiview/uiview.html#//apple_ref/occ/instm/UIView/hitTest:withEvent:
*/
GREY_EXTERN const CGFloat kGREYMinimumVisibleAlpha;
/**
* Amount of time a "fast" swipe should last for, in seconds.
*/
GREY_EXTERN const CFTimeInterval kGREYSwipeFastDuration;
/**
* Amount of time a "slow" swipe should last for, in seconds.
*/
GREY_EXTERN const CFTimeInterval kGREYSwipeSlowDuration;
/**
* Amount of time a "fast" pinch should last for, in seconds
*/
GREY_EXTERN const CFTimeInterval kGREYPinchFastDuration;
/**
* Amount of time a "slow" pinch should last for, in seconds
*/
GREY_EXTERN const CFTimeInterval kGREYPinchSlowDuration;
/**
* Infinite timeout.
*/
GREY_EXTERN const CFTimeInterval kGREYInfiniteTimeout;
/**
* Limit on the number of UIPickerViews that can be pulled for getting the hierarchy.
*/
GREY_EXTERN const NSInteger kUIPickerViewMaxAccessibilityViews;
/**
* Amount of time a normal long press should last for, in seconds. Extracted from:
* @see
* https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UILongPressGestureRecognizer_Class/index.html#//apple_ref/occ/instp/UILongPressGestureRecognizer/minimumPressDuration
*/
GREY_EXTERN const CFTimeInterval kGREYLongPressDefaultDuration;
/**
* Minimum acceptable difference between two floating-point values when comparing them.
*/
GREY_EXTERN const CGFloat kGREYAcceptableFloatDifference;
/**
* NSUserDefaults key for checking if verbose logging is turned on. (i.e. logs with
* GREYLogVerbose are printed.)
*/
GREY_EXTERN NSString *const kGREYAllowVerboseLogging;
/**
* The default pinch angle for the pinch action, specified by an approximate angle for a right
* handed two finger pinch.
*/
GREY_EXTERN const double kGREYPinchAngleDefault;
/**
* Directions for scrolling and swiping.
*
* The direction describes the motion of the view port as a result of the swipe, which is opposite
* to the direction the user's finger moves. For example, a scroll down the page should be
* expressed with @c kGREYDirectionDown as it simulates a touch that starts somewhere in the middle
* of the screen and moves up to simulate an absolute scroll down behavior.
*/
typedef NS_ENUM(NSInteger, GREYDirection) {
/**
* The finger is moving to the right, view port is moving left.
*/
kGREYDirectionLeft = 1,
/**
* The finger is moving to the left, view port is moving right.
*/
kGREYDirectionRight,
/**
* The finger is moving downwards, view port is moving up.
*/
kGREYDirectionUp,
/**
* The finger is moving upwards, view port is moving down.
*/
kGREYDirectionDown,
};
/**
* Directions for pinch gesture.
*
* The direction describes the motion of the view port as a result of pinch. There are two
* possible directions for pinch action inward and outward.
*/
typedef NS_ENUM(NSInteger, GREYPinchDirection) {
/**
* Two fingers pinching outward.
*/
kGREYPinchDirectionOutward = 1,
/**
* Two fingers pinching inward.
*/
kGREYPinchDirectionInward,
};
/**
* Content edges for scrolling.
*/
typedef NS_ENUM(NSInteger, GREYContentEdge) {
/**
* The left content edge of the screen in the current orientation.
*/
kGREYContentEdgeLeft,
/**
* The right content edge of the screen in the current orientation.
*/
kGREYContentEdgeRight,
/**
* The top content edge of the screen in the current orientation.
*/
kGREYContentEdgeTop,
/**
* The bottom content edge of the screen in the current orientation.
*/
kGREYContentEdgeBottom,
};
/**
* Directions for layout specification.
*/
typedef NS_ENUM(NSInteger, GREYLayoutDirection) {
/**
* To the left of the current element.
*/
kGREYLayoutDirectionLeft = 1,
/**
* To the right of the current element.
*/
kGREYLayoutDirectionRight,
/**
* Above the current element.
*/
kGREYLayoutDirectionUp,
/**
* Below the current element.
*/
kGREYLayoutDirectionDown,
};
/**
* Layout attributes for matching on layouts (modelled after @c NSLayoutAttribute).
*/
typedef NS_ENUM(NSInteger, GREYLayoutAttribute) {
/**
* The left edge of element.
*/
kGREYLayoutAttributeLeft = 1,
/**
* The right edge of element.
*/
kGREYLayoutAttributeRight,
/**
* The top edge of element.
*/
kGREYLayoutAttributeTop,
/**
* The bottom edge of element.
*/
kGREYLayoutAttributeBottom,
};
/**
* Layout relations for comparison of layout attributes (modelled after @c NSLayoutRelation).
*/
typedef NS_ENUM(NSInteger, GREYLayoutRelation) {
/**
* Value is less than or equal to the other operand.
*/
kGREYLayoutRelationLessThanOrEqual = -1,
/**
* Value is equal to the other operand.
*/
kGREYLayoutRelationEqual = 0,
/**
* Value is greater than or equal to the other operand.
*/
kGREYLayoutRelationGreaterThanOrEqual = 1,
};
/**
* Types of tap actions
*/
typedef NS_ENUM(NSInteger, GREYTapType) {
/**
* Tap action for basic tap.
*/
kGREYTapTypeShort,
/**
* Tap action for long press tap.
*/
kGREYTapTypeLong,
/**
* Tap action for multiple taps (for example double tap).
*/
kGREYTapTypeMultiple,
/**
* Tap action for keyboard keys.
*/
kGREYTapTypeKBKey,
};
/**
* @return A string representation of the given @c deviceOrientation.
*/
NSString *NSStringFromUIDeviceOrientation(UIDeviceOrientation deviceOrientation);
/**
* @return A string representation of the given @c direction.
*/
NSString *NSStringFromGREYDirection(GREYDirection direction);
/**
* Returns a string representation of the given @c pinchDirection.
*/
NSString *NSStringFromPinchDirection(GREYPinchDirection pinchDirection);
/**
* @return A string representation of the given @c edge.
*/
NSString *NSStringFromGREYContentEdge(GREYContentEdge edge);
/**
* @return A string representation of the given layout @c attribute.
*/
NSString *NSStringFromGREYLayoutAttribute(GREYLayoutAttribute attribute);
/**
* @return A string representation of the given layout @c relation.
*/
NSString *NSStringFromGREYLayoutRelation(GREYLayoutRelation relation);
/**
* @return A string representation of the given accessibility trait.
*/
NSString *NSStringFromUIAccessibilityTraits(UIAccessibilityTraits traits);
/**
* A class containing helper methods for conversion to-and-from constants.
*/
@interface GREYConstants : NSObject
/**
* @return The direction from center to the given @c edge.
*/
+ (GREYDirection)directionFromCenterForEdge:(GREYContentEdge)edge;
/**
* @return The edge that is in the given @c direction from the center.
*/
+ (GREYContentEdge)edgeInDirectionFromCenter:(GREYDirection)direction;
/**
* @return The reverse direction of the given @c direction.
*/
+ (GREYDirection)reverseOfDirection:(GREYDirection)direction;
/**
* @return A normalized vector in the given @c direction.
*/
+ (CGVector)normalizedVectorFromDirection:(GREYDirection)direction;
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
* An block-based enumerator that repeatedly invokes the block to return the next object.
*/
@interface GREYDataEnumerator : NSEnumerator
/**
* @remark init is not an available initializer. Use the other initializers.
*/
- (instancetype)init NS_UNAVAILABLE;
/**
* Instantiates the enumerator with custom information and a block to return the next object.
*
* @param userInfo Custom object that is passed into the block. Use this for passing any
* additional information required by the block.
* @param nextObjectBlock A block that is invoked to return the next object in the enumerator.
*
* @return An instance of GREYDataEnumerator, initialized with the specified information.
*/
- (instancetype)initWithUserInfo:(id)userInfo
block:(id(^)(id))nextObjectBlock NS_DESIGNATED_INITIALIZER;
#pragma mark - NSEnumerator
/**
* @return The next object in the enumerator returned by the @c nextObjectBlock.
*/
- (id _Nullable)nextObject;
/**
* @return An array of all the objects in the enumerator.
*/
- (NSArray *)allObjects;
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
/**
* @file GREYDefines.h
* @brief Miscellaneous defines and macros for EarlGrey.
*/
#import <UIKit/UIKit.h>
#ifndef GREY_DEFINES_H
#define GREY_DEFINES_H
#define GREY_EXPORT FOUNDATION_EXPORT __used
#define GREY_EXTERN FOUNDATION_EXTERN
#define GREY_UNUSED_VARIABLE __attribute__((unused))
#define iOS8_0_OR_ABOVE() ([UIDevice currentDevice].systemVersion.doubleValue >= 8.0)
#define iOS8_1_OR_ABOVE() ([UIDevice currentDevice].systemVersion.doubleValue >= 8.1)
#define iOS8_2_OR_ABOVE() ([UIDevice currentDevice].systemVersion.doubleValue >= 8.2)
#define iOS9_OR_ABOVE() ([UIDevice currentDevice].systemVersion.intValue >= 9)
#define iOS10_OR_ABOVE() ([UIDevice currentDevice].systemVersion.intValue >= 10)
#define iOS11_OR_ABOVE() ([UIDevice currentDevice].systemVersion.intValue >= 11)
#pragma mark - Math
/**
* @return The smallest @c int following the @c double @c x. This macro is needed to avoid
* rounding errors when "modules" project setting is enabled causing math functions to
* map from tgmath.h to math.h.
*/
#define grey_ceil(x) ((CGFloat)ceil(x))
/**
* @return The largest @c int less than the @c double @c x. This macro is needed to avoid
* rounding errors when "modules" project setting is enabled causing math functions to
* map from tgmath.h to math.h.
*/
#define grey_floor(x) ((CGFloat)floor(x))
#endif // GREY_DEFINES_H
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
* A protocol that defines the layout of an object that conforms to GREYMatcher.
*/
@protocol GREYDescription<NSObject>
/**
* Appends the provided text to the GREYDescription.
*
* @param text The text to be appended to the GREYDescription.
*
* @return An instance of an object conforming to GREYDescription with the provided
* @c text appended to it.
*/
- (id<GREYDescription>)appendText:(NSString *)text;
/**
* Appends the description of the provided object to the GREYDescription.
*
* @param object The object whose description is to be appended to the GREYDescription.
*
* @return An instance of an object conforming to GREYDescription with the provided
* object's description appended to it.
*/
- (id<GREYDescription>)appendDescriptionOf:(id)object;
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <EarlGrey/GREYIdlingResource.h>
NS_ASSUME_NONNULL_BEGIN
/**
* Idling resource that tracks blocks sent to a dispatch queue.
*/
@interface GREYDispatchQueueIdlingResource : NSObject<GREYIdlingResource>
/**
* Creates an idling resource backed by the specified @c queue.
*
* @c dispatch_sync blocks and dispatch_sync_f tasks sent to @c queue are tracked.
* @c dispatch_async blocks and @c dispatch_async_f tasks sent to @c queue are tracked.
* @c dispatch_after blocks and @c dispatch_after_f tasks sent to @c queue are tracked if they are
* delayed no more than the delay amount set for the
* @c kGREYConfigKeyTrackableDispatchAfterDuration configuration. A weak reference is held to
* @c queue. If @c queue is deallocated, then the idling resource will deregister itself from the
* UI thread executor.
*
* @param queue The dispatch queue that will be tracked by the resource.
* @param name A descriptive name for the idling resource.
*
* @return An idling resource backed by the specified dispatch queue.
*/
+ (instancetype)resourceWithDispatchQueue:(dispatch_queue_t)queue name:(NSString *)name;
/**
* @remark init is not an available initializer. Use the other initializers.
*/
- (instancetype)init NS_UNAVAILABLE;
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <Foundation/Foundation.h>
@protocol GREYMatcher, GREYProvider;
NS_ASSUME_NONNULL_BEGIN
/**
* Finds UI elements in GREYProvider that are accepted by a matcher.
*/
@interface GREYElementFinder : NSObject
/**
* The matcher the element finder is initialized with. Objects returned from this class
* must match this matcher.
*/
@property(nonatomic, readonly) id<GREYMatcher> matcher;
/**
* @remark init is not an available initializer. Use the other initializers.
*/
- (instancetype)init NS_UNAVAILABLE;
/**
* Initializes the finder with a given @c matcher.
*
* @param matcher Matcher that defines what elements the finder should search for.
*
* @return An instance of GREYElementFinder, initialized with a matcher.
*/
- (instancetype)initWithMatcher:(id<GREYMatcher>)matcher NS_DESIGNATED_INITIALIZER;
/**
* Performs a search on elements provided by @c elementProvider and returns all the elements
* that are accepted by the matcher this object is initialized with.
*
* @param elementProvider Provides elements to run through the matcher.
*
* @return An array of matched elements. If no matching element is found, then it is empty.
* The relative order of the elements is preserved when returned.
*/
- (NSArray *)elementsMatchedInProvider:(id<GREYProvider>)elementProvider;
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
* A utility to get the string representation of the UI hierarchy.
*/
@interface GREYElementHierarchy : NSObject
/**
* Returns UI hierarchy with @c element as the root. @c element can be either a UIView or an
* Accessibility element.
*
* @param element The root element for the hierarchy.
*
* @return The UI hierarchy as a string.
*/
+ (NSString *)hierarchyStringForElement:(id)element;
/**
* Similar to hierarchyStringForElement: with additional parameters for providing annotations
* for printed views. @c annotationDictionary is a dictionary of type
* @code @{[NSValue valueWithNonretainedObject:id]:NSString} @endcode with UI elements that
* require special formatting i.e. special text to be appended to the description. For example,
* @code @{viewA : @"This is a special view"} @endcode or
* @code @{elementA : @"This is a special view"} @endcode will have it's description as:
* @"<DESCRIPTION> This is a special view".
*
* @param element The root element for the hierarchy.
* @param annotationDictionary A dictionary of annotations.
*
* @return The UI hierarchy as a string.
*/
+ (NSString *)hierarchyStringForElement:(id)element
withAnnotationDictionary:(NSDictionary *_Nullable)annotationDictionary;
/**
* Returns the UI hierarchy for all @c UIWindows provided by the GREYUIWindowProvider.
*/
+ (NSString *)hierarchyStringForAllUIWindows;
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <Foundation/Foundation.h>
#import <EarlGrey/GREYInteraction.h>
NS_ASSUME_NONNULL_BEGIN
/**
* Interface for creating an interaction with a UI element. If no datasource is set,
* a default datasource is used. The default datasource provides access to the entire UI element
* hierarchy of all the windows in the application.
*/
@interface GREYElementInteraction : NSObject<GREYInteraction>
/**
* @remark init is not an available initializer. Use the other initializers.
*/
- (instancetype)init NS_UNAVAILABLE;
/**
* Initializes the interaction with a single UI element matching @c elementMatcher.
*
* @param elementMatcher Matcher for selecting UI element to interact with.
*
* @return An instance of GREYElementInteraction, initialized with a specified matcher.
*/
- (instancetype)initWithElementMatcher:(id<GREYMatcher>)elementMatcher;
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <EarlGrey/GREYBaseMatcher.h>
NS_ASSUME_NONNULL_BEGIN
/**
* A block for implementing GREYBaseMatcher::matches:.
*
* @param element The element passed to the block for matching.
*
* @return @c YES if the matcher's specified condition was matched by the element, else @c NO.
*/
typedef BOOL (^MatchesBlock)(id element);
/**
* A block for implementing GREYBaseMatcher::describeTo:.
*
* @param description The description for the matcher.
*/
typedef void (^DescribeToBlock)(id<GREYDescription> description);
@protocol GREYDescription;
/**
* A block based implementation of GREYBaseMatcher. Enables custom implementation of protocol
* method using blocks.
*/
@interface GREYElementMatcherBlock : GREYBaseMatcher
/**
* The block which will be invoked for the GREYBaseMatcher::matches: method.
*/
@property(nonatomic, copy) MatchesBlock matcherBlock;
/**
* The block which will be invoked for the GREYBaseMatcher::describeTo: method.
*/
@property(nonatomic, copy) DescribeToBlock descriptionBlock;
/**
* Class method to instantiate a custom matcher.
*
* @param matchBlock A block for implementing GREYBaseMatcher::matches: method.
* @param describeBlock The block which will be invoked for the GREYBaseMatcher::describeTo:
* method.
*
* @return A GREYElementMatcherBlock instance, initialized with the required matching
* condition and description.
*/
+ (instancetype)matcherWithMatchesBlock:(MatchesBlock)matchBlock
descriptionBlock:(DescribeToBlock)describeBlock;
/**
* @remark init is not an available initializer. Use the other initializers.
*/
- (instancetype)init NS_UNAVAILABLE;
/**
* Initializes a custom matcher.
*
* @param matchBlock A block for implementing GREYBaseMatcher::matches: method.
* @param describeBlock The block which will be invoked for the
* GREYBaseMatcher::describeTo: method.
*
* @return A GREYElementMatcherBlock instance, initialized with the required matching
* condition and description.
*/
- (instancetype)initWithMatchesBlock:(MatchesBlock)matchBlock
descriptionBlock:(DescribeToBlock)describeBlock NS_DESIGNATED_INITIALIZER;
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <Foundation/Foundation.h>
@class GREYFrameworkException;
NS_ASSUME_NONNULL_BEGIN
/**
* Protocol for handling failures (such as failure of actions and assertions) raised by EarlGrey.
*/
@protocol GREYFailureHandler<NSObject>
/**
* Called by the framework to raise an exception.
*
* @param exception The exception to be handled.
* @param details Extra information about the failure.
*/
- (void)handleException:(GREYFrameworkException *)exception details:(NSString *)details;
@optional
/**
* Sets the file name and line number of operation that caused the failure.
*
* @param fileName The name of the file where the error happened.
* @param lineNumber The line number in the file that caused the error.
*/
- (void)setInvocationFile:(NSString *)fileName andInvocationLine:(NSUInteger)lineNumber;
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <Foundation/Foundation.h>
#import <EarlGrey/GREYDefines.h>
NS_ASSUME_NONNULL_BEGIN
/**
* Generic framework failure.
*/
GREY_EXTERN NSString *const kGREYGenericFailureException;
/**
* Thrown on action failure.
*/
GREY_EXTERN NSString *const kGREYActionFailedException;
/**
* Thrown on assertion failure.
*/
GREY_EXTERN NSString *const kGREYAssertionFailedException;
/**
* Thrown when assertion failed due to an unexpected @c nil parameter.
*/
GREY_EXTERN NSString *const kGREYNilException;
/**
* Thrown when assertion failed due to an unexpected non-nil parameter.
*/
GREY_EXTERN NSString *const kGREYNotNilException;
/**
* Thrown by the selection API when no UI element matches the selection matcher.
*/
GREY_EXTERN NSString *const kGREYNoMatchingElementException;
/**
* Thrown by the interaction API when either an action or assertion matcher matches multiple
* elements in the UI hierarchy.
*/
GREY_EXTERN NSString *const kGREYMultipleElementsFoundException;
/**
* Thrown by the interaction API when either an action or assertion times out waiting for the
* app to become idle.
*/
GREY_EXTERN NSString *const kGREYTimeoutException;
/**
* Thrown by the action API when the constraints required for performing the action are not
* satisfied.
*/
GREY_EXTERN NSString *const kGREYConstraintFailedException;
/**
* Exception raised by the framework which results in a test failure.
* To catch such exceptions, install a custom failure handler
* using EarlGrey::setFailureHandler:. A default failure handler is provided by the framework.
*/
@interface GREYFrameworkException : NSException
/**
* @remark init is not an available initializer. Use the other initializers.
*/
- (instancetype)init NS_UNAVAILABLE;
/**
* Creates a new exception instance.
*
* @param name The name of the exception.
* @param reason The reason for the exception.
*
* @return A GREYFrameworkException instance, initialized with a @c name and @c reason.
*/
+ (instancetype)exceptionWithName:(NSString *)name reason:(nullable NSString *)reason;
/**
* Creates a new exception instance.
*
* @param name The name of the exception.
* @param reason The reason for the exception.
* @param userInfo userInfo as used by @c NSException.
* EarlGrey doesn't use this param so it's safe to pass nil.
*
* @return A GREYFrameworkException instance, initialized with a @c name and @c reason.
*/
+ (instancetype)exceptionWithName:(NSString *)name
reason:(nullable NSString *)reason
userInfo:(nullable NSDictionary *)userInfo;
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
* A protocol for resources that can potentially modify the UI and should be synchronized with
* before performing any interaction or verification with UI element.
*/
@protocol GREYIdlingResource<NSObject>
/**
* A method to query idleness of this resource.
*
* Note: This method is called on the main thread and polled continuously until this resource goes
* into idle state or a test timeout occurs. It is discouraged to perform any heavy tasks in this
* method.
*
* @return @c YES if the resource is currently idle; @c NO otherwise.
*/
- (BOOL)isIdleNow;
/**
* @return A user friendly name that will be printed if this resource fails to idle leading to a
* test timeout.
*/
- (NSString *)idlingResourceName;
/**
* @return Information that will be printed alongside the name if this resource fails to idle in
* the given timeout.
*/
- (NSString *)idlingResourceDescription;
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <EarlGrey/GREYConstants.h>
NS_ASSUME_NONNULL_BEGIN
/**
* Modeled after NSLayoutConstraint, this class captures information related to a layout
* constraint: two attributes and a relation that must be satisfied between them.
*/
@interface GREYLayoutConstraint : NSObject
/**
* Creates a GREYLayoutConstraint to verify a constraint attribute on an element. The relation is
* given by : @c attribute value = @c referenceAttribute * @c multiplier + @c constant.
*
* For example, with constraint relation @c kGREYLayoutRelationEqual, multiplier 2.0 and
* constant 10.0, the attribute values of 20.0 and 5.0 satisfy the constraint because:
* 20.0 = 5.0 * 2.0 + 10.0 but 30.0 and 40.0 don't because 30.0 != 40.0 * 2.0 + 10.0.
*
* @param attribute A layout attribute to create the constraint from.
* @param relation The GREYLayoutRelation between the @c attribute and
* the @c referenceAttribute
* @param referenceAttribute The layout attribute whose relation is being checked
* with respect to @attribute.
* @param multiplier Value to multiply the @c referenceAttribute value.
* @param constant Any constant to be added to the relation being checked.
*
* @return A GREYLayoutConstraint instance, that constrains an element's attribute with
* respect to a reference.
*/
+ (instancetype)layoutConstraintWithAttribute:(GREYLayoutAttribute)attribute
relatedBy:(GREYLayoutRelation)relation
toReferenceAttribute:(GREYLayoutAttribute)referenceAttribute
multiplier:(CGFloat)multiplier
constant:(CGFloat)constant;
/**
* Creates a GREYLayoutConstraint that checks the position of a UI element with respect to a
* particular direction
*
* @param direction The direction being checked against the reference element.
* @param separation The separation between an element and an edge in the given @c direction.
*
* @return A GREYLayoutConstraint instance that constrains an element to a particular direction.
*/
+ (instancetype)layoutConstraintForDirection:(GREYLayoutDirection)direction
andMinimumSeparation:(CGFloat)separation;
/**
* @remark init is not an available initializer. Use the other initializers.
*/
- (instancetype)init NS_UNAVAILABLE;
/**
* Checks if the given element satisfies the provided constraints, as shown by a reference element.
*
* @param element The element being checked for the constraints.
* @param referenceElement The reference element to check the @c element against.
*
* @return @c YES if the the given elements satisify the constraint, else @NO.
*/
- (BOOL)satisfiedByElement:(id)element andReferenceElement:(id)referenceElement;
/**
* @return A description of the GREYLayoutConstraint created.
*/
- (NSString *)description;
/**
* The attribute constraint being checked.
*/
@property(nonatomic, assign) GREYLayoutAttribute attribute;
/**
* The GREYLayoutRelation between the @c attribute and the @c referenceAttribute.
*/
@property(nonatomic, assign) GREYLayoutRelation relation;
/**
* The value the @c attribute is being compared to.
*/
@property(nonatomic, assign) GREYLayoutAttribute referenceAttribute;
/**
* Value to multiply the @c referenceAttribute value with.
*/
@property(nonatomic, assign) CGFloat multiplier;
/**
* Any constant to be added to the relation being checked.
*/
@property(nonatomic, assign) CGFloat constant;
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <EarlGrey/GREYIdlingResource.h>
@class NSManagedObjectContext;
NS_ASSUME_NONNULL_BEGIN
/**
* Idling resource that tracks core data managed object context operations.
*
* Tracks the managed object context's internal operation queue and optionally any pending changes
* yet to be committed.
*/
@interface GREYManagedObjectContextIdlingResource : NSObject<GREYIdlingResource>
/**
* Creates an idling resource tracking @c managedObjectContext.
*
* A weak reference is held to @c managedObjectContext. If @c managedObjectContext is deallocated,
* then the idling resource will deregister itself from the thread executor.
*
* @param managedObjectContext The managed object context to be tracked by the resource.
* @param trackPendingChanges If @c YES, then the idling resource will report that it is busy
* when the managed object context has pending changes.
* @param name A descriptive name for the idling resource.
*
* @return An idling resource tracking @c managedObjectContext.
*/
+ (instancetype)resourceWithManagedObjectContext:(NSManagedObjectContext *)managedObjectContext
trackPendingChanges:(BOOL)trackPendingChanges
name:(NSString *)name;
/**
* @remark init is not an available initializer. Use the other initializers.
*/
- (instancetype)init NS_UNAVAILABLE;
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <Foundation/Foundation.h>
#import <EarlGrey/GREYDescription.h>
NS_ASSUME_NONNULL_BEGIN
/**
* Matchers are another way of expressing simple or complex logical expressions. This protocol
* defines a set of methods that must be implemented by every matcher object.
*/
@protocol GREYMatcher<NSObject>
/**
* A method to evaluate the matcher for the provided @c item.
*
* @param item The object which is to be evaluated against the matcher.
*
* @return @c YES if the object matched the matcher, @c NO otherwise.
*/
- (BOOL)matches:(_Nullable id)item;
/**
* A method to evaluate the matcher for the provided @c item with a description for the issue
* in case of a mismatch.
*
* @param item The object which is to be evaluated against the matcher.
*
* @param mismatchDescription The description that is built or appended if the provided @c item
* does not match the matcher.
*
* @return @c YES if the object matched the matcher, @c NO otherwise. In case of a mismatch, the
* reason for mismatch is added to @c mismatchDescription.
*/
- (BOOL)matches:(_Nullable id)item describingMismatchTo:(id<GREYDescription>)mismatchDescription;
/**
* A method to generate the description containing the reason for why a matcher did not match an
* item.
*
* @param item The object which is to be evaluated against the matcher.
*
* @param mismatchDescription The description that is built or appended if the provided @c item
* does not match the matcher.
*
* @remark This method assumes that GREYMatcher::matches: is false, but will not check this.
*/
- (void)describeMismatchOf:(_Nullable id)item to:(id<GREYDescription>)mismatchDescription;
/**
* A method to generate a description of an object.
*
* @param description The description that is built or appended.
*/
- (void)describeTo:(id<GREYDescription>)description;
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <EarlGrey/GREYIdlingResource.h>
NS_ASSUME_NONNULL_BEGIN
/**
* An idling resource to track NSTimer firing events so that the framework can synchronize
* with them.
*/
@interface GREYNSTimerIdlingResource : NSObject<GREYIdlingResource>
/**
* @remark init is not an available initializer. Use the other initializers.
*/
- (instancetype)init NS_UNAVAILABLE;
/**
* Creates an idling resource that tracks the specified @c timer, causing actions to wait until
* the timer is fired or invalidated. If @c removeOnIdle is @c YES, the idling resource will
* automatically remove itself from the list of registered idling resources when it becomes idle.
*
* @param timer The timer that will be tracked by the idling resource.
* @param name A descriptive name for the idling resource.
* @param removeOnIdle Defines whether the resource should unregister itself when it becomes idle.
*
* @return A new and initialized GREYNSTimerIdlingResource instance.
*/
+ (instancetype)trackTimer:(NSTimer *)timer name:(NSString *)name removeOnIdle:(BOOL)removeOnIdle;
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <EarlGrey/GREYDefines.h>
#import <EarlGrey/GREYBaseMatcher.h>
NS_ASSUME_NONNULL_BEGIN
/**
* A matcher to negate the result of another matcher.
*/
@interface GREYNot : GREYBaseMatcher
/**
* @remark init is not an available initializer. Use the other initializers.
*/
- (instancetype)init NS_UNAVAILABLE;
/**
* Initializes this matcher with another @c matcher whose result is negated.
*
* @param matcher A matcher whose result will be negated.
*
* @return An instance of GREYNot, initialized with a matcher.
*/
- (instancetype)initWithMatcher:(id<GREYMatcher>)matcher NS_DESIGNATED_INITIALIZER;
#if !(GREY_DISABLE_SHORTHAND)
/** Shorthand macro for GREYNot::initWithMatcher:. */
GREY_EXPORT id<GREYMatcher> grey_not(id<GREYMatcher> matcher);
#endif // GREY_DISABLE_SHORTHAND
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <EarlGrey/GREYIdlingResource.h>
NS_ASSUME_NONNULL_BEGIN
/**
* Idling resource that monitors operation queues.
*/
@interface GREYOperationQueueIdlingResource : NSObject<GREYIdlingResource>
/**
* Creates an idling resource for monitoring @c queue for idleness.
* A queue is considered idle when it has no pending operations.
* A weak reference is held to @c queue. If @c queue is deallocated, then the idling resource will
* deregister itself from the UI thread executor.
*
* @param queue The queue that will be tracked by the resource.
* @param name A descriptive name for the idling resource.
*
* @return Returns an idling resource for the specified NSOperationQueue.
*/
+ (instancetype)resourceWithNSOperationQueue:(NSOperationQueue *)queue name:(NSString *)name;
/**
* @remark init is not an available initializer. Use the other initializers.
*/
- (instancetype)init NS_UNAVAILABLE;
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
* A protocol for providing arbitrary data as an enumeration.
*/
@protocol GREYProvider<NSObject>
/**
* @return A new enumerator that can be used to enumerate data backed by this provider.
*/
- (NSEnumerator *)dataEnumerator;
@end
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <UIKit/UIKit.h>
#import <EarlGrey/GREYDefines.h>
NS_ASSUME_NONNULL_BEGIN
/**
* Provides interfaces for taking screenshots of the entire screen and UI elements of the App.
*/
@interface GREYScreenshotUtil : NSObject
/**
* Draws the application's main screen using the bitmap graphics context specified by the @c
* bitmapContextRef reference, centering it if the context size is different than the screen size.
* The provided reference must point to a CGBitmapContext. When @c afterUpdates is set to @c YES,
* this method waits for the screen to draw pending changes before taking a screenshot, otherwise
* the screenshot contains the current contents of the screen.
*
* @param bitmapContextRef Target bitmap context for rendering.
* @param afterUpdates Boolean indicating whether to render before (@c NO) or after (@c YES)
* screen updates.
*/
+ (void)drawScreenInContext:(CGContextRef)bitmapContextRef afterScreenUpdates:(BOOL)afterUpdates;
/**
* @return An image of the current app's screen frame buffer. This method waits for any pending
* screen updates to go through before taking a screenshot. Returned image orientation is
* same as the current interface orientation.
*/
+ (UIImage *)takeScreenshot;
/**
* @return The App Store and iTunes Connect friendly image of the current screen frame buffer.
*/
+ (UIImage *)takeScreenshotForAppStore;
/**
* @return A snapshot of the provided @c element. @c element must be an instance of @c UIView or
* an accessibility element.
*/
+ (UIImage *)snapshotElement:(id)element;
/**
* Saves the provided @c image as a PNG to the given @c filename under the given @c directoryPath.
* If the given directory path doesn't exist, it will be created.
*
* @param image The source image.
* @param filename The target file name.
* @param directoryPath The path to the directory where the image must be saved.
*
* @return The complete filepath and name of the saved image or @c nil on failure.
*/
+ (NSString *)saveImageAsPNG:(UIImage *)image
toFile:(NSString *)filename
inDirectory:(NSString *)directoryPath;
@end
/**
* Returns a new buffer that contains XRGB pixels for the provided @c imageRef i.e. the alpha
* channel is removed. If @c outBitmapContext is not @c NULL, it is set to the bitmap context of
* the returned buffer and caller must call CGContextRelease on it. Each pixel in returned buffer
* occupies 4 bytes and the buffer must be free()'d by the caller.
*
* @param imageRef The source image.
* @param[out] outBmpCtx Optional bitmap context that holds the returned buffer.
*
* @return A new buffer that contains XRGB pixels for the provided image.
*/
GREY_EXPORT unsigned char *_Nullable grey_createImagePixelDataFromCGImageRef(
CGImageRef imageRef, CGContextRef _Nullable *_Nullable outBmpCtx);
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <Foundation/Foundation.h>
#import <EarlGrey/GREYDefines.h>
/**
* The Error domain for a scroll error.
*/
GREY_EXTERN NSString *const kGREYScrollErrorDomain;
/**
* Error codes for scrolling related errors.
*/
typedef NS_ENUM(NSInteger, GREYScrollErrorCode) {
/**
* Reached content edge before the entire scroll action was complete.
*/
kGREYScrollReachedContentEdge,
/**
* It is not possible to scroll.
*/
kGREYScrollImpossible,
/**
* Could not scroll to the element we are looking for.
*/
kGREYScrollToElementFailed,
};
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <Foundation/Foundation.h>
#import <EarlGrey/GREYDefines.h>
/**
* @file
* @brief Methods for executing sync or async blocks with EarlGrey operations.
*/
NS_ASSUME_NONNULL_BEGIN
/**
* Executes a block containing EarlGrey statements on the main thread and waits for it to
* complete. @c block is retained until execution completes.
* Important: Must be called from a non-main thread otherwise it will block main thread
* indefinitely.
*
* @param block Block that will be executed.
*/
GREY_EXPORT void grey_execute_sync(void (^block)(void));
/**
* Executes a block containing EarlGrey statements on the main thread without waiting for it to
* complete. @c block is retained until execution completes.
* Can be invoked safely from the main or non-main thread.
*
* @param block Block that will be executed.
*/
GREY_EXPORT void grey_execute_async(void (^block)(void));
NS_ASSUME_NONNULL_END
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
* Provides interface for test helper methods.
*/
@interface GREYTestHelper : NSObject
/**
* Enables fast animation. Invoke in the XCTest setUp method to increase
* the speed of your tests by not having to wait on slow animations.
*/
+ (void)enableFastAnimation;
/**
* Disables fast animation.
*/
+ (void)disableFastAnimation;
@end
NS_ASSUME_NONNULL_END
framework module EarlGrey {
umbrella header "EarlGrey.h"
export *
module * { export * }
}
//
// Copyright 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <QuartzCore/QuartzCore.h>
/**
* An enumeration of all states that EarlGrey identifies a CAAnimation to be in.
*/
typedef NS_ENUM(NSUInteger, GREYCAAnimationState) {
/**
* Default state every animation is in.
*/
kGREYAnimationPendingStart = 0,
/**
* State the animation is in when it begins.
*/
kGREYAnimationStarted,
/**
* State the animation is in when it ends.
*/
kGREYAnimationStopped,
};
NS_ASSUME_NONNULL_BEGIN
/**
* EarlGrey specific addition for CAAnimation to track currently running animations.
*/
@interface CAAnimation (GREYAdditions)
/**
* Sets the animation state to @c state.
*
* @param state The target state.
*/
- (void)grey_setAnimationState:(GREYCAAnimationState)state;
/**
* Returns the current state of the animation. If CAAnimation::grey_setAnimationState was never
* called on this animation, @c kGREYANIMATION_PENDING_START is returned.
*
* @return The current state.
*/
- (GREYCAAnimationState)grey_animationState;
/**
* Tracks the animation with GREYAppStateTracker until the expected animation runtime has elapsed,
* after which it untracks itself.
*/
- (void)grey_trackForDurationOfAnimation;
/**
* Force untrack itself from GREYAppStateTracker, regardless of completion status.
*/
- (void)grey_untrack;
@end
NS_ASSUME_NONNULL_END
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment