Skip to content

Commit

Permalink
Remove unneeded GREYKeyboard method. Add Examples and more samples, t…
Browse files Browse the repository at this point in the history
…ests and any comment/ test changes
  • Loading branch information
tirodkar committed Jul 4, 2016
1 parent d970e65 commit 6cbd0f5
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@
"version" : 1,
"author" : "xcode"
}
}
}

2 changes: 1 addition & 1 deletion EarlGrey/Common/GREYConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ GREY_EXTERN NSString *const kGREYConfigKeyCALayerModifyAnimations;
* specified by this config.
*
* Accepted values: @c double (negative values shouldn't be used)
* Default value: 5.0
* Default value: 10.0
*/
GREY_EXTERN NSString *const kGREYConfigKeyCALayerMaxAnimationDuration;

Expand Down
6 changes: 0 additions & 6 deletions EarlGrey/Core/GREYKeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,4 @@
*/
+ (BOOL)waitForKeyboardToAppear;

/**
* Waits until the keyboard is not visible on the screen.
* @return @c YES if the keyboard did disaappear after the wait, @c NO otherwise.
*/
+ (BOOL)waitForKeyboardToDisappear;

@end
12 changes: 0 additions & 12 deletions EarlGrey/Core/GREYKeyboard.m
Original file line number Diff line number Diff line change
Expand Up @@ -263,18 +263,6 @@ + (BOOL)waitForKeyboardToAppear {
return [keyboardIsShownCondition waitWithTimeout:kKeyboardWillAppearOrDisappearTimeout];
}

+ (BOOL)waitForKeyboardToDisappear {
if (!gIsKeyboardShown) {
return YES;
}
GREYCondition *keyboardIsNotShownCondition =
[[GREYCondition alloc] initWithName:@"Keyboard is will disappear." block:^BOOL {
return !gIsKeyboardShown;
}];
return [keyboardIsNotShownCondition waitWithTimeout:kKeyboardWillAppearOrDisappearTimeout];
}


#pragma mark - Private Methods

/**
Expand Down
2 changes: 0 additions & 2 deletions Scripts/setup-earlgrey.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ obtain_ochamcrest() {
readonly OCHAMCREST_VERSION="OCHamcrest-5.0.0"
# URL for OCHamcrest to be downloaded from.
readonly OCHAMCREST_URL="https://github.com/hamcrest/OCHamcrest/releases/download/v5.0.0/${OCHAMCREST_VERSION}.zip"
# URL for Google Analytics Call.
readonly ANALYTICS_URL="http://www.google-analytics.com/collect?v=1&tid=UA-54227235-2&cid=$RANDOM&ec=Install&ea=Github&ev=1&t=event"

echo "Obtaining the OCHamcrest dependency."

Expand Down
45 changes: 45 additions & 0 deletions docs/examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# EarlGrey Usage Examples
# Add any example of custom matchers, asserts etc. that you have found very
# useful in your EarlGrey tests.

**Selecting the first match via a custom Swift matcher**

When an application has exact duplicate elements (every attribute is the same,
including their hierarchy), then the correct fix is to update the app to avoid
duplicating the UI. When that's not possible, a workaround is to match on
the first element.

```swift
// Swift Custom Matcher
/**
* Example Usage:
*
* EarlGrey().selectElementWithMatcher(grey_allOfMatchers(
* grey_accessibilityID("some_id"),
* grey_interactable(),
* grey_firstElement())).assertWithMatcher(grey_notNil())
*
* Only intended to be used with selectElementWithMatcher. Don't
* use grey_firstElement in assertWithMatcher as it won't do anything.
*/
func grey_firstElement() -> GREYMatcher {
var firstMatch = true
let matches: MatchesBlock = { (element: AnyObject!) -> Bool in
if firstMatch {
firstMatch = false
return true
}

return false
}

let description: DescribeToBlock = { (description: GREYDescription!) -> Void in
guard let description = description else {
return
}
description.appendText("first match")
}

return GREYElementMatcherBlock.init(matchesBlock: matches, descriptionBlock: description)
}
```
43 changes: 39 additions & 4 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ Here's an example of storing an element's text attribute.

```swift
// Swift
/*
/**
* Example Usage:
*
* var textValue:String = ""
*
* domainField.performAction(grey_typeText("hello.there"))
* .performAction(grey_getText(&textValue))
* .performAction(grey_getText(&textValue))
*/
func grey_getText(inout text: String) -> GREYActionBlock {
return GREYActionBlock.actionWithName("get text",
Expand Down Expand Up @@ -181,8 +181,7 @@ GREYConfiguration.sharedInstance()
.setValue(false, forConfigKey: kGREYConfigKeySynchronizationEnabled)
```

Alternatively, conditionally disable the
animation using `#if EARLGREY_ENV`.
Alternatively, conditionally disable the animation using `#if EARLGREY_ENV`.

**How do I match an element when it's duplicated in the app?**

Expand Down Expand Up @@ -367,3 +366,39 @@ When searching for AX=N elements, the following accessibility matchers won't wor

If the `AX=N` element can't be matched by `grey_accessibilityID`, then you'll have to use non-accessibility
matchers to locate the element.

**Why does my Swift project throw compiler errors for all the shorthand matchers?**

A few times, we've noticed Source-Kit issues with Swift projects not finding the EarlGrey C-macros
when the project is built with CocoaPods. This seems to be caused by the naming scheme of the EarlGrey
`Pods/` directory. You might face compilation errors such as :

<img src="images/image12.png" width="900" height="400">

The immediate solution for this is to update your **Xcode version** to the latest one. We can confirm that
the issue does not exist on Xcode 7.3.1. In case that does not work, you can also get rid of this problem by
manually changing the filename for the CocoaPods EarlGrey folder from `Pods/EarlGrey/EarlGrey-1.0.0` to
`Pods/EarlGrey/EarlGrey`. Once this is done, please re-add the`EarlGrey.framework` file in the `Pods/` folder
in your Project Navigator and also completely remove any Framework Search Paths in your target's Build
Settings pointing to `EarlGrey-1.0.0`. The project should run fine now.

**How do I create a custom action in Swift?**

You need to create a new object of type `GREYActionBlock` and call pass it to `performAction`. For example,
take a look at [checkHiddenBlock](../Tests/FunctionalTests/Sources/FTRSwiftTests.swift#L65) in our Functional
Test App's Swift Tests, which creates it as:

```
let checkHiddenBlock:GREYActionBlock =
GREYActionBlock.actionWithName("checkHiddenBlock", performBlock: { element, errorOrNil in
// Check if the found element is hidden or not.
let superView:UIView! = element as! UIView
return (superView.hidden == false)
})

...

EarlGrey().selectElementWithMatcher(grey_accessibilityLabel("label"))
.performAction(checkHiddenBlock)

```
Binary file added docs/images/image12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6cbd0f5

Please sign in to comment.